mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-03 23:12:20 +02:00
Remove conditional queue
This commit is contained in:
parent
f4d3bed3ee
commit
8bc6b4b9fa
@ -220,7 +220,6 @@ export type PhaseConstructorMap = typeof PHASES;
|
|||||||
export class PhaseManager {
|
export class PhaseManager {
|
||||||
/** PhaseQueue: dequeue/remove the first element to get the next phase */
|
/** PhaseQueue: dequeue/remove the first element to get the next phase */
|
||||||
private phaseQueue: Phase[] = [];
|
private phaseQueue: Phase[] = [];
|
||||||
private conditionalQueue: Array<[() => boolean, Phase]> = [];
|
|
||||||
/** PhaseQueuePrepend: is a temp storage of what will be added to PhaseQueue */
|
/** PhaseQueuePrepend: is a temp storage of what will be added to PhaseQueue */
|
||||||
private phaseQueuePrepend: Phase[] = [];
|
private phaseQueuePrepend: Phase[] = [];
|
||||||
|
|
||||||
@ -242,20 +241,6 @@ export class PhaseManager {
|
|||||||
return this.standbyPhase;
|
return this.standbyPhase;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a phase to the conditional queue and ensures it is executed only when the specified condition is met.
|
|
||||||
*
|
|
||||||
* This method allows deferring the execution of a phase until certain conditions are met, which is useful for handling
|
|
||||||
* situations like abilities and entry hazards that depend on specific game states.
|
|
||||||
*
|
|
||||||
* @param phase - The phase to be added to the conditional queue.
|
|
||||||
* @param condition - A function that returns a boolean indicating whether the phase should be executed.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
pushConditionalPhase(phase: Phase, condition: () => boolean): void {
|
|
||||||
this.conditionalQueue.push([condition, phase]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a phase to nextCommandPhaseQueue, as long as boolean passed in is false
|
* Adds a phase to nextCommandPhaseQueue, as long as boolean passed in is false
|
||||||
* @param phase {@linkcode Phase} the phase to add
|
* @param phase {@linkcode Phase} the phase to add
|
||||||
@ -292,7 +277,7 @@ export class PhaseManager {
|
|||||||
* Clears all phase-related stuff, including all phase queues, the current and standby phases, and a splice index
|
* Clears all phase-related stuff, including all phase queues, the current and standby phases, and a splice index
|
||||||
*/
|
*/
|
||||||
clearAllPhases(): void {
|
clearAllPhases(): void {
|
||||||
for (const queue of [this.phaseQueue, this.phaseQueuePrepend, this.conditionalQueue, this.nextCommandPhaseQueue]) {
|
for (const queue of [this.phaseQueue, this.phaseQueuePrepend, this.nextCommandPhaseQueue]) {
|
||||||
queue.splice(0, queue.length);
|
queue.splice(0, queue.length);
|
||||||
}
|
}
|
||||||
this.dynamicQueueManager.clearQueues();
|
this.dynamicQueueManager.clearQueues();
|
||||||
@ -340,8 +325,6 @@ export class PhaseManager {
|
|||||||
}
|
}
|
||||||
if (!this.phaseQueue.length) {
|
if (!this.phaseQueue.length) {
|
||||||
this.populatePhaseQueue();
|
this.populatePhaseQueue();
|
||||||
// Clear the conditionalQueue if there are no phases left in the phaseQueue
|
|
||||||
this.conditionalQueue = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.phaseQueue[0].is("WeatherEffectPhase")) {
|
if (this.phaseQueue[0].is("WeatherEffectPhase")) {
|
||||||
@ -353,24 +336,6 @@ export class PhaseManager {
|
|||||||
|
|
||||||
this.currentPhase = this.phaseQueue.shift() ?? null;
|
this.currentPhase = this.phaseQueue.shift() ?? null;
|
||||||
|
|
||||||
const unactivatedConditionalPhases: [() => boolean, Phase][] = [];
|
|
||||||
// Check if there are any conditional phases queued
|
|
||||||
while (this.conditionalQueue?.length) {
|
|
||||||
// Retrieve the first conditional phase from the queue
|
|
||||||
const conditionalPhase = this.conditionalQueue.shift();
|
|
||||||
// Evaluate the condition associated with the phase
|
|
||||||
if (conditionalPhase?.[0]()) {
|
|
||||||
// If the condition is met, add the phase to the phase queue
|
|
||||||
this.pushPhase(conditionalPhase[1]);
|
|
||||||
} else if (conditionalPhase) {
|
|
||||||
// If the condition is not met, re-add the phase back to the front of the conditional queue
|
|
||||||
unactivatedConditionalPhases.push(conditionalPhase);
|
|
||||||
} else {
|
|
||||||
console.warn("condition phase is undefined/null!", conditionalPhase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.conditionalQueue.push(...unactivatedConditionalPhases);
|
|
||||||
|
|
||||||
if (this.currentPhase) {
|
if (this.currentPhase) {
|
||||||
console.log(`%cStart Phase ${this.currentPhase.constructor.name}`, "color:green;");
|
console.log(`%cStart Phase ${this.currentPhase.constructor.name}`, "color:green;");
|
||||||
this.currentPhase.start();
|
this.currentPhase.start();
|
||||||
|
@ -562,29 +562,7 @@ export class EncounterPhase extends BattlePhase {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (![BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER].includes(globalScene.currentBattle.battleType)) {
|
if (![BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER].includes(globalScene.currentBattle.battleType)) {
|
||||||
enemyField.map(p =>
|
enemyField.map(p => globalScene.phaseManager.pushNew("PostSummonPhase", p.getBattlerIndex()));
|
||||||
globalScene.phaseManager.pushConditionalPhase(
|
|
||||||
globalScene.phaseManager.create("PostSummonPhase", p.getBattlerIndex()),
|
|
||||||
() => {
|
|
||||||
// if there is not a player party, we can't continue
|
|
||||||
if (!globalScene.getPlayerParty().length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// how many player pokemon are on the field ?
|
|
||||||
const pokemonsOnFieldCount = globalScene.getPlayerParty().filter(p => p.isOnField()).length;
|
|
||||||
// if it's a 2vs1, there will never be a 2nd pokemon on our field even
|
|
||||||
const requiredPokemonsOnField = Math.min(
|
|
||||||
globalScene.getPlayerParty().filter(p => !p.isFainted()).length,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
// if it's a double, there should be 2, otherwise 1
|
|
||||||
if (globalScene.currentBattle.double) {
|
|
||||||
return pokemonsOnFieldCount === requiredPokemonsOnField;
|
|
||||||
}
|
|
||||||
return pokemonsOnFieldCount === 1;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const ivScannerModifier = globalScene.findModifier(m => m instanceof IvScannerModifier);
|
const ivScannerModifier = globalScene.findModifier(m => m instanceof IvScannerModifier);
|
||||||
if (ivScannerModifier) {
|
if (ivScannerModifier) {
|
||||||
enemyField.map(p => globalScene.phaseManager.pushNew("ScanIvsPhase", p.getBattlerIndex()));
|
enemyField.map(p => globalScene.phaseManager.pushNew("ScanIvsPhase", p.getBattlerIndex()));
|
||||||
|
Loading…
Reference in New Issue
Block a user