From b71ddda1916257b83557cb5c9ec705eab104b30c Mon Sep 17 00:00:00 2001 From: RedstonewolfX <108761527+RedstonewolfX@users.noreply.github.com> Date: Tue, 27 Aug 2024 18:52:07 -0400 Subject: [PATCH] (Temporary) Implement startBattle fix --- src/test/daily_mode.test.ts | 6 ++--- src/test/utils/gameManager.ts | 21 +++++++++------ src/test/utils/helpers/classicModeHelper.ts | 27 +++++++++++++++++++ src/test/utils/helpers/dailyModeHelper.ts | 29 ++++++++++++++++++++- 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/test/daily_mode.test.ts b/src/test/daily_mode.test.ts index f0a1dc5cfe0..5947e010cbb 100644 --- a/src/test/daily_mode.test.ts +++ b/src/test/daily_mode.test.ts @@ -50,8 +50,7 @@ describe("Daily Mode", () => { game.phaseInterceptor.restoreOg(); }); it("should only allow Mini Black Hole and Eviolite outside of Daily if unlocked", async () => { - await game.classicMode.runToSummon(); - await game.startBattle(); + await game.classicMode.startBattle(); game.move.select(Moves.SURF); await game.phaseInterceptor.to(SelectModifierPhase, false); @@ -59,8 +58,7 @@ describe("Daily Mode", () => { expect(poolHasBlackHole).toBeFalsy(); }); it("should allow Eviolite and Mini Black Hole in shop when in Daily Run", async () => { - await game.dailyMode.runToSummon(); - await game.startBattle(); + await game.dailyMode.startBattle(); game.move.select(Moves.SURF); await game.phaseInterceptor.to(SelectModifierPhase, false); diff --git a/src/test/utils/gameManager.ts b/src/test/utils/gameManager.ts index cb3c547744b..d3c2652fcbe 100644 --- a/src/test/utils/gameManager.ts +++ b/src/test/utils/gameManager.ts @@ -1,6 +1,7 @@ import { updateUserInfo } from "#app/account"; import { BattlerIndex } from "#app/battle"; import BattleScene from "#app/battle-scene"; +import { BattleStyle } from "#app/enums/battle-style"; import { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; import Trainer from "#app/field/trainer"; import { GameModes, getGameMode } from "#app/game-mode"; @@ -170,6 +171,8 @@ export default class GameManager { } /** + * @deprecated Use `game.classicMode.startBattle()` or `game.dailyMode.startBattle()` instead + * * Transitions to the start of a battle. * @param species - Optional array of species to start the battle with. * @returns A promise that resolves when the battle is started. @@ -177,15 +180,17 @@ export default class GameManager { async startBattle(species?: Species[]) { await this.classicMode.runToSummon(species); - this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { - this.setMode(Mode.MESSAGE); - this.endPhase(); - }, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnInitPhase)); + if (this.scene.battleStyle === BattleStyle.SWITCH) { + this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { + this.setMode(Mode.MESSAGE); + this.endPhase(); + }, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnInitPhase)); - this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { - this.setMode(Mode.MESSAGE); - this.endPhase(); - }, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnInitPhase)); + this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { + this.setMode(Mode.MESSAGE); + this.endPhase(); + }, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnInitPhase)); + } await this.phaseInterceptor.to(CommandPhase); console.log("==================[New Turn]=================="); diff --git a/src/test/utils/helpers/classicModeHelper.ts b/src/test/utils/helpers/classicModeHelper.ts index f41472303b4..55e995fc9dc 100644 --- a/src/test/utils/helpers/classicModeHelper.ts +++ b/src/test/utils/helpers/classicModeHelper.ts @@ -1,8 +1,11 @@ +import { BattleStyle } from "#app/enums/battle-style"; import { Species } from "#app/enums/species"; import { GameModes, getGameMode } from "#app/game-mode"; import overrides from "#app/overrides"; +import { CommandPhase } from "#app/phases/command-phase"; import { EncounterPhase } from "#app/phases/encounter-phase"; import { SelectStarterPhase } from "#app/phases/select-starter-phase"; +import { TurnInitPhase } from "#app/phases/turn-init-phase"; import { Mode } from "#app/ui/ui"; import { generateStarter } from "../gameManagerUtils"; import { GameManagerHelper } from "./gameManagerHelper"; @@ -33,4 +36,28 @@ export class ClassicModeHelper extends GameManagerHelper { this.game.removeEnemyHeldItems(); } } + + /** + * Transitions to the start of a battle. + * @param species - Optional array of species to start the battle with. + * @returns A promise that resolves when the battle is started. + */ + async startBattle(species?: Species[]) { + await this.runToSummon(species); + + if (this.game.scene.battleStyle === BattleStyle.SWITCH) { + this.game.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { + this.game.setMode(Mode.MESSAGE); + this.game.endPhase(); + }, () => this.game.isCurrentPhase(CommandPhase) || this.game.isCurrentPhase(TurnInitPhase)); + + this.game.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { + this.game.setMode(Mode.MESSAGE); + this.game.endPhase(); + }, () => this.game.isCurrentPhase(CommandPhase) || this.game.isCurrentPhase(TurnInitPhase)); + } + + await this.game.phaseInterceptor.to(CommandPhase); + console.log("==================[New Turn]=================="); + } } diff --git a/src/test/utils/helpers/dailyModeHelper.ts b/src/test/utils/helpers/dailyModeHelper.ts index 8f60981f4d8..c535533c9e7 100644 --- a/src/test/utils/helpers/dailyModeHelper.ts +++ b/src/test/utils/helpers/dailyModeHelper.ts @@ -1,7 +1,11 @@ + +import { BattleStyle } from "#app/enums/battle-style"; import { Button } from "#app/enums/buttons"; import overrides from "#app/overrides"; +import { CommandPhase } from "#app/phases/command-phase"; import { EncounterPhase } from "#app/phases/encounter-phase"; import { TitlePhase } from "#app/phases/title-phase"; +import { TurnInitPhase } from "#app/phases/turn-init-phase"; import SaveSlotSelectUiHandler from "#app/ui/save-slot-select-ui-handler"; import { Mode } from "#app/ui/ui"; import { GameManagerHelper } from "./gameManagerHelper"; @@ -28,10 +32,33 @@ export class DailyModeHelper extends GameManagerHelper { uihandler.processInput(Button.ACTION); // select first slot. that's fine }); - await this.game.phaseInterceptor.run(EncounterPhase); + await this.game.phaseInterceptor.to(EncounterPhase); if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) { this.game.removeEnemyHeldItems(); } } + + /** + * Transitions to the start of a battle. + * @returns A promise that resolves when the battle is started. + */ + async startBattle() { + await this.runToSummon(); + + if (this.game.scene.battleStyle === BattleStyle.SWITCH) { + this.game.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { + this.game.setMode(Mode.MESSAGE); + this.game.endPhase(); + }, () => this.game.isCurrentPhase(CommandPhase) || this.game.isCurrentPhase(TurnInitPhase)); + + this.game.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { + this.game.setMode(Mode.MESSAGE); + this.game.endPhase(); + }, () => this.game.isCurrentPhase(CommandPhase) || this.game.isCurrentPhase(TurnInitPhase)); + } + + await this.game.phaseInterceptor.to(CommandPhase); + console.log("==================[New Turn]=================="); + } }