Skip to content

Commit

Permalink
Gen II: Cap stat boosting properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Marty-D committed Mar 16, 2019
1 parent 39a8b42 commit 9315b8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion data/mods/gen2/scripts.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand All @@ -63,6 +64,32 @@ let BattleScripts = {

return stat;
},
boostBy(boost) {
let delta = 0;
for (let i in boost) {

This comment has been minimized.

Copy link
@Zarel

Zarel Mar 17, 2019

Member

let i: StatName; would prevent the need for the ten ts-ignores in a row.

This comment has been minimized.

Copy link
@Marty-D

Marty-D Mar 17, 2019

Author Collaborator

This file isn't native TypeScript.

This comment has been minimized.

Copy link
@Zarel

Zarel Mar 17, 2019

Member
/** @type {StatName} */
let i;
// @ts-ignore
delta = boost[i];
// @ts-ignore
if (delta > 0 && this.getStat(i, false, true, true) === 999) return 0;

This comment has been minimized.

Copy link
@Zarel

Zarel Mar 17, 2019

Member

Not continue?

This comment has been minimized.

Copy link
@Marty-D

Marty-D Mar 17, 2019

Author Collaborator

Individual boosts are sent here from Battle#boost. I agree continue would be needed if anything used Pokemon#boostBy directly, but at the moment nothing in Gen 2 does.

This comment has been minimized.

Copy link
@Zarel

Zarel Mar 17, 2019

Member

What about other gens?

I would throw if there's multiple boosts passed here, to make it clear it's not a supported use-case.

This comment has been minimized.

Copy link
@Marty-D

Marty-D Mar 17, 2019

Author Collaborator

I had already changed it in 2d08a1e.
Other gens use it; it's useful in tests because it doesn't matter whether the client receives the new stat stage infomation. I was planning to write some tests for this stat cap thing later anyway, so I would have run into this problem and had to change it then regardless.

// @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) {
Expand Down
4 changes: 2 additions & 2 deletions dev-tools/globals.ts
Expand Up @@ -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
Expand Down

0 comments on commit 9315b8d

Please sign in to comment.