pokerogue/src/phases/show-ability-phase.ts
Sirz Benjie 1c4edabd1d
[Refactor] Ensure that new phases are created through the phase manager
https://github.com/pagefaultgames/pokerogue/pull/5955

* Add newPhase method to phase-manager

* Update calls to append/prepend phase to use string phase

* Replace instantiations of new phase with phase manager
2025-06-07 23:55:30 -07:00

59 lines
1.9 KiB
TypeScript

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 {
public readonly phaseName = "ShowAbilityPhase";
private passive: boolean;
private pokemonName: string;
private abilityName: string;
private pokemonOnField: boolean;
constructor(battlerIndex: BattlerIndex, passive = false) {
super(battlerIndex);
this.passive = passive;
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 || !this.getPokemon()) {
return this.end();
}
// If the bar is already out, hide it before showing the new one
if (globalScene.abilityBar.isVisible()) {
globalScene.phaseManager.unshiftNew("HideAbilityPhase");
globalScene.phaseManager.unshiftNew("ShowAbilityPhase", this.battlerIndex, this.passive);
return this.end();
}
const pokemon = this.getPokemon();
if (!pokemon.isPlayer()) {
/** If its an enemy pokemon, list it as last enemy to use ability or move */
globalScene.currentBattle.lastEnemyInvolved = pokemon.getBattlerIndex() % 2;
} else {
globalScene.currentBattle.lastPlayerInvolved = pokemon.getBattlerIndex() % 2;
}
globalScene.abilityBar.showAbility(this.pokemonName, this.abilityName, this.passive, this.player).then(() => {
pokemon.waveData.abilityRevealed = true;
this.end();
});
}
}