mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-24 05:55:56 +02:00
* Extract Mode enum out of UI and into its own file Reduces circular imports from 909 to 773 * Move around utility files Reduces cyclical dependencies from 773 to 765 * Remove starterColors and bypassLogin from battle-scene Reduces cyclical dependencies from 765 to 623 * Fix test runner error * Update import for bypassLogin in test * Update mocks for utils in tests * Fix broken tests * Update selectWithTera override * Update path for utils in ab-attr.ts * Update path for utils in ability-class.ts * Fix utils import path in healer.test.ts
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
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();
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|