Pivot to using sort strategy instead

This commit is contained in:
Dean 2025-03-11 22:13:18 -07:00
parent d0362e4fc6
commit 20c1e05c41
2 changed files with 4 additions and 27 deletions

View File

@ -2879,27 +2879,6 @@ export default class BattleScene extends SceneBase {
return false; 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<Phase>,
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 * Adds a MessagePhase, either to PhaseQueuePrepend or nextCommandPhaseQueue
* @param message string for MessagePhase * @param message string for MessagePhase

View File

@ -14,7 +14,6 @@ export class PostSummonPhase extends PokemonPhase {
const pokemon = this.getPokemon(); const pokemon = this.getPokemon();
// If another PostSummonPhase exists which should go first, move this one back
globalScene.phaseQueue; globalScene.phaseQueue;
const fasterPhase = globalScene.findPhase( const fasterPhase = globalScene.findPhase(
phase => phase =>
@ -22,11 +21,10 @@ export class PostSummonPhase extends PokemonPhase {
phase.getPokemon().getEffectiveStat(Stat.SPD) > pokemon.getEffectiveStat(Stat.SPD), phase.getPokemon().getEffectiveStat(Stat.SPD) > pokemon.getEffectiveStat(Stat.SPD),
); );
if (fasterPhase) { if (fasterPhase) {
globalScene.prependToPhaseWithCondition( globalScene.pushPhase(new PostSummonPhase(pokemon.getBattlerIndex()));
new PostSummonPhase(this.getPokemon().getBattlerIndex()), globalScene.phaseQueue.sort(
PostSummonPhase, (phaseA: PostSummonPhase, phaseB: PostSummonPhase) =>
(newPhase: PostSummonPhase, prependPhase: PostSummonPhase) => phaseB.getPokemon().getEffectiveStat(Stat.SPD) - phaseA.getPokemon().getEffectiveStat(Stat.SPD),
prependPhase.getPokemon().getEffectiveStat(Stat.SPD) < newPhase.getPokemon().getEffectiveStat(Stat.SPD),
); );
this.end(); this.end();
return; return;