SHARE
TWEET

N-shot percentage chance (Pokémon damage calc)

luckytyphlosion Apr 25th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static double nShotPercentage(Move attack, Pokemon attacker, Pokemon defender, StatModifier atkMod,
  2.         StatModifier defMod, int numHitsNonCrit, int numHitsCrit) {
  3.     int rawHitDamageNC = damage(attack, attacker, defender, atkMod, defMod, MAX_RANGE, false);
  4.     int minDamageNC = rawHitDamageNC * MIN_RANGE / 255;
  5.     int[] probsNC = new int[rawHitDamageNC - minDamageNC + 1];
  6.     for (int i = MIN_RANGE; i <= MAX_RANGE; i++) {
  7.         int dmg = rawHitDamageNC * i / 255;
  8.         probsNC[dmg - minDamageNC]++;
  9.     }
  10.     int rawHitDamageCR = damage(attack, attacker, defender, atkMod, defMod, MAX_RANGE, true);
  11.     int minDamageCR = rawHitDamageCR * MIN_RANGE / 255;
  12.     int[] probsCR = new int[rawHitDamageCR - minDamageCR + 1];
  13.     for (int i = MIN_RANGE; i <= MAX_RANGE; i++) {
  14.         int dmg = rawHitDamageCR * i / 255;
  15.         probsCR[dmg - minDamageCR]++;
  16.     }
  17.     double chances = 0;
  18.     int rawHP = defender.getHP();
  19.     if (numHitsNonCrit > 0) {
  20.         for (int i = minDamageNC; i <= rawHitDamageNC; i++) {
  21.             chances += nShotPctInner(minDamageNC, rawHitDamageNC, minDamageCR, rawHitDamageCR, rawHP, 0, i,
  22.                     numHitsNonCrit, numHitsCrit, probsNC, probsCR);
  23.         }
  24.     } else {
  25.         for (int i = minDamageCR; i <= rawHitDamageCR; i++) {
  26.             chances += nShotPctInner(minDamageNC, rawHitDamageNC, minDamageCR, rawHitDamageCR, rawHP, 0, i,
  27.                     numHitsNonCrit, numHitsCrit, probsNC, probsCR);
  28.         }
  29.     }
  30.     return 100.0 * chances / Math.pow(MAX_RANGE - MIN_RANGE + 1, numHitsNonCrit + numHitsCrit);
  31. }
  32.  
  33. private static double nShotPctInner(int minDamageNC, int maxDamageNC, int minDamageCR, int maxDamageCR, int hp,
  34.         int stackedDmg, int rolledDamage, int hitsLeftNonCrit, int hitsLeftCrit, int[] probsNC, int[] probsCR) {
  35.     boolean wasCritical = false;
  36.     if (hitsLeftNonCrit > 0) {
  37.         hitsLeftNonCrit--;
  38.     } else {
  39.         hitsLeftCrit--;
  40.         wasCritical = true;
  41.     }
  42.     stackedDmg += rolledDamage;
  43.     if (stackedDmg >= hp || (stackedDmg + hitsLeftNonCrit * minDamageNC + hitsLeftCrit * minDamageCR) >= hp) {
  44.         return Math.pow(MAX_RANGE - MIN_RANGE + 1, hitsLeftNonCrit + hitsLeftCrit)
  45.                 * (wasCritical ? probsCR[rolledDamage - minDamageCR] : probsNC[rolledDamage - minDamageNC]);
  46.     } else if (hitsLeftNonCrit == 0 && hitsLeftCrit == 0) {
  47.         return 0;
  48.     } else if (stackedDmg + hitsLeftNonCrit * maxDamageNC + hitsLeftCrit * maxDamageCR < hp) {
  49.         return 0;
  50.     } else {
  51.         double chances = 0;
  52.         if (hitsLeftNonCrit > 0) {
  53.             for (int i = minDamageNC; i <= maxDamageNC; i++) {
  54.                 chances += nShotPctInner(minDamageNC, maxDamageNC, minDamageCR, maxDamageCR, hp, stackedDmg, i,
  55.                         hitsLeftNonCrit, hitsLeftCrit, probsNC, probsCR);
  56.             }
  57.         } else {
  58.             for (int i = minDamageCR; i <= maxDamageCR; i++) {
  59.                 chances += nShotPctInner(minDamageNC, maxDamageNC, minDamageCR, maxDamageCR, hp, stackedDmg, i,
  60.                         hitsLeftNonCrit, hitsLeftCrit, probsNC, probsCR);
  61.             }
  62.         }
  63.         return chances * (wasCritical ? probsCR[rolledDamage - minDamageCR] : probsNC[rolledDamage - minDamageNC]);
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top