Create the appropriate startBattle() functions in the helper classes (#3855)

This commit is contained in:
NightKev 2024-08-27 17:47:09 -07:00 committed by GitHub
parent 214a9275a9
commit 4124ad0b93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 66 additions and 8 deletions

View File

@ -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,6 +180,7 @@ export default class GameManager {
async startBattle(species?: Species[]) {
await this.classicMode.runToSummon(species);
if (this.scene.battleStyle === BattleStyle.SWITCH) {
this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => {
this.setMode(Mode.MESSAGE);
this.endPhase();
@ -186,6 +190,7 @@ export default class GameManager {
this.setMode(Mode.MESSAGE);
this.endPhase();
}, () => this.isCurrentPhase(CommandPhase) || this.isCurrentPhase(TurnInitPhase));
}
await this.phaseInterceptor.to(CommandPhase);
console.log("==================[New Turn]==================");

View File

@ -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]==================");
}
}

View File

@ -1,7 +1,10 @@
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";
@ -34,4 +37,27 @@ export class DailyModeHelper extends GameManagerHelper {
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]==================");
}
}