Fix gameManager.setTurnOrder

This commit is contained in:
Dean 2025-06-14 19:19:45 -07:00
parent 08090a8c14
commit 46c709ffad
5 changed files with 23 additions and 3 deletions

View File

@ -228,7 +228,7 @@ export class PhaseManager {
private phaseQueuePrependSpliceIndex = -1;
private nextCommandPhaseQueue: Phase[] = [];
private dynamicQueueManager = new DynamicQueueManager();
public dynamicQueueManager = new DynamicQueueManager();
private currentPhase: Phase | null = null;
private standbyPhase: Phase | null = null;

View File

@ -6,6 +6,7 @@ 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 type { BattlerIndex } from "#enums/battler-index";
import type { MovePhaseTimingModifier } from "#enums/move-phase-timing-modifier";
export class DynamicQueueManager {
private dynamicPhaseMap: Map<PhaseString, PhasePriorityQueue<Phase>>;
@ -43,4 +44,8 @@ export class DynamicQueueManager {
const movePhaseQueue: MovePhasePriorityQueue = this.dynamicPhaseMap.get("MovePhase") as MovePhasePriorityQueue;
movePhaseQueue.setTimingModifier(condition, modifier);
}
public setMoveOrder(order: BattlerIndex[]) {
(this.dynamicPhaseMap.get("MovePhase") as MovePhasePriorityQueue).setMoveOrder(order);
}
}

View File

@ -2,6 +2,7 @@ import type { PhaseConditionFunc } from "#app/@types/phase-condition";
import type { MovePhase } from "#app/phases/move-phase";
import { PokemonPhasePriorityQueue } from "#app/queues/pokemon-phase-priority-queue";
import { isNullOrUndefined } from "#app/utils/common";
import type { BattlerIndex } from "#enums/battler-index";
import type { MovePhaseTimingModifier } from "#enums/move-phase-timing-modifier";
export class MovePhasePriorityQueue extends PokemonPhasePriorityQueue<MovePhase> {
@ -17,6 +18,10 @@ export class MovePhasePriorityQueue extends PokemonPhasePriorityQueue<MovePhase>
}
}
public setMoveOrder(order: BattlerIndex[]) {
this.setOrder = order;
}
private sortPostSpeed(): void {
this.queue.sort((a: MovePhase, b: MovePhase) => {
const priority = [a, b].map(movePhase => {

View File

@ -2,9 +2,19 @@ import type { PartyMemberPokemonPhase } from "#app/phases/party-member-pokemon-p
import type { PokemonPhase } from "#app/phases/pokemon-phase";
import { PhasePriorityQueue } from "#app/queues/phase-priority-queue";
import { sortInSpeedOrder } from "#app/utils/speed-order";
import type { BattlerIndex } from "#enums/battler-index";
export class PokemonPhasePriorityQueue<T extends PokemonPhase | PartyMemberPokemonPhase> extends PhasePriorityQueue<T> {
protected setOrder: BattlerIndex[] | undefined;
public override reorder(): void {
if (this.setOrder) {
this.queue.sort(
(a, b) =>
this.setOrder!.indexOf(a.getPokemon().getBattlerIndex()) -
this.setOrder!.indexOf(b.getPokemon().getBattlerIndex()),
);
} else {
this.queue = sortInSpeedOrder(this.queue);
}
}
}

View File

@ -531,7 +531,7 @@ export default class GameManager {
async setTurnOrder(order: BattlerIndex[]): Promise<void> {
await this.phaseInterceptor.to(TurnStartPhase, false);
vi.spyOn(this.scene.phaseManager.getCurrentPhase() as TurnStartPhase, "getSpeedOrder").mockReturnValue(order);
this.scene.phaseManager.dynamicQueueManager.setMoveOrder(order);
}
/**