From c8802a4e3ac76b3a9efd18f67671055b02a95908 Mon Sep 17 00:00:00 2001 From: xsn34kzx Date: Fri, 9 Aug 2024 22:16:46 -0400 Subject: [PATCH] Adjust Types, Refactor `White Herb` Modifier --- src/enums/stat.ts | 6 ++++-- src/field/pokemon.ts | 29 +++++++++++++++------------ src/locales/ca_ES/modifier.ts | 2 +- src/locales/de/modifier.ts | 2 +- src/locales/en/modifier.ts | 2 +- src/locales/es/modifier.ts | 2 +- src/locales/fr/modifier.ts | 2 +- src/locales/it/modifier.ts | 2 +- src/locales/ja/modifier.ts | 2 +- src/locales/ko/modifier.ts | 2 +- src/locales/pt_BR/modifier.ts | 2 +- src/locales/zh_CN/modifier.ts | 2 +- src/locales/zh_TW/modifier.ts | 2 +- src/modifier/modifier-type.ts | 4 ++-- src/modifier/modifier.ts | 37 +++++++++++++++++++++-------------- 15 files changed, 56 insertions(+), 42 deletions(-) diff --git a/src/enums/stat.ts b/src/enums/stat.ts index 730b040d6e3..457689a57dc 100644 --- a/src/enums/stat.ts +++ b/src/enums/stat.ts @@ -17,8 +17,10 @@ export enum Stat { EVA } -export type PermanentStat = Exclude; +export const PERMANENT_STATS = [ Stat.HP, Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD ] as const; +export type PermanentStat = typeof PERMANENT_STATS[number]; -export type BattleStat = Exclude; +export const BATTLE_STATS = [ Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.SPD, Stat.ACC, Stat.EVA] as const; +export type BattleStat = typeof BATTLE_STATS[number]; export type TempBattleStat = Exclude; diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 7f10611656f..53196409964 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -50,7 +50,7 @@ import { Biome } from "#enums/biome"; import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import { getPokemonNameWithAffix } from "#app/messages.js"; -import { PermanentStat, BattleStat } from "#app/enums/stat"; +import { PermanentStat, BattleStat, PERMANENT_STATS } from "#app/enums/stat"; export enum FieldPosition { CENTER, @@ -665,7 +665,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { /** * Retrieves the entire set of stats of the {@linkcode Pokemon}. - * @param ignoreOverride {@linkcode boolean} to prefer actual stats (`true` by default) or in-battle overriden stats (`false`) + * @param ignoreOverride prefer actual stats (`true` by default) or in-battle overriden stats (`false`) * @returns the numeric values of the {@linkcode Pokemon}'s stats */ getStats(ignoreOverride: boolean = true): number[] { @@ -678,11 +678,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { /** * Retrieves the corresponding {@linkcode PermanentStat} of the {@linkcode Pokemon}. * @param stat the desired {@linkcode PermanentStat} - * @param ignoreOverride {@linkcode boolean} to prefer actual stats (`true` by default) or in-battle overridden stats (`false`) + * @param ignoreOverride prefer actual stats (`true` by default) or in-battle overridden stats (`false`) * @returns the numeric value of the desired {@linkcode Stat} */ getStat(stat: PermanentStat, ignoreOverride: boolean = true): number { - if (!ignoreOverride && this.summonData?.stats[stat] !== 0) { + if (!ignoreOverride && (this.summonData?.stats[stat] !== 0)) { return this.summonData.stats[stat]; } return this.stats[stat]; @@ -694,7 +694,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * Note that this does nothing if {@linkcode value} is less than 0. * @param stat the desired {@linkcode PermanentStat} to be overwritten * @param value the desired numeric value - * @param ignoreOverride {@linkcode boolean} to write to actual stats (`true` by default) or in-battle overridden stats (`false`) + * @param ignoreOverride write to actual stats (`true` by default) or in-battle overridden stats (`false`) */ setStat(stat: PermanentStat, value: number, ignoreOverride: boolean = true): void { if (value >= 0) { @@ -707,15 +707,20 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } /** - * Retrieves the in-battle stage of the {@linkcode BattleStat}. + * Retrieves the entire set of in-battle stat stages of the {@linkcode Pokemon}. + * @returns the numeric values of the {@linkcode Pokemon}'s in-battle stat stages if available, undefined otherwise + */ + getStatStages(): number[] | undefined { + return this.summonData ? this.summonData.statStages : undefined; + } + + /** + * Retrieves the in-battle stage of the specified {@linkcode BattleStat}. * @param stat the {@linkcode BattleStat} whose stage is desired * @returns the stage of the desired {@linkcode BattleStat} if available, 0 otherwise */ getStatStage(stat: BattleStat): number { - if (this.summonData) { - return this.summonData.statStages[stat - 1]; - } - return 0; + return this.summonData ? this.summonData.statStages[stat - 1] : 0; } /** @@ -827,7 +832,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } this.scene.applyModifiers(PokemonBaseStatModifier, this.isPlayer(), this, baseStats); - for (let s = Stat.HP; s <= Stat.SPD; s++) { + for (const s of PERMANENT_STATS) { const baseStat = baseStats[s]; let value = Math.floor(((2 * baseStat + this.ivs[s]) * this.level) * 0.01); if (s === Stat.HP) { @@ -852,7 +857,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - this.setStat(s as PermanentStat , value); + this.setStat(s, value); } } diff --git a/src/locales/ca_ES/modifier.ts b/src/locales/ca_ES/modifier.ts index 26a6a9c18ae..a72cd38252d 100644 --- a/src/locales/ca_ES/modifier.ts +++ b/src/locales/ca_ES/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "hitHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} was revived\nby its {{typeName}}!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "You received interest of ₽{{moneyAmount}}\nfrom the {{typeName}}!", "turnHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was absorbed\nby {{pokemonName}}'s {{typeName}}!", "contactHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was snatched\nby {{pokemonName}}'s {{typeName}}!", diff --git a/src/locales/de/modifier.ts b/src/locales/de/modifier.ts index 5a8126e3d85..b61a7cb6a32 100644 --- a/src/locales/de/modifier.ts +++ b/src/locales/de/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{typeName}} von {{pokemonNameWithAffix}} füllt einige KP auf!", "hitHealApply": "{{typeName}} von {{pokemonNameWithAffix}} füllt einige KP auf!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} wurde durch {{typeName}} wiederbelebt!", - "pokemonResetNegativeStatStageApply": "Die negative Statuswertveränderung von {{pokemonNameWithAffix}} wurde durch {{typeName}} aufgehoben!", + "resetNegativeStatStageApply": "Die negative Statuswertveränderung von {{pokemonNameWithAffix}} wurde durch {{typeName}} aufgehoben!", "moneyInterestApply": "Du erhählst {{moneyAmount}} ₽ durch das Item {{typeName}}!", "turnHeldItemTransferApply": "{{itemName}} von {{pokemonNameWithAffix}} wurde durch {{typeName}} von {{pokemonName}} absorbiert!", "contactHeldItemTransferApply": "{{itemName}} von {{pokemonNameWithAffix}} wurde durch {{typeName}} von {{pokemonName}} geklaut!", diff --git a/src/locales/en/modifier.ts b/src/locales/en/modifier.ts index 26a6a9c18ae..a72cd38252d 100644 --- a/src/locales/en/modifier.ts +++ b/src/locales/en/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "hitHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} was revived\nby its {{typeName}}!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "You received interest of ₽{{moneyAmount}}\nfrom the {{typeName}}!", "turnHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was absorbed\nby {{pokemonName}}'s {{typeName}}!", "contactHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was snatched\nby {{pokemonName}}'s {{typeName}}!", diff --git a/src/locales/es/modifier.ts b/src/locales/es/modifier.ts index b0a3d36e233..5cc0203efdd 100644 --- a/src/locales/es/modifier.ts +++ b/src/locales/es/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "hitHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} was revived\nby its {{typeName}}!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "You received interest of ₽{{moneyAmount}}\nfrom the {{typeName}}!", "turnHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was absorbed\nby {{pokemonName}}'s {{typeName}}!", "contactHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was snatched\nby {{pokemonName}}'s {{typeName}}!", diff --git a/src/locales/fr/modifier.ts b/src/locales/fr/modifier.ts index 368b186a07b..d3a5f87e0c6 100644 --- a/src/locales/fr/modifier.ts +++ b/src/locales/fr/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "Les PV de {{pokemonNameWithAffix}}\nsont un peu restaurés par les {{typeName}} !", "hitHealApply": "Les PV de {{pokemonNameWithAffix}}\nsont un peu restaurés par le {{typeName}} !", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} a repris connaissance\navec sa {{typeName}} et est prêt à se battre de nouveau !", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "La {{typeName}} vous rapporte\n{{moneyAmount}} ₽ d’intérêts !", "turnHeldItemTransferApply": "{{itemName}} de {{pokemonNameWithAffix}} est absorbé·e\npar le {{typeName}} de {{pokemonName}} !", "contactHeldItemTransferApply": "{{itemName}} de {{pokemonNameWithAffix}} est volé·e\npar l’{{typeName}} de {{pokemonName}} !", diff --git a/src/locales/it/modifier.ts b/src/locales/it/modifier.ts index 810524a9e5e..d8eca95aeed 100644 --- a/src/locales/it/modifier.ts +++ b/src/locales/it/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "hitHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} was revived\nby its {{typeName}}!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "You received interest of ₽{{moneyAmount}}\nfrom the {{typeName}}!", "turnHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was absorbed\nby {{pokemonName}}'s {{typeName}}!", "contactHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was snatched\nby {{pokemonName}}'s {{typeName}}!", diff --git a/src/locales/ja/modifier.ts b/src/locales/ja/modifier.ts index 26a6a9c18ae..a72cd38252d 100644 --- a/src/locales/ja/modifier.ts +++ b/src/locales/ja/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "hitHealApply": "{{pokemonNameWithAffix}} restored a little HP using\nits {{typeName}}!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} was revived\nby its {{typeName}}!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "You received interest of ₽{{moneyAmount}}\nfrom the {{typeName}}!", "turnHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was absorbed\nby {{pokemonName}}'s {{typeName}}!", "contactHeldItemTransferApply": "{{pokemonNameWithAffix}}'s {{itemName}} was snatched\nby {{pokemonName}}'s {{typeName}}!", diff --git a/src/locales/ko/modifier.ts b/src/locales/ko/modifier.ts index 98460b118f1..cce8adeaf3e 100644 --- a/src/locales/ko/modifier.ts +++ b/src/locales/ko/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}}[[는]]\n{{typeName}}[[로]] 인해 조금 회복했다.", "hitHealApply": "{{pokemonNameWithAffix}}[[는]]\n{{typeName}}[[로]] 인해 조금 회복했다.", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}}[[는]] {{typeName}}[[로]]\n정신을 차려 싸울 수 있게 되었다!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "{{typeName}}[[로]]부터\n₽{{moneyAmount}}[[를]] 받았다!", "turnHeldItemTransferApply": "{{pokemonName}}의 {{typeName}}[[는]]\n{{pokemonNameWithAffix}}의 {{itemName}}[[를]] 흡수했다!", "contactHeldItemTransferApply": "{{pokemonName}}의 {{typeName}}[[는]]\n{{pokemonNameWithAffix}}의 {{itemName}}[[를]] 가로챘다!", diff --git a/src/locales/pt_BR/modifier.ts b/src/locales/pt_BR/modifier.ts index 168665205c3..f206e712813 100644 --- a/src/locales/pt_BR/modifier.ts +++ b/src/locales/pt_BR/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}} restaurou um pouco de PS usando\nsuas {{typeName}}!", "hitHealApply": "{{pokemonNameWithAffix}} restaurou um pouco de PS usando\nsua {{typeName}}!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}} foi revivido\npor sua {{typeName}}!", - "pokemonResetNegativeStatStageApply": "Os atributos diminuídos de {{pokemonNameWithAffix}} foram\nrestaurados por seu(sua) {{typeName}}!", + "resetNegativeStatStageApply": "Os atributos diminuídos de {{pokemonNameWithAffix}} foram\nrestaurados por seu(sua) {{typeName}}!", "moneyInterestApply": "Você recebeu um juros de ₽{{moneyAmount}}\nde sua {{typeName}}!", "turnHeldItemTransferApply": "{{itemName}} de {{pokemonNameWithAffix}} foi absorvido(a)\npelo {{typeName}} de {{pokemonName}}!", "contactHeldItemTransferApply": "{{itemName}} de {{pokemonNameWithAffix}} foi pego(a)\npela {{typeName}} de {{pokemonName}}!", diff --git a/src/locales/zh_CN/modifier.ts b/src/locales/zh_CN/modifier.ts index 6900e99dfb6..1bddb63dd98 100644 --- a/src/locales/zh_CN/modifier.ts +++ b/src/locales/zh_CN/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}}用{{typeName}}\n回复了体力!", "hitHealApply": "{{pokemonNameWithAffix}}用{{typeName}}\n回复了体力!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}}用{{typeName}}\n恢复了活力!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}降低的能力被{{typeName}}\n复原了!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}降低的能力被{{typeName}}\n复原了!", "moneyInterestApply": "用{{typeName}}\n获得了 ₽{{moneyAmount}} 利息!", "turnHeldItemTransferApply": "{{pokemonNameWithAffix}}的{{itemName}}被\n{{pokemonName}}的{{typeName}}吸收了!", "contactHeldItemTransferApply": "{{pokemonNameWithAffix}}的{{itemName}}被\n{{pokemonName}}的{{typeName}}夺取了!", diff --git a/src/locales/zh_TW/modifier.ts b/src/locales/zh_TW/modifier.ts index 7909e8150a0..a07968ab4f7 100644 --- a/src/locales/zh_TW/modifier.ts +++ b/src/locales/zh_TW/modifier.ts @@ -5,7 +5,7 @@ export const modifier: SimpleTranslationEntries = { "turnHealApply": "{{pokemonNameWithAffix}}用{{typeName}}\n回復了體力!", "hitHealApply": "{{pokemonNameWithAffix}}用{{typeName}}\n回復了體力!", "pokemonInstantReviveApply": "{{pokemonNameWithAffix}}用{{typeName}}\n回復了活力!", - "pokemonResetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", + "resetNegativeStatStageApply": "{{pokemonNameWithAffix}}'s lowered stats were restored\nby its {{typeName}}!", "moneyInterestApply": "用{{typeName}}\n獲得了 ₽{{moneyAmount}} 利息!", "turnHeldItemTransferApply": "{{pokemonNameWithAffix}}的{{itemName}}被\n{{pokemonName}}的{{typeName}}吸收了!", "contactHeldItemTransferApply": "{{pokemonNameWithAffix}}的{{itemName}}被\n{{pokemonName}}的{{typeName}}奪取了!", diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index 07a9b74b9ff..42527234685 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -1252,7 +1252,7 @@ export const modifierTypes = { SACRED_ASH: () => new AllPokemonFullReviveModifierType("modifierType:ModifierType.SACRED_ASH", "sacred_ash"), REVIVER_SEED: () => new PokemonHeldItemModifierType("modifierType:ModifierType.REVIVER_SEED", "reviver_seed", (type, args) => new Modifiers.PokemonInstantReviveModifier(type, (args[0] as Pokemon).id)), - WHITE_HERB: () => new PokemonHeldItemModifierType("modifierType:ModifierType.WHITE_HERB", "white_herb", (type, args) => new Modifiers.PokemonResetNegativeStatStageModifier(type, (args[0] as Pokemon).id)), + WHITE_HERB: () => new PokemonHeldItemModifierType("modifierType:ModifierType.WHITE_HERB", "white_herb", (type, args) => new Modifiers.ResetNegativeStatStageModifier(type, (args[0] as Pokemon).id)), ETHER: () => new PokemonPpRestoreModifierType("modifierType:ModifierType.ETHER", "ether", 10), MAX_ETHER: () => new PokemonPpRestoreModifierType("modifierType:ModifierType.MAX_ETHER", "max_ether", -1), @@ -1571,7 +1571,7 @@ const modifierPool: ModifierPool = { new WeightedModifierType(modifierTypes.WHITE_HERB, (party: Pokemon[]) => { const checkedAbilities = [Abilities.WEAK_ARMOR, Abilities.CONTRARY, Abilities.MOODY, Abilities.ANGER_SHELL, Abilities.COMPETITIVE, Abilities.DEFIANT]; const weightMultiplier = party.filter( - p => !p.getHeldItems().some(i => i instanceof Modifiers.PokemonResetNegativeStatStageModifier && i.stackCount >= i.getMaxHeldItemCount(p)) && + p => !p.getHeldItems().some(i => i instanceof Modifiers.ResetNegativeStatStageModifier && i.stackCount >= i.getMaxHeldItemCount(p)) && (checkedAbilities.some(a => p.hasAbility(a, false, true)) || p.getMoveset(true).some(m => m && selfStatLowerMoves.includes(m.moveId)))).length; // If a party member has one of the above moves or abilities and doesn't have max herbs, the herb will appear more frequently return 0 * (weightMultiplier ? 2 : 1) + (weightMultiplier ? weightMultiplier * 0 : 0); diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index c6871353a7d..54e1fdbba75 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -24,6 +24,7 @@ import Overrides from "#app/overrides"; import { ModifierType, modifierTypes } from "./modifier-type"; import { Command } from "#app/ui/command-ui-handler.js"; import { Species } from "#enums/species"; +import { BATTLE_STATS } from "#app/enums/stat"; import i18next from "i18next"; import { allMoves } from "#app/data/move.js"; @@ -1395,42 +1396,48 @@ export class PokemonInstantReviveModifier extends PokemonHeldItemModifier { } /** - * Modifier used for White Herb, which resets negative {@linkcode Stat} changes + * Modifier used for held items, namely White Herb, that restore adverse stat + * stages in battle. * @extends PokemonHeldItemModifier * @see {@linkcode apply} */ -export class PokemonResetNegativeStatStageModifier extends PokemonHeldItemModifier { +export class ResetNegativeStatStageModifier extends PokemonHeldItemModifier { constructor(type: ModifierType, pokemonId: integer, stackCount?: integer) { super(type, pokemonId, stackCount); } matchType(modifier: Modifier) { - return modifier instanceof PokemonResetNegativeStatStageModifier; + return modifier instanceof ResetNegativeStatStageModifier; } clone() { - return new PokemonResetNegativeStatStageModifier(this.type, this.pokemonId, this.stackCount); + return new ResetNegativeStatStageModifier(this.type, this.pokemonId, this.stackCount); } /** - * Restores any negative stat stages of the mon to 0 - * @param args args[0] is the {@linkcode Pokemon} whose stat stages are being checked - * @returns true if any stat changes were applied (item was used), false otherwise + * Goes through the holder's stat stages and, if any are negative, resets that + * stat stage back to 0. + * @param args [0] {@linkcode Pokemon} that holds the held item + * @returns true if any stat stages were reset, false otherwise */ apply(args: any[]): boolean { const pokemon = args[0] as Pokemon; - const loweredStats = pokemon.summonData.battleStats.filter(s => s < 0); - if (loweredStats.length) { - for (let s = 0; s < pokemon.summonData.battleStats.length; s++) { - pokemon.summonData.battleStats[s] = Math.max(0, pokemon.summonData.battleStats[s]); + let statRestored = false; + + for (const s of BATTLE_STATS) { + if (pokemon.getStatStage(s) < 0) { + pokemon.setStatStage(s, 0); + statRestored = true; } - pokemon.scene.queueMessage(i18next.t("modifier:pokemonResetNegativeStatStageApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name })); - return true; } - return false; + + if (statRestored) { + pokemon.scene.queueMessage(i18next.t("modifier:resetNegativeStatStageApply", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon), typeName: this.type.name })); + } + return statRestored; } - getMaxHeldItemCount(pokemon: Pokemon): integer { + getMaxHeldItemCount(_pokemon: Pokemon): integer { return 2; } }