From 20c1e05c41300908bd30ce2b6ad532e1b0193722 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 11 Mar 2025 22:13:18 -0700 Subject: [PATCH] Pivot to using sort strategy instead --- src/battle-scene.ts | 21 --------------------- src/phases/post-summon-phase.ts | 10 ++++------ 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 455b440ce56..1712cf9236f 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -2879,27 +2879,6 @@ export default class BattleScene extends SceneBase { return false; } - /** - * Prepends a phase to the first occurence of {@linkcode targetPhase} which satisfies {@linkcode condition} - * - * Pushes the phase to the end of the queue if no occurrence is found - * @param newPhase The phase to be added - * @param targetPhase The type of phase to search for - * @param condition The condition that the target phase must meet - */ - prependToPhaseWithCondition( - newPhase: Phase, - targetPhase: Constructor, - condition: (newPhase: Phase, prependPhase: Phase) => boolean, - ) { - const prependPhase = this.findPhase(phase => phase instanceof targetPhase && condition(newPhase, phase)); - if (prependPhase) { - this.phaseQueue.splice(this.phaseQueue.indexOf(prependPhase), 0, newPhase); - } else { - this.pushPhase(newPhase); - } - } - /** * Adds a MessagePhase, either to PhaseQueuePrepend or nextCommandPhaseQueue * @param message string for MessagePhase diff --git a/src/phases/post-summon-phase.ts b/src/phases/post-summon-phase.ts index 25fac6eb453..b31682dd250 100644 --- a/src/phases/post-summon-phase.ts +++ b/src/phases/post-summon-phase.ts @@ -14,7 +14,6 @@ export class PostSummonPhase extends PokemonPhase { const pokemon = this.getPokemon(); - // If another PostSummonPhase exists which should go first, move this one back globalScene.phaseQueue; const fasterPhase = globalScene.findPhase( phase => @@ -22,11 +21,10 @@ export class PostSummonPhase extends PokemonPhase { phase.getPokemon().getEffectiveStat(Stat.SPD) > pokemon.getEffectiveStat(Stat.SPD), ); if (fasterPhase) { - globalScene.prependToPhaseWithCondition( - new PostSummonPhase(this.getPokemon().getBattlerIndex()), - PostSummonPhase, - (newPhase: PostSummonPhase, prependPhase: PostSummonPhase) => - prependPhase.getPokemon().getEffectiveStat(Stat.SPD) < newPhase.getPokemon().getEffectiveStat(Stat.SPD), + globalScene.pushPhase(new PostSummonPhase(pokemon.getBattlerIndex())); + globalScene.phaseQueue.sort( + (phaseA: PostSummonPhase, phaseB: PostSummonPhase) => + phaseB.getPokemon().getEffectiveStat(Stat.SPD) - phaseA.getPokemon().getEffectiveStat(Stat.SPD), ); this.end(); return;