smogon / damage-calc

Pokemon games damage calculator
https://calc.pokemonshowdown.com
MIT License
397 stars 367 forks source link

Providing fraction of the pokemon hp for damage calculation #638

Closed BaiqingL closed 4 months ago

BaiqingL commented 4 months ago

Is it possible to provide say, 70% as an argument to the defender side pokemon and calculate damage given the assumption that the pokemon is already at 70% health?

thejetou commented 4 months ago

If you have the exact HP number you can assign it to the curHP property in the options object of the Pokemon, but if you need a percentage you'll have to calculate it yourself. Here's a simple example to calculate Gengar using Focus Blast vs a Chansey at 70% HP

const chansey = new Pokemon(gen, 'Chansey', {
  item: 'Eviolite',
  nature: 'Calm',
  evs: {hp: 252, spd: 252},
});
chansey.originalCurHP = Math.round(70 * chansey.maxHP() / 100);

const result = calculate(
  gen,
  new Pokemon(gen, 'Gengar', {
    item: 'Choice Specs',
    nature: 'Timid',
    evs: {spa: 252},
    boosts: {spa: 1},
  }),
  chansey,
  new Move(gen, 'Focus Blast')
);
BaiqingL commented 4 months ago

I see, this works, thank you!