account for undefined egg moves

This commit is contained in:
ImperialSympathizer 2024-09-24 14:06:59 -04:00
parent 219215f54c
commit d52f691d43
4 changed files with 36 additions and 37 deletions

View File

@ -25,7 +25,6 @@ import { getEncounterText, showEncounterText } from "#app/data/mystery-encounter
import { trainerNamePools } from "#app/data/trainer-names"; import { trainerNamePools } from "#app/data/trainer-names";
import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/game-mode"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/game-mode";
import { addPokemonDataToDexAndValidateAchievements } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils"; import { addPokemonDataToDexAndValidateAchievements } from "#app/data/mystery-encounters/utils/encounter-pokemon-utils";
import { Moves } from "#enums/moves";
/** the i18n namespace for the encounter */ /** the i18n namespace for the encounter */
const namespace = "mysteryEncounter:globalTradeSystem"; 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 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)) { if (!tradePokemon.shiny && (!tradePokemon.species.abilityHidden || tradePokemon.abilityIndex < hiddenIndex)) {
const eggMoves: Moves[] = tradePokemon.getEggMoves(); const eggMoves = tradePokemon.getEggMoves();
if (eggMoves) { if (eggMoves) {
// Cannot gen the rare egg move, only 1 of the first 3 common moves
} const eggMove = eggMoves[randSeedInt(3)];
// Cannot gen the rare egg move, only 1 of the first 3 common moves if (!tradePokemon.moveset.some(m => m?.moveId === eggMove)) {
const eggMove = eggMoves[randSeedInt(3)]; if (tradePokemon.moveset.length < 4) {
if (!tradePokemon.moveset.some(m => m?.moveId === eggMove)) { tradePokemon.moveset.push(new PokemonMove(eggMove));
if (tradePokemon.moveset.length < 4) { } else {
tradePokemon.moveset.push(new PokemonMove(eggMove)); const eggMoveIndex = randSeedInt(4);
} else { tradePokemon.moveset[eggMoveIndex] = new PokemonMove(eggMove);
const eggMoveIndex = randSeedInt(4); }
tradePokemon.moveset[eggMoveIndex] = new PokemonMove(eggMove);
} }
} }
} }

View File

@ -54,16 +54,18 @@ export const UncommonBreedEncounter: MysteryEncounter =
const pokemon = new EnemyPokemon(scene, species, level, TrainerSlot.NONE, true); const pokemon = new EnemyPokemon(scene, species, level, TrainerSlot.NONE, true);
// Pokemon will always have one of its egg moves in its moveset // Pokemon will always have one of its egg moves in its moveset
const eggMoves: Moves[] = pokemon.getEggMoves(); const eggMoves = pokemon.getEggMoves();
const eggMoveIndex = randSeedInt(4); if (eggMoves) {
const randomEggMove: Moves = eggMoves[eggMoveIndex]; const eggMoveIndex = randSeedInt(4);
encounter.misc = { const randomEggMove: Moves = eggMoves[eggMoveIndex];
eggMove: randomEggMove encounter.misc = {
}; eggMove: randomEggMove
if (pokemon.moveset.length < 4) { };
pokemon.moveset.push(new PokemonMove(randomEggMove)); if (pokemon.moveset.length < 4) {
} else { pokemon.moveset.push(new PokemonMove(randomEggMove));
pokemon.moveset[0] = new PokemonMove(randomEggMove); } else {
pokemon.moveset[0] = new PokemonMove(randomEggMove);
}
} }
encounter.misc.pokemon = pokemon; encounter.misc.pokemon = pokemon;
@ -243,14 +245,16 @@ export const UncommonBreedEncounter: MysteryEncounter =
.build(); .build();
function givePokemonExtraEggMove(pokemon: EnemyPokemon, previousEggMove: Moves) { function givePokemonExtraEggMove(pokemon: EnemyPokemon, previousEggMove: Moves) {
const eggMoves: Moves[] = pokemon.getEggMoves(); const eggMoves = pokemon.getEggMoves();
let randomEggMove: Moves = eggMoves[randSeedInt(4)]; if (eggMoves) {
while (randomEggMove === previousEggMove) { let randomEggMove: Moves = eggMoves[randSeedInt(4)];
randomEggMove = eggMoves[randSeedInt(4)]; while (randomEggMove === previousEggMove) {
} randomEggMove = eggMoves[randSeedInt(4)];
if (pokemon.moveset.length < 4) { }
pokemon.moveset.push(new PokemonMove(randomEggMove)); if (pokemon.moveset.length < 4) {
} else { pokemon.moveset.push(new PokemonMove(randomEggMove));
pokemon.moveset[1] = new PokemonMove(randomEggMove); } else {
pokemon.moveset[1] = new PokemonMove(randomEggMove);
}
} }
} }

