Teambuilder: Update HP type when IVs change

This commit is contained in:
Guangcong Luo
2016-05-27 12:55:25 -04:00
parent 60c5b8f1cd
commit 79031a3b9a

View File

@@ -2097,11 +2097,49 @@
if (!set.ivs) set.ivs = {};
if (set.ivs[stat] !== val) {
set.ivs[stat] = val;
this.updateIVs();
this.updateStatGraph();
}
}
this.save();
},
updateIVs: function () {
var set = this.curSet;
if (!set.moves) return;
var hasHiddenPower = false;
for (var i = 0; i < set.moves.length; i++) {
if (toId(set.moves[i]).slice(0, 11) === 'hiddenpower') {
hasHiddenPower = true;
}
break;
}
if (!hasHiddenPower) return;
var hpTypes = ['Fighting', 'Flying', 'Poison', 'Ground', 'Rock', 'Bug', 'Ghost', 'Steel', 'Fire', 'Water', 'Grass', 'Electric', 'Psychic', 'Ice', 'Dragon', 'Dark'];
var hpType;
if (this.curTeam.gen <= 2) {
var atkDV = Math.floor(set.ivs.atk / 2);
var defDV = Math.floor(set.ivs.def / 2);
var speDV = Math.floor(set.ivs.spe / 2);
var spcDV = Math.floor(set.ivs.spa / 2);
hpType = hpTypes[4 * (atkDV % 4) + (defDV % 4)];
} else {
var hpTypeX = 0;
var i = 1;
var stats = {hp: 31, atk: 31, def: 31, spe: 31, spa: 31, spd: 31};
for (var s in stats) {
if (set.ivs[s] === undefined) set.ivs[s] = 31;
hpTypeX += i * (set.ivs[s] % 2);
i *= 2;
}
hpType = hpTypes[Math.floor(hpTypeX * 15 / 63)];
}
for (var i = 0; i < set.moves.length; i++) {
if (toId(set.moves[i]).slice(0, 11) === 'hiddenpower') {
set.moves[i] = "Hidden Power " + hpType;
if (i < 4) this.$('input[name=move' + (i + 1) + ']').val("Hidden Power " + hpType);
}
}
},
statSlide: function (val, slider) {
var stat = slider.inputNode[0].name.substr(9);
var set = this.curSet;