doshidak / showdex

Pokémon Showdown extension that harnesses the power of parabolic calculus to strategically extract your opponents' Elo.
GNU Affero General Public License v3.0
104 stars 18 forks source link

fix Last Respects BP when Terastallized #135

Closed doshidak closed 1 year ago

doshidak commented 1 year ago

Reported by: Sorrica

Last Respects worked as intended with the manual override on Calcdex's end, but now that the Tera STAB BP boost mechanic (which brings any STAB move with < 60 BP to 60 when Terastallized) has been natively implemented into @smogon/calc, the manually boosted BP is overwritten to 60, which deflates the resulting damages.

Before Tera After Tera
calcdex-last-respects-pre-tera calcdex-last-respects-post-tera

Also rather curiously, the manually boosted BP (from the move's tooltip) goes from 250 to 300 after Terastallizing. (Though, due to the internal mechanic, damages are calculated at 60 BP, as you can see from the matchup tooltip.)

doshidak commented 1 year ago

Figured out why the BP of Last Respects is 300 in the Calcdex when Terastallized: the manual implementation of the Tera STAB BP mechanic (shouldBoostTeraStab()) still exists in the utility that actually performs the manual boost (calcMoveBasePower()).

However, shouldBoostTeraStab() runs first, outputting 60, then calculates the boosted BP of Last Respects with the faintCounter of the passed-in pokemon (e.g., 4 in the example screenshots). So with the math of basePower * (1 + faintCounter), which in this case, becomes 60 * (1 + 4) = 60 * 5 = 300.

300 BP is actually incorrect since the Smogon Dex entry for Last Respects says:

Power is equal to 50+(X*50), where X is the total number of times any Pokemon has fainted on the user's side, and X cannot be greater than 100.

As for how the interaction is supposed to go, no idea on that front (need to do some research into how Showdown handles it).

Do we:

I'm thinking it's the former, since the formula could look like basePower + (50 * faintCounter) (clamping faintCounter to a max value of 100). But I'll still check how Showdown's server calculates the move's final BP, just to make sure.

doshidak commented 1 year ago

It appears from Showdown's server source code that it's the latter: don't boost the BP as the resulting BP is > 60.

From sim/battle-actions.ts, we can see that the basePower is initially set from move.basePower, but calls the move's basePowerCallback() function if it exists:

let basePower: number | false | null = move.basePower;
if (move.basePowerCallback) {
  basePower = move.basePowerCallback.call(this.battle, source, target, move);
}

Last Respects has a basePowerCallback() defined in data/moves.ts:

export const Moves: {[moveid: string]: MoveData} = {
  // ...
  lastrespects: {
    num: 854,
    accuracy: 100,
    basePower: 50,
    basePowerCallback(pokemon, target, move) {
      return 50 + 50 * pokemon.side.totalFainted;
    },
    category: "Physical",
    name: "Last Respects",
    pp: 10,
    priority: 0,
    flags: {protect: 1, mirror: 1},
    secondary: null,
    target: "normal",
    type: "Ghost",
  },
  // ...
};

A couple lines below the basePowerCallback() call in moves.ts, we can find the implementation of the Tera STAB BP boost mechanic:

if (
  basePower < 60 && source.getTypes(true).includes(move.type) && source.terastallized && move.priority <= 0 &&
  // Hard move.basePower check for moves like Dragon Energy that have variable BP
  !move.multihit && !((move.basePower === 0 || move.basePower === 150) && move.basePowerCallback)
) {
  basePower = 60;
}

From the example above, once basePowerCallback() is called, basePower is 250, which fails the first basePower < 60 conditional in the mechanic implementation.

In other words, the BP is not set to 60, but remains at 250.

doshidak commented 1 year ago

Fixed! (...I hope LOL. Looks right tho!)

calcdex-last-respects-post-fix

Verified this on calc.ps after importing the exact spreads (from Gen 9 Randoms) & overriding the BP of Last Respects to 250:

Basculegion-F Gyarados
Basculegion-F (F) @ Choice Scarf
Ability: Adaptability
Tera Type: Ghost
Level: 73
EVs: 84 HP / 84 Atk / 84 Def / 84 SpA / 84 SpD / 84 Spe
Hardy Nature
- Hydro Pump
- Ice Beam
- Last Respects
- Wave Crash
        
Gyarados (F) @ Heavy-Duty Boots
Ability: Intimidate
Tera Type: Ground
Level: 79
EVs: 84 HP / 84 Atk / 84 Def / 84 SpA / 84 SpD / 84 Spe
Hardy Nature
- Dragon Dance
- Earthquake
- Stone Edge
- Waterfall
        

smogon-calc-last-respects-verification

smogon-calc-last-respects-bp-override

Will close this via reference on the next PR.