From d52f691d43501f3ea8ca5a20807e2db23d02251a Mon Sep 17 00:00:00 2001 From: ImperialSympathizer Date: Tue, 24 Sep 2024 14:06:59 -0400 Subject: [PATCH] account for undefined egg moves --- .../global-trade-system-encounter.ts | 23 +++++----- .../encounters/uncommon-breed-encounter.ts | 42 ++++++++++--------- .../encounters/weird-dream-encounter.ts | 6 +-- src/field/pokemon.ts | 2 +- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts b/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts index 99be66b820f..f3765c9acba 100644 --- a/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts +++ b/src/data/mystery-encounters/encounters/global-trade-system-encounter.ts @@ -25,7 +25,6 @@ import { getEncounterText, showEncounterText } from "#app/data/mystery-encounter import { trainerNamePools } from "#app/data/trainer-names"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/game-mode"; import { addPokemonDataToDexAndValidateAchievements } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils"; -import { Moves } from "#enums/moves"; /** the i18n namespace for the encounter */ const namespace = "mysteryEncounter:globalTradeSystem"; @@ -258,19 +257,17 @@ export const GlobalTradeSystemEncounter: MysteryEncounter = // If Pokemon is still not shiny or with HA, give the Pokemon a random Common egg move in its moveset if (!tradePokemon.shiny && (!tradePokemon.species.abilityHidden || tradePokemon.abilityIndex < hiddenIndex)) { - const eggMoves: Moves[] = tradePokemon.getEggMoves(); - + const eggMoves = tradePokemon.getEggMoves(); if (eggMoves) { - - } - // Cannot gen the rare egg move, only 1 of the first 3 common moves - const eggMove = eggMoves[randSeedInt(3)]; - if (!tradePokemon.moveset.some(m => m?.moveId === eggMove)) { - if (tradePokemon.moveset.length < 4) { - tradePokemon.moveset.push(new PokemonMove(eggMove)); - } else { - const eggMoveIndex = randSeedInt(4); - tradePokemon.moveset[eggMoveIndex] = new PokemonMove(eggMove); + // Cannot gen the rare egg move, only 1 of the first 3 common moves + const eggMove = eggMoves[randSeedInt(3)]; + if (!tradePokemon.moveset.some(m => m?.moveId === eggMove)) { + if (tradePokemon.moveset.length < 4) { + tradePokemon.moveset.push(new PokemonMove(eggMove)); + } else { + const eggMoveIndex = randSeedInt(4); + tradePokemon.moveset[eggMoveIndex] = new PokemonMove(eggMove); + } } } } diff --git a/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts b/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts index c283ff0aa69..24298a633df 100644 --- a/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts +++ b/src/data/mystery-encounters/encounters/uncommon-breed-encounter.ts @@ -54,16 +54,18 @@ export const UncommonBreedEncounter: MysteryEncounter = const pokemon = new EnemyPokemon(scene, species, level, TrainerSlot.NONE, true); // Pokemon will always have one of its egg moves in its moveset - const eggMoves: Moves[] = pokemon.getEggMoves(); - const eggMoveIndex = randSeedInt(4); - const randomEggMove: Moves = eggMoves[eggMoveIndex]; - encounter.misc = { - eggMove: randomEggMove - }; - if (pokemon.moveset.length < 4) { - pokemon.moveset.push(new PokemonMove(randomEggMove)); - } else { - pokemon.moveset[0] = new PokemonMove(randomEggMove); + const eggMoves = pokemon.getEggMoves(); + if (eggMoves) { + const eggMoveIndex = randSeedInt(4); + const randomEggMove: Moves = eggMoves[eggMoveIndex]; + encounter.misc = { + eggMove: randomEggMove + }; + if (pokemon.moveset.length < 4) { + pokemon.moveset.push(new PokemonMove(randomEggMove)); + } else { + pokemon.moveset[0] = new PokemonMove(randomEggMove); + } } encounter.misc.pokemon = pokemon; @@ -243,14 +245,16 @@ export const UncommonBreedEncounter: MysteryEncounter = .build(); function givePokemonExtraEggMove(pokemon: EnemyPokemon, previousEggMove: Moves) { - const eggMoves: Moves[] = pokemon.getEggMoves(); - let randomEggMove: Moves = eggMoves[randSeedInt(4)]; - while (randomEggMove === previousEggMove) { - randomEggMove = eggMoves[randSeedInt(4)]; - } - if (pokemon.moveset.length < 4) { - pokemon.moveset.push(new PokemonMove(randomEggMove)); - } else { - pokemon.moveset[1] = new PokemonMove(randomEggMove); + const eggMoves = pokemon.getEggMoves(); + if (eggMoves) { + let randomEggMove: Moves = eggMoves[randSeedInt(4)]; + while (randomEggMove === previousEggMove) { + randomEggMove = eggMoves[randSeedInt(4)]; + } + if (pokemon.moveset.length < 4) { + pokemon.moveset.push(new PokemonMove(randomEggMove)); + } else { + pokemon.moveset[1] = new PokemonMove(randomEggMove); + } } } diff --git a/src/data/mystery-encounters/encounters/weird-dream-encounter.ts b/src/data/mystery-encounters/encounters/weird-dream-encounter.ts index 33573fbe2d8..8fa60774a72 100644 --- a/src/data/mystery-encounters/encounters/weird-dream-encounter.ts +++ b/src/data/mystery-encounters/encounters/weird-dream-encounter.ts @@ -12,7 +12,6 @@ import { IntegerHolder, isNullOrUndefined, randSeedInt, randSeedShuffle } from " import PokemonSpecies, { allSpecies, getPokemonSpecies } from "#app/data/pokemon-species"; import { HiddenAbilityRateBoosterModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier } from "#app/modifier/modifier"; import { achvs } from "#app/system/achv"; -import { speciesEggMoves } from "#app/data/egg-moves"; import { MysteryEncounterPokemonData } from "#app/data/mystery-encounters/mystery-encounter-pokemon-data"; import { showEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils"; import { modifierTypes } from "#app/modifier/modifier-type"; @@ -22,7 +21,6 @@ import { getLevelTotalExp } from "#app/data/exp"; import { Stat } from "#enums/stat"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/game-mode"; import { Challenges } from "#enums/challenges"; -import { Moves } from "#enums/moves"; /** i18n namespace for encounter */ const namespace = "mysteryEncounter:weirdDream"; @@ -553,8 +551,8 @@ function doSideBySideTransformations(scene: BattleScene, transformations: Pokemo */ async function addEggMoveToNewPokemonMoveset(scene: BattleScene, newPokemon: PlayerPokemon, speciesRootForm: Species): Promise { let eggMoveIndex: null | number = null; - if (speciesEggMoves.hasOwnProperty(speciesRootForm)) { - const eggMoves: Moves[] = newPokemon.getEggMoves().slice(0); + const eggMoves = newPokemon.getEggMoves()?.slice(0); + if (eggMoves) { const eggMoveIndices = [0, 1, 2, 3]; randSeedShuffle(eggMoveIndices); let randomEggMoveIndex = eggMoveIndices.pop(); diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index f1183fa579e..14f93809414 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1799,7 +1799,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * * @returns list of egg moves */ - getEggMoves() : Moves[] { + getEggMoves() : Moves[] | undefined { return speciesEggMoves[this.getSpeciesForm().getRootSpeciesId(true)]; }