From 9315b8d4d83df31265bf0e43250118c61ae015b3 Mon Sep 17 00:00:00 2001 From: Marty-D Date: Sat, 16 Mar 2019 17:49:25 -0400 Subject: [PATCH] Gen II: Cap stat boosting properly --- data/mods/gen2/scripts.js | 29 ++++++++++++++++++++++++++++- dev-tools/globals.ts | 4 ++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/data/mods/gen2/scripts.js b/data/mods/gen2/scripts.js index 8aa763e23763..12f5e81efbb7 100644 --- a/data/mods/gen2/scripts.js +++ b/data/mods/gen2/scripts.js @@ -10,7 +10,7 @@ let BattleScripts = { gen: 2, // BattlePokemon scripts. pokemon: { - getStat(statName, unboosted, unmodified) { + getStat(statName, unboosted, unmodified, fastReturn) { statName = /** @type {StatNameExceptHP} */(toId(statName)); // @ts-ignore - type checking prevents 'hp' from being passed, but we're paranoid if (statName === 'hp') throw new Error("Please read `maxhp` directly"); @@ -46,6 +46,7 @@ let BattleScripts = { // Gen 2 caps stats at 999 and min is 1. stat = this.battle.clampIntRange(stat, 1, 999); + if (fastReturn) return stat; // Screens if (!unboosted) { @@ -63,6 +64,32 @@ let BattleScripts = { return stat; }, + boostBy(boost) { + let delta = 0; + for (let i in boost) { + // @ts-ignore + delta = boost[i]; + // @ts-ignore + if (delta > 0 && this.getStat(i, false, true, true) === 999) return 0; + // @ts-ignore + this.boosts[i] += delta; + // @ts-ignore + if (this.boosts[i] > 6) { + // @ts-ignore + delta -= this.boosts[i] - 6; + // @ts-ignore + this.boosts[i] = 6; + } + // @ts-ignore + if (this.boosts[i] < -6) { + // @ts-ignore + delta -= this.boosts[i] - (-6); + // @ts-ignore + this.boosts[i] = -6; + } + } + return delta; + }, }, // Battle scripts. runMove(moveOrMoveName, pokemon, targetLoc, sourceEffect) { diff --git a/dev-tools/globals.ts b/dev-tools/globals.ts index 443acd0310d3..dcf94094ac61 100644 --- a/dev-tools/globals.ts +++ b/dev-tools/globals.ts @@ -763,11 +763,11 @@ interface ModdedBattleSide { interface ModdedBattlePokemon { inherit?: boolean - boostBy?: (this: Pokemon, boost: SparseBoostsTable) => boolean + boostBy?: (this: Pokemon, boost: SparseBoostsTable) => boolean | number calculateStat?: (this: Pokemon, statName: StatNameExceptHP, boost: number, modifier?: number) => number getActionSpeed?: (this: Pokemon) => number getRequestData?: (this: Pokemon) => {moves: {move: string, id: string, target?: string, disabled?: boolean}[], maybeDisabled?: boolean, trapped?: boolean, maybeTrapped?: boolean, canMegaEvo?: boolean, canUltraBurst?: boolean, canZMove?: AnyObject | null} - getStat?: (this: Pokemon, statName: StatNameExceptHP, unboosted?: boolean, unmodified?: boolean) => number + getStat?: (this: Pokemon, statName: StatNameExceptHP, unboosted?: boolean, unmodified?: boolean, fastReturn?: boolean) => number getWeight?: (this: Pokemon) => number hasAbility?: (this: Pokemon, ability: string | string[]) => boolean isGrounded?: (this: Pokemon, negateImmunity: boolean | undefined) => boolean | null