Skip to content

Commit

Permalink
Fix wimp out causing battles to skip
Browse files Browse the repository at this point in the history
  • Loading branch information
SirzBenjie committed Feb 6, 2025
1 parent a99cc4f commit 8c41b1c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/phases/battle-end-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 && globalScene.currentBattle.waveIndex + 1 > globalScene.gameData.gameStats.highestEndlessWave) {
globalScene.gameData.gameStats.highestEndlessWave = globalScene.currentBattle.waveIndex + 1;
Expand Down
5 changes: 5 additions & 0 deletions src/phases/new-battle-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 26 additions & 0 deletions src/test/abilities/wimp_out.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,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
Expand Down Expand Up @@ -662,4 +663,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);

});
});

0 comments on commit 8c41b1c

Please sign in to comment.