[Bug] [Ability] Fix trace's RNG (#6398)

* Fix rng in trace

* Fix undefined var
This commit is contained in:
Sirz Benjie 2025-08-24 16:24:12 -05:00 committed by GitHub
parent 30b7a62988
commit cd610ff2c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3014,41 +3014,44 @@ export class PostSummonFormChangeAbAttr extends PostSummonAbAttr {
} }
} }
/** Attempts to copy a pokemon's ability */ /**
* Attempts to copy a pokemon's ability
*
* @remarks
* Hardcodes idiosyncrasies specific to trace, so should not be used for other abilities
* that might copy abilities in the future
* @sealed
*/
export class PostSummonCopyAbilityAbAttr extends PostSummonAbAttr { export class PostSummonCopyAbilityAbAttr extends PostSummonAbAttr {
private target: Pokemon; private target: Pokemon;
private targetAbilityName: string; private targetAbilityName: string;
override canApply({ pokemon }: AbAttrBaseParams): boolean { override canApply({ pokemon, simulated }: AbAttrBaseParams): boolean {
const targets = pokemon.getOpponents(); const targets = pokemon
.getOpponents()
.filter(t => t.getAbility().isCopiable || t.getAbility().id === AbilityId.WONDER_GUARD);
if (!targets.length) { if (!targets.length) {
return false; return false;
} }
let target: Pokemon; let target: Pokemon;
if (targets.length > 1) { // simulated call always chooses first target so as to not advance RNG
globalScene.executeWithSeedOffset(() => (target = randSeedItem(targets)), globalScene.currentBattle.waveIndex); if (targets.length > 1 && !simulated) {
target = targets[randSeedInt(targets.length)];
} else { } else {
target = targets[0]; target = targets[0];
} }
if ( this.target = target;
!target!.getAbility().isCopiable && this.targetAbilityName = allAbilities[target.getAbility().id].name;
// Wonder Guard is normally uncopiable so has the attribute, but Trace specifically can copy it
!(pokemon.hasAbility(AbilityId.TRACE) && target!.getAbility().id === AbilityId.WONDER_GUARD)
) {
return false;
}
this.target = target!;
this.targetAbilityName = allAbilities[target!.getAbility().id].name;
return true; return true;
} }
override apply({ pokemon, simulated }: AbAttrBaseParams): void { override apply({ pokemon, simulated }: AbAttrBaseParams): void {
if (!simulated) { // Protect against this somehow being called before canApply by ensuring target is defined
pokemon.setTempAbility(this.target!.getAbility()); if (!simulated && this.target) {
setAbilityRevealed(this.target!); pokemon.setTempAbility(this.target.getAbility());
setAbilityRevealed(this.target);
pokemon.updateInfo(); pokemon.updateInfo();
} }
} }