Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teambuilder: Fix HPIvs ignoring hypertraining #2317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions play.pokemonshowdown.com/js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,19 +1149,11 @@
var reader = new FileReader();
var self = this;
reader.onload = function (e) {
var team;
try {
team = Storage.packTeam(Storage.importTeam(e.target.result));
} catch (err) {
app.addPopupMessage("Your file is not a valid team.");
self.updateTeamList();
return;
}
var name = file.name;
if (name.slice(name.length - 4).toLowerCase() === '.txt') {
name = name.substr(0, name.length - 4);
}
var format = '';
var format = 'gen9';
var bracketIndex = name.indexOf(']');
var capacity = 6;
if (bracketIndex >= 0) {
Expand All @@ -1173,6 +1165,14 @@
}
name = $.trim(name.substr(bracketIndex + 1));
}
var team;
try {
team = Storage.packTeam(Storage.importTeam(e.target.result), false, format);
} catch (err) {
app.addPopupMessage("Your file is not a valid team.");
self.updateTeamList();
return;
}
Storage.teams.push({
name: name,
format: format,
Expand Down Expand Up @@ -1438,9 +1438,9 @@
self.$('.teamnameedit').val(title).change();
}

Storage.activeSetList = self.curSetList = Storage.importTeam(data.paste);
Storage.activeSetList = self.curSetList = Storage.importTeam(data.paste, false, self.curTeam.format);
} else {
Storage.activeSetList = self.curSetList = Storage.importTeam(data);
Storage.activeSetList = self.curSetList = Storage.importTeam(data, false, self.curTeam.format);
}
self.$('.teamedit textarea, .teamedit .savebutton').attr('disabled', null);
self.back();
Expand All @@ -1451,7 +1451,7 @@
}
});
} else {
Storage.activeSetList = this.curSetList = Storage.importTeam(text);
Storage.activeSetList = this.curSetList = Storage.importTeam(text, false, this.curTeam.format);
this.back();
}
},
Expand Down Expand Up @@ -1901,7 +1901,7 @@
},
savePokemonImport: function (i) {
i = +(this.$('li').attr('value'));
var curSet = Storage.importTeam(this.$('.pokemonedit').val())[0];
var curSet = Storage.importTeam(this.$('.pokemonedit').val(), false, this.curTeam.format)[0];
if (curSet) {
this.curSet = curSet;
this.curSetList[i] = curSet;
Expand Down Expand Up @@ -3493,6 +3493,8 @@
}
}

var canHT = this.canHyperTrain(set);

if (!set.ivs) {
if (minSpe === undefined && (!minAtk || gen < 3)) return;
set.ivs = {};
Expand All @@ -3503,7 +3505,7 @@
set.ivs['spe'] = (hasHiddenPower ? set.ivs['spe'] % hpModulo : 0);
} else if (minSpe === false) {
// max Spe
set.ivs['spe'] = (hasHiddenPower ? 30 + (set.ivs['spe'] % 2) : 31);
set.ivs['spe'] = (hasHiddenPower && !canHT ? 30 + (set.ivs['spe'] % 2) : 31);
}
if (gen < 3) return;
if (!set.ivs['atk'] && set.ivs['atk'] !== 0) set.ivs['atk'] = 31;
Expand All @@ -3520,7 +3522,7 @@
}
} else {
// max Atk
set.ivs['atk'] = (hasHiddenPower ? 30 + (set.ivs['atk'] % 2) : 31);
set.ivs['atk'] = (hasHiddenPower && !canHT ? 30 + (set.ivs['atk'] % 2) : 31);
}
},
setPokemon: function (val, selectNext) {
Expand Down
22 changes: 18 additions & 4 deletions play.pokemonshowdown.com/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ Storage.getPackedTeam = function (team) {
return team.team;
};

Storage.importTeam = function (buffer, teams) {
Storage.importTeam = function (buffer, teams, format) {
if (!format) format = 'gen9';
var text = buffer.split("\n");
var team = teams ? null : [];
var curSet = null;
Expand All @@ -1204,7 +1205,6 @@ Storage.importTeam = function (buffer, teams) {
} else if (line.substr(0, 3) === '===' && teams) {
team = [];
line = $.trim(line.substr(3, line.length - 6));
var format = 'gen9';
var capacity = 6;
var bracketIndex = line.indexOf(']');
if (bracketIndex >= 0) {
Expand Down Expand Up @@ -1334,7 +1334,21 @@ Storage.importTeam = function (buffer, teams) {
var hptype = line.substr(14, line.length - 15);
line = 'Hidden Power ' + hptype;
var type = Dex.types.get(hptype);
if (!curSet.ivs && type) {
var gen = parseInt(format[3], 10);
var canHT = false;
if (gen >= 7 & format !== 'gen7hiddentype') {
if (!curSet.level || curSet.level === 100) {
canHT = true;
}
var formatName = format.substr(0, 3) === 'gen' ? format.substr(4) : format;
if (formatName.substr(0, 10) === 'battlespot' || formatName.substr(0, 3) === 'vgc' ||
formatName === 'ultrasinnohclassic') {
if (curSet.level === 50) {
canHT = true;
}
}
}
if (!curSet.ivs && type && !canHT) {
curSet.ivs = {};
for (var stat in type.HPivs) {
curSet.ivs[stat] = type.HPivs[stat];
Expand Down Expand Up @@ -1673,7 +1687,7 @@ Storage.nwLoadTeamFile = function (filename, localApp) {
name: line,
format: format,
gen: parseInt(format[3], 10) || 6,
team: Storage.packTeam(Storage.importTeam('' + data)),
team: Storage.packTeam(Storage.importTeam('' + data), false, format),
capacity: capacity,
folder: folder,
iconCache: '',
Expand Down
Loading