pokerogue/src/phases/level-up-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

80 lines
2.6 KiB
TypeScript

import { globalScene } from "#app/global-scene";
import { ExpNotification } from "#app/enums/exp-notification";
import type { PlayerPokemon } from "#app/field/pokemon";
import { getPokemonNameWithAffix } from "#app/messages";
import { PlayerPartyMemberPokemonPhase } from "#app/phases/player-party-member-pokemon-phase";
import { LevelAchv } from "#app/system/achv";
import { NumberHolder } from "#app/utils/common";
import i18next from "i18next";
export class LevelUpPhase extends PlayerPartyMemberPokemonPhase {
public readonly phaseName = "LevelUpPhase";
protected lastLevel: number;
protected level: number;
protected pokemon: PlayerPokemon = this.getPlayerPokemon();
constructor(partyMemberIndex: number, lastLevel: number, level: number) {
super(partyMemberIndex);
this.lastLevel = lastLevel;
this.level = level;
}
public override start() {
super.start();
if (this.level > globalScene.gameData.gameStats.highestLevel) {
globalScene.gameData.gameStats.highestLevel = this.level;
}
globalScene.validateAchvs(LevelAchv, new NumberHolder(this.level));
const prevStats = this.pokemon.stats.slice(0);
this.pokemon.calculateStats();
this.pokemon.updateInfo();
if (globalScene.expParty === ExpNotification.DEFAULT) {
globalScene.playSound("level_up_fanfare");
globalScene.ui.showText(
i18next.t("battle:levelUp", {
pokemonName: getPokemonNameWithAffix(this.pokemon),
level: this.level,
}),
null,
() =>
globalScene.ui
.getMessageHandler()
.promptLevelUpStats(this.partyMemberIndex, prevStats, false)
.then(() => this.end()),
null,
true,
);
} else if (globalScene.expParty === ExpNotification.SKIP) {
this.end();
} else {
// we still want to display the stats if activated
globalScene.ui
.getMessageHandler()
.promptLevelUpStats(this.partyMemberIndex, prevStats, false)
.then(() => this.end());
}
}
public override end() {
if (this.lastLevel < 100) {
// this feels like an unnecessary optimization
const levelMoves = this.getPokemon().getLevelMoves(this.lastLevel + 1);
for (const lm of levelMoves) {
globalScene.phaseManager.unshiftNew("LearnMovePhase", this.partyMemberIndex, lm[1]);
}
}
if (!this.pokemon.pauseEvolutions) {
const evolution = this.pokemon.getEvolution();
if (evolution) {
this.pokemon.breakIllusion();
globalScene.phaseManager.unshiftNew("EvolutionPhase", this.pokemon, evolution, this.lastLevel);
}
}
return super.end();
}
}