From 302f1e51a0b20ba2c40ff309e58462b69d841284 Mon Sep 17 00:00:00 2001 From: "Amani H." <109637146+xsn34kzx@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:51:20 -0400 Subject: [PATCH] [Enhancement] Allow Starters to Remember Egg Moves (#2482) * Allow Starters to Remember Egg Moves * Adjust Documentation * Minor NIT --- src/field/pokemon.ts | 39 +++++++++++++++++++++++++++++++++++--- src/system/pokemon-data.ts | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 22d0410233f..f2b0d02e245 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -84,6 +84,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { public friendship: integer; public metLevel: integer; public metBiome: Biome | -1; + public metSpecies: Species; public luck: integer; public pauseEvolutions: boolean; public pokerus: boolean; @@ -173,6 +174,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.metLevel = dataSource.metLevel || 5; this.luck = dataSource.luck; this.metBiome = dataSource.metBiome; + this.metSpecies = dataSource.metSpecies ?? (this.metBiome !== -1 ? this.species.speciesId : this.species.getRootSpeciesId(true)); this.pauseEvolutions = dataSource.pauseEvolutions; this.pokerus = !!dataSource.pokerus; this.fusionSpecies = dataSource.fusionSpecies instanceof PokemonSpecies ? dataSource.fusionSpecies : getPokemonSpecies(dataSource.fusionSpecies); @@ -213,6 +215,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.friendship = species.baseFriendship; this.metLevel = level; this.metBiome = scene.currentBattle ? scene.arena.biomeType : -1; + this.metSpecies = species.speciesId; this.pokerus = false; if (level > 1) { @@ -885,11 +888,40 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } /** - * All moves that could be relearned by this pokemon at this point. Used for memory mushrooms. - * @returns {Moves[]} The valid moves + * Checks which egg moves have been unlocked for the {@linkcode Pokemon} based + * on the species it was met at or by the first {@linkcode Pokemon} in its evolution + * line that can act as a starter and provides those egg moves. + * @returns an array of {@linkcode Moves}, the length of which is determined by how many + * egg moves are unlocked for that species. + */ + getUnlockedEggMoves(): Moves[] { + const moves: Moves[] = []; + const species = this.metSpecies in speciesEggMoves ? this.metSpecies : this.getSpeciesForm(true).getRootSpeciesId(true); + if (species in speciesEggMoves) { + for (let i = 0; i < 4; i++) { + if (this.scene.gameData.starterData[species].eggMoves & (1 << i)) { + moves.push(speciesEggMoves[species][i]); + } + } + } + return moves; + } + + /** + * Gets all possible learnable level moves for the {@linkcode Pokemon}, + * excluding any moves already known. + * + * Available egg moves are only included if the {@linkcode Pokemon} was + * in the starting party of the run. + * @returns an array of {@linkcode Moves}, the length of which is determined + * by how many learnable moves there are for the {@linkcode Pokemon}. */ getLearnableLevelMoves(): Moves[] { - return this.getLevelMoves(1, true, false, true).map(lm => lm[1]).filter(lm => !this.moveset.filter(m => m.moveId === lm).length).filter((move: Moves, i: integer, array: Moves[]) => array.indexOf(move) === i); + let levelMoves = this.getLevelMoves(1, true).map(lm => lm[1]); + if (this.metBiome === -1) { + levelMoves = this.getUnlockedEggMoves().concat(levelMoves); + } + return levelMoves.filter(lm => !this.moveset.some(m => m.moveId === lm)); } /** @@ -4075,6 +4107,7 @@ export class EnemyPokemon extends Pokemon { this.pokeball = pokeballType; this.metLevel = this.level; this.metBiome = this.scene.arena.biomeType; + this.metSpecies = this.species.speciesId; const newPokemon = this.scene.addPlayerPokemon(this.species, this.level, this.abilityIndex, this.formIndex, this.gender, this.shiny, this.variant, this.ivs, this.nature, this); party.push(newPokemon); ret = newPokemon; diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 7e8f1e21c07..ca072c9eec8 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -38,6 +38,7 @@ export default class PokemonData { public friendship: integer; public metLevel: integer; public metBiome: Biome | -1; + public metSpecies: Species; public luck: integer; public pauseEvolutions: boolean; public pokerus: boolean; @@ -83,6 +84,7 @@ export default class PokemonData { this.friendship = source.friendship !== undefined ? source.friendship : getPokemonSpecies(this.species).baseFriendship; this.metLevel = source.metLevel || 5; this.metBiome = source.metBiome !== undefined ? source.metBiome : -1; + this.metSpecies = source.metSpecies; this.luck = source.luck !== undefined ? source.luck : (source.shiny ? (source.variant + 1) : 0); if (!forHistory) { this.pauseEvolutions = !!source.pauseEvolutions;