diff --git a/src/phases/battle-end-phase.ts b/src/phases/battle-end-phase.ts index a7158264ab7..e6a0c66548e 100644 --- a/src/phases/battle-end-phase.ts +++ b/src/phases/battle-end-phase.ts @@ -17,6 +17,23 @@ export class BattleEndPhase extends BattlePhase { start() { super.start(); + // cull any extra `BattleEnd` phases from the queue. + globalScene.phaseQueue = globalScene.phaseQueue.filter(phase => { + if (phase instanceof BattleEndPhase) { + this.isVictory ||= phase.isVictory; + return false; + } + return true; + }); + // `phaseQueuePrepend` is private, so we have to use this inefficient loop. + while (globalScene.tryRemoveUnshiftedPhase(phase => { + if (phase instanceof BattleEndPhase) { + this.isVictory ||= phase.isVictory; + return true; + } + return false; + })) {} + globalScene.gameData.gameStats.battles++; if ( globalScene.gameMode.isEndless && diff --git a/src/phases/new-battle-phase.ts b/src/phases/new-battle-phase.ts index 8cdbdc5891a..09b8ab1d335 100644 --- a/src/phases/new-battle-phase.ts +++ b/src/phases/new-battle-phase.ts @@ -5,6 +5,11 @@ export class NewBattlePhase extends BattlePhase { start() { super.start(); + // cull any extra `NewBattle` phases from the queue. + globalScene.phaseQueue = globalScene.phaseQueue.filter(phase => !(phase instanceof NewBattlePhase)); + // `phaseQueuePrepend` is private, so we have to use this inefficient loop. + while (globalScene.tryRemoveUnshiftedPhase(phase => phase instanceof NewBattlePhase)) {} + globalScene.newBattle(); this.end(); diff --git a/test/abilities/wimp_out.test.ts b/test/abilities/wimp_out.test.ts index ef201cbf8dd..294025a10e7 100644 --- a/test/abilities/wimp_out.test.ts +++ b/test/abilities/wimp_out.test.ts @@ -498,6 +498,7 @@ describe("Abilities - Wimp Out", () => { const hasFled = enemyPokemon.switchOutStatus; expect(isVisible && !hasFled).toBe(true); }); + it("wimp out will not skip battles when triggered in a double battle", async () => { const wave = 2; game.override @@ -525,4 +526,29 @@ describe("Abilities - Wimp Out", () => { await game.toNextWave(); expect(game.scene.currentBattle.waveIndex).toBe(wave + 1); }); + + it("wimp out should not skip battles when triggering the same turn as another enemy faints", async () => { + const wave = 2; + game.override + .enemySpecies(Species.WIMPOD) + .enemyAbility(Abilities.WIMP_OUT) + .startingLevel(50) + .enemyLevel(1) + .enemyMoveset([ Moves.SPLASH, Moves.ENDURE ]) + .battleType("double") + .moveset([ Moves.DRAGON_ENERGY, Moves.SPLASH ]) + .startingWave(wave); + + await game.classicMode.startBattle([ Species.REGIDRAGO, Species.MAGIKARP ]); + + // turn 1 + game.move.select(Moves.DRAGON_ENERGY, 0); + game.move.select(Moves.SPLASH, 1); + await game.forceEnemyMove(Moves.SPLASH); + await game.forceEnemyMove(Moves.ENDURE); + + await game.phaseInterceptor.to("SelectModifierPhase"); + expect(game.scene.currentBattle.waveIndex).toBe(wave + 1); + + }); });