diff --git a/src/data/abilities/ability.ts b/src/data/abilities/ability.ts index faa9a8afafe..621dd011650 100644 --- a/src/data/abilities/ability.ts +++ b/src/data/abilities/ability.ts @@ -7451,7 +7451,7 @@ class ForceSwitchOutHelper { : 0; globalScene.phaseManager.prependNewToPhase( "MoveEndPhase", - "SwitchSummonPhase", + "StaticSwitchSummonPhase", this.switchType, switchOutTarget.getFieldIndex(), summonIndex, diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index a55e8c94803..79656c7fc40 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -6192,13 +6192,15 @@ export class RevivalBlessingAttr extends MoveEffectAttr { if (globalScene.currentBattle.double && globalScene.getEnemyParty().length > 1 && !isNullOrUndefined(allyPokemon)) { // Handle cases where revived pokemon needs to get switched in on same turn if (allyPokemon.isFainted() || allyPokemon === pokemon) { + // Enemy switch phase should be removed and replaced with the revived pkmn switching in + globalScene.phaseManager.tryRemovePhase((phase: SwitchSummonPhase) => phase.is("StaticSwitchSummonPhase") && phase.getPokemon() === pokemon); // If the pokemon being revived was alive earlier in the turn, cancel its move // (revived pokemon can't move in the turn they're brought back) globalScene.phaseManager.findPhase("MovePhase", (phase: MovePhase) => phase.pokemon === pokemon)?.cancel(); if (user.fieldPosition === FieldPosition.CENTER) { user.setFieldPosition(FieldPosition.LEFT); } - globalScene.phaseManager.pushNew("SwitchSummonPhase", SwitchType.SWITCH, allyPokemon.getFieldIndex(), slotIndex, false, false); + globalScene.phaseManager.unshiftNew("StaticSwitchSummonPhase", SwitchType.SWITCH, allyPokemon.getFieldIndex(), slotIndex, false, false); } } return true; @@ -6278,7 +6280,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { const slotIndex = eligibleNewIndices[user.randBattleSeedInt(eligibleNewIndices.length)]; globalScene.phaseManager.prependNewToPhase( "MoveEndPhase", - "SwitchSummonPhase", + "StaticSwitchSummonPhase", this.switchType, switchOutTarget.getFieldIndex(), slotIndex, @@ -6317,7 +6319,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { switchOutTarget.leaveField(true); const slotIndex = eligibleNewIndices[user.randBattleSeedInt(eligibleNewIndices.length)]; globalScene.phaseManager.prependNewToPhase("MoveEndPhase", - "SwitchSummonPhase", + "StaticSwitchSummonPhase", this.switchType, switchOutTarget.getFieldIndex(), slotIndex, @@ -6327,7 +6329,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { } else { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); globalScene.phaseManager.prependNewToPhase("MoveEndPhase", - "SwitchSummonPhase", + "StaticSwitchSummonPhase", this.switchType, switchOutTarget.getFieldIndex(), (globalScene.currentBattle.trainer ? globalScene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot) : 0), diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 67b04b6b49e..c393c809742 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -5598,7 +5598,7 @@ export class PlayerPokemon extends Pokemon { if (slotIndex >= globalScene.currentBattle.getBattlerCount() && slotIndex < 6) { globalScene.phaseManager.prependNewToPhase( "MoveEndPhase", - "SwitchSummonPhase", + "StaticSwitchSummonPhase", switchType, this.getFieldIndex(), slotIndex, diff --git a/src/phase-manager.ts b/src/phase-manager.ts index cd67f144496..f0a138a02f5 100644 --- a/src/phase-manager.ts +++ b/src/phase-manager.ts @@ -99,6 +99,7 @@ import { DynamicQueueManager } from "#app/queues/dynamic-queue-manager"; import type { PhaseConditionFunc } from "#app/@types/phase-condition"; import { MovePhaseTimingModifier } from "#enums/move-phase-timing-modifier"; import type { PokemonMove } from "#app/data/moves/pokemon-move"; +import { StaticSwitchSummonPhase } from "#app/phases/static-switch-summon-phase"; /** * Manager for phases used by battle scene. @@ -189,6 +190,7 @@ const PHASES = Object.freeze({ ShowAbilityPhase, ShowPartyExpBarPhase, ShowTrainerPhase, + StaticSwitchSummonPhase, StatStageChangePhase, SummonMissingPhase, SummonPhase, diff --git a/src/phases/faint-phase.ts b/src/phases/faint-phase.ts index 675a198d096..9e28829b27b 100644 --- a/src/phases/faint-phase.ts +++ b/src/phases/faint-phase.ts @@ -183,7 +183,14 @@ export class FaintPhase extends PokemonPhase { .filter(p => p.isActive() && !p.isOnField() && p.trainerSlot === (pokemon as EnemyPokemon).trainerSlot) .length; if (hasReservePartyMember) { - globalScene.phaseManager.pushNew("SwitchSummonPhase", SwitchType.SWITCH, this.fieldIndex, -1, false, false); + globalScene.phaseManager.pushNew( + "StaticSwitchSummonPhase", + SwitchType.SWITCH, + this.fieldIndex, + -1, + false, + false, + ); } } } diff --git a/src/phases/revival-blessing-phase.ts b/src/phases/revival-blessing-phase.ts index e3e69f7ef25..fcbc276ea71 100644 --- a/src/phases/revival-blessing-phase.ts +++ b/src/phases/revival-blessing-phase.ts @@ -50,7 +50,7 @@ export class RevivalBlessingPhase extends BattlePhase { if (slotIndex <= 1) { // Revived ally pokemon globalScene.phaseManager.unshiftNew( - "SwitchSummonPhase", + "StaticSwitchSummonPhase", SwitchType.SWITCH, pokemon.getFieldIndex(), slotIndex, @@ -61,7 +61,7 @@ export class RevivalBlessingPhase extends BattlePhase { } else if (allyPokemon.isFainted()) { // Revived party pokemon, and ally pokemon is fainted globalScene.phaseManager.unshiftNew( - "SwitchSummonPhase", + "StaticSwitchSummonPhase", SwitchType.SWITCH, allyPokemon.getFieldIndex(), slotIndex, diff --git a/src/phases/static-switch-summon-phase.ts b/src/phases/static-switch-summon-phase.ts new file mode 100644 index 00000000000..5fe8ef17bd0 --- /dev/null +++ b/src/phases/static-switch-summon-phase.ts @@ -0,0 +1,5 @@ +import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; + +export class StaticSwitchSummonPhase extends SwitchSummonPhase { + public readonly phaseName = "StaticSwitchSummonPhase"; +} diff --git a/src/phases/summon-phase.ts b/src/phases/summon-phase.ts index 8ed33e12870..2c95e7a273f 100644 --- a/src/phases/summon-phase.ts +++ b/src/phases/summon-phase.ts @@ -15,7 +15,12 @@ import { globalScene } from "#app/global-scene"; export class SummonPhase extends PartyMemberPokemonPhase { // The union type is needed to keep typescript happy as these phases extend from SummonPhase - public readonly phaseName: "SummonPhase" | "SummonMissingPhase" | "SwitchSummonPhase" | "ReturnPhase" = "SummonPhase"; + public readonly phaseName: + | "SummonPhase" + | "SummonMissingPhase" + | "SwitchSummonPhase" + | "ReturnPhase" + | "StaticSwitchSummonPhase" = "SummonPhase"; private loaded: boolean; constructor(fieldIndex: number, player = true, loaded = false) { diff --git a/src/phases/switch-phase.ts b/src/phases/switch-phase.ts index 94c4800c823..49d84909895 100644 --- a/src/phases/switch-phase.ts +++ b/src/phases/switch-phase.ts @@ -79,7 +79,13 @@ export class SwitchPhase extends BattlePhase { p => p.is("PostSummonPhase") && p.player && p.fieldIndex === this.fieldIndex, ); const switchType = option === PartyOption.PASS_BATON ? SwitchType.BATON_PASS : this.switchType; - globalScene.phaseManager.pushNew("SwitchSummonPhase", switchType, fieldIndex, slotIndex, this.doReturn); + globalScene.phaseManager.unshiftNew( + "StaticSwitchSummonPhase", + switchType, + fieldIndex, + slotIndex, + this.doReturn, + ); } globalScene.ui.setMode(UiMode.MESSAGE).then(() => super.end()); }, diff --git a/src/phases/switch-summon-phase.ts b/src/phases/switch-summon-phase.ts index 7d1403b8de9..175621918a2 100644 --- a/src/phases/switch-summon-phase.ts +++ b/src/phases/switch-summon-phase.ts @@ -14,7 +14,7 @@ import { SubstituteTag } from "#app/data/battler-tags"; import { SwitchType } from "#enums/switch-type"; export class SwitchSummonPhase extends SummonPhase { - public readonly phaseName: "SwitchSummonPhase" | "ReturnPhase" = "SwitchSummonPhase"; + public readonly phaseName: "SwitchSummonPhase" | "ReturnPhase" | "StaticSwitchSummonPhase" = "SwitchSummonPhase"; private readonly switchType: SwitchType; private readonly slotIndex: number; private readonly doReturn: boolean; diff --git a/src/queues/switch-summon-phase-priority-queue.ts b/src/queues/switch-summon-phase-priority-queue.ts index eb4ad1d7c28..adc1508c275 100644 --- a/src/queues/switch-summon-phase-priority-queue.ts +++ b/src/queues/switch-summon-phase-priority-queue.ts @@ -4,7 +4,7 @@ import { PokemonPhasePriorityQueue } from "#app/queues/pokemon-phase-priority-qu export class SwitchSummonPhasePriorityQueue extends PokemonPhasePriorityQueue { public override push(phase: SwitchSummonPhase): void { // The same pokemon or slot cannot be switched into at the same time - this.queue.filter( + this.queue = this.queue.filter( old => old.getPokemon() !== phase.getPokemon() && !(old.isPlayer() === phase.isPlayer() && old.getFieldIndex() === phase.getFieldIndex()),