From 0fd323fee7755861e7ef7df6d3b0d23807e17fdc Mon Sep 17 00:00:00 2001 From: Waleed Hassan Date: Wed, 30 Oct 2024 21:35:35 +0300 Subject: [PATCH] Imported HP IVs shouldn't be overwritten Fixes #650 --- src/js/shared_controls.js | 44 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/js/shared_controls.js b/src/js/shared_controls.js index 1e25679cc..97ddf326a 100644 --- a/src/js/shared_controls.js +++ b/src/js/shared_controls.js @@ -968,29 +968,33 @@ function correctHiddenPower(pokemon) { for (var i = 0; i < pokemon.moves.length; i++) { var m = pokemon.moves[i].match(HIDDEN_POWER_REGEX); if (!m) continue; + // The Hidden Power type matches the IVs provided so we don't need to do anything else + if (expected.type === m[1]) { + continue; + } // The Pokemon has Hidden Power and is not maxed but the types don't match we don't // want to attempt to reconcile the user's IVs so instead just correct the HP type - if (!maxed && expected.type !== m[1]) { + if (!maxed) { pokemon.moves[i] = "Hidden Power " + expected.type; - } else { - // Otherwise, use the default preset hidden power IVs that PS would use - var hpIVs = calc.Stats.getHiddenPowerIVs(GENERATION, m[1]); - if (!hpIVs) continue; // some impossible type was specified, ignore - pokemon.ivs = pokemon.ivs || {hp: 31, at: 31, df: 31, sa: 31, sd: 31, sp: 31}; - pokemon.dvs = pokemon.dvs || {hp: 15, at: 15, df: 15, sa: 15, sd: 15, sp: 15}; - for (var stat in hpIVs) { - pokemon.ivs[calc.Stats.shortForm(stat)] = hpIVs[stat]; - pokemon.dvs[calc.Stats.shortForm(stat)] = calc.Stats.IVToDV(hpIVs[stat]); - } - if (gen < 3) { - pokemon.dvs.hp = calc.Stats.getHPDV({ - atk: pokemon.ivs.at || 31, - def: pokemon.ivs.df || 31, - spe: pokemon.ivs.sp || 31, - spc: pokemon.ivs.sa || 31 - }); - pokemon.ivs.hp = calc.Stats.DVToIV(pokemon.dvs.hp); - } + continue; + } + // Otherwise, use the default preset hidden power IVs that PS would use + var hpIVs = calc.Stats.getHiddenPowerIVs(GENERATION, m[1]); + if (!hpIVs) continue; // some impossible type was specified, ignore + pokemon.ivs = pokemon.ivs || {hp: 31, at: 31, df: 31, sa: 31, sd: 31, sp: 31}; + pokemon.dvs = pokemon.dvs || {hp: 15, at: 15, df: 15, sa: 15, sd: 15, sp: 15}; + for (var stat in hpIVs) { + pokemon.ivs[calc.Stats.shortForm(stat)] = hpIVs[stat]; + pokemon.dvs[calc.Stats.shortForm(stat)] = calc.Stats.IVToDV(hpIVs[stat]); + } + if (gen < 3) { + pokemon.dvs.hp = calc.Stats.getHPDV({ + atk: pokemon.ivs.at || 31, + def: pokemon.ivs.df || 31, + spe: pokemon.ivs.sp || 31, + spc: pokemon.ivs.sa || 31 + }); + pokemon.ivs.hp = calc.Stats.DVToIV(pokemon.dvs.hp); } } return pokemon;