From d0842a7f95e8d7d9a8b9dc6f4a8a85f25e824734 Mon Sep 17 00:00:00 2001 From: AJ Fontaine Date: Mon, 19 Aug 2024 20:31:00 -0400 Subject: [PATCH] Allow mons to track and relearn used TMs --- src/field/pokemon.ts | 9 ++++++++- src/modifier/modifier.ts | 2 +- src/phases/learn-move-phase.ts | 10 +++++++++- src/system/pokemon-data.ts | 2 ++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 6a445a83b4e..ee9802d2e7f 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -118,6 +118,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { public maskEnabled: boolean; public maskSprite: Phaser.GameObjects.Sprite | null; + public usedTMs: Moves[]; + private shinySparkle: Phaser.GameObjects.Sprite; constructor(scene: BattleScene, x: number, y: number, species: PokemonSpecies, level: integer, abilityIndex?: integer, formIndex?: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData) { @@ -195,6 +197,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.fusionVariant = dataSource.fusionVariant || 0; this.fusionGender = dataSource.fusionGender; this.fusionLuck = dataSource.fusionLuck; + this.usedTMs = dataSource.usedTMs || []; } else { this.id = Utils.randSeedInt(4294967296); this.ivs = ivs || Utils.getIvsFromId(this.id); @@ -933,7 +936,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (this.metBiome === -1 && !this.scene.gameMode.isFreshStartChallenge() && !this.scene.gameMode.isDaily) { levelMoves = this.getUnlockedEggMoves().concat(levelMoves); } - return levelMoves.filter(lm => !this.moveset.some(m => m?.moveId === lm)); + levelMoves = this.usedTMs.filter(m => !levelMoves.includes(m)).concat(levelMoves); + levelMoves = levelMoves.filter(lm => !this.moveset.some(m => m?.moveId === lm)); + return levelMoves; } /** @@ -3275,6 +3280,7 @@ export default interface Pokemon { export class PlayerPokemon extends Pokemon { public compatibleTms: Moves[]; + public usedTms: Moves[]; constructor(scene: BattleScene, species: PokemonSpecies, level: integer, abilityIndex?: integer, formIndex?: integer, gender?: Gender, shiny?: boolean, variant?: Variant, ivs?: integer[], nature?: Nature, dataSource?: Pokemon | PokemonData) { super(scene, 106, 148, species, level, abilityIndex, formIndex, gender, shiny, variant, ivs, nature, dataSource); @@ -3298,6 +3304,7 @@ export class PlayerPokemon extends Pokemon { } } this.generateCompatibleTms(); + this.usedTms = []; } initBattleInfo(): void { diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 8a6598f5849..ab415d370d1 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -1625,7 +1625,7 @@ export class TmModifier extends ConsumablePokemonModifier { apply(args: any[]): boolean { const pokemon = args[0] as PlayerPokemon; - pokemon.scene.unshiftPhase(new LearnMovePhase(pokemon.scene, pokemon.scene.getParty().indexOf(pokemon), (this.type as ModifierTypes.TmModifierType).moveId)); + pokemon.scene.unshiftPhase(new LearnMovePhase(pokemon.scene, pokemon.scene.getParty().indexOf(pokemon), (this.type as ModifierTypes.TmModifierType).moveId, true)); return true; } diff --git a/src/phases/learn-move-phase.ts b/src/phases/learn-move-phase.ts index e30fc0c3d10..e128d390463 100644 --- a/src/phases/learn-move-phase.ts +++ b/src/phases/learn-move-phase.ts @@ -12,11 +12,13 @@ import { PlayerPartyMemberPokemonPhase } from "./player-party-member-pokemon-pha export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { private moveId: Moves; + private fromTM: boolean; - constructor(scene: BattleScene, partyMemberIndex: integer, moveId: Moves) { + constructor(scene: BattleScene, partyMemberIndex: integer, moveId: Moves, fromTM?: boolean) { super(scene, partyMemberIndex); this.moveId = moveId; + this.fromTM = fromTM || false; } start() { @@ -41,6 +43,9 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { if (emptyMoveIndex > -1) { pokemon.setMove(emptyMoveIndex, this.moveId); + if (this.fromTM) { + pokemon.usedTMs.push(this.moveId); + } initMoveAnim(this.scene, this.moveId).then(() => { loadMoveAnimAssets(this.scene, [this.moveId], true) .then(() => { @@ -84,6 +89,9 @@ export class LearnMovePhase extends PlayerPartyMemberPokemonPhase { this.scene.ui.showText(i18next.t("battle:countdownPoof"), null, () => { this.scene.ui.showText(i18next.t("battle:learnMoveForgetSuccess", { pokemonName: getPokemonNameWithAffix(pokemon), moveName: pokemon.moveset[moveIndex]!.getName() }), null, () => { // TODO: is the bang correct? this.scene.ui.showText(i18next.t("battle:learnMoveAnd"), null, () => { + if (this.fromTM) { + pokemon.usedTMs.push(this.moveId); + } pokemon.setMove(moveIndex, Moves.NONE); this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, this.moveId)); this.end(); diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 8f094379434..4adca443e60 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -42,6 +42,7 @@ export default class PokemonData { public luck: integer; public pauseEvolutions: boolean; public pokerus: boolean; + public usedTMs: Moves[]; public fusionSpecies: Species; public fusionFormIndex: integer; @@ -98,6 +99,7 @@ export default class PokemonData { this.fusionVariant = source.fusionVariant; this.fusionGender = source.fusionGender; this.fusionLuck = source.fusionLuck !== undefined ? source.fusionLuck : (source.fusionShiny ? source.fusionVariant + 1 : 0); + this.usedTMs = source.usedTMs || []; if (!forHistory) { this.boss = (source instanceof EnemyPokemon && !!source.bossSegments) || (!this.player && !!source.boss);