From 5111c916a86a7e2f34f70852dc290d2d27319bbf Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:38:06 -0700 Subject: [PATCH] [Bug] Make on-summon abilities trigger after the switch check (#3118) * Make on-summon abilities trigger after the switch check * Add test --- src/battle-scene.ts | 4 +- src/test/abilities/ability_timing.test.ts | 53 +++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/test/abilities/ability_timing.test.ts diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 961abe1eea5..19f8dad862e 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -2056,8 +2056,8 @@ export default class BattleScene extends SceneBase { const conditionalPhase = this.conditionalQueue.shift(); // Evaluate the condition associated with the phase if (conditionalPhase[0]()) { - // If the condition is met, add the phase to the front of the phase queue - this.unshiftPhase(conditionalPhase[1]); + // If the condition is met, add the phase to the phase queue + this.pushPhase(conditionalPhase[1]); } else { // If the condition is not met, re-add the phase back to the front of the conditional queue this.conditionalQueue.unshift(conditionalPhase); diff --git a/src/test/abilities/ability_timing.test.ts b/src/test/abilities/ability_timing.test.ts new file mode 100644 index 00000000000..84d4390652e --- /dev/null +++ b/src/test/abilities/ability_timing.test.ts @@ -0,0 +1,53 @@ +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import Phaser from "phaser"; +import GameManager from "#app/test/utils/gameManager"; +import Overrides from "#app/overrides"; +import { CommandPhase, MessagePhase, TurnInitPhase } from "#app/phases"; +import { Mode } from "#app/ui/ui"; +import { Abilities } from "#enums/abilities"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import i18next, { initI18n } from "#app/plugins/i18n"; + + +describe("Ability Timing", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + vi.spyOn(Overrides, "BATTLE_TYPE_OVERRIDE", "get").mockReturnValue("single"); + + vi.spyOn(Overrides, "OPP_SPECIES_OVERRIDE", "get").mockReturnValue(Species.PIDGEY); + vi.spyOn(Overrides, "OPP_ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.INTIMIDATE); + vi.spyOn(Overrides, "OPP_MOVESET_OVERRIDE", "get").mockReturnValue(Array(4).fill(Moves.SPLASH)); + + vi.spyOn(Overrides, "ABILITY_OVERRIDE", "get").mockReturnValue(Abilities.BALL_FETCH); + vi.spyOn(Overrides, "MOVESET_OVERRIDE", "get").mockReturnValue([Moves.SPLASH, Moves.ICE_BEAM]); + }); + + it("should trigger after switch check", async() => { + initI18n(); + i18next.changeLanguage("en"); + await game.runToSummon([Species.EEVEE, Species.FEEBAS]); + + game.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { + game.setMode(Mode.MESSAGE); + game.endPhase(); + }, () => game.isCurrentPhase(CommandPhase) || game.isCurrentPhase(TurnInitPhase)); + + await game.phaseInterceptor.to(MessagePhase); + const message = game.textInterceptor.getLatestMessage(); + expect(message).toContain("Attack fell"); + }, 5000); +});