From 0128d673b5d167dbf04b21cc11faed0f88db7877 Mon Sep 17 00:00:00 2001 From: Dean Date: Sun, 15 Jun 2025 23:05:31 -0700 Subject: [PATCH] Add move header queue to fix ordering --- src/@types/phase-types.ts | 2 +- src/field/pokemon.ts | 1 - src/phases/move-header-phase.ts | 16 +++++++--------- src/phases/turn-start-phase.ts | 5 +---- src/queues/dynamic-queue-manager.ts | 3 +++ 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/@types/phase-types.ts b/src/@types/phase-types.ts index dab8bfeea12..9abc3dadf8d 100644 --- a/src/@types/phase-types.ts +++ b/src/@types/phase-types.ts @@ -24,6 +24,6 @@ export type PhaseClass = PhaseConstructorMap[keyof PhaseConstructorMap]; */ export type PhaseString = keyof PhaseMap; -export type DynamicPhaseString = "PostSummonPhase" | "SwitchSummonPhase" | "MovePhase"; +export type DynamicPhaseString = "PostSummonPhase" | "SwitchSummonPhase" | "MovePhase" | "MoveHeaderPhase"; export type StaticPhaseString = Exclude; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index f12b2d44fb7..67b04b6b49e 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -6883,7 +6883,6 @@ export class PokemonTurnData { public singleHitDamageDealt = 0; public damageTaken = 0; public attacksReceived: AttackMoveResult[] = []; - public order: number; public statStagesIncreased = false; public statStagesDecreased = false; public moveEffectiveness: TypeDamageMultiplier | null = null; diff --git a/src/phases/move-header-phase.ts b/src/phases/move-header-phase.ts index 8c2d184c3f5..a5bf6083898 100644 --- a/src/phases/move-header-phase.ts +++ b/src/phases/move-header-phase.ts @@ -1,29 +1,27 @@ import { applyMoveAttrs } from "#app/data/moves/apply-attrs"; import type { PokemonMove } from "#app/data/moves/pokemon-move"; -import type Pokemon from "#app/field/pokemon"; -import { BattlePhase } from "./battle-phase"; +import { PokemonPhase } from "#app/phases/pokemon-phase"; +import type { BattlerIndex } from "#enums/battler-index"; -export class MoveHeaderPhase extends BattlePhase { +export class MoveHeaderPhase extends PokemonPhase { public readonly phaseName = "MoveHeaderPhase"; - public pokemon: Pokemon; public move: PokemonMove; - constructor(pokemon: Pokemon, move: PokemonMove) { - super(); + constructor(battlerIndex: BattlerIndex, move: PokemonMove) { + super(battlerIndex); - this.pokemon = pokemon; this.move = move; } canMove(): boolean { - return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon); + return this.getPokemon().isActive(true) && this.move.isUsable(this.getPokemon()); } start() { super.start(); if (this.canMove()) { - applyMoveAttrs("MoveHeaderAttr", this.pokemon, null, this.move.getMove()); + applyMoveAttrs("MoveHeaderAttr", this.getPokemon(), null, this.move.getMove()); } this.end(); } diff --git a/src/phases/turn-start-phase.ts b/src/phases/turn-start-phase.ts index c9a9b2a57a4..b1070243c4e 100644 --- a/src/phases/turn-start-phase.ts +++ b/src/phases/turn-start-phase.ts @@ -58,8 +58,6 @@ export class TurnStartPhase extends FieldPhase { const activeField = globalScene.getField(true); const moveOrder = this.getCommandOrder(); - let orderIndex = 0; - applyInSpeedOrder(activeField, (p: Pokemon) => { const preTurnCommand = globalScene.currentBattle.preTurnCommands[p.getBattlerIndex()]; @@ -91,7 +89,6 @@ export class TurnStartPhase extends FieldPhase { case Command.FIGHT: { const queuedMove = turnCommand.move; - pokemon.turnData.order = orderIndex++; if (!queuedMove) { continue; } @@ -99,7 +96,7 @@ export class TurnStartPhase extends FieldPhase { pokemon.getMoveset().find(m => m.moveId === queuedMove.move && m.ppUsed < m.getMovePp()) || new PokemonMove(queuedMove.move); if (move.getMove().hasAttr("MoveHeaderAttr")) { - phaseManager.unshiftNew("MoveHeaderPhase", pokemon, move); + phaseManager.pushNew("MoveHeaderPhase", pokemon.getBattlerIndex(), move); } if (pokemon.isPlayer()) { if (turnCommand.cursor === -1) { diff --git a/src/queues/dynamic-queue-manager.ts b/src/queues/dynamic-queue-manager.ts index c2e5d52ca01..14c45f2b6c6 100644 --- a/src/queues/dynamic-queue-manager.ts +++ b/src/queues/dynamic-queue-manager.ts @@ -3,8 +3,10 @@ import type { DynamicPhaseString, PhaseString } from "#app/@types/phase-types"; import type { PokemonMove } from "#app/data/moves/pokemon-move"; import type Pokemon from "#app/field/pokemon"; import type { Phase } from "#app/phase"; +import type { MoveHeaderPhase } from "#app/phases/move-header-phase"; import { MovePhasePriorityQueue } from "#app/queues/move-phase-priority-queue"; import type { PhasePriorityQueue } from "#app/queues/phase-priority-queue"; +import { PokemonPhasePriorityQueue } from "#app/queues/pokemon-phase-priority-queue"; import { PostSummonPhasePriorityQueue } from "#app/queues/post-summon-phase-priority-queue"; import { SwitchSummonPhasePriorityQueue } from "#app/queues/switch-summon-phase-priority-queue"; import type { BattlerIndex } from "#enums/battler-index"; @@ -16,6 +18,7 @@ export class DynamicQueueManager { constructor() { this.dynamicPhaseMap = new Map(); this.dynamicPhaseMap.set("SwitchSummonPhase", new SwitchSummonPhasePriorityQueue()); + this.dynamicPhaseMap.set("MoveHeaderPhase", new PokemonPhasePriorityQueue()); this.dynamicPhaseMap.set("PostSummonPhase", new PostSummonPhasePriorityQueue()); this.dynamicPhaseMap.set("MovePhase", new MovePhasePriorityQueue()); }