From d3ccc86468f45562d8a14781cc9c36c22cf5fc45 Mon Sep 17 00:00:00 2001 From: Jakub Hanko <60473007+JakubHanko@users.noreply.github.com> Date: Mon, 13 May 2024 22:18:34 +0200 Subject: [PATCH] Refactor BattleStatRatioPowerAttr into two distinct classes --- src/data/move.ts | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index 5d6c84bc8..dd5bf4fbe 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1914,37 +1914,14 @@ export class WeightPowerAttr extends VariablePowerAttr { } } -export class BattleStatRatioPowerAttr extends VariablePowerAttr { - private stat: Stat; - private invert: boolean; - - constructor(stat: Stat, invert: boolean = false) { - super(); - - this.stat = stat; - this.invert = invert; - } - +export class ElectroBallPowerAttr extends VariablePowerAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const power = args[0] as Utils.NumberHolder; - const statRatio = target.getBattleStat(this.stat) / user.getBattleStat(this.stat); + const statRatio = target.getBattleStat(Stat.SPD) / user.getBattleStat(Stat.SPD); const statThresholds = [ 0.25, 1 / 3, 0.5, 1, -1 ]; const statThresholdPowers = [ 150, 120, 80, 60, 40 ]; - if (this.invert) { - // Gyro ball uses a specific formula - const userSpeed = user.getBattleStat(this.stat); - if (userSpeed < 1) { - // Gen 6+ always have 1 base power - power.value = 1; - return true; - } - const bp = Math.floor(Math.min(150, 25 * target.getBattleStat(this.stat) / userSpeed + 1)); - power.value = bp; - return true; - } - let w = 0; while (w < statThresholds.length - 1 && statRatio > statThresholds[w]) { if (++w === statThresholds.length) @@ -1952,7 +1929,21 @@ export class BattleStatRatioPowerAttr extends VariablePowerAttr { } power.value = statThresholdPowers[w]; + return true; + } +} +export class GyroBallPowerAttr extends VariablePowerAttr { + apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { + const power = args[0] as Utils.NumberHolder; + const userSpeed = user.getBattleStat(Stat.SPD); + if (userSpeed < 1) { + // Gen 6+ always have 1 base power + power.value = 1; + return true; + } + + power.value = Math.floor(Math.min(150, 25 * target.getBattleStat(Stat.SPD) / userSpeed + 1)); return true; } } @@ -5092,7 +5083,7 @@ export function initMoves() { .attr(StatChangeAttr, BattleStat.SPD, -1, true) .punchingMove(), new AttackMove(Moves.GYRO_BALL, Type.STEEL, MoveCategory.PHYSICAL, -1, 100, 5, -1, 0, 4) - .attr(BattleStatRatioPowerAttr, Stat.SPD, true) + .attr(GyroBallPowerAttr) .ballBombMove(), new SelfStatusMove(Moves.HEALING_WISH, Type.PSYCHIC, -1, 10, -1, 0, 4) .attr(SacrificialFullRestoreAttr) @@ -5441,7 +5432,7 @@ export function initMoves() { .condition(unknownTypeCondition) .attr(hitsSameTypeAttr), new AttackMove(Moves.ELECTRO_BALL, Type.ELECTRIC, MoveCategory.SPECIAL, -1, 100, 10, -1, 0, 5) - .attr(BattleStatRatioPowerAttr, Stat.SPD) + .attr(ElectroBallPowerAttr) .ballBombMove(), new StatusMove(Moves.SOAK, Type.WATER, 100, 20, -1, 0, 5) .attr(ChangeTypeAttr, Type.WATER),