From f5468f8d58fed2a31f7d85ac75d26393a6bcba9e Mon Sep 17 00:00:00 2001 From: Dean Date: Sat, 22 Feb 2025 01:06:29 -0800 Subject: [PATCH] Prevent crashes in case an ability for a pokemon not on the field is shown --- src/data/ability.ts | 1 - src/phases/show-ability-phase.ts | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index f38fd1b11f2..08482df5ef5 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1408,7 +1408,6 @@ export class AddSecondStrikeAbAttr extends PreAttackAbAttr { override applyPreAttack(pokemon: Pokemon, passive: boolean, simulated: boolean, defender: Pokemon, move: Move, args: any[]): void { const hitCount = args[0] as Utils.NumberHolder; const multiplier = args[1] as Utils.NumberHolder; - this.showAbility = !!hitCount?.value; if (hitCount?.value) { hitCount.value += 1; } diff --git a/src/phases/show-ability-phase.ts b/src/phases/show-ability-phase.ts index 60bb9b50198..efae46d7bb8 100644 --- a/src/phases/show-ability-phase.ts +++ b/src/phases/show-ability-phase.ts @@ -7,19 +7,30 @@ export class ShowAbilityPhase extends PokemonPhase { private passive: boolean; private pokemonName: string; private abilityName: string; + private pokemonOnField: boolean; constructor(battlerIndex: BattlerIndex, passive: boolean = false) { super(battlerIndex); this.passive = passive; - // Set these now as the pokemon object may change before the queued phase is run - this.pokemonName = getPokemonNameWithAffix(this.getPokemon()); - this.abilityName = (passive ? this.getPokemon().getPassiveAbility() : this.getPokemon().getAbility()).name; + + const pokemon = this.getPokemon(); + if (pokemon) { + // Set these now as the pokemon object may change before the queued phase is run + this.pokemonName = getPokemonNameWithAffix(pokemon); + this.abilityName = (passive ? this.getPokemon().getPassiveAbility() : this.getPokemon().getAbility()).name; + this.pokemonOnField = true; + } else { + this.pokemonOnField = false; + } } start() { super.start(); + if (!this.pokemonOnField) { + return this.end(); + } const pokemon = this.getPokemon(); if (pokemon) {