diff --git a/js/client-battle.js b/js/client-battle.js index c60df1d62..ae17e1054 100644 --- a/js/client-battle.js +++ b/js/client-battle.js @@ -1029,8 +1029,8 @@ updateSideLocation: function (sideData) { if (!sideData.id) return; this.side = sideData.id; - if (this.battle.sidesSwitched !== !!(this.side === 'p2' || this.side === 'p4')) { - this.battle.switchSides(); + if (this.battle.mySide.id !== this.side) { + this.battle.setPerspective(this.side); this.$chat = this.$chatFrame.find('.inner'); } }, diff --git a/src/battle-animations.ts b/src/battle-animations.ts index b63455887..7e98b3670 100644 --- a/src/battle-animations.ts +++ b/src/battle-animations.ts @@ -208,7 +208,7 @@ class BattleScene { this.curTerrain = ''; this.curWeather = ''; - this.log.battleParser!.perspective = this.battle.mySide!.sideid; + this.log.battleParser!.perspective = this.battle.mySide.sideid; this.resetSides(true); } diff --git a/src/battle.ts b/src/battle.ts index 9befe4ac1..c23954826 100644 --- a/src/battle.ts +++ b/src/battle.ts @@ -1023,7 +1023,12 @@ class Battle { pseudoWeather = [] as WeatherState[]; weatherTimeLeft = 0; weatherMinTimeLeft = 0; - mySide: Side | null = null; + /** + * The side from which perspective we're viewing. Should be identical to + * `nearSide` except in multi battles, where `nearSide` is always the first + * near side, and `mySide` is the active player. + */ + mySide: Side = null!; nearSide: Side = null!; farSide: Side = null!; p1: Side = null!; @@ -1190,24 +1195,30 @@ class Battle { this.seekTurn(this.ended ? Infinity : this.turn, true); } switchSides() { - this.setSidesSwitched(!this.sidesSwitched); - this.resetToCurrentTurn(); + this.setPerspective(this.sidesSwitched ? 'p1' : 'p2'); } - setSidesSwitched(sidesSwitched: boolean) { - this.sidesSwitched = sidesSwitched; - if (this.sidesSwitched) { - this.nearSide = this.p2; - this.farSide = this.p1; - } else { + setPerspective(sideid: SideID) { + if (this.mySide.id === sideid) return; + const side = this[sideid]; + if (!side) return; + this.mySide = side; + + if (side === this.p1 || side.ally === this.p1) { + this.sidesSwitched = false; this.nearSide = this.p1; this.farSide = this.p2; + } else { + this.sidesSwitched = true; + this.nearSide = this.p2; + this.farSide = this.p1; } + this.nearSide.isFar = false; if (this.nearSide.ally) this.nearSide.ally.isFar = false; this.farSide.isFar = true; if (this.farSide.ally) this.farSide.ally.isFar = true; - // nothing else should need updating - don't call this function after sending out pokemon + this.resetToCurrentTurn(); } // diff --git a/src/panel-battle.tsx b/src/panel-battle.tsx index b0538a4a1..a7bc99d11 100644 --- a/src/panel-battle.tsx +++ b/src/panel-battle.tsx @@ -304,9 +304,7 @@ class BattlePanel extends PSRoomPanel { if (request.side) { room.battle.myPokemon = request.side.pokemon; - if (room.battle.sidesSwitched !== !!(request.side.id === 'p2')) { - room.battle.switchSides(); - } + room.battle.setPerspective(request.side.id); room.side = request.side; }