Skip to content

Commit

Permalink
[P2] Fix issue with Pokemon not evolving until the next floor and cle…
Browse files Browse the repository at this point in the history
…an up `LevelUpPhase` (pagefaultgames#4854)
  • Loading branch information
DayKev authored Nov 12, 2024
1 parent 6f3fd0f commit b6b756a
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/phases/level-up-phase.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,66 @@
import BattleScene from "#app/battle-scene";
import type BattleScene from "#app/battle-scene";
import { ExpNotification } from "#app/enums/exp-notification";
import { EvolutionPhase } from "#app/phases/evolution-phase";
import { PlayerPokemon } from "#app/field/pokemon";
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";
import * as Utils from "#app/utils";
import { PlayerPartyMemberPokemonPhase } from "./player-party-member-pokemon-phase";
import { LearnMovePhase } from "./learn-move-phase";

export class LevelUpPhase extends PlayerPartyMemberPokemonPhase {
private lastLevel: integer;
private level: integer;
protected lastLevel: number;
protected level: number;
protected pokemon: PlayerPokemon = this.getPlayerPokemon();

constructor(scene: BattleScene, partyMemberIndex: integer, lastLevel: integer, level: integer) {
constructor(scene: BattleScene, partyMemberIndex: number, lastLevel: number, level: number) {
super(scene, partyMemberIndex);

this.lastLevel = lastLevel;
this.level = level;
this.scene = scene;
}

start() {
public override start() {
super.start();

if (this.level > this.scene.gameData.gameStats.highestLevel) {
this.scene.gameData.gameStats.highestLevel = this.level;
}

this.scene.validateAchvs(LevelAchv, new Utils.NumberHolder(this.level));
this.scene.validateAchvs(LevelAchv, new NumberHolder(this.level));

const pokemon = this.getPokemon();
const prevStats = pokemon.stats.slice(0);
pokemon.calculateStats();
pokemon.updateInfo();
const prevStats = this.pokemon.stats.slice(0);
this.pokemon.calculateStats();
this.pokemon.updateInfo();
if (this.scene.expParty === ExpNotification.DEFAULT) {
this.scene.playSound("level_up_fanfare");
this.scene.ui.showText(i18next.t("battle:levelUp", { pokemonName: getPokemonNameWithAffix(this.getPokemon()), level: this.level }), null, () => this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false).then(() => this.end()), null, true);
this.scene.ui.showText(
i18next.t("battle:levelUp", { pokemonName: getPokemonNameWithAffix(this.pokemon), level: this.level }),
null,
() => this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false)
.then(() => this.end()), null, true);
} else if (this.scene.expParty === ExpNotification.SKIP) {
this.end();
} else {
// we still want to display the stats if activated
this.scene.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) {
this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, lm[1]));
}
}
if (!pokemon.pauseEvolutions) {
const evolution = pokemon.getEvolution();
if (!this.pokemon.pauseEvolutions) {
const evolution = this.pokemon.getEvolution();
if (evolution) {
this.scene.unshiftPhase(new EvolutionPhase(this.scene, pokemon as PlayerPokemon, evolution, this.lastLevel));
this.scene.unshiftPhase(new EvolutionPhase(this.scene, this.pokemon, evolution, this.lastLevel));
}
}
return super.end();
}
}

0 comments on commit b6b756a

Please sign in to comment.