From edbb09f4d6f78af31b2ee68b4685fa93d7a21b5f Mon Sep 17 00:00:00 2001 From: Xavion3 Date: Sat, 28 Sep 2024 03:11:08 +1000 Subject: [PATCH] [Beta][P2 Bug] Fix macho brace stat calculation for HP (#4467) --- src/field/pokemon.ts | 25 ++++++++++++++----------- src/modifier/modifier.ts | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 0fda3d075be..07525e92157 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -952,32 +952,35 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const baseStats = this.calculateBaseStats(); // Using base stats, calculate and store stats one by one for (const s of PERMANENT_STATS) { - let value = Math.floor(((2 * baseStats[s] + this.ivs[s]) * this.level) * 0.01); + const statHolder = new Utils.IntegerHolder(Math.floor(((2 * baseStats[s] + this.ivs[s]) * this.level) * 0.01)); if (s === Stat.HP) { - value = value + this.level + 10; + statHolder.value = statHolder.value + this.level + 10; + this.scene.applyModifier(PokemonIncrementingStatModifier, this.isPlayer(), this, s, statHolder); if (this.hasAbility(Abilities.WONDER_GUARD, false, true)) { - value = 1; + statHolder.value = 1; } - if (this.hp > value || this.hp === undefined) { - this.hp = value; + if (this.hp > statHolder.value || this.hp === undefined) { + this.hp = statHolder.value; } else if (this.hp) { const lastMaxHp = this.getMaxHp(); - if (lastMaxHp && value > lastMaxHp) { - this.hp += value - lastMaxHp; + if (lastMaxHp && statHolder.value > lastMaxHp) { + this.hp += statHolder.value - lastMaxHp; } } } else { - value += 5; + statHolder.value += 5; const natureStatMultiplier = new Utils.NumberHolder(getNatureStatMultiplier(this.getNature(), s)); this.scene.applyModifier(PokemonNatureWeightModifier, this.isPlayer(), this, natureStatMultiplier); if (natureStatMultiplier.value !== 1) { - value = Math.max(Math[natureStatMultiplier.value > 1 ? "ceil" : "floor"](value * natureStatMultiplier.value), 1); + statHolder.value = Math.max(Math[natureStatMultiplier.value > 1 ? "ceil" : "floor"](statHolder.value * natureStatMultiplier.value), 1); } + this.scene.applyModifier(PokemonIncrementingStatModifier, this.isPlayer(), this, s, statHolder); } - this.setStat(s, value); + statHolder.value = Utils.clampInt(statHolder.value, 1, Number.MAX_SAFE_INTEGER); + + this.setStat(s, statHolder.value); } - this.scene.applyModifier(PokemonIncrementingStatModifier, this.isPlayer(), this, this.stats); } calculateBaseStats(): number[] { diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index f53a07e8e21..cf9cf78225e 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -998,26 +998,26 @@ export class PokemonIncrementingStatModifier extends PokemonHeldItemModifier { } shouldApply(args: any[]): boolean { - return super.shouldApply(args) && args.length === 2 && args[1] instanceof Array; + return super.shouldApply(args) && args.length === 3 && args[2] instanceof Utils.IntegerHolder; } apply(args: any[]): boolean { - // Modifies the passed in stats[] array by +1 per stack for HP, +2 per stack for other stats + // Modifies the passed in stat integer holder by +1 per stack for HP, +2 per stack for other stats // If the Macho Brace is at max stacks (50), adds additional 5% to total HP and 10% to other stats - const targetToApply = args[0] as Pokemon; + const isHp = args[1] === Stat.HP; + const statHolder = args[2] as Utils.IntegerHolder; - args[1].forEach((v, i) => { - const isHp = i === 0; - // Doesn't modify HP if holder has Wonder Guard - if (!isHp || !targetToApply.hasAbility(Abilities.WONDER_GUARD)) { - let mult = 1; - if (this.stackCount === this.getMaxHeldItemCount()) { - mult = isHp ? 1.05 : 1.1; - } - const newVal = Math.floor((v + this.stackCount * (isHp ? 1 : 2)) * mult); - args[1][i] = Math.min(Math.max(newVal, 1), 999999); + if (isHp) { + statHolder.value += this.stackCount; + if (this.stackCount === this.getMaxHeldItemCount()) { + statHolder.value = Math.floor(statHolder.value * 1.05); } - }); + } else { + statHolder.value += 2 * this.stackCount; + if (this.stackCount === this.getMaxHeldItemCount()) { + statHolder.value = Math.floor(statHolder.value * 1.1); + } + } return true; }