Add move header queue to fix ordering

This commit is contained in:
Dean 2025-06-15 23:05:31 -07:00
parent c790f2e84f
commit 0128d673b5
5 changed files with 12 additions and 15 deletions

View File

@ -24,6 +24,6 @@ export type PhaseClass = PhaseConstructorMap[keyof PhaseConstructorMap];
*/ */
export type PhaseString = keyof PhaseMap; export type PhaseString = keyof PhaseMap;
export type DynamicPhaseString = "PostSummonPhase" | "SwitchSummonPhase" | "MovePhase"; export type DynamicPhaseString = "PostSummonPhase" | "SwitchSummonPhase" | "MovePhase" | "MoveHeaderPhase";
export type StaticPhaseString = Exclude<PhaseString, DynamicPhaseString>; export type StaticPhaseString = Exclude<PhaseString, DynamicPhaseString>;

View File

@ -6883,7 +6883,6 @@ export class PokemonTurnData {
public singleHitDamageDealt = 0; public singleHitDamageDealt = 0;
public damageTaken = 0; public damageTaken = 0;
public attacksReceived: AttackMoveResult[] = []; public attacksReceived: AttackMoveResult[] = [];
public order: number;
public statStagesIncreased = false; public statStagesIncreased = false;
public statStagesDecreased = false; public statStagesDecreased = false;
public moveEffectiveness: TypeDamageMultiplier | null = null; public moveEffectiveness: TypeDamageMultiplier | null = null;

View File

@ -1,29 +1,27 @@
import { applyMoveAttrs } from "#app/data/moves/apply-attrs"; import { applyMoveAttrs } from "#app/data/moves/apply-attrs";
import type { PokemonMove } from "#app/data/moves/pokemon-move"; import type { PokemonMove } from "#app/data/moves/pokemon-move";
import type Pokemon from "#app/field/pokemon"; import { PokemonPhase } from "#app/phases/pokemon-phase";
import { BattlePhase } from "./battle-phase"; import type { BattlerIndex } from "#enums/battler-index";
export class MoveHeaderPhase extends BattlePhase { export class MoveHeaderPhase extends PokemonPhase {
public readonly phaseName = "MoveHeaderPhase"; public readonly phaseName = "MoveHeaderPhase";
public pokemon: Pokemon;
public move: PokemonMove; public move: PokemonMove;
constructor(pokemon: Pokemon, move: PokemonMove) { constructor(battlerIndex: BattlerIndex, move: PokemonMove) {
super(); super(battlerIndex);
this.pokemon = pokemon;
this.move = move; this.move = move;
} }
canMove(): boolean { canMove(): boolean {
return this.pokemon.isActive(true) && this.move.isUsable(this.pokemon); return this.getPokemon().isActive(true) && this.move.isUsable(this.getPokemon());
} }
start() { start() {
super.start(); super.start();
if (this.canMove()) { if (this.canMove()) {
applyMoveAttrs("MoveHeaderAttr", this.pokemon, null, this.move.getMove()); applyMoveAttrs("MoveHeaderAttr", this.getPokemon(), null, this.move.getMove());
} }
this.end(); this.end();
} }

View File

@ -58,8 +58,6 @@ export class TurnStartPhase extends FieldPhase {
const activeField = globalScene.getField(true); const activeField = globalScene.getField(true);
const moveOrder = this.getCommandOrder(); const moveOrder = this.getCommandOrder();
let orderIndex = 0;
applyInSpeedOrder(activeField, (p: Pokemon) => { applyInSpeedOrder(activeField, (p: Pokemon) => {
const preTurnCommand = globalScene.currentBattle.preTurnCommands[p.getBattlerIndex()]; const preTurnCommand = globalScene.currentBattle.preTurnCommands[p.getBattlerIndex()];
@ -91,7 +89,6 @@ export class TurnStartPhase extends FieldPhase {
case Command.FIGHT: case Command.FIGHT:
{ {
const queuedMove = turnCommand.move; const queuedMove = turnCommand.move;
pokemon.turnData.order = orderIndex++;
if (!queuedMove) { if (!queuedMove) {
continue; continue;
} }
@ -99,7 +96,7 @@ export class TurnStartPhase extends FieldPhase {
pokemon.getMoveset().find(m => m.moveId === queuedMove.move && m.ppUsed < m.getMovePp()) || pokemon.getMoveset().find(m => m.moveId === queuedMove.move && m.ppUsed < m.getMovePp()) ||
new PokemonMove(queuedMove.move); new PokemonMove(queuedMove.move);
if (move.getMove().hasAttr("MoveHeaderAttr")) { if (move.getMove().hasAttr("MoveHeaderAttr")) {
phaseManager.unshiftNew("MoveHeaderPhase", pokemon, move); phaseManager.pushNew("MoveHeaderPhase", pokemon.getBattlerIndex(), move);
} }
if (pokemon.isPlayer()) { if (pokemon.isPlayer()) {
if (turnCommand.cursor === -1) { if (turnCommand.cursor === -1) {

View File

@ -3,8 +3,10 @@ import type { DynamicPhaseString, PhaseString } from "#app/@types/phase-types";
import type { PokemonMove } from "#app/data/moves/pokemon-move"; import type { PokemonMove } from "#app/data/moves/pokemon-move";
import type Pokemon from "#app/field/pokemon"; import type Pokemon from "#app/field/pokemon";
import type { Phase } from "#app/phase"; 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 { MovePhasePriorityQueue } from "#app/queues/move-phase-priority-queue";
import type { PhasePriorityQueue } from "#app/queues/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 { PostSummonPhasePriorityQueue } from "#app/queues/post-summon-phase-priority-queue";
import { SwitchSummonPhasePriorityQueue } from "#app/queues/switch-summon-phase-priority-queue"; import { SwitchSummonPhasePriorityQueue } from "#app/queues/switch-summon-phase-priority-queue";
import type { BattlerIndex } from "#enums/battler-index"; import type { BattlerIndex } from "#enums/battler-index";
@ -16,6 +18,7 @@ export class DynamicQueueManager {
constructor() { constructor() {
this.dynamicPhaseMap = new Map(); this.dynamicPhaseMap = new Map();
this.dynamicPhaseMap.set("SwitchSummonPhase", new SwitchSummonPhasePriorityQueue()); this.dynamicPhaseMap.set("SwitchSummonPhase", new SwitchSummonPhasePriorityQueue());
this.dynamicPhaseMap.set("MoveHeaderPhase", new PokemonPhasePriorityQueue<MoveHeaderPhase>());
this.dynamicPhaseMap.set("PostSummonPhase", new PostSummonPhasePriorityQueue()); this.dynamicPhaseMap.set("PostSummonPhase", new PostSummonPhasePriorityQueue());
this.dynamicPhaseMap.set("MovePhase", new MovePhasePriorityQueue()); this.dynamicPhaseMap.set("MovePhase", new MovePhasePriorityQueue());
} }