diff --git a/src/data/move.ts b/src/data/move.ts index bcd99978192..a836bdc10f0 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -7670,7 +7670,16 @@ 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)) { - target.scene.prependToPhase(new MovePhase(target.scene, target, [ ...targetMovePhase.targets ], targetMovePhase.move), WeatherEffectPhase); + const weatherPhase = target.scene.findPhase((phase) => phase instanceof WeatherEffectPhase)!; + let newMovePhaseIndex = target.scene.phaseQueue.indexOf(weatherPhase); + let nextMovePhase = target.scene.phaseQueue[newMovePhaseIndex - 1]; + while (nextMovePhase instanceof MovePhase + && nextMovePhase.isForcedLast() + && nextMovePhase.pokemon.getEffectiveStat(Stat.SPD) < user.getEffectiveStat(Stat.SPD)) { + newMovePhaseIndex--; + nextMovePhase = target.scene.phaseQueue[newMovePhaseIndex]; + } + target.scene.phaseQueue.splice(newMovePhaseIndex, 0, new MovePhase(target.scene, target, [ ...targetMovePhase.targets ], targetMovePhase.move, false, false, true)); } return true; } diff --git a/src/phases/move-phase.ts b/src/phases/move-phase.ts index 089386bee00..0cd200b5db6 100644 --- a/src/phases/move-phase.ts +++ b/src/phases/move-phase.ts @@ -56,6 +56,7 @@ export class MovePhase extends BattlePhase { protected ignorePp: boolean; protected failed: boolean = false; protected cancelled: boolean = false; + protected forcedLast: boolean = false; public get pokemon(): Pokemon { return this._pokemon; @@ -114,6 +115,21 @@ export class MovePhase extends BattlePhase { this.cancelled = true; } + /** + * Flags that the current move has been forced to the end of the turn + * Needed for speed order, see {@linkcode Moves.QUASH} + * */ + public forceLast(): MovePhase { + this.forcedLast = true; + return this; + } + + + public isForcedLast(): boolean { + return this.forcedLast; + } + + public start(): void { super.start();