(Temporary) Implement startBattle fix

This commit is contained in:
RedstonewolfX 2024-08-27 18:52:07 -04:00
parent 49036f9522
commit b71ddda191
4 changed files with 70 additions and 13 deletions

View File

@ -50,8 +50,7 @@ describe("Daily Mode", () => {
game.phaseInterceptor.restoreOg(); game.phaseInterceptor.restoreOg();
}); });
it("should only allow Mini Black Hole and Eviolite outside of Daily if unlocked", async () => { it("should only allow Mini Black Hole and Eviolite outside of Daily if unlocked", async () => {
await game.classicMode.runToSummon(); await game.classicMode.startBattle();
await game.startBattle();
game.move.select(Moves.SURF); game.move.select(Moves.SURF);
await game.phaseInterceptor.to(SelectModifierPhase, false); await game.phaseInterceptor.to(SelectModifierPhase, false);
@ -59,8 +58,7 @@ describe("Daily Mode", () => {
expect(poolHasBlackHole).toBeFalsy(); expect(poolHasBlackHole).toBeFalsy();
}); });
it("should allow Eviolite and Mini Black Hole in shop when in Daily Run", async () => { it("should allow Eviolite and Mini Black Hole in shop when in Daily Run", async () => {
await game.dailyMode.runToSummon(); await game.dailyMode.startBattle();
await game.startBattle();
game.move.select(Moves.SURF); game.move.select(Moves.SURF);
await game.phaseInterceptor.to(SelectModifierPhase, false); await game.phaseInterceptor.to(SelectModifierPhase, false);

View File

@ -1,6 +1,7 @@
import { updateUserInfo } from "#app/account"; import { updateUserInfo } from "#app/account";
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import BattleScene from "#app/battle-scene"; import BattleScene from "#app/battle-scene";
import { BattleStyle } from "#app/enums/battle-style";
import { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon"; import { EnemyPokemon, PlayerPokemon } from "#app/field/pokemon";
import Trainer from "#app/field/trainer"; import Trainer from "#app/field/trainer";
import { GameModes, getGameMode } from "#app/game-mode"; 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. * Transitions to the start of a battle.
* @param species - Optional array of species to start the battle with. * @param species - Optional array of species to start the battle with.
* @returns A promise that resolves when the battle is started. * @returns A promise that resolves when the battle is started.
@ -177,6 +180,7 @@ export default class GameManager {
async startBattle(species?: Species[]) { async startBattle(species?: Species[]) {
await this.classicMode.runToSummon(species); await this.classicMode.runToSummon(species);
if (this.scene.battleStyle === BattleStyle.SWITCH) {
this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => { this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => {
this.setMode(Mode.MESSAGE); this.setMode(Mode.MESSAGE);
this.endPhase(); this.endPhase();
@ -186,6 +190,7 @@ export default class GameManager {
this.setMode(Mode.MESSAGE); this.setMode(Mode.MESSAGE);
this.endPhase(); this.endPhase();
}, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnInitPhase)); }, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnInitPhase));
}
await this.phaseInterceptor.to(CommandPhase); await this.phaseInterceptor.to(CommandPhase);
console.log("==================[New Turn]=================="); console.log("==================[New Turn]==================");

View File

@ -1,8 +1,11 @@
import { BattleStyle } from "#app/enums/battle-style";
import { Species } from "#app/enums/species"; import { Species } from "#app/enums/species";
import { GameModes, getGameMode } from "#app/game-mode"; import { GameModes, getGameMode } from "#app/game-mode";
import overrides from "#app/overrides"; import overrides from "#app/overrides";
import { CommandPhase } from "#app/phases/command-phase";
import { EncounterPhase } from "#app/phases/encounter-phase"; import { EncounterPhase } from "#app/phases/encounter-phase";
import { SelectStarterPhase } from "#app/phases/select-starter-phase"; import { SelectStarterPhase } from "#app/phases/select-starter-phase";
import { TurnInitPhase } from "#app/phases/turn-init-phase";
import { Mode } from "#app/ui/ui"; import { Mode } from "#app/ui/ui";
import { generateStarter } from "../gameManagerUtils"; import { generateStarter } from "../gameManagerUtils";
import { GameManagerHelper } from "./gameManagerHelper"; import { GameManagerHelper } from "./gameManagerHelper";
@ -33,4 +36,28 @@ export class ClassicModeHelper extends GameManagerHelper {
this.game.removeEnemyHeldItems(); 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]==================");
}
} }

View File

@ -1,7 +1,11 @@
import { BattleStyle } from "#app/enums/battle-style";
import { Button } from "#app/enums/buttons"; import { Button } from "#app/enums/buttons";
import overrides from "#app/overrides"; import overrides from "#app/overrides";
import { CommandPhase } from "#app/phases/command-phase";
import { EncounterPhase } from "#app/phases/encounter-phase"; import { EncounterPhase } from "#app/phases/encounter-phase";
import { TitlePhase } from "#app/phases/title-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 SaveSlotSelectUiHandler from "#app/ui/save-slot-select-ui-handler";
import { Mode } from "#app/ui/ui"; import { Mode } from "#app/ui/ui";
import { GameManagerHelper } from "./gameManagerHelper"; import { GameManagerHelper } from "./gameManagerHelper";
@ -28,10 +32,33 @@ export class DailyModeHelper extends GameManagerHelper {
uihandler.processInput(Button.ACTION); // select first slot. that's fine 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) { if (overrides.OPP_HELD_ITEMS_OVERRIDE.length === 0) {
this.game.removeEnemyHeldItems(); 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]==================");
}
} }