From a1600161c1de5d0dc11ade9712deb7ff5c7cfd2b Mon Sep 17 00:00:00 2001 From: Dean Date: Fri, 27 Dec 2024 12:04:17 -0800 Subject: [PATCH] Use findPhase instead of looping to search --- src/data/move.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index 71386945db1..cd40e7a6e21 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -7669,16 +7669,11 @@ export class ForceLastAttr extends MoveEffectAttr { override apply(user: Pokemon, target: Pokemon, _move: Move, _args: any[]): boolean { const targetMovePhase = target.scene.findPhase((phase) => phase.pokemon === target); if (targetMovePhase && target.scene.tryRemovePhase((phase: MovePhase) => phase.pokemon === target)) { - let newMovePhaseIndex = 1; - let nextMovePhase = target.scene.phaseQueue[newMovePhaseIndex]; - // Search until a slower quashed move or end of turn is found - // Means that a speed tie will go in "order quashed" - need to see if this is the case (it's prob random) - while (nextMovePhase instanceof MovePhase - && (!nextMovePhase.isForcedLast() || nextMovePhase.pokemon.getEffectiveStat(Stat.SPD) >= user.getEffectiveStat(Stat.SPD))) { - newMovePhaseIndex++; - nextMovePhase = target.scene.phaseQueue[newMovePhaseIndex]; + const prependPhase = target.scene.findPhase((phase) => [ MovePhase, MoveEndPhase ].every(cls => !(phase instanceof cls)) + || (phase instanceof MovePhase) && (phase.isForcedLast() && phase.pokemon.getEffectiveStat(Stat.SPD) < user.getEffectiveStat(Stat.SPD))); + if (prependPhase) { + target.scene.phaseQueue.splice(target.scene.phaseQueue.indexOf(prependPhase), 0, new MovePhase(target.scene, target, [ ...targetMovePhase.targets ], targetMovePhase.move, false, false, true)); } - target.scene.phaseQueue.splice(newMovePhaseIndex, 0, new MovePhase(target.scene, target, [ ...targetMovePhase.targets ], targetMovePhase.move, false, false, true)); } return true; }