[Beta][P2 Bug] Fix macho brace stat calculation for HP (#4467)

This commit is contained in:
Xavion3 2024-09-28 03:11:08 +10:00 committed by GitHub
parent b426340aee
commit edbb09f4d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 25 deletions

View File

@ -952,32 +952,35 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
const baseStats = this.calculateBaseStats(); const baseStats = this.calculateBaseStats();
// Using base stats, calculate and store stats one by one // Using base stats, calculate and store stats one by one
for (const s of PERMANENT_STATS) { 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) { 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)) { if (this.hasAbility(Abilities.WONDER_GUARD, false, true)) {
value = 1; statHolder.value = 1;
} }
if (this.hp > value || this.hp === undefined) { if (this.hp > statHolder.value || this.hp === undefined) {
this.hp = value; this.hp = statHolder.value;
} else if (this.hp) { } else if (this.hp) {
const lastMaxHp = this.getMaxHp(); const lastMaxHp = this.getMaxHp();
if (lastMaxHp && value > lastMaxHp) { if (lastMaxHp && statHolder.value > lastMaxHp) {
this.hp += value - lastMaxHp; this.hp += statHolder.value - lastMaxHp;
} }
} }
} else { } else {
value += 5; statHolder.value += 5;
const natureStatMultiplier = new Utils.NumberHolder(getNatureStatMultiplier(this.getNature(), s)); const natureStatMultiplier = new Utils.NumberHolder(getNatureStatMultiplier(this.getNature(), s));
this.scene.applyModifier(PokemonNatureWeightModifier, this.isPlayer(), this, natureStatMultiplier); this.scene.applyModifier(PokemonNatureWeightModifier, this.isPlayer(), this, natureStatMultiplier);
if (natureStatMultiplier.value !== 1) { 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[] { calculateBaseStats(): number[] {

View File

@ -998,26 +998,26 @@ export class PokemonIncrementingStatModifier extends PokemonHeldItemModifier {
} }
shouldApply(args: any[]): boolean { 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 { 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 // 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) => { if (isHp) {
const isHp = i === 0; statHolder.value += this.stackCount;
// Doesn't modify HP if holder has Wonder Guard
if (!isHp || !targetToApply.hasAbility(Abilities.WONDER_GUARD)) {
let mult = 1;
if (this.stackCount === this.getMaxHeldItemCount()) { if (this.stackCount === this.getMaxHeldItemCount()) {
mult = isHp ? 1.05 : 1.1; 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);
} }
const newVal = Math.floor((v + this.stackCount * (isHp ? 1 : 2)) * mult);
args[1][i] = Math.min(Math.max(newVal, 1), 999999);
} }
});
return true; return true;
} }