diff --git a/src/data/abilities/ability.ts b/src/data/abilities/ability.ts index 9269f84d269..5e529a3a60a 100644 --- a/src/data/abilities/ability.ts +++ b/src/data/abilities/ability.ts @@ -55,7 +55,6 @@ import { SwitchPhase } from "#app/phases/switch-phase"; import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; import { BattleEndPhase } from "#app/phases/battle-end-phase"; import { NewBattlePhase } from "#app/phases/new-battle-phase"; -import { MoveEndPhase } from "#app/phases/move-end-phase"; import { PokemonTransformPhase } from "#app/phases/pokemon-transform-phase"; import { allAbilities } from "#app/data/data-lists"; import { AbAttr } from "#app/data/abilities/ab-attrs/ab-attr"; @@ -7243,7 +7242,7 @@ class ForceSwitchOutHelper { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); globalScene.phaseManager.prependToPhase( new SwitchPhase(this.switchType, switchOutTarget.getFieldIndex(), true, true), - MoveEndPhase, + "MoveEndPhase", ); return true; } @@ -7262,7 +7261,7 @@ class ForceSwitchOutHelper { : 0; globalScene.phaseManager.prependToPhase( new SwitchSummonPhase(this.switchType, switchOutTarget.getFieldIndex(), summonIndex, false, false), - MoveEndPhase, + "MoveEndPhase", ); return true; } diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index d0b4620d8eb..ad8511e93ff 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -29,7 +29,7 @@ import { HitResult, MoveResult } from "#app/field/pokemon"; import { getPokemonNameWithAffix } from "#app/messages"; import { CommonAnimPhase } from "#app/phases/common-anim-phase"; import type { MoveEffectPhase } from "#app/phases/move-effect-phase"; -import { MovePhase } from "#app/phases/move-phase"; +import type { MovePhase } from "#app/phases/move-phase"; import { PokemonHealPhase } from "#app/phases/pokemon-heal-phase"; import type { StatStageChangeCallback } from "#app/phases/stat-stage-change-phase"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; @@ -560,7 +560,7 @@ export class ShellTrapTag extends BattlerTag { // Only shift MovePhase timing if it's not already next up if (shellTrapPhaseIndex !== -1 && shellTrapPhaseIndex !== firstMovePhaseIndex) { const shellTrapMovePhase = globalScene.phaseManager.phaseQueue.splice(shellTrapPhaseIndex, 1)[0]; - globalScene.phaseManager.prependToPhase(shellTrapMovePhase, MovePhase); + globalScene.phaseManager.prependToPhase(shellTrapMovePhase, "MovePhase"); } this.activated = true; @@ -1194,7 +1194,7 @@ export class EncoreTag extends MoveRestrictionBattlerTag { const lastMove = pokemon.getLastXMoves(1)[0]; globalScene.phaseManager.tryReplacePhase( m => m.is("MovePhase") && m.pokemon === pokemon, - new MovePhase(pokemon, lastMove.targets ?? [], movesetMove), + globalScene.phaseManager.newPhase("MovePhase", pokemon, lastMove.targets ?? [], movesetMove), ); } } diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index d44ecbed4cf..5f28865f363 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -3125,7 +3125,7 @@ export class AwaitCombinedPledgeAttr extends OverrideMoveEffectAttr { const allyMovePhaseIndex = globalScene.phaseManager.phaseQueue.indexOf(allyMovePhase); const firstMovePhaseIndex = globalScene.phaseManager.phaseQueue.findIndex((phase) => phase.is("MovePhase")); if (allyMovePhaseIndex !== firstMovePhaseIndex) { - globalScene.phaseManager.prependToPhase(globalScene.phaseManager.phaseQueue.splice(allyMovePhaseIndex, 1)[0], MovePhase); + globalScene.phaseManager.prependToPhase(globalScene.phaseManager.phaseQueue.splice(allyMovePhaseIndex, 1)[0], "MovePhase"); } overridden.value = true; @@ -4488,7 +4488,7 @@ export class CueNextRoundAttr extends MoveEffectAttr { const nextRoundIndex = globalScene.phaseManager.phaseQueue.indexOf(nextRoundPhase); const nextMoveIndex = globalScene.phaseManager.phaseQueue.findIndex(phase => phase.is("MovePhase")); if (nextRoundIndex !== nextMoveIndex) { - globalScene.phaseManager.prependToPhase(globalScene.phaseManager.phaseQueue.splice(nextRoundIndex, 1)[0], MovePhase); + globalScene.phaseManager.prependToPhase(globalScene.phaseManager.phaseQueue.splice(nextRoundIndex, 1)[0], "MovePhase"); } // Mark the corresponding Pokemon as having "joined the Round" (for doubling power later) @@ -6263,7 +6263,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { false, true ), - MoveEndPhase + "MoveEndPhase" ); } else { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); @@ -6274,7 +6274,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { true, true ), - MoveEndPhase + "MoveEndPhase" ); return true; } @@ -6306,7 +6306,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { false, false ), - MoveEndPhase + "MoveEndPhase" ); } else { switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH); @@ -6318,7 +6318,7 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { false, false ), - MoveEndPhase + "MoveEndPhase" ); } } @@ -7050,7 +7050,7 @@ export class RepeatMoveAttr extends MoveEffectAttr { })); target.getMoveQueue().unshift({ move: lastMove.move, targets: moveTargets, ignorePP: false }); target.turnData.extraTurns++; - globalScene.phaseManager.appendToPhase(new MovePhase(target, moveTargets, movesetMove), MoveEndPhase); + globalScene.phaseManager.appendToPhase(new MovePhase(target, moveTargets, movesetMove), "MoveEndPhase"); return true; } @@ -7852,7 +7852,7 @@ export class AfterYouAttr extends MoveEffectAttr { //Will find next acting phase of the targeted pokémon, delete it and queue it next on successful delete. const nextAttackPhase = globalScene.phaseManager.findPhase((phase) => phase.pokemon === target); if (nextAttackPhase && globalScene.phaseManager.tryRemovePhase((phase: MovePhase) => phase.pokemon === target)) { - globalScene.phaseManager.prependToPhase(new MovePhase(target, [ ...nextAttackPhase.targets ], nextAttackPhase.move), MovePhase); + globalScene.phaseManager.prependToPhase(new MovePhase(target, [ ...nextAttackPhase.targets ], nextAttackPhase.move), "MovePhase"); } return true; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 5b38419e708..0a65ddcd3c5 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -233,7 +233,6 @@ import { getPokemonNameWithAffix } from "#app/messages"; import { DamageAnimPhase } from "#app/phases/damage-anim-phase"; import { FaintPhase } from "#app/phases/faint-phase"; import { LearnMovePhase } from "#app/phases/learn-move-phase"; -import { MoveEndPhase } from "#app/phases/move-end-phase"; import { ObtainStatusEffectPhase } from "#app/phases/obtain-status-effect-phase"; import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase"; import { SwitchSummonPhase } from "#app/phases/switch-summon-phase"; @@ -5637,7 +5636,7 @@ export class PlayerPokemon extends Pokemon { if (slotIndex >= globalScene.currentBattle.getBattlerCount() && slotIndex < 6) { globalScene.phaseManager.prependToPhase( new SwitchSummonPhase(switchType, this.getFieldIndex(), slotIndex, false), - MoveEndPhase, + "MoveEndPhase", ); } globalScene.ui.setMode(UiMode.MESSAGE).then(resolve); diff --git a/src/phase-manager.ts b/src/phase-manager.ts index 5254dffdbf5..c5585af296a 100644 --- a/src/phase-manager.ts +++ b/src/phase-manager.ts @@ -1,6 +1,6 @@ import type { Phase } from "#app/phase"; import type { default as Pokemon } from "#app/field/pokemon"; -import type { Constructor } from "./utils/common"; +import type { PhaseMap, PhaseString } from "./@types/phase-types"; import { globalScene } from "#app/global-scene"; import { AddEnemyBuffModifierPhase } from "#app/phases/add-enemy-buff-modifier-phase"; import { AttemptCapturePhase } from "#app/phases/attempt-capture-phase"; @@ -95,7 +95,6 @@ import { UnavailablePhase } from "#app/phases/unavailable-phase"; import { UnlockPhase } from "#app/phases/unlock-phase"; import { VictoryPhase } from "#app/phases/victory-phase"; import { WeatherEffectPhase } from "#app/phases/weather-effect-phase"; -import type { PhaseString } from "./@types/phase-types"; /** * Manager for phases used by battle scene. @@ -111,7 +110,7 @@ import type { PhaseString } from "./@types/phase-types"; * The keys of this object are the names of the phases, and the values are the constructors of the phases. * This allows for easy creation of new phases without needing to import each phase individually. */ -const Phases = Object.freeze({ +const PHASES = Object.freeze({ AddEnemyBuffModifierPhase, AttemptCapturePhase, AttemptRunPhase, @@ -207,7 +206,7 @@ const Phases = Object.freeze({ // This type export cannot be moved to `@types`, as `Phases` is intentionally private to this file /** Maps Phase strings to their constructors */ -export type PhaseConstructorMap = typeof Phases; +export type PhaseConstructorMap = typeof PHASES; /** * PhaseManager is responsible for managing the phases in the battle scene @@ -412,15 +411,16 @@ export class PhaseManager { /** * Tries to add the input phase to index before target phase in the phaseQueue, else simply calls unshiftPhase() - * @param phase {@linkcode Phase} the phase to be added - * @param targetPhase {@linkcode Phase} the type of phase to search for in phaseQueue + * @param phase - The phase to be added + * @param targetPhase - The phase to search for in phaseQueue * @returns boolean if a targetPhase was found and added */ - prependToPhase(phase: Phase | Phase[], targetPhase: Constructor): boolean { + prependToPhase(phase: Phase | Phase[], targetPhase: PhaseString): boolean { if (!Array.isArray(phase)) { phase = [phase]; } - const targetIndex = this.phaseQueue.findIndex(ph => ph instanceof targetPhase); + const target = PHASES[targetPhase]; + const targetIndex = this.phaseQueue.findIndex(ph => ph instanceof target); if (targetIndex !== -1) { this.phaseQueue.splice(targetIndex, 0, ...phase); @@ -433,14 +433,15 @@ export class PhaseManager { /** * Attempt to add the input phase(s) to index after target phase in the {@linkcode phaseQueue}, else simply calls {@linkcode unshiftPhase()} * @param phase - The phase(s) to be added - * @param targetPhase - The type of phase to search for in {@linkcode phaseQueue} + * @param targetPhase - The phase to search for in phaseQueue * @returns `true` if a `targetPhase` was found to append to */ - appendToPhase(phase: Phase | Phase[], targetPhase: Constructor): boolean { + appendToPhase(phase: Phase | Phase[], targetPhase: PhaseString): boolean { if (!Array.isArray(phase)) { phase = [phase]; } - const targetIndex = this.phaseQueue.findIndex(ph => ph instanceof targetPhase); + const target = PHASES[targetPhase]; + const targetIndex = this.phaseQueue.findIndex(ph => ph instanceof target); if (targetIndex !== -1 && this.phaseQueue.length > targetIndex) { this.phaseQueue.splice(targetIndex + 1, 0, ...phase); @@ -520,8 +521,8 @@ export class PhaseManager { public newPhase( phase: T, ...args: ConstructorParameters - ): InstanceType<(typeof Phases)[T]> { - const PhaseClass = Phases[phase]; + ): PhaseMap[T] { + const PhaseClass = PHASES[phase]; if (!PhaseClass) { throw new Error(`Phase ${phase} does not exist in PhaseMap.`); diff --git a/src/phases/move-effect-phase.ts b/src/phases/move-effect-phase.ts index e135f5bd161..ac2bb67e8b9 100644 --- a/src/phases/move-effect-phase.ts +++ b/src/phases/move-effect-phase.ts @@ -70,7 +70,6 @@ import i18next from "i18next"; import type { Phase } from "#app/phase"; import { ShowAbilityPhase } from "./show-ability-phase"; import { MovePhase } from "./move-phase"; -import { MoveEndPhase } from "./move-end-phase"; import { HideAbilityPhase } from "#app/phases/hide-ability-phase"; import type { TypeDamageMultiplier } from "#app/data/type"; import { HitCheckResult } from "#enums/hit-check-result"; @@ -384,7 +383,7 @@ export class MoveEffectPhase extends PokemonPhase { } if (this.queuedPhases.length) { - globalScene.phaseManager.appendToPhase(this.queuedPhases, MoveEndPhase); + globalScene.phaseManager.appendToPhase(this.queuedPhases, "MoveEndPhase"); } const moveType = user.getMoveType(this.move, true); if (this.move.category !== MoveCategory.STATUS && !user.stellarTypesBoosted.includes(moveType)) {