mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-29 02:06:07 +00:00
[Refactor] Optimize trick room ordering code (#4468)
This commit is contained in:
parent
3976d115d8
commit
b43620b8c5
@ -43,20 +43,17 @@ export class TurnStartPhase extends FieldPhase {
|
|||||||
orderedTargets = Utils.randSeedShuffle(orderedTargets);
|
orderedTargets = Utils.randSeedShuffle(orderedTargets);
|
||||||
}, this.scene.currentBattle.turn, this.scene.waveSeed);
|
}, this.scene.currentBattle.turn, this.scene.waveSeed);
|
||||||
|
|
||||||
orderedTargets.sort((a: Pokemon, b: Pokemon) => {
|
// Next, a check for Trick Room is applied to determine sort order.
|
||||||
const aSpeed = a?.getEffectiveStat(Stat.SPD) || 0;
|
|
||||||
const bSpeed = b?.getEffectiveStat(Stat.SPD) || 0;
|
|
||||||
|
|
||||||
return bSpeed - aSpeed;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Next, a check for Trick Room is applied. If Trick Room is present, the order is reversed.
|
|
||||||
const speedReversed = new Utils.BooleanHolder(false);
|
const speedReversed = new Utils.BooleanHolder(false);
|
||||||
this.scene.arena.applyTags(TrickRoomTag, speedReversed);
|
this.scene.arena.applyTags(TrickRoomTag, speedReversed);
|
||||||
|
|
||||||
if (speedReversed.value) {
|
// Adjust the sort function based on whether Trick Room is active.
|
||||||
orderedTargets = orderedTargets.reverse();
|
orderedTargets.sort((a: Pokemon, b: Pokemon) => {
|
||||||
}
|
const aSpeed = a?.getEffectiveStat(Stat.SPD) ?? 0;
|
||||||
|
const bSpeed = b?.getEffectiveStat(Stat.SPD) ?? 0;
|
||||||
|
|
||||||
|
return speedReversed.value ? aSpeed - bSpeed : bSpeed - aSpeed;
|
||||||
|
});
|
||||||
|
|
||||||
return orderedTargets.map(t => t.getFieldIndex() + (!t.isPlayer() ? BattlerIndex.ENEMY : BattlerIndex.PLAYER));
|
return orderedTargets.map(t => t.getFieldIndex() + (!t.isPlayer() ? BattlerIndex.ENEMY : BattlerIndex.PLAYER));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user