mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-27 17:26:11 +00:00
[Bug] fix training session encounter not applying nature correctly (#4801)
* fix training session encounter not applying nature correctly * implement pokemon.setCustomNature + nature unlock utility method(s) * update doc --------- Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>
This commit is contained in:
parent
c2afac8b02
commit
7dc4210f71
@ -138,7 +138,7 @@ export const ShadyVitaminDealerEncounter: MysteryEncounter =
|
|||||||
newNature = randSeedInt(25) as Nature;
|
newNature = randSeedInt(25) as Nature;
|
||||||
}
|
}
|
||||||
|
|
||||||
chosenPokemon.customPokemonData.nature = newNature;
|
chosenPokemon.setCustomNature(newNature);
|
||||||
encounter.setDialogueToken("newNature", getNatureName(newNature));
|
encounter.setDialogueToken("newNature", getNatureName(newNature));
|
||||||
queueEncounterMessage(scene, `${namespace}:cheap_side_effects`);
|
queueEncounterMessage(scene, `${namespace}:cheap_side_effects`);
|
||||||
setEncounterExp(scene, [ chosenPokemon.id ], 100);
|
setEncounterExp(scene, [ chosenPokemon.id ], 100);
|
||||||
|
@ -226,8 +226,8 @@ export const TrainingSessionEncounter: MysteryEncounter =
|
|||||||
const onBeforeRewardsPhase = () => {
|
const onBeforeRewardsPhase = () => {
|
||||||
queueEncounterMessage(scene, `${namespace}:option.2.finished`);
|
queueEncounterMessage(scene, `${namespace}:option.2.finished`);
|
||||||
// Add the pokemon back to party with Nature change
|
// Add the pokemon back to party with Nature change
|
||||||
playerPokemon.setNature(encounter.misc.chosenNature);
|
playerPokemon.setCustomNature(encounter.misc.chosenNature);
|
||||||
scene.gameData.setPokemonCaught(playerPokemon, false);
|
scene.gameData.unlockSpeciesNature(playerPokemon.species, encounter.misc.chosenNature);
|
||||||
|
|
||||||
// Add pokemon and modifiers back
|
// Add pokemon and modifiers back
|
||||||
scene.getPlayerParty().push(playerPokemon);
|
scene.getPlayerParty().push(playerPokemon);
|
||||||
|
@ -1072,6 +1072,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
this.calculateStats();
|
this.calculateStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCustomNature(nature: Nature): void {
|
||||||
|
this.customPokemonData.nature = nature;
|
||||||
|
this.calculateStats();
|
||||||
|
}
|
||||||
|
|
||||||
generateNature(naturePool?: Nature[]): void {
|
generateNature(naturePool?: Nature[]): void {
|
||||||
if (naturePool === undefined) {
|
if (naturePool === undefined) {
|
||||||
naturePool = Utils.getEnumValues(Nature);
|
naturePool = Utils.getEnumValues(Nature);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import type BattleScene from "#app/battle-scene";
|
import type BattleScene from "#app/battle-scene";
|
||||||
import { FusionSpeciesFormEvolution, pokemonEvolutions, pokemonPrevolutions } from "#app/data/balance/pokemon-evolutions";
|
import { FusionSpeciesFormEvolution, pokemonEvolutions } from "#app/data/balance/pokemon-evolutions";
|
||||||
import { getBerryEffectFunc, getBerryPredicate } from "#app/data/berry";
|
import { getBerryEffectFunc, getBerryPredicate } from "#app/data/berry";
|
||||||
import { getLevelTotalExp } from "#app/data/exp";
|
import { getLevelTotalExp } from "#app/data/exp";
|
||||||
import { allMoves } from "#app/data/move";
|
import { allMoves } from "#app/data/move";
|
||||||
@ -2197,14 +2197,8 @@ export class PokemonNatureChangeModifier extends ConsumablePokemonModifier {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
override apply(playerPokemon: PlayerPokemon): boolean {
|
override apply(playerPokemon: PlayerPokemon): boolean {
|
||||||
playerPokemon.customPokemonData.nature = this.nature;
|
playerPokemon.setCustomNature(this.nature);
|
||||||
let speciesId = playerPokemon.species.speciesId;
|
playerPokemon.scene.gameData.unlockSpeciesNature(playerPokemon.species, this.nature);
|
||||||
playerPokemon.scene.gameData.dexData[speciesId].natureAttr |= 1 << (this.nature + 1);
|
|
||||||
|
|
||||||
while (pokemonPrevolutions.hasOwnProperty(speciesId)) {
|
|
||||||
speciesId = pokemonPrevolutions[speciesId];
|
|
||||||
playerPokemon.scene.gameData.dexData[speciesId].natureAttr |= 1 << (this.nature + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1791,6 +1791,32 @@ export class GameData {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the root species of a given {@PokemonSpecies} has been unlocked in the dex
|
||||||
|
*/
|
||||||
|
isRootSpeciesUnlocked(species: PokemonSpecies): boolean {
|
||||||
|
return !!this.dexData[species.getRootSpeciesId()]?.caughtAttr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlocks the given {@linkcode Nature} for a {@linkcode PokemonSpecies} and its prevolutions.
|
||||||
|
* Will fail silently if root species has not been unlocked
|
||||||
|
*/
|
||||||
|
unlockSpeciesNature(species: PokemonSpecies, nature: Nature): void {
|
||||||
|
if (!this.isRootSpeciesUnlocked(species)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//recursively unlock nature for species and prevolutions
|
||||||
|
const _unlockSpeciesNature = (speciesId: Species) => {
|
||||||
|
this.dexData[speciesId].natureAttr |= 1 << (nature + 1);
|
||||||
|
if (pokemonPrevolutions.hasOwnProperty(speciesId)) {
|
||||||
|
_unlockSpeciesNature(pokemonPrevolutions[speciesId]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
_unlockSpeciesNature(species.speciesId);
|
||||||
|
}
|
||||||
|
|
||||||
updateSpeciesDexIvs(speciesId: Species, ivs: integer[]): void {
|
updateSpeciesDexIvs(speciesId: Species, ivs: integer[]): void {
|
||||||
let dexEntry: DexEntry;
|
let dexEntry: DexEntry;
|
||||||
do {
|
do {
|
||||||
|
Loading…
Reference in New Issue
Block a user