mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-01 05:52:17 +02:00
Pivot to using sort strategy instead
This commit is contained in:
parent
d0362e4fc6
commit
20c1e05c41
@ -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<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
|
||||
* @param message string for MessagePhase
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user