From 60f191e60d43a0ec92b1a1e030b7eace34c729ad Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 2 May 2023 00:11:31 -0400 Subject: [PATCH] Add battler stat multiplier ability attribute --- src/data/ability.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/data/ability.ts b/src/data/ability.ts index ac8f7e239..2a05a8d2d 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -222,6 +222,27 @@ export class RecoilMovePowerBoostAbAttr extends VariableMovePowerAbAttr { } } +export class BattleStatMultiplierAbAttr extends AbAttr { + private battleStat: BattleStat; + private multiplier: number; + + constructor(battleStat: BattleStat, multiplier: number) { + super(); + + this.battleStat = battleStat; + this.multiplier = multiplier; + } + + applyBattleStat(pokemon: Pokemon, battleStat: BattleStat, statValue: Utils.NumberHolder, args: any[]) { + if (battleStat === this.battleStat) { + statValue.value *= this.multiplier; + return true; + } + + return false; + } +} + export class PreStatChangeAbAttr extends AbAttr { applyPreStatChange(pokemon: Pokemon, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): boolean { return false; @@ -360,6 +381,28 @@ export function applyPreDefendAbAttrs(attrType: { new(...args: any[]): PreDefend pokemon.scene.clearPhaseQueueSplice(); } +export function applyBattleStatMultiplierAbAttrs(attrType: { new(...args: any[]): BattleStatMultiplierAbAttr }, + pokemon: Pokemon, battleStat: BattleStat, statValue: Utils.NumberHolder, ...args: any[]) { + if (!pokemon.canApplyAbility()) + return; + + const ability = pokemon.getAbility(); + const attrs = ability.getAttrs(attrType) as BattleStatMultiplierAbAttr[]; + for (let attr of attrs) { + if (!canApplyAttr(pokemon, attr)) + continue; + pokemon.scene.setPhaseQueueSplice(); + if (attr.applyBattleStat(pokemon, battleStat, statValue, args)) { + queueShowAbility(pokemon); + const message = attr.getTriggerMessage(pokemon); + if (message) + pokemon.scene.queueMessage(message); + } + } + + pokemon.scene.clearPhaseQueueSplice(); +} + export function applyPreAttackAbAttrs(attrType: { new(...args: any[]): PreAttackAbAttr }, pokemon: Pokemon, defender: Pokemon, move: PokemonMove, ...args: any[]): void { if (!pokemon.canApplyAbility())