Fix injective field position indexing (#11789)

This commit is contained in:
André Bastos Dias 2026-03-03 22:32:45 +01:00 committed by GitHub
parent cf8cbd8f5d
commit f494d48434
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View File

@ -180,7 +180,7 @@ export class BattleActions {
}
const allActive = this.battle.getAllActive(true);
this.battle.speedSort(allActive);
this.battle.speedOrder = allActive.map(a => a.side.n * a.battle.sides.length + a.position);
this.battle.speedOrder = allActive.map(a => a.getFieldPositionValue());
this.battle.fieldEvent('SwitchIn', switchersIn);
for (const poke of switchersIn) {

View File

@ -1009,8 +1009,7 @@ export class Battle {
// Pokemon speeds including ties are resolved before all onSwitchIn handlers and aren't re-sorted in-between
// so we subtract a fractional speed from each Pokemon's respective event handlers by using the index of their
// unique field position in a pre-sorted-by-speed array
const fieldPositionValue = pokemon.side.n * this.sides.length + pokemon.position;
handler.speed -= this.speedOrder.indexOf(fieldPositionValue) / (this.activePerHalf * 2);
handler.speed -= this.speedOrder.indexOf(pokemon.getFieldPositionValue()) / (this.activePerHalf * 2);
}
}
return handler;

View File

@ -518,6 +518,11 @@ export class Pokemon {
return (this.side.id + positionLetter) as PokemonSlot;
}
getFieldPositionValue() {
// p1a, p2a, p3a, ..., p1b, p2b, p3b, ...
return this.side.n + this.battle.sides.length * this.position;
}
toString() {
const fullname = (this.illusion) ? this.illusion.fullname : this.fullname;
return this.isActive ? this.getSlot() + fullname.slice(2) : fullname;