pokerogue/src/phases/level-up-phase.ts
NightKev 0107b1d47e
[Refactor] Create global scene variable (#4766)
* Replace various `scene` pass-arounds with global scene variable

* Modify tests

* Add scene back to `fade[in|out]()` calls

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>

* Fix Bug Superfan ME test

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>

* Re-enable fixed test

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>

* Rename `gScene` to `globalScene`

* Move `globalScene` to its own file to fix import/async issues

* Fix `SelectModifierPhase` tests

* Fix ME tests by removing `scene` from `expect()`s

* Resolve merge issues

* Remove tsdocs referencing `scene` params

Remove missed instances of `.scene`

* Remove unnecessary `globalScene` usage in `loading-scene.ts`

* Fix merge conflicts

* Attempt to fix circular import issue

* Found the source of the import issue

* Fix merge issues

---------

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>
2025-01-12 15:33:05 -08:00

67 lines
2.5 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 { EvolutionPhase } from "#app/phases/evolution-phase";
import { LearnMovePhase } from "#app/phases/learn-move-phase";
import { PlayerPartyMemberPokemonPhase } from "#app/phases/player-party-member-pokemon-phase";
import { LevelAchv } from "#app/system/achv";
import { NumberHolder } from "#app/utils";
import i18next from "i18next";
export class LevelUpPhase extends PlayerPartyMemberPokemonPhase {
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.unshiftPhase(new LearnMovePhase(this.partyMemberIndex, lm[1]));
}
}
if (!this.pokemon.pauseEvolutions) {
const evolution = this.pokemon.getEvolution();
if (evolution) {
globalScene.unshiftPhase(new EvolutionPhase(this.pokemon, evolution, this.lastLevel));
}
}
return super.end();
}
}