From b0360123e0245366f4a514d60fdb2c8899617f4b Mon Sep 17 00:00:00 2001 From: AJ Fontaine <36677462+Fontbane@users.noreply.github.com> Date: Mon, 2 Sep 2024 19:25:41 -0400 Subject: [PATCH] [Balance] [QoL] [Feature] Allow mons to track and relearn used TMs (#3656) * Allow mons to track and relearn used TMs * Fix issue getting level moves * Apply suggested safety measures --- src/field/pokemon.ts | 11 ++++++++++- src/modifier/modifier.ts | 2 +- src/phases/learn-move-phase.ts | 10 +++++++++- src/system/pokemon-data.ts | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index cce613f1ec4..9c4a290d7a5 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -119,6 +119,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); @@ -935,7 +938,11 @@ 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)); + if (Array.isArray(this.usedTMs) && this.usedTMs.length > 0) { + levelMoves = this.usedTMs.filter(m => !levelMoves.includes(m)).concat(levelMoves); + } + levelMoves = levelMoves.filter(lm => !this.moveset.some(m => m?.moveId === lm)); + return levelMoves; } /** @@ -3357,6 +3364,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); @@ -3380,6 +3388,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 ca0b18ce18b..c1defc4abfd 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 5a9a16b6f5e..201019e8860 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(() => { @@ -85,6 +90,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..928077608ed 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);