import { globalScene } from "#app/global-scene"; import { BattleStyle } from "#app/enums/battle-style"; import { BattlerTagType } from "#app/enums/battler-tag-type"; import { getPokemonNameWithAffix } from "#app/messages"; import { UiMode } from "#enums/ui-mode"; import i18next from "i18next"; import { BattlePhase } from "./battle-phase"; import { SummonMissingPhase } from "./summon-missing-phase"; import { SwitchPhase } from "./switch-phase"; import { SwitchType } from "#enums/switch-type"; export class CheckSwitchPhase extends BattlePhase { protected fieldIndex: number; protected useName: boolean; constructor(fieldIndex: number, useName: boolean) { super(); this.fieldIndex = fieldIndex; this.useName = useName; } start() { super.start(); const pokemon = globalScene.getPlayerField()[this.fieldIndex]; // End this phase early... // ...if the user is playing in Set Mode if (globalScene.battleStyle === BattleStyle.SET) { return super.end(); } // ...if the checked Pokemon is somehow not on the field if (globalScene.field.getAll().indexOf(pokemon) === -1) { globalScene.unshiftPhase(new SummonMissingPhase(this.fieldIndex)); return super.end(); } // ...if there are no other allowed Pokemon in the player's party to switch with if ( !globalScene .getPlayerParty() .slice(1) .filter(p => p.isActive()).length ) { return super.end(); } // ...or if any player Pokemon has an effect that prevents the checked Pokemon from switching if ( pokemon.getTag(BattlerTagType.FRENZY) || pokemon.isTrapped() || globalScene.getPlayerField().some(p => p.getTag(BattlerTagType.COMMANDED)) ) { return super.end(); } globalScene.ui.showText( i18next.t("battle:switchQuestion", { pokemonName: this.useName ? getPokemonNameWithAffix(pokemon) : i18next.t("battle:pokemon"), }), null, () => { globalScene.ui.setMode( UiMode.CONFIRM, () => { globalScene.ui.setMode(UiMode.MESSAGE); globalScene.unshiftPhase(new SwitchPhase(SwitchType.INITIAL_SWITCH, this.fieldIndex, false, true)); this.end(); }, () => { globalScene.ui.setMode(UiMode.MESSAGE); this.end(); }, ); }, ); } }