Prevent crashes in case an ability for a pokemon not on the field is shown

This commit is contained in:
Dean 2025-02-22 01:06:29 -08:00
parent e5f5f1bd9a
commit f5468f8d58
2 changed files with 14 additions and 4 deletions

View File

@ -1408,7 +1408,6 @@ export class AddSecondStrikeAbAttr extends PreAttackAbAttr {
override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void { override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void {
const hitCount = args[0] as Utils.NumberHolder; const hitCount = args[0] as Utils.NumberHolder;
const multiplier = args[1] as Utils.NumberHolder; const multiplier = args[1] as Utils.NumberHolder;
this.showAbility = !!hitCount?.value;
if (hitCount?.value) { if (hitCount?.value) {
hitCount.value += 1; hitCount.value += 1;
} }

View File

@ -7,19 +7,30 @@ export class ShowAbilityPhase extends PokemonPhase {
private passive: boolean; private passive: boolean;
private pokemonName: string; private pokemonName: string;
private abilityName: string; private abilityName: string;
private pokemonOnField: boolean;
constructor(battlerIndex: BattlerIndex, passive: boolean = false) { constructor(battlerIndex: BattlerIndex, passive: boolean = false) {
super(battlerIndex); super(battlerIndex);
this.passive = passive; this.passive = passive;
const pokemon = this.getPokemon();
if (pokemon) {
// Set these now as the pokemon object may change before the queued phase is run // Set these now as the pokemon object may change before the queued phase is run
this.pokemonName = getPokemonNameWithAffix(this.getPokemon()); this.pokemonName = getPokemonNameWithAffix(pokemon);
this.abilityName = (passive ? this.getPokemon().getPassiveAbility() : this.getPokemon().getAbility()).name; this.abilityName = (passive ? this.getPokemon().getPassiveAbility() : this.getPokemon().getAbility()).name;
this.pokemonOnField = true;
} else {
this.pokemonOnField = false;
}
} }
start() { start() {
super.start(); super.start();
if (!this.pokemonOnField) {
return this.end();
}
const pokemon = this.getPokemon(); const pokemon = this.getPokemon();
if (pokemon) { if (pokemon) {