From bbca34bfcd5aa71b3ca96a9fa3059ae9999bc29e Mon Sep 17 00:00:00 2001 From: Mason S <132116525+ElizaAlex@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:09:21 -0400 Subject: [PATCH] [Feature] Updated Smeargle learnset to pre gen-9 implementation (#2986) Updated Pokemon.getLevelMoves() Now enforces uniqueness AFTER filtering moves within the given range. This allows a pokemon to learn the same move at two different levels. Updated pokemon-level-moves.ts Changed Smeargle to learn Sketch at levels 11, 21, 31, ..., 91, instead of only at level 1. --- src/data/pokemon-level-moves.ts | 13 ++++++-- src/field/pokemon.ts | 53 +++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/data/pokemon-level-moves.ts b/src/data/pokemon-level-moves.ts index 704640a3c1e..9e8c7053334 100644 --- a/src/data/pokemon-level-moves.ts +++ b/src/data/pokemon-level-moves.ts @@ -4074,11 +4074,18 @@ export const pokemonSpeciesLevelMoves: PokemonSpeciesLevelMoves = { [ 49, Moves.IMPRISON ], [ 55, Moves.DOUBLE_EDGE ], ], + // Reverting Smeargle back to pre gen9 implementation, to make it less dependent on access to Memory Mushrooms [Species.SMEARGLE]: [ [ 1, Moves.SKETCH ], - [ 1, Moves.SKETCH ], - [ 1, Moves.SKETCH ], - [ 1, Moves.SKETCH ], + [ 11, Moves.SKETCH ], + [ 21, Moves.SKETCH ], + [ 31, Moves.SKETCH ], + [ 41, Moves.SKETCH ], + [ 51, Moves.SKETCH ], + [ 61, Moves.SKETCH ], + [ 71, Moves.SKETCH ], + [ 81, Moves.SKETCH ], + [ 91, Moves.SKETCH ], ], [Species.TYROGUE]: [ [ 1, Moves.TACKLE ], diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 4e6b365d093..b669e030acb 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1413,30 +1413,53 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } levelMoves.sort((lma: [integer, integer], lmb: [integer, integer]) => lma[0] > lmb[0] ? 1 : lma[0] < lmb[0] ? -1 : 0); - const uniqueMoves: Moves[] = []; + + + /** + * Filter out moves not within the correct level range(s) + * Includes moves below startingLevel, or of specifically level 0 if + * includeRelearnerMoves or includeEvolutionMoves are true respectively + */ levelMoves = levelMoves.filter(lm => { - if (uniqueMoves.find(m => m === lm[1])) { - return false; - } - uniqueMoves.push(lm[1]); - return true; + const level = lm[0]; + const isRelearner = level < startingLevel; + const allowedEvolutionMove = (level === 0) && includeEvolutionMoves; + + return !(level > this.level) + && (includeRelearnerMoves || !isRelearner || allowedEvolutionMove); }); + /** + * This must be done AFTER filtering by level, else if the same move shows up + * in levelMoves multiple times all but the lowest level one will be skipped. + * This causes problems when there are intentional duplicates (i.e. Smeargle with Sketch) + */ if (levelMoves) { - for (const lm of levelMoves) { - const level = lm[0]; - if (!includeRelearnerMoves && ((level > 0 && level < startingLevel) || (!includeEvolutionMoves && level === 0) || level < 0)) { - continue; - } else if (level > this.level) { - break; - } - ret.push(lm); - } + this.getUniqueMoves(levelMoves,ret); } return ret; } + /** + * Helper function for getLevelMoves. + * Finds all non-duplicate items from the input, and pushes them into the output. + * Two items count as duplicate if they have the same Move, regardless of level. + * + * @param levelMoves the input array to search for non-duplicates from + * @param ret the output array to be pushed into. + */ + private getUniqueMoves(levelMoves: LevelMoves, ret: LevelMoves ): void { + const uniqueMoves : Moves[] = []; + for (const lm of levelMoves) { + if (!uniqueMoves.find(m => m === lm[1])) { + uniqueMoves.push(lm[1]); + ret.push(lm); + } + } + } + + setMove(moveIndex: integer, moveId: Moves): void { const move = moveId ? new PokemonMove(moveId) : null; this.moveset[moveIndex] = move;