From 825b36fcde0386c9c61e6c885e205e97eff38bc9 Mon Sep 17 00:00:00 2001 From: xsn34kzx Date: Thu, 20 Jun 2024 21:51:32 -0400 Subject: [PATCH] Allow Starters to Remember Egg Moves --- src/field/pokemon.ts | 39 +++++++++++++++++++++++++++++++++++++- src/system/pokemon-data.ts | 2 ++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 5b37365bec16..91a4b8d4f243 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -82,6 +82,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; @@ -160,6 +161,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); @@ -200,6 +202,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) { @@ -847,8 +850,41 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return ret; } + /** + * 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 + */ getLearnableLevelMoves(): Moves[] { - return this.getLevelMoves(1, 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)); } getTypes(includeTeraType = false, forDefend: boolean = false, ignoreOverride?: boolean): Type[] { @@ -3795,6 +3831,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 e30cfd7e24e1..0fbc9bfb368a 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -37,6 +37,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; @@ -80,6 +81,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;