diff --git a/src/phases/show-ability-phase.ts b/src/phases/show-ability-phase.ts index 1e45818af1d..ded480867e1 100644 --- a/src/phases/show-ability-phase.ts +++ b/src/phases/show-ability-phase.ts @@ -1,14 +1,20 @@ import { globalScene } from "#app/global-scene"; import type { BattlerIndex } from "#app/battle"; import { PokemonPhase } from "./pokemon-phase"; +import { getPokemonNameWithAffix } from "#app/messages"; export class ShowAbilityPhase extends PokemonPhase { private passive: boolean; + private pokemonName: string; + private abilityName: string; 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().name : this.getPokemon().getAbility().name; } start() { @@ -17,7 +23,7 @@ export class ShowAbilityPhase extends PokemonPhase { const pokemon = this.getPokemon(); if (pokemon) { - globalScene.abilityBar.showAbility(pokemon, this.passive).then(() => { + globalScene.abilityBar.showAbility(this.pokemonName, this.abilityName, this.passive).then(() => { if (pokemon?.battleData) { pokemon.battleData.abilityRevealed = true; } diff --git a/src/ui/ability-bar.ts b/src/ui/ability-bar.ts index 602bf1ec87f..5eea44f4e91 100644 --- a/src/ui/ability-bar.ts +++ b/src/ui/ability-bar.ts @@ -1,6 +1,4 @@ -import { getPokemonNameWithAffix } from "#app/messages"; import { globalScene } from "#app/global-scene"; -import type Pokemon from "../field/pokemon"; import { TextStyle, addTextObject } from "./text"; import i18next from "i18next"; @@ -57,8 +55,8 @@ export default class AbilityBar extends Phaser.GameObjects.Container { }); } - showAbility(pokemon: Pokemon, passive: boolean = false): Promise { - const text = (`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: getPokemonNameWithAffix(pokemon), passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: !passive ? pokemon.getAbility().name : pokemon.getPassiveAbility().name })}`); + showAbility(pokemonName: string, abilityName: string, passive: boolean = false): Promise { + const text = (`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: pokemonName, passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: abilityName })}`); globalScene.fieldUI.bringToTop(this);