From 84f6456972fb514fbce017a0d7b981ea0f88dbb2 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 2 Apr 2024 23:00:56 -0400 Subject: [PATCH] Use nature override property instead of overwriting base nature --- src/data/ability.ts | 2 +- src/data/daily-run.ts | 2 +- src/data/pokemon-evolutions.ts | 2 +- src/data/pokemon-forms.ts | 2 +- src/field/pokemon.ts | 23 +++++++++++++++-------- src/modifier/modifier-type.ts | 2 +- src/modifier/modifier.ts | 2 +- src/system/pokemon-data.ts | 2 ++ src/ui/pokemon-info-container.ts | 2 +- src/ui/summary-ui-handler.ts | 4 ++-- 10 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 923a34ecdea..3d9280ecb46 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1503,7 +1503,7 @@ export class SyncEncounterNatureAbAttr extends AbAttr { } apply(pokemon: Pokemon, cancelled: Utils.BooleanHolder, args: any[]): boolean { - (args[0] as Pokemon).setNature(pokemon.nature); + (args[0] as Pokemon).setNature(pokemon.getNature()); return true; } diff --git a/src/data/daily-run.ts b/src/data/daily-run.ts index 858552ef9b5..14401d7bbd6 100644 --- a/src/data/daily-run.ts +++ b/src/data/daily-run.ts @@ -64,7 +64,7 @@ function getDailyRunStarter(scene: BattleScene, starterSpeciesForm: PokemonSpeci const starter: Starter = { species: starterSpecies, dexAttr: pokemon.getDexAttr(), - nature: pokemon.nature, + nature: pokemon.getNature(), pokerus: pokemon.pokerus }; pokemon.destroy(); diff --git a/src/data/pokemon-evolutions.ts b/src/data/pokemon-evolutions.ts index d4a9591b5da..cc9d07dc92d 100644 --- a/src/data/pokemon-evolutions.ts +++ b/src/data/pokemon-evolutions.ts @@ -1038,7 +1038,7 @@ export const pokemonEvolutions: PokemonEvolutions = { ], [Species.TOXEL]: [ new SpeciesFormEvolution(Species.TOXTRICITY, '', 'lowkey', 30, null, - new SpeciesEvolutionCondition(p => [ Nature.LONELY, Nature.BOLD, Nature.RELAXED, Nature.TIMID, Nature.SERIOUS, Nature.MODEST, Nature.MILD, Nature.QUIET, Nature.BASHFUL, Nature.CALM, Nature.GENTLE, Nature.CAREFUL ].indexOf(p.nature) > -1)), + new SpeciesEvolutionCondition(p => [ Nature.LONELY, Nature.BOLD, Nature.RELAXED, Nature.TIMID, Nature.SERIOUS, Nature.MODEST, Nature.MILD, Nature.QUIET, Nature.BASHFUL, Nature.CALM, Nature.GENTLE, Nature.CAREFUL ].indexOf(p.getNature()) > -1)), new SpeciesFormEvolution(Species.TOXTRICITY, '', 'amped', 30, null, null) ], [Species.SIZZLIPEDE]: [ diff --git a/src/data/pokemon-forms.ts b/src/data/pokemon-forms.ts index 1a76a3600d7..e2871f6c2b4 100644 --- a/src/data/pokemon-forms.ts +++ b/src/data/pokemon-forms.ts @@ -293,7 +293,7 @@ export class SpeciesDefaultFormMatchTrigger extends SpeciesFormChangeTrigger { } canChange(pokemon: Pokemon): boolean { - return this.formKey === pokemon.species.forms[pokemon.scene.getSpeciesFormIndex(pokemon.species, pokemon.gender, pokemon.nature, true)].formKey; + return this.formKey === pokemon.species.forms[pokemon.scene.getSpeciesFormIndex(pokemon.species, pokemon.gender, pokemon.getNature(), true)].formKey; } } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 839b54844a7..7442501aa88 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -64,6 +64,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { public stats: integer[]; public ivs: integer[]; public nature: Nature; + public natureOverride: Nature | -1; public moveset: PokemonMove[]; public status: Status; public friendship: integer; @@ -125,6 +126,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.stats = dataSource.stats; this.ivs = dataSource.ivs; this.nature = dataSource.nature || 0 as Nature; + this.natureOverride = dataSource.natureOverride !== undefined ? dataSource.natureOverride : -1; this.moveset = dataSource.moveset; this.status = dataSource.status; this.friendship = dataSource.friendship !== undefined ? dataSource.friendship : this.species.baseFriendship; @@ -152,18 +154,18 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.gender = Gender.FEMALE; } } - - if (this.formIndex === undefined) - this.formIndex = this.scene.getSpeciesFormIndex(species, this.gender, this.nature, this.isPlayer()); - - if (this.shiny === undefined) - this.trySetShiny(); - + if (nature !== undefined) this.setNature(nature); else this.generateNature(); + if (this.formIndex === undefined) + this.formIndex = this.scene.getSpeciesFormIndex(species, this.gender, this.getNature(), this.isPlayer()); + + if (this.shiny === undefined) + this.trySetShiny(); + this.friendship = species.baseFriendship; this.metLevel = level; this.metBiome = scene.currentBattle ? scene.arena.biomeType : -1; @@ -560,6 +562,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } + getNature(): Nature { + return this.natureOverride !== -1 ? this.natureOverride : this.nature; + } + setNature(nature: Nature): void { this.nature = nature; this.calculateStats(); @@ -887,7 +893,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.fusionGender = Gender.FEMALE; } - this.fusionFormIndex = this.scene.getSpeciesFormIndex(this.fusionSpecies, this.fusionGender, this.nature, true); + this.fusionFormIndex = this.scene.getSpeciesFormIndex(this.fusionSpecies, this.fusionGender, this.getNature(), true); this.generateName(); } @@ -2119,6 +2125,7 @@ export class PlayerPokemon extends Pokemon { const newEvolution = pokemonEvolutions[this.species.speciesId][1]; if (newEvolution.condition.predicate(this)) { const newPokemon = this.scene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.ivs, this.nature); + newPokemon.natureOverride = this.natureOverride; this.scene.getParty().push(newPokemon); newPokemon.evolve(newEvolution); const modifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index abe7121471f..a090cac1b7e 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -271,7 +271,7 @@ export class PokemonNatureChangeModifierType extends PokemonModifierType { constructor(nature: Nature) { super(`${getNatureName(nature)} Mint`, `Changes a Pokémon\'s nature to ${getNatureName(nature, true, true, true)}`, ((_type, args) => new Modifiers.PokemonNatureChangeModifier(this, (args[0] as PlayerPokemon).id, this.nature)), ((pokemon: PlayerPokemon) => { - if (pokemon.nature === this.nature) + if (pokemon.getNature() === this.nature) return PartyUiHandler.NoEffectMessage; return null; }), `mint_${Utils.getEnumKeys(Stat).find(s => getNatureStatMultiplier(nature, Stat[s]) > 1)?.toLowerCase() || 'neutral' }`, 'mint'); diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 31a5f5dbb43..8e21da544ed 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -1105,7 +1105,7 @@ export class PokemonNatureChangeModifier extends ConsumablePokemonModifier { apply(args: any[]): boolean { const pokemon = args[0] as Pokemon; - pokemon.nature = this.nature; + pokemon.natureOverride = this.nature; return true; } diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index c2cfff0d5d2..0ad01dd0f36 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -27,6 +27,7 @@ export default class PokemonData { public stats: integer[]; public ivs: integer[]; public nature: Nature; + public natureOverride: Nature | -1; public moveset: PokemonMove[]; public status: Status; public friendship: integer; @@ -64,6 +65,7 @@ export default class PokemonData { this.stats = source.stats; this.ivs = source.ivs; this.nature = source.nature !== undefined ? source.nature : 0 as Nature; + this.natureOverride = source.natureOverride !== undefined ? source.natureOverride : -1; this.friendship = source.friendship !== undefined ? source.friendship : getPokemonSpecies(this.species).baseFriendship; this.metLevel = source.metLevel || 5; this.metBiome = source.metBiome !== undefined ? source.metBiome : -1; diff --git a/src/ui/pokemon-info-container.ts b/src/ui/pokemon-info-container.ts index 355c08e2716..75c394896d6 100644 --- a/src/ui/pokemon-info-container.ts +++ b/src/ui/pokemon-info-container.ts @@ -121,7 +121,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { this.pokemonGenderText.setVisible(false); this.pokemonAbilityText.setText(pokemon.getAbility(true).name); - this.pokemonNatureText.setText(getNatureName(pokemon.nature, true)); + this.pokemonNatureText.setText(getNatureName(pokemon.getNature(), true)); const originalIvs: integer[] = this.scene.gameData.dexData[pokemon.species.speciesId].caughtAttr ? this.scene.gameData.dexData[pokemon.species.speciesId].ivs diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index 97aea72d40a..5c50946283e 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -574,7 +574,7 @@ export default class SummaryUiHandler extends UiHandler { }); } - let memoString = `${getBBCodeFrag(Utils.toReadableString(Nature[this.pokemon.nature]), TextStyle.SUMMARY_RED)}${getBBCodeFrag(' nature,', TextStyle.WINDOW_ALT)}\n${getBBCodeFrag(`${this.pokemon.metBiome === -1 ? 'apparently ' : ''}met at Lv`, TextStyle.WINDOW_ALT)}${getBBCodeFrag(this.pokemon.metLevel.toString(), TextStyle.SUMMARY_RED)}${getBBCodeFrag(',', TextStyle.WINDOW_ALT)}\n${getBBCodeFrag(getBiomeName(this.pokemon.metBiome), TextStyle.SUMMARY_RED)}${getBBCodeFrag('.', TextStyle.WINDOW_ALT)}`; + let memoString = `${getBBCodeFrag(Utils.toReadableString(Nature[this.pokemon.getNature()]), TextStyle.SUMMARY_RED)}${getBBCodeFrag(' nature,', TextStyle.WINDOW_ALT)}\n${getBBCodeFrag(`${this.pokemon.metBiome === -1 ? 'apparently ' : ''}met at Lv`, TextStyle.WINDOW_ALT)}${getBBCodeFrag(this.pokemon.metLevel.toString(), TextStyle.SUMMARY_RED)}${getBBCodeFrag(',', TextStyle.WINDOW_ALT)}\n${getBBCodeFrag(getBiomeName(this.pokemon.metBiome), TextStyle.SUMMARY_RED)}${getBBCodeFrag('.', TextStyle.WINDOW_ALT)}`; const memoText = addBBCodeTextObject(this.scene, 7, 113, memoString, TextStyle.WINDOW_ALT); memoText.setOrigin(0, 0); @@ -593,7 +593,7 @@ export default class SummaryUiHandler extends UiHandler { const rowIndex = s % 3; const colIndex = Math.floor(s / 3); - const natureStatMultiplier = getNatureStatMultiplier(this.pokemon.nature, s); + const natureStatMultiplier = getNatureStatMultiplier(this.pokemon.getNature(), s); const statLabel = addTextObject(this.scene, 27 + 115 * colIndex, 56 + 16 * rowIndex, statName, natureStatMultiplier === 1 ? TextStyle.SUMMARY : natureStatMultiplier > 1 ? TextStyle.SUMMARY_PINK : TextStyle.SUMMARY_BLUE); statLabel.setOrigin(0.5, 0);