diff --git a/src/phases/check-switch-phase.ts b/src/phases/check-switch-phase.ts index acf17c75668..18b999ed210 100644 --- a/src/phases/check-switch-phase.ts +++ b/src/phases/check-switch-phase.ts @@ -5,7 +5,6 @@ import { getPokemonNameWithAffix } from "#app/messages"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; import { BattlePhase } from "./battle-phase"; -import { PostSummonPhase } from "./post-summon-phase"; import { SummonMissingPhase } from "./summon-missing-phase"; import { SwitchPhase } from "./switch-phase"; import { SwitchType } from "#enums/switch-type"; @@ -54,7 +53,6 @@ export class CheckSwitchPhase extends BattlePhase { this.scene.ui.showText(i18next.t("battle:switchQuestion", { pokemonName: this.useName ? getPokemonNameWithAffix(pokemon) : i18next.t("battle:pokemon") }), null, () => { this.scene.ui.setMode(Mode.CONFIRM, () => { this.scene.ui.setMode(Mode.MESSAGE); - this.scene.tryRemovePhase(p => p instanceof PostSummonPhase && p.player && p.fieldIndex === this.fieldIndex); this.scene.unshiftPhase(new SwitchPhase(this.scene, SwitchType.INITIAL_SWITCH, this.fieldIndex, false, true)); this.end(); }, () => { diff --git a/src/phases/post-summon-phase.ts b/src/phases/post-summon-phase.ts index 644a6235a42..42e5b930eb1 100644 --- a/src/phases/post-summon-phase.ts +++ b/src/phases/post-summon-phase.ts @@ -27,9 +27,12 @@ export class PostSummonPhase extends PokemonPhase { pokemon.lapseTag(BattlerTagType.MYSTERY_ENCOUNTER_POST_SUMMON); } - applyPostSummonAbAttrs(PostSummonAbAttr, pokemon).then(() => this.end()); + applyPostSummonAbAttrs(PostSummonAbAttr, pokemon) + .then(() => { + const field = pokemon.isPlayer() ? this.scene.getPlayerField() : this.scene.getEnemyField(); + field.forEach((p) => applyAbAttrs(CommanderAbAttr, p, null, false)); - const field = pokemon.isPlayer() ? this.scene.getPlayerField() : this.scene.getEnemyField(); - field.forEach((p) => applyAbAttrs(CommanderAbAttr, p, null, false)); + this.end(); + }); } } diff --git a/src/phases/switch-phase.ts b/src/phases/switch-phase.ts index 2abb109a529..481d64c451e 100644 --- a/src/phases/switch-phase.ts +++ b/src/phases/switch-phase.ts @@ -3,6 +3,7 @@ import PartyUiHandler, { PartyOption, PartyUiMode } from "#app/ui/party-ui-handl import { Mode } from "#app/ui/ui"; import { SwitchType } from "#enums/switch-type"; import { BattlePhase } from "./battle-phase"; +import { PostSummonPhase } from "./post-summon-phase"; import { SwitchSummonPhase } from "./switch-summon-phase"; /** @@ -63,6 +64,9 @@ export class SwitchPhase extends BattlePhase { this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.POST_BATTLE_SWITCH, fieldIndex, (slotIndex: integer, option: PartyOption) => { if (slotIndex >= this.scene.currentBattle.getBattlerCount() && slotIndex < 6) { + // Remove any pre-existing PostSummonPhase under the same field index. + // Pre-existing PostSummonPhases may occur when this phase is invoked during a prompt to switch at the start of a wave. + this.scene.tryRemovePhase(p => p instanceof PostSummonPhase && p.player && p.fieldIndex === this.fieldIndex); const switchType = (option === PartyOption.PASS_BATON) ? SwitchType.BATON_PASS : this.switchType; this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, switchType, fieldIndex, slotIndex, this.doReturn)); }