View File

@ -12,7 +12,6 @@ import { IntegerHolder, isNullOrUndefined, randSeedInt, randSeedShuffle } from "
import PokemonSpecies, { allSpecies, getPokemonSpecies } from "#app/data/pokemon-species"; import PokemonSpecies, { allSpecies, getPokemonSpecies } from "#app/data/pokemon-species";
import { HiddenAbilityRateBoosterModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier } from "#app/modifier/modifier"; import { HiddenAbilityRateBoosterModifier, PokemonFormChangeItemModifier, PokemonHeldItemModifier } from "#app/modifier/modifier";
import { achvs } from "#app/system/achv"; 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 { MysteryEncounterPokemonData } from "#app/data/mystery-encounters/mystery-encounter-pokemon-data";
import { showEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils"; import { showEncounterText } from "#app/data/mystery-encounters/utils/encounter-dialogue-utils";
import { modifierTypes } from "#app/modifier/modifier-type"; import { modifierTypes } from "#app/modifier/modifier-type";
@ -22,7 +21,6 @@ import { getLevelTotalExp } from "#app/data/exp";
import { Stat } from "#enums/stat"; import { Stat } from "#enums/stat";
import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/game-mode"; import { CLASSIC_MODE_MYSTERY_ENCOUNTER_WAVES } from "#app/game-mode";
import { Challenges } from "#enums/challenges"; import { Challenges } from "#enums/challenges";
import { Moves } from "#enums/moves";
/** i18n namespace for encounter */ /** i18n namespace for encounter */
const namespace = "mysteryEncounter:weirdDream"; const namespace = "mysteryEncounter:weirdDream";
@ -553,8 +551,8 @@ function doSideBySideTransformations(scene: BattleScene, transformations: Pokemo
*/ */
async function addEggMoveToNewPokemonMoveset(scene: BattleScene, newPokemon: PlayerPokemon, speciesRootForm: Species): Promise<number | null> { async function addEggMoveToNewPokemonMoveset(scene: BattleScene, newPokemon: PlayerPokemon, speciesRootForm: Species): Promise<number | null> {
let eggMoveIndex: null | number = null; let eggMoveIndex: null | number = null;
if (speciesEggMoves.hasOwnProperty(speciesRootForm)) { const eggMoves = newPokemon.getEggMoves()?.slice(0);
const eggMoves: Moves[] = newPokemon.getEggMoves().slice(0); if (eggMoves) {
const eggMoveIndices = [0, 1, 2, 3]; const eggMoveIndices = [0, 1, 2, 3];
randSeedShuffle(eggMoveIndices); randSeedShuffle(eggMoveIndices);
let randomEggMoveIndex = eggMoveIndices.pop(); let randomEggMoveIndex = eggMoveIndices.pop();

View File

@ -1799,7 +1799,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* *
* @returns list of egg moves * @returns list of egg moves
*/ */
getEggMoves() : Moves[] { getEggMoves() : Moves[] | undefined {
return speciesEggMoves[this.getSpeciesForm().getRootSpeciesId(true)]; return speciesEggMoves[this.getSpeciesForm().getRootSpeciesId(true)];
} }