Skip to content

Commit

Permalink
Allow Starters to Remember Egg Moves
Browse files Browse the repository at this point in the history
  • Loading branch information
xsn34kzx committed Jun 21, 2024
1 parent a3b029f commit 825b36f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/field/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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[] {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/system/pokemon-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 825b36f

Please sign in to comment.