mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-01 05:52:17 +02:00
Add prependToPhaseWithCondition and use it in SummonPhase to determine speed order
This commit is contained in:
parent
b298138157
commit
3ab6f15e49
@ -2879,6 +2879,27 @@ 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,6 +14,7 @@ import { GameOverPhase } from "./game-over-phase";
|
||||
import { ShinySparklePhase } from "./shiny-sparkle-phase";
|
||||
import { MysteryEncounterMode } from "#enums/mystery-encounter-mode";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { Stat } from "#enums/stat";
|
||||
|
||||
export class SummonPhase extends PartyMemberPokemonPhase {
|
||||
private loaded: boolean;
|
||||
@ -283,7 +284,13 @@ export class SummonPhase extends PartyMemberPokemonPhase {
|
||||
}
|
||||
|
||||
queuePostSummon(): void {
|
||||
globalScene.pushPhase(new PostSummonPhase(this.getPokemon().getBattlerIndex()));
|
||||
// Insert PostSummonPhase in speed order
|
||||
globalScene.prependToPhaseWithCondition(
|
||||
new PostSummonPhase(this.getPokemon().getBattlerIndex()),
|
||||
PostSummonPhase,
|
||||
(newPhase: PostSummonPhase, prependPhase: PostSummonPhase) =>
|
||||
prependPhase.getPokemon().getEffectiveStat(Stat.SPD) < newPhase.getPokemon().getEffectiveStat(Stat.SPD),
|
||||
);
|
||||
}
|
||||
|
||||
end() {
|
||||
|
Loading…
Reference in New Issue
Block a user