Update Dex API to match server API (#1746)

This commit is contained in:
Mia
2021-04-14 03:22:38 -05:00
committed by GitHub
parent b6193fbe7d
commit 31fcd418ec
13 changed files with 471 additions and 455 deletions

View File

@@ -537,10 +537,10 @@
var gigantamax = curActive.gigantamax;
if (canZMove && typeof canZMove[0] === 'string') {
canZMove = _.map(canZMove, function (move) {
return {move: move, target: Dex.getMove(move).target};
return {move: move, target: Dex.moves.get(move).target};
});
}
if (gigantamax) gigantamax = Dex.getMove(gigantamax);
if (gigantamax) gigantamax = Dex.moves.get(gigantamax);
this.finalDecisionMove = curActive.maybeDisabled || false;
this.finalDecisionSwitch = curActive.maybeTrapped || false;
@@ -632,7 +632,7 @@
var currentlyDynamaxed = (!canDynamax && maxMoves);
for (var i = 0; i < curActive.moves.length; i++) {
var moveData = curActive.moves[i];
var move = this.battle.dex.getMove(moveData.move);
var move = this.battle.dex.moves.get(moveData.move);
var name = move.name;
var pp = moveData.pp + '/' + moveData.maxpp;
if (!moveData.maxpp) pp = '&ndash;';
@@ -647,7 +647,7 @@
movebuttons += '<button class="type-' + moveType + ' has-tooltip" name="chooseMove" value="' + (i + 1) + '" data-move="' + BattleLog.escapeHTML(moveData.move) + '" data-target="' + BattleLog.escapeHTML(moveData.target) + '" data-tooltip="' + BattleLog.escapeHTML(tooltipArgs) + '">';
hasMoves = true;
}
movebuttons += name + '<br /><small class="type">' + (moveType ? Dex.getType(moveType).name : "Unknown") + '</small> <small class="pp">' + pp + '</small>&nbsp;</button> ';
movebuttons += name + '<br /><small class="type">' + (moveType ? Dex.types.get(moveType).name : "Unknown") + '</small> <small class="pp">' + pp + '</small>&nbsp;</button> ';
}
if (!hasMoves) {
moveMenu += '<button class="movebutton" name="chooseMove" value="0" data-move="Struggle" data-target="randomNormal">Struggle<br /><small class="type">Normal</small> <small class="pp">&ndash;</small>&nbsp;</button> ';
@@ -663,9 +663,9 @@
for (var i = 0; i < curActive.moves.length; i++) {
if (specialMoves[i]) {
// when possible, use Z move to decide type, for cases like Z-Hidden Power
var baseMove = this.battle.dex.getMove(curActive.moves[i].move);
var baseMove = this.battle.dex.moves.get(curActive.moves[i].move);
// might not exist, such as for Z status moves - fall back on base move to determine type then
var specialMove = gigantamax || this.battle.dex.getMove(specialMoves[i].move);
var specialMove = gigantamax || this.battle.dex.moves.get(specialMoves[i].move);
var moveType = this.tooltips.getMoveType(specialMove.exists && !specialMove.isMax ? specialMove : baseMove, typeValueTracker, specialMove.isMax ? gigantamax || switchables[pos].gigantamax || true : undefined)[0];
var tooltipArgs = classType + 'move|' + baseMove.id + '|' + pos;
if (specialMove.id.startsWith('gmax')) tooltipArgs += '|' + specialMove.id;
@@ -677,7 +677,7 @@
} else if (!curActive.moves[i].maxpp) {
pp = '&ndash;';
}
movebuttons += specialMove.name + '<br /><small class="type">' + (moveType ? Dex.getType(moveType).name : "Unknown") + '</small> <small class="pp">' + pp + '</small>&nbsp;</button> ';
movebuttons += specialMove.name + '<br /><small class="type">' + (moveType ? Dex.types.get(moveType).name : "Unknown") + '</small> <small class="pp">' + pp + '</small>&nbsp;</button> ';
} else {
movebuttons += '<button disabled="disabled">&nbsp;</button>';
}
@@ -945,7 +945,7 @@
}
}
}
buf += 'use ' + Dex.getMove(move).name + (target ? ' at ' + target : '') + '.<br />';
buf += 'use ' + Dex.moves.get(move).name + (target ? ' at ' + target : '') + '.<br />';
break;
case 'switch':
buf += '' + myPokemon[parts[1] - 1].speciesForme + ' will switch in';

View File

@@ -1146,7 +1146,7 @@
if ($(window).width() < 640) this.show();
},
renderSet: function (set, i) {
var species = Dex.getSpecies(set.species);
var species = Dex.species.get(set.species);
var isLetsGo = this.curTeam.format.includes('letsgo');
var isNatDex = this.curTeam.format.includes('nationaldex');
var buf = '<li value="' + i + '">';
@@ -1212,7 +1212,7 @@
buf += '<div class="setcell">';
var itemicon = '<span class="itemicon"></span>';
if (set.item) {
var item = Dex.getItem(set.item);
var item = Dex.items.get(set.item);
itemicon = '<span class="itemicon" style="' + Dex.getItemIcon(item) + '"></span>';
}
buf += itemicon;
@@ -1436,7 +1436,7 @@
var buf = '';
for (var i = 0; i < this.clipboardCount(); i++) {
var res = this.clipboard[i];
var species = Dex.getSpecies(res.species);
var species = Dex.species.get(res.species);
buf += '<div class="result" data-id="' + i + '">';
buf += '<div class="section"><span class="icon" style="' + Dex.getPokemonIcon(species.name) + '"></span>';
@@ -1734,9 +1734,9 @@
buf += '<button disabled="disabled" class="addpokemon" aria-label="Add Pok&eacute;mon"><i class="fa fa-plus"></i></button> ';
isAdd = true;
} else if (i == this.curSetLoc) {
buf += '<button disabled="disabled" class="pokemon">' + pokemonicon + BattleLog.escapeHTML(set.name || Dex.getSpecies(set.species).baseSpecies || '<i class="fa fa-plus"></i>') + '</button> ';
buf += '<button disabled="disabled" class="pokemon">' + pokemonicon + BattleLog.escapeHTML(set.name || Dex.species.get(set.species).baseSpecies || '<i class="fa fa-plus"></i>') + '</button> ';
} else {
buf += '<button name="selectPokemon" value="' + i + '" class="pokemon">' + pokemonicon + BattleLog.escapeHTML(set.name || Dex.getSpecies(set.species).baseSpecies) + '</button> ';
buf += '<button name="selectPokemon" value="' + i + '" class="pokemon">' + pokemonicon + BattleLog.escapeHTML(set.name || Dex.species.get(set.species).baseSpecies) + '</button> ';
}
}
if (this.curSetList.length < this.curTeam.capacity && !isAdd) {
@@ -1752,7 +1752,7 @@
this.$('.pokemonicon-' + this.curSetLoc).css('background', Dex.getPokemonIcon(set).substr(11));
var item = Dex.getItem(set.item);
var item = Dex.items.get(set.item);
if (item.id) {
this.$('.setcol-details .itemicon').css('background', Dex.getItemIcon(item).substr(11));
} else {
@@ -1921,7 +1921,7 @@
plus: '',
minus: '',
smogdexLink: function (s) {
var species = Dex.getSpecies(s);
var species = Dex.species.get(s);
var format = this.curTeam && this.curTeam.format;
var smogdexid = toID(species.baseSpecies);
@@ -1982,7 +1982,7 @@
updateStatForm: function (setGuessed) {
var buf = '';
var set = this.curSet;
var species = Dex.forGen(this.curTeam.gen).getSpecies(this.curSet.species);
var species = Dex.forGen(this.curTeam.gen).species.get(this.curSet.species);
var baseStats = species.baseStats;
@@ -2505,7 +2505,7 @@
var set = this.curSet;
var isLetsGo = this.curTeam.format.includes('letsgo');
var isNatDex = this.curTeam.gen === 8 && this.curTeam.format.includes('nationaldex');
var species = Dex.getSpecies(set.species);
var species = Dex.species.get(set.species);
if (!set) return;
buf += '<div class="resultheader"><h3>Details</h3></div>';
buf += '<form class="detailsform">';
@@ -2586,7 +2586,7 @@
e.stopPropagation();
var set = this.curSet;
if (!set) return;
var species = Dex.getSpecies(set.species);
var species = Dex.species.get(set.species);
var isLetsGo = this.curTeam.format.includes('letsgo');
var isNatDex = this.curTeam.format.includes('nationaldex');
@@ -2629,7 +2629,7 @@
// pokeball
var pokeball = this.$chart.find('select[name=pokeball]').val();
if (pokeball && Dex.forGen(this.curTeam.gen).getItem(pokeball).isPokeball) {
if (pokeball && Dex.forGen(this.curTeam.gen).items.get(pokeball).isPokeball) {
set.pokeball = pokeball;
} else {
delete set.pokeball;
@@ -2834,7 +2834,7 @@
var val = '';
switch (name) {
case 'pokemon':
val = (id in BattlePokedex ? Dex.getSpecies(e.currentTarget.value).name : '');
val = (id in BattlePokedex ? Dex.species.get(e.currentTarget.value).name : '');
break;
case 'ability':
if (id in BattleItems && this.curTeam.format == "gen8dualwielding") {
@@ -3053,7 +3053,7 @@
for (var i = 0; i < moves.length; ++i) {
if (!moves[i]) continue;
if (moves[i].substr(0, 13) === 'Hidden Power ') hasHiddenPower = true;
var move = Dex.forGen(this.curTeam.gen).getMove(moves[i]);
var move = Dex.forGen(this.curTeam.gen).moves.get(moves[i]);
if (move.id === 'transform') {
hasHiddenPower = true; // A Pokemon with Transform can copy another Pokemon that knows Hidden Power
@@ -3100,7 +3100,7 @@
},
setPokemon: function (val, selectNext) {
var set = this.curSet;
var species = Dex.forGen(this.curTeam.gen).getSpecies(val);
var species = Dex.forGen(this.curTeam.gen).species.get(val);
if (!species.exists || set.species === species.name) {
if (selectNext) this.$('input[name=item]').select();
return;
@@ -3167,7 +3167,7 @@
// do this after setting set.evs because it's assumed to exist
// after getStat is run
var species = Dex.forGen(this.curTeam.gen).getSpecies(set.species);
var species = Dex.forGen(this.curTeam.gen).species.get(set.species);
if (!species.exists) return 0;
if (!set.level) set.level = 100;
@@ -3271,7 +3271,7 @@
this.room = data.room;
this.curSet = data.curSet;
this.chartIndex = data.index;
var species = Dex.getSpecies(this.curSet.species);
var species = Dex.species.get(this.curSet.species);
var baseid = toID(species.baseSpecies);
var forms = [baseid].concat(species.cosmeticFormes.map(toID));
var spriteDir = Dex.resourcePrefix + 'sprites/';
@@ -3307,9 +3307,9 @@
this.$el.html(buf).css({'max-width': (4 + spriteSize) * width, 'height': 42 + (4 + spriteSize) * height});
},
setForm: function (form) {
var species = Dex.getSpecies(this.curSet.species);
var species = Dex.species.get(this.curSet.species);
if (form && form !== species.form) {
this.curSet.species = Dex.getSpecies(species.baseSpecies + form).name;
this.curSet.species = Dex.species.get(species.baseSpecies + form).name;
} else if (!form) {
this.curSet.species = species.baseSpecies;
}

View File

@@ -108,8 +108,8 @@
var buf = '<p>Filters: ';
for (var i = 0; i < this.filters.length; i++) {
var text = this.filters[i][1];
if (this.filters[i][0] === 'move') text = Dex.getMove(text).name;
if (this.filters[i][0] === 'pokemon') text = Dex.getSpecies(text).name;
if (this.filters[i][0] === 'move') text = Dex.moves.get(text).name;
if (this.filters[i][0] === 'pokemon') text = Dex.species.get(text).name;
buf += '<button class="filter" value="' + BattleLog.escapeHTML(this.filters[i].join(':')) + '">' + text + ' <i class="fa fa-times-circle"></i></button> ';
}
if (!q) buf += '<small style="color: #888">(backspace = delete filter)</small>';
@@ -197,16 +197,16 @@
case 'sortmove':
return this.renderMoveSortRow();
case 'pokemon':
var pokemon = this.engine.dex.getSpecies(id);
var pokemon = this.engine.dex.species.get(id);
return this.renderPokemonRow(pokemon, matchStart, matchLength, errorMessage, attrs);
case 'move':
var move = this.engine.dex.getMove(id);
var move = this.engine.dex.moves.get(id);
return this.renderMoveRow(move, matchStart, matchLength, errorMessage, attrs);
case 'item':
var item = this.engine.dex.getItem(id);
var item = this.engine.Dex.items.get(id);
return this.renderItemRow(item, matchStart, matchLength, errorMessage, attrs);
case 'ability':
var ability = this.engine.dex.getAbility(id);
var ability = this.engine.dex.abilities.get(id);
return this.renderAbilityRow(ability, matchStart, matchLength, errorMessage, attrs);
case 'type':
var type = {name: id[0].toUpperCase() + id.substr(1)};
@@ -339,7 +339,7 @@
// abilities
if (gen >= 3) {
var abilities = Dex.forGen(gen).getSpecies(id).abilities;
var abilities = Dex.forGen(gen).species.get(id).abilities;
if (abilities['1']) {
buf += '<span class="col twoabilitycol">' + abilities['0'] + '<br />' +
abilities['1'] + '</span>';

View File

@@ -806,7 +806,7 @@ Storage.fastUnpackTeam = function (buf) {
// ability
j = buf.indexOf('|', i);
var ability = buf.substring(i, j);
var species = Dex.getSpecies(set.species);
var species = Dex.species.get(set.species);
if (species.baseSpecies === 'Zygarde' && ability === 'H') ability = 'Power Construct';
set.ability = (species.abilities && ['', '0', '1', 'H', 'S'].includes(ability) ? species.abilities[ability] || '!!!ERROR!!!' : ability);
i = j + 1;
@@ -910,25 +910,25 @@ Storage.unpackTeam = function (buf) {
// species
j = buf.indexOf('|', i);
set.species = Dex.getSpecies(buf.substring(i, j)).name || set.name;
set.species = Dex.species.get(buf.substring(i, j)).name || set.name;
i = j + 1;
// item
j = buf.indexOf('|', i);
set.item = Dex.getItem(buf.substring(i, j)).name;
set.item = Dex.items.get(buf.substring(i, j)).name;
i = j + 1;
// ability
j = buf.indexOf('|', i);
var ability = Dex.getAbility(buf.substring(i, j)).name;
var species = Dex.getSpecies(set.species);
var ability = Dex.abilities.get(buf.substring(i, j)).name;
var species = Dex.species.get(set.species);
set.ability = (species.abilities && ability in {'':1, 0:1, 1:1, H:1} ? species.abilities[ability || '0'] : ability);
i = j + 1;
// moves
j = buf.indexOf('|', i);
set.moves = buf.substring(i, j).split(',').map(function (moveid) {
return Dex.getMove(moveid).name;
return Dex.moves.get(moveid).name;
});
i = j + 1;
@@ -1152,11 +1152,11 @@ Storage.importTeam = function (buffer, teams) {
var parenIndex = line.lastIndexOf(' (');
if (line.substr(line.length - 1) === ')' && parenIndex !== -1) {
line = line.substr(0, line.length - 1);
curSet.species = Dex.getSpecies(line.substr(parenIndex + 2)).name;
curSet.species = Dex.species.get(line.substr(parenIndex + 2)).name;
line = line.substr(0, parenIndex);
curSet.name = line;
} else {
curSet.species = Dex.getSpecies(line).name;
curSet.species = Dex.species.get(line).name;
curSet.name = '';
}
} else if (line.substr(0, 7) === 'Trait: ') {

View File

@@ -515,7 +515,7 @@ class BattleScene {
let animEntry = BattleMoveAnims[moveid];
if (this.acceleration >= 3) {
const targetsSelf = !participants[1] || participants[0] === participants[1];
const isSpecial = !targetsSelf && this.battle.dex.getMove(moveid).category === 'Special';
const isSpecial = !targetsSelf && this.battle.dex.moves.get(moveid).category === 'Special';
animEntry = BattleOtherAnims[targetsSelf ? 'fastanimself' : isSpecial ? 'fastanimspecial' : 'fastanimattack'];
} else if (!animEntry) {
animEntry = BattleMoveAnims['tackle'];
@@ -868,7 +868,7 @@ class BattleScene {
}
pseudoWeatherLeft(pWeather: WeatherState) {
let buf = '<br />' + Dex.getMove(pWeather[0]).name;
let buf = '<br />' + Dex.moves.get(pWeather[0]).name;
if (!pWeather[1] && pWeather[2]) {
pWeather[1] = pWeather[2];
pWeather[2] = 0;
@@ -884,7 +884,7 @@ class BattleScene {
}
sideConditionLeft(cond: [string, number, number, number], isFoe: boolean, all?: boolean) {
if (!cond[2] && !cond[3] && !all) return '';
let buf = `<br />${isFoe && !all ? "Foe's " : ""}${Dex.getMove(cond[0]).name}`;
let buf = `<br />${isFoe && !all ? "Foe's " : ""}${Dex.moves.get(cond[0]).name}`;
if (this.battle.gen < 7 && this.battle.hardcoreMode) return buf;
if (!cond[2] && !cond[3]) return buf;

View File

@@ -377,7 +377,7 @@ class BattleChoiceBuilder {
curMatchLevel = 8;
} else if (choiceid === toID(serverPokemon.speciesForme)) {
curMatchLevel = 7;
} else if (choiceid === toID(Dex.getSpecies(serverPokemon.speciesForme).baseSpecies)) {
} else if (choiceid === toID(Dex.species.get(serverPokemon.speciesForme).baseSpecies)) {
curMatchLevel = 6;
}
if (curMatchLevel > matchLevel) {
@@ -473,7 +473,7 @@ class BattleChoiceBuilder {
active.maxMoves = active.maxMoves.maxMoves;
}
for (const move of active.maxMoves) {
if (move.move) move.name = Dex.getMove(move.move).name;
if (move.move) move.name = Dex.moves.get(move.move).name;
move.id = toID(move.name);
}
}

View File

@@ -455,17 +455,17 @@ class DexSearch {
buf.push(['header', `${type}-type Pok&eacute;mon`]);
for (let id in BattlePokedex) {
if (!BattlePokedex[id].types) continue;
if (this.dex.getSpecies(id).types.includes(type)) {
if (this.dex.species.get(id).types.includes(type)) {
(illegal && id in illegal ? illegalBuf : buf).push(['pokemon', id as ID]);
}
}
break;
case 'ability':
let ability = Dex.getAbility(fId).name;
let ability = Dex.abilities.get(fId).name;
buf.push(['header', `${ability} Pok&eacute;mon`]);
for (let id in BattlePokedex) {
if (!BattlePokedex[id].abilities) continue;
if (Dex.hasAbility(this.dex.getSpecies(id), ability)) {
if (Dex.hasAbility(this.dex.species.get(id), ability)) {
(illegal && id in illegal ? illegalBuf : buf).push(['pokemon', id as ID]);
}
}
@@ -688,7 +688,7 @@ abstract class BattleTypedSearch<T extends SearchType> {
}
protected firstLearnsetid(speciesid: ID) {
if (speciesid in BattleTeambuilderTable.learnsets) return speciesid;
const species = this.dex.getSpecies(speciesid);
const species = this.dex.species.get(speciesid);
if (!species.exists) return '' as ID;
let baseLearnsetid = toID(species.baseSpecies);
@@ -702,7 +702,7 @@ abstract class BattleTypedSearch<T extends SearchType> {
if (learnsetid === 'lycanrocdusk' || (speciesid === 'rockruff' && learnsetid === 'rockruff')) {
return 'rockruffdusk' as ID;
}
const lsetSpecies = this.dex.getSpecies(learnsetid);
const lsetSpecies = this.dex.species.get(learnsetid);
if (!lsetSpecies.exists) return '' as ID;
if (lsetSpecies.id === 'gastrodoneast') return 'gastrodon' as ID;
@@ -714,7 +714,7 @@ abstract class BattleTypedSearch<T extends SearchType> {
return '' as ID;
}
protected canLearn(speciesid: ID, moveid: ID) {
if (this.dex.gen >= 8 && this.dex.getMove(moveid).isNonstandard === 'Past' && this.formatType !== 'natdex') {
if (this.dex.gen >= 8 && this.dex.moves.get(moveid).isNonstandard === 'Past' && this.formatType !== 'natdex') {
return false;
}
let genChar = `${this.dex.gen}`;
@@ -889,8 +889,9 @@ class BattlePokemonSearch extends BattleTypedSearch<'pokemon'> {
else if (format === 'lc' || format === 'lcuu' || format.startsWith('lc') || (format !== 'caplc' && format.endsWith('lc'))) tierSet = tierSet.slice(slices.LC);
else if (format === 'cap') tierSet = tierSet.slice(0, slices.Uber).concat(tierSet.slice(slices.OU));
else if (format === 'caplc') tierSet = tierSet.slice(slices['CAP LC'], slices.Uber).concat(tierSet.slice(slices.LC));
else if (format === 'anythinggoes' || format.endsWith('ag') || format.startsWith('ag')) tierSet = tierSet.slice(slices.AG);
else if (format.includes('hackmons') || format.endsWith('bh')) tierSet = tierSet.slice(slices.AG);
else if (format === 'anythinggoes' || format.endsWith('ag') || format.startsWith('ag')) {
tierSet = tierSet.slice(slices.AG);
} else if (format.includes('hackmons') || format.endsWith('bh')) tierSet = tierSet.slice(slices.AG);
else if (format === 'doublesubers') tierSet = tierSet.slice(slices.DUber);
else if (format === 'doublesou' && dex.gen > 4) tierSet = tierSet.slice(slices.DOU);
else if (format === 'doublesuu') tierSet = tierSet.slice(slices.DUU);
@@ -941,7 +942,7 @@ class BattlePokemonSearch extends BattleTypedSearch<'pokemon'> {
filter(row: SearchRow, filters: string[][]) {
if (!filters) return true;
if (row[0] !== 'pokemon') return true;
const species = this.dex.getSpecies(row[1]);
const species = this.dex.species.get(row[1]);
for (const [filterType, value] of filters) {
switch (filterType) {
case 'type':
@@ -1005,12 +1006,12 @@ class BattleAbilitySearch extends BattleTypedSearch<'ability'> {
const isHackmons = (format.includes('hackmons') || format.endsWith('bh'));
const isAAA = (format === 'almostanyability' || format.includes('aaa'));
const dex = this.dex;
let species = dex.getSpecies(this.species);
let species = dex.species.get(this.species);
let abilitySet: SearchRow[] = [['header', "Abilities"]];
if (species.isMega) {
abilitySet.unshift(['html', `Will be <strong>${species.abilities['0']}</strong> after Mega Evolving.`]);
species = dex.getSpecies(species.baseSpecies);
species = dex.species.get(species.baseSpecies);
}
abilitySet.push(['ability', toID(species.abilities['0'])]);
if (species.abilities['1']) {
@@ -1027,7 +1028,7 @@ class BattleAbilitySearch extends BattleTypedSearch<'ability'> {
if (isAAA || format === 'metronomebattle' || isHackmons) {
let abilities: ID[] = [];
for (let i in this.getTable()) {
const ability = dex.getAbility(i);
const ability = dex.abilities.get(i);
if (ability.isNonstandard) continue;
if (ability.gen > dex.gen) continue;
abilities.push(ability.id);
@@ -1036,7 +1037,7 @@ class BattleAbilitySearch extends BattleTypedSearch<'ability'> {
let goodAbilities: SearchRow[] = [['header', "Abilities"]];
let poorAbilities: SearchRow[] = [['header', "Situational Abilities"]];
let badAbilities: SearchRow[] = [['header', "Unviable Abilities"]];
for (const ability of abilities.sort().map(abil => dex.getAbility(abil))) {
for (const ability of abilities.sort().map(abil => dex.abilities.get(abil))) {
let rating = ability.rating;
if (ability.id === 'normalize') rating = 3;
if (rating >= 3) {
@@ -1060,11 +1061,11 @@ class BattleAbilitySearch extends BattleTypedSearch<'ability'> {
filter(row: SearchRow, filters: string[][]) {
if (!filters) return true;
if (row[0] !== 'ability') return true;
const ability = this.dex.getAbility(row[1]);
const ability = this.dex.abilities.get(row[1]);
for (const [filterType, value] of filters) {
switch (filterType) {
case 'pokemon':
if (!Dex.hasAbility(this.dex.getSpecies(value), ability.name)) return false;
if (!Dex.hasAbility(this.dex.species.get(value), ability.name)) return false;
break;
}
}
@@ -1101,12 +1102,12 @@ class BattleItemSearch extends BattleTypedSearch<'item'> {
}
getBaseResults(): SearchRow[] {
if (!this.species) return this.getDefaultResults();
const speciesName = this.dex.getSpecies(this.species).name;
const speciesName = this.dex.species.get(this.species).name;
const results = this.getDefaultResults();
const speciesSpecific: SearchRow[] = [];
for (const row of results) {
if (row[0] !== 'item') continue;
if (this.dex.getItem(row[1]).itemUser?.includes(speciesName)) {
if (this.dex.items.get(row[1]).itemUser?.includes(speciesName)) {
speciesSpecific.push(row);
}
}
@@ -1122,11 +1123,11 @@ class BattleItemSearch extends BattleTypedSearch<'item'> {
filter(row: SearchRow, filters: string[][]) {
if (!filters) return true;
if (row[0] !== 'ability') return true;
const ability = this.dex.getAbility(row[1]);
const ability = this.dex.abilities.get(row[1]);
for (const [filterType, value] of filters) {
switch (filterType) {
case 'pokemon':
if (!Dex.hasAbility(this.dex.getSpecies(value), ability.name)) return false;
if (!Dex.hasAbility(this.dex.species.get(value), ability.name)) return false;
break;
}
}
@@ -1351,7 +1352,7 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
getBaseResults() {
if (!this.species) return this.getDefaultResults();
const dex = this.dex;
let species = dex.getSpecies(this.species);
let species = dex.species.get(this.species);
const format = this.format;
const isHackmons = (format.includes('hackmons') || format.endsWith('bh'));
const isSTABmons = (format.includes('stabmons') || format === 'staaabmons');
@@ -1380,8 +1381,18 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
} else if (!learnsetEntry.includes(gen)) {
continue;
}
if (this.dex.gen >= 8 && BattleMovedex[moveid].isNonstandard === "Past" && this.formatType !== 'natdex') continue;
if (this.formatType?.startsWith('dlc1') && BattleTeambuilderTable['gen8dlc1']?.nonstandardMoves.includes(moveid)) continue;
if (
this.dex.gen >= 8 && this.formatType !== 'natdex' &&
BattleMovedex[moveid].isNonstandard === "Past"
) {
continue;
}
if (
this.formatType?.startsWith('dlc1') &&
BattleTeambuilderTable['gen8dlc1']?.nonstandardMoves.includes(moveid)
) {
continue;
}
if (moves.includes(moveid)) continue;
moves.push(moveid);
if (moveid === 'sketch') sketch = true;
@@ -1398,7 +1409,7 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
if (isHackmons) moves = [];
for (let id in BattleMovedex) {
if (!format.startsWith('cap') && (id === 'paleowave' || id === 'shadowstrike')) continue;
const move = dex.getMove(id);
const move = dex.moves.get(id);
if (move.gen > dex.gen) continue;
if (sketch) {
if (move.isMax || move.isZ || move.isNonstandard) continue;
@@ -1416,11 +1427,11 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
if (isSTABmons) {
for (let id in this.getTable()) {
let types: string[] = [];
let baseSpecies = dex.getSpecies(species.changesFrom || species.name);
let baseSpecies = dex.species.get(species.changesFrom || species.name);
if (!species.battleOnly) types.push(...species.types);
let prevo = species.prevo;
while (prevo) {
const prevoSpecies = dex.getSpecies(prevo);
const prevoSpecies = dex.species.get(prevo);
types.push(...prevoSpecies.types);
prevo = prevoSpecies.prevo;
}
@@ -1429,11 +1440,11 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
if (baseSpecies.otherFormes && !['Wormadam', 'Urshifu'].includes(baseSpecies.baseSpecies)) {
if (!excludedForme(species)) types.push(...baseSpecies.types);
for (const formeName of baseSpecies.otherFormes) {
const forme = dex.getSpecies(formeName);
const forme = dex.species.get(formeName);
if (!forme.battleOnly && !excludedForme(forme)) types.push(...forme.types);
}
}
const move = Dex.getMove(id);
const move = Dex.moves.get(id);
if (!types.includes(move.type)) continue;
if (moves.includes(move.id)) continue;
if (move.gen > dex.gen) continue;
@@ -1474,7 +1485,7 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
filter(row: SearchRow, filters: string[][]) {
if (!filters) return true;
if (row[0] !== 'move') return true;
const move = this.dex.getMove(row[1]);
const move = this.dex.moves.get(row[1]);
for (const [filterType, value] of filters) {
switch (filterType) {
case 'type':

View File

@@ -260,56 +260,58 @@ const Dex = new class implements ModdedDex {
getEffect(name: string | null | undefined): PureEffect | Item | Ability | Move {
name = (name || '').trim();
if (name.substr(0, 5) === 'item:') {
return Dex.getItem(name.substr(5).trim());
return Dex.items.get(name.substr(5).trim());
} else if (name.substr(0, 8) === 'ability:') {
return Dex.getAbility(name.substr(8).trim());
return Dex.abilities.get(name.substr(8).trim());
} else if (name.substr(0, 5) === 'move:') {
return Dex.getMove(name.substr(5).trim());
return Dex.moves.get(name.substr(5).trim());
}
let id = toID(name);
return new PureEffect(id, name);
}
getMove(nameOrMove: string | Move | null | undefined): Move {
if (nameOrMove && typeof nameOrMove !== 'string') {
// TODO: don't accept Moves here
return nameOrMove;
}
let name = nameOrMove || '';
let id = toID(nameOrMove);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (!window.BattleMovedex) window.BattleMovedex = {};
let data = window.BattleMovedex[id];
if (data && typeof data.exists === 'boolean') return data;
moves = {
get: (nameOrMove: string | Move | null | undefined): Move => {
if (nameOrMove && typeof nameOrMove !== 'string') {
// TODO: don't accept Moves here
return nameOrMove;
}
let name = nameOrMove || '';
let id = toID(nameOrMove);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (!window.BattleMovedex) window.BattleMovedex = {};
let data = window.BattleMovedex[id];
if (data && typeof data.exists === 'boolean') return data;
if (!data && id.substr(0, 11) === 'hiddenpower' && id.length > 11) {
let [, hpWithType, hpPower] = /([a-z]*)([0-9]*)/.exec(id)!;
data = {
...(window.BattleMovedex[hpWithType] || {}),
basePower: Number(hpPower) || 60,
};
}
if (!data && id.substr(0, 6) === 'return' && id.length > 6) {
data = {
...(window.BattleMovedex['return'] || {}),
basePower: Number(id.slice(6)),
};
}
if (!data && id.substr(0, 11) === 'frustration' && id.length > 11) {
data = {
...(window.BattleMovedex['frustration'] || {}),
basePower: Number(id.slice(11)),
};
}
if (!data && id.substr(0, 11) === 'hiddenpower' && id.length > 11) {
let [, hpWithType, hpPower] = /([a-z]*)([0-9]*)/.exec(id)!;
data = {
...(window.BattleMovedex[hpWithType] || {}),
basePower: Number(hpPower) || 60,
};
}
if (!data && id.substr(0, 6) === 'return' && id.length > 6) {
data = {
...(window.BattleMovedex['return'] || {}),
basePower: Number(id.slice(6)),
};
}
if (!data && id.substr(0, 11) === 'frustration' && id.length > 11) {
data = {
...(window.BattleMovedex['frustration'] || {}),
basePower: Number(id.slice(11)),
};
}
if (!data) data = {exists: false};
let move = new Move(id, name, data);
window.BattleMovedex[id] = move;
return move;
}
if (!data) data = {exists: false};
let move = new Move(id, name, data);
window.BattleMovedex[id] = move;
return move;
},
};
getGen3Category(type: string) {
return [
@@ -317,143 +319,127 @@ const Dex = new class implements ModdedDex {
].includes(type) ? 'Special' : 'Physical';
}
getItem(nameOrItem: string | Item | null | undefined): Item {
if (nameOrItem && typeof nameOrItem !== 'string') {
// TODO: don't accept Items here
return nameOrItem;
}
let name = nameOrItem || '';
let id = toID(nameOrItem);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (!window.BattleItems) window.BattleItems = {};
let data = window.BattleItems[id];
if (data && typeof data.exists === 'boolean') return data;
if (!data) data = {exists: false};
let item = new Item(id, name, data);
window.BattleItems[id] = item;
return item;
}
getAbility(nameOrAbility: string | Ability | null | undefined): Ability {
if (nameOrAbility && typeof nameOrAbility !== 'string') {
// TODO: don't accept Abilities here
return nameOrAbility;
}
let name = nameOrAbility || '';
let id = toID(nameOrAbility);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (!window.BattleAbilities) window.BattleAbilities = {};
let data = window.BattleAbilities[id];
if (data && typeof data.exists === 'boolean') return data;
if (!data) data = {exists: false};
let ability = new Ability(id, name, data);
window.BattleAbilities[id] = ability;
return ability;
}
getSpecies(nameOrSpecies: string | Species | null | undefined): Species {
if (nameOrSpecies && typeof nameOrSpecies !== 'string') {
// TODO: don't accept Species' here
return nameOrSpecies;
}
let name = nameOrSpecies || '';
let id = toID(nameOrSpecies);
let formid = id;
if (!window.BattlePokedexAltForms) window.BattlePokedexAltForms = {};
if (formid in window.BattlePokedexAltForms) return window.BattlePokedexAltForms[formid];
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
} else if (window.BattlePokedex && !(id in BattlePokedex) && window.BattleBaseSpeciesChart) {
for (const baseSpeciesId of BattleBaseSpeciesChart) {
if (formid.startsWith(baseSpeciesId)) {
id = baseSpeciesId;
break;
}
items = {
get: (nameOrItem: string | Item | null | undefined): Item => {
if (nameOrItem && typeof nameOrItem !== 'string') {
// TODO: don't accept Items here
return nameOrItem;
}
}
if (!window.BattlePokedex) window.BattlePokedex = {};
let data = window.BattlePokedex[id];
let species: Species;
if (data && typeof data.exists === 'boolean') {
species = data;
} else {
let name = nameOrItem || '';
let id = toID(nameOrItem);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (!window.BattleItems) window.BattleItems = {};
let data = window.BattleItems[id];
if (data && typeof data.exists === 'boolean') return data;
if (!data) data = {exists: false};
if (!data.tier && id.slice(-5) === 'totem') {
data.tier = this.getSpecies(id.slice(0, -5)).tier;
}
if (!data.tier && data.baseSpecies && toID(data.baseSpecies) !== id) {
data.tier = this.getSpecies(data.baseSpecies).tier;
}
species = new Species(id, name, data);
window.BattlePokedex[id] = species;
}
let item = new Item(id, name, data);
window.BattleItems[id] = item;
return item;
},
};
if (species.cosmeticFormes) {
for (const forme of species.cosmeticFormes) {
if (toID(forme) === formid) {
species = new Species(formid, name, {
...species,
name: forme,
forme: forme.slice(species.name.length + 1),
baseForme: "",
baseSpecies: species.name,
otherFormes: null,
});
window.BattlePokedexAltForms[formid] = species;
break;
abilities = {
get: (nameOrAbility: string | Ability | null | undefined): Ability => {
if (nameOrAbility && typeof nameOrAbility !== 'string') {
// TODO: don't accept Abilities here
return nameOrAbility;
}
let name = nameOrAbility || '';
let id = toID(nameOrAbility);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (!window.BattleAbilities) window.BattleAbilities = {};
let data = window.BattleAbilities[id];
if (data && typeof data.exists === 'boolean') return data;
if (!data) data = {exists: false};
let ability = new Ability(id, name, data);
window.BattleAbilities[id] = ability;
return ability;
},
};
species = {
get: (nameOrSpecies: string | Species | null | undefined): Species => {
if (nameOrSpecies && typeof nameOrSpecies !== 'string') {
// TODO: don't accept Species' here
return nameOrSpecies;
}
let name = nameOrSpecies || '';
let id = toID(nameOrSpecies);
let formid = id;
if (!window.BattlePokedexAltForms) window.BattlePokedexAltForms = {};
if (formid in window.BattlePokedexAltForms) return window.BattlePokedexAltForms[formid];
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
} else if (window.BattlePokedex && !(id in BattlePokedex) && window.BattleBaseSpeciesChart) {
for (const baseSpeciesId of BattleBaseSpeciesChart) {
if (formid.startsWith(baseSpeciesId)) {
id = baseSpeciesId;
break;
}
}
}
}
if (!window.BattlePokedex) window.BattlePokedex = {};
let data = window.BattlePokedex[id];
return species;
}
/** @deprecated */
getTier(pokemon: string, genNum = 8, mod?: string): string {
let species = this.getSpecies(pokemon);
if (genNum < 8) species = this.forGen(genNum).getSpecies(pokemon);
let table = window.BattleTeambuilderTable;
if (!table) return species.tier;
if (mod === 'doubles') {
table = table[`gen${genNum}doubles`];
} else if (genNum < 8) {
table = table[`gen${genNum}`];
} else if (mod && table[toID(mod)]) {
table = table[toID(mod)];
}
if (!table.overrideTier) return species.tier;
let id = species.id;
if (id in table.overrideTier) {
return table.overrideTier[id];
}
return species.tier;
}
getType(type: any): Effect & {damageTaken?: AnyObject, HPivs?: Partial<StatsTable>, HPdvs: Partial<StatsTable>} {
if (!type || typeof type === 'string') {
let id = toID(type) as string;
id = id.substr(0, 1).toUpperCase() + id.substr(1);
type = (window.BattleTypeChart && window.BattleTypeChart[id]) || {};
if (type.damageTaken) type.exists = true;
if (!type.id) type.id = id;
if (!type.name) type.name = id;
if (!type.effectType) {
type.effectType = 'Type';
let species: Species;
if (data && typeof data.exists === 'boolean') {
species = data;
} else {
if (!data) data = {exists: false};
if (!data.tier && id.slice(-5) === 'totem') {
data.tier = this.species.get(id.slice(0, -5)).tier;
}
if (!data.tier && data.baseSpecies && toID(data.baseSpecies) !== id) {
data.tier = this.species.get(data.baseSpecies).tier;
}
species = new Species(id, name, data);
window.BattlePokedex[id] = species;
}
}
return type;
}
if (species.cosmeticFormes) {
for (const forme of species.cosmeticFormes) {
if (toID(forme) === formid) {
species = new Species(formid, name, {
...species,
name: forme,
forme: forme.slice(species.name.length + 1),
baseForme: "",
baseSpecies: species.name,
otherFormes: null,
});
window.BattlePokedexAltForms[formid] = species;
break;
}
}
}
return species;
},
};
types = {
get: (type: any): Effect & {damageTaken?: AnyObject, HPivs?: Partial<StatsTable>, HPdvs: Partial<StatsTable>} => {
if (!type || typeof type === 'string') {
let id = toID(type) as string;
id = id.substr(0, 1).toUpperCase() + id.substr(1);
type = (window.BattleTypeChart && window.BattleTypeChart[id]) || {};
if (type.damageTaken) type.exists = true;
if (!type.id) type.id = id;
if (!type.name) type.name = id;
if (!type.effectType) {
type.effectType = 'Type';
}
}
return type;
},
};
hasAbility(species: Species, ability: string) {
for (const i in species.abilities) {
@@ -497,7 +483,7 @@ const Dex = new class implements ModdedDex {
if (pokemon.volatiles.dynamax) isDynamax = true;
pokemon = pokemon.getSpeciesForme();
}
const species = Dex.getSpecies(pokemon);
const species = Dex.species.get(pokemon);
// Gmax sprites are already extremely large, so we don't need to double.
if (species.name.endsWith('-Gmax')) isDynamax = false;
let spriteData = {
@@ -727,7 +713,7 @@ const Dex = new class implements ModdedDex {
getTeambuilderSpriteData(pokemon: any, gen: number = 0): TeambuilderSpriteData {
let id = toID(pokemon.species);
let spriteid = pokemon.spriteid;
let species = Dex.getSpecies(pokemon.species);
let species = Dex.species.get(pokemon.species);
if (pokemon.species && !spriteid) {
spriteid = species.spriteid || toID(pokemon.species);
}
@@ -788,7 +774,7 @@ const Dex = new class implements ModdedDex {
}
getTypeIcon(type: string | null, b?: boolean) { // b is just for utilichart.js
type = this.getType(type).name;
type = this.types.get(type).name;
if (!type) type = '???';
let sanitizedType = type.replace(/\?/g, '%3f');
return `<img src="${Dex.resourcePrefix}sprites/types/${sanitizedType}.png" alt="${type}" height="14" width="32" class="pixelated${b ? ' b' : ''}" />`;
@@ -839,146 +825,161 @@ class ModdedDex {
if (!modid.startsWith('gen') || !gen) throw new Error("Unsupported modid");
this.gen = gen;
}
getMove(name: string): Move {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (this.cache.Moves.hasOwnProperty(id)) return this.cache.Moves[id];
let data = {...Dex.getMove(name)};
const table = window.BattleTeambuilderTable[this.modid];
if (id in table.overrideAcc) data.accuracy = table.overrideAcc[id];
if (id in table.overrideBP) data.basePower = table.overrideBP[id];
if (id in table.overridePP) data.pp = table.overridePP[id];
if (id in table.overrideMoveType) data.type = table.overrideMoveType[id];
for (let i = this.gen; i < 8; i++) {
if (id in window.BattleTeambuilderTable['gen' + i].overrideMoveDesc) {
data.shortDesc = window.BattleTeambuilderTable['gen' + i].overrideMoveDesc[id];
break;
moves = {
get: (name: string): Move => {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
}
if (this.gen <= 3 && data.category !== 'Status') {
data.category = Dex.getGen3Category(data.type);
}
if (this.cache.Moves.hasOwnProperty(id)) return this.cache.Moves[id];
const move = new Move(id, name, data);
this.cache.Moves[id] = move;
return move;
}
getItem(name: string): Item {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (this.cache.Items.hasOwnProperty(id)) return this.cache.Items[id];
let data = {...Dex.moves.get(name)};
let data = {...Dex.getItem(name)};
for (let i = this.gen; i < 8; i++) {
if (id in window.BattleTeambuilderTable['gen' + i].overrideItemDesc) {
data.shortDesc = window.BattleTeambuilderTable['gen' + i].overrideItemDesc[id];
break;
const table = window.BattleTeambuilderTable[this.modid];
if (id in table.overrideAcc) data.accuracy = table.overrideAcc[id];
if (id in table.overrideBP) data.basePower = table.overrideBP[id];
if (id in table.overridePP) data.pp = table.overridePP[id];
if (id in table.overrideMoveType) data.type = table.overrideMoveType[id];
for (let i = this.gen; i < 8; i++) {
if (id in window.BattleTeambuilderTable['gen' + i].overrideMoveDesc) {
data.shortDesc = window.BattleTeambuilderTable['gen' + i].overrideMoveDesc[id];
break;
}
}
}
const item = new Item(id, name, data);
this.cache.Items[id] = item;
return item;
}
getAbility(name: string): Ability {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (this.cache.Abilities.hasOwnProperty(id)) return this.cache.Abilities[id];
let data = {...Dex.getAbility(name)};
for (let i = this.gen; i < 8; i++) {
if (id in window.BattleTeambuilderTable['gen' + i].overrideAbilityDesc) {
data.shortDesc = window.BattleTeambuilderTable['gen' + i].overrideAbilityDesc[id];
break;
if (this.gen <= 3 && data.category !== 'Status') {
data.category = Dex.getGen3Category(data.type);
}
}
const ability = new Ability(id, name, data);
this.cache.Abilities[id] = ability;
return ability;
}
getSpecies(name: string): Species {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (this.cache.Species.hasOwnProperty(id)) return this.cache.Species[id];
const move = new Move(id, name, data);
this.cache.Moves[id] = move;
return move;
},
};
let data = {...Dex.getSpecies(name)};
const table = window.BattleTeambuilderTable[this.modid];
if (this.gen < 3) {
data.abilities = {0: "None"};
} else {
let abilities = {...data.abilities};
if (id in table.overrideAbility) {
abilities['0'] = table.overrideAbility[id];
items = {
get: (name: string): Item => {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (id in table.removeSecondAbility) {
delete abilities['1'];
if (this.cache.Items.hasOwnProperty(id)) return this.cache.Items[id];
let data = {...Dex.items.get(name)};
for (let i = this.gen; i < 8; i++) {
if (id in window.BattleTeambuilderTable['gen' + i].overrideItemDesc) {
data.shortDesc = window.BattleTeambuilderTable['gen' + i].overrideItemDesc[id];
break;
}
}
if (id in table.overrideHiddenAbility) {
abilities['H'] = table.overrideHiddenAbility[id];
const item = new Item(id, name, data);
this.cache.Items[id] = item;
return item;
},
};
abilities = {
get: (name: string): Ability => {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (this.gen < 5) delete abilities['H'];
if (this.gen < 7) delete abilities['S'];
if (this.cache.Abilities.hasOwnProperty(id)) return this.cache.Abilities[id];
data.abilities = abilities;
}
if (id in table.overrideStats) {
data.baseStats = {...data.baseStats, ...table.overrideStats[id]};
}
if (id in table.overrideType) data.types = table.overrideType[id].split('/');
let data = {...Dex.abilities.get(name)};
if (id in table.overrideTier) data.tier = table.overrideTier[id];
if (!data.tier && id.slice(-5) === 'totem') {
data.tier = this.getSpecies(id.slice(0, -5)).tier;
}
if (!data.tier && data.baseSpecies && toID(data.baseSpecies) !== id) {
data.tier = this.getSpecies(data.baseSpecies).tier;
}
if (data.gen > this.gen) data.tier = 'Illegal';
const species = new Species(id, name, data);
this.cache.Species[id] = species;
return species;
}
getType(name: string): Effect {
let id = toID(name) as string;
id = id.substr(0, 1).toUpperCase() + id.substr(1);
if (this.cache.Types.hasOwnProperty(id)) return this.cache.Types[id];
let data = {...Dex.getType(name)};
for (let i = 7; i >= this.gen; i--) {
if (id in window.BattleTeambuilderTable['gen' + i].removeType) {
data.exists = false;
// don't bother correcting its attributes given it doesn't exist
break;
for (let i = this.gen; i < 8; i++) {
if (id in window.BattleTeambuilderTable['gen' + i].overrideAbilityDesc) {
data.shortDesc = window.BattleTeambuilderTable['gen' + i].overrideAbilityDesc[id];
break;
}
}
if (id in window.BattleTeambuilderTable['gen' + i].overrideTypeChart) {
data = {...data, ...window.BattleTeambuilderTable['gen' + i].overrideTypeChart[id]};
}
}
this.cache.Types[id] = data;
return data;
}
const ability = new Ability(id, name, data);
this.cache.Abilities[id] = ability;
return ability;
},
};
species = {
get: (name: string): Species => {
let id = toID(name);
if (window.BattleAliases && id in BattleAliases) {
name = BattleAliases[id];
id = toID(name);
}
if (this.cache.Species.hasOwnProperty(id)) return this.cache.Species[id];
let data = {...Dex.species.get(name)};
const table = window.BattleTeambuilderTable[this.modid];
if (this.gen < 3) {
data.abilities = {0: "None"};
} else {
let abilities = {...data.abilities};
if (id in table.overrideAbility) {
abilities['0'] = table.overrideAbility[id];
}
if (id in table.removeSecondAbility) {
delete abilities['1'];
}
if (id in table.overrideHiddenAbility) {
abilities['H'] = table.overrideHiddenAbility[id];
}
if (this.gen < 5) delete abilities['H'];
if (this.gen < 7) delete abilities['S'];
data.abilities = abilities;
}
if (id in table.overrideStats) {
data.baseStats = {...data.baseStats, ...table.overrideStats[id]};
}
if (id in table.overrideType) data.types = table.overrideType[id].split('/');
if (id in table.overrideTier) data.tier = table.overrideTier[id];
if (!data.tier && id.slice(-5) === 'totem') {
data.tier = this.species.get(id.slice(0, -5)).tier;
}
if (!data.tier && data.baseSpecies && toID(data.baseSpecies) !== id) {
data.tier = this.species.get(data.baseSpecies).tier;
}
if (data.gen > this.gen) data.tier = 'Illegal';
const species = new Species(id, name, data);
this.cache.Species[id] = species;
return species;
},
};
types = {
get: (name: string): Effect => {
let id = toID(name) as string;
id = id.substr(0, 1).toUpperCase() + id.substr(1);
if (this.cache.Types.hasOwnProperty(id)) return this.cache.Types[id];
let data = {...Dex.types.get(name)};
for (let i = 7; i >= this.gen; i--) {
if (id in window.BattleTeambuilderTable['gen' + i].removeType) {
data.exists = false;
// don't bother correcting its attributes given it doesn't exist
break;
}
if (id in window.BattleTeambuilderTable['gen' + i].overrideTypeChart) {
data = {...data, ...window.BattleTeambuilderTable['gen' + i].overrideTypeChart[id]};
}
}
this.cache.Types[id] = data;
return data;
},
};
getPokeballs() {
if (this.pokeballs) return this.pokeballs;
this.pokeballs = [];

View File

@@ -42,7 +42,7 @@ class PSSearchResults extends preact.Component<{search: DexSearch}> {
renderPokemonRow(id: ID, matchStart: number, matchEnd: number, errorMessage?: preact.ComponentChildren) {
const search = this.props.search;
const pokemon = search.dex.getSpecies(id);
const pokemon = search.dex.species.get(id);
if (!pokemon) return <li class="result">Unrecognized pokemon</li>;
let tagStart = (pokemon.forme ? pokemon.name.length - pokemon.forme.length - 1 : 0);
@@ -141,7 +141,7 @@ class PSSearchResults extends preact.Component<{search: DexSearch}> {
renderItemRow(id: ID, matchStart: number, matchEnd: number, errorMessage?: preact.ComponentChildren) {
const search = this.props.search;
const item = search.dex.getItem(id);
const item = search.dex.items.get(id);
if (!item) return <li class="result">Unrecognized item</li>;
return <li class="result"><a href={`${this.URL_ROOT}items/${id}`} data-target="push" data-entry={`item|${item.name}`}>
@@ -159,7 +159,7 @@ class PSSearchResults extends preact.Component<{search: DexSearch}> {
renderAbilityRow(id: ID, matchStart: number, matchEnd: number, errorMessage?: preact.ComponentChildren) {
const search = this.props.search;
const ability = search.dex.getAbility(id);
const ability = search.dex.abilities.get(id);
if (!ability) return <li class="result">Unrecognized ability</li>;
return <li class="result"><a href={`${this.URL_ROOT}abilitys/${id}`} data-target="push" data-entry={`ability|${ability.name}`}>
@@ -173,7 +173,7 @@ class PSSearchResults extends preact.Component<{search: DexSearch}> {
renderMoveRow(id: ID, matchStart: number, matchEnd: number, errorMessage?: preact.ComponentChildren) {
const search = this.props.search;
const move = search.dex.getMove(id);
const move = search.dex.moves.get(id);
if (!move) return <li class="result">Unrecognized move</li>;
const tagStart = (move.name.startsWith('Hidden Power') ? 12 : 0);

View File

@@ -25,11 +25,11 @@ class ModifiableValue {
this.pokemon = pokemon;
this.serverPokemon = serverPokemon;
this.itemName = Dex.getItem(serverPokemon.item).name;
this.itemName = Dex.items.get(serverPokemon.item).name;
const ability = serverPokemon.ability || pokemon?.ability || serverPokemon.baseAbility;
this.abilityName = Dex.getAbility(ability).name;
this.weatherName = Dex.getMove(battle.weather).exists ?
Dex.getMove(battle.weather).name : Dex.getAbility(battle.weather).name;
this.abilityName = Dex.abilities.get(ability).name;
this.weatherName = Dex.moves.get(battle.weather).exists ?
Dex.moves.get(battle.weather).name : Dex.abilities.get(battle.weather).name;
}
reset(value = 0, isAccuracy?: boolean) {
this.value = value;
@@ -272,12 +272,12 @@ class BattleTooltips {
case 'move':
case 'zmove':
case 'maxmove': { // move|MOVE|ACTIVEPOKEMON|[GMAXMOVE]
let move = this.battle.dex.getMove(args[1]);
let move = this.battle.dex.moves.get(args[1]);
let teamIndex = parseInt(args[2], 10);
let pokemon = this.battle.nearSide.active[
teamIndex + this.battle.pokemonControlled * Math.floor(this.battle.mySide.n / 2)
];
let gmaxMove = args[3] ? this.battle.dex.getMove(args[3]) : undefined;
let gmaxMove = args[3] ? this.battle.dex.moves.get(args[3]) : undefined;
if (!pokemon) return false;
let serverPokemon = this.battle.myPokemon![teamIndex];
buf = this.showMoveTooltip(move, type, pokemon, serverPokemon, gmaxMove);
@@ -519,10 +519,10 @@ class BattleTooltips {
getMaxMoveFromType(type: TypeName, gmaxMove?: string | Move) {
if (gmaxMove) {
gmaxMove = Dex.getMove(gmaxMove);
gmaxMove = Dex.moves.get(gmaxMove);
if (type === gmaxMove.type) return gmaxMove;
}
return Dex.getMove(BattleTooltips.maxMoveTable[type]);
return Dex.moves.get(BattleTooltips.maxMoveTable[type]);
}
showMoveTooltip(move: Move, isZOrMax: string, pokemon: Pokemon, serverPokemon: ServerPokemon, gmaxMove?: Move) {
@@ -533,14 +533,14 @@ class BattleTooltips {
// TODO: move this somewhere it makes more sense
if (pokemon.ability === '(suppressed)') serverPokemon.ability = '(suppressed)';
let ability = toID(serverPokemon.ability || pokemon.ability || serverPokemon.baseAbility);
let item = this.battle.dex.getItem(serverPokemon.item);
let item = this.battle.dex.items.get(serverPokemon.item);
let value = new ModifiableValue(this.battle, pokemon, serverPokemon);
let [moveType, category] = this.getMoveType(move, value, gmaxMove || isZOrMax === 'maxmove');
if (isZOrMax === 'zmove') {
if (item.zMoveFrom === move.name) {
move = this.battle.dex.getMove(item.zMove as string);
move = this.battle.dex.moves.get(item.zMove as string);
} else if (move.category === 'Status') {
move = new Move(move.id, "", {
...move,
@@ -549,27 +549,27 @@ class BattleTooltips {
zEffect = this.getStatusZMoveEffect(move);
} else {
let moveName = BattleTooltips.zMoveTable[item.zMoveType as TypeName];
let zMove = this.battle.dex.getMove(moveName);
let zMove = this.battle.dex.moves.get(moveName);
let movePower = move.zMove!.basePower;
// the different Hidden Power types don't have a Z power set, fall back on base move
if (!movePower && move.id.startsWith('hiddenpower')) {
movePower = this.battle.dex.getMove('hiddenpower').zMove!.basePower;
movePower = this.battle.dex.moves.get('hiddenpower').zMove!.basePower;
}
if (move.id === 'weatherball') {
switch (this.battle.weather) {
case 'sunnyday':
case 'desolateland':
zMove = this.battle.dex.getMove(BattleTooltips.zMoveTable['Fire']);
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Fire']);
break;
case 'raindance':
case 'primordialsea':
zMove = this.battle.dex.getMove(BattleTooltips.zMoveTable['Water']);
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Water']);
break;
case 'sandstorm':
zMove = this.battle.dex.getMove(BattleTooltips.zMoveTable['Rock']);
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Rock']);
break;
case 'hail':
zMove = this.battle.dex.getMove(BattleTooltips.zMoveTable['Ice']);
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Ice']);
break;
}
}
@@ -581,7 +581,7 @@ class BattleTooltips {
}
} else if (isZOrMax === 'maxmove') {
if (move.category === 'Status') {
move = this.battle.dex.getMove('Max Guard');
move = this.battle.dex.moves.get('Max Guard');
} else {
let maxMove = this.getMaxMoveFromType(moveType, gmaxMove);
const basePower = ['gmaxdrumsolo', 'gmaxfireball', 'gmaxhydrosnipe'].includes(maxMove.id) ?
@@ -653,7 +653,7 @@ class BattleTooltips {
// In gen 3 it calls Swift, so it retains its normal typing.
calls = 'Swift';
}
let calledMove = this.battle.dex.getMove(calls);
let calledMove = this.battle.dex.moves.get(calls);
text += 'Calls ' + Dex.getTypeIcon(this.getMoveType(calledMove, value)[0]) + ' ' + calledMove.name;
}
@@ -833,10 +833,10 @@ class BattleTooltips {
let itemEffect = '';
if (clientPokemon?.prevItem) {
item = 'None';
let prevItem = Dex.getItem(clientPokemon.prevItem).name;
let prevItem = Dex.items.get(clientPokemon.prevItem).name;
itemEffect += clientPokemon.prevItemEffect ? prevItem + ' was ' + clientPokemon.prevItemEffect : 'was ' + prevItem;
}
if (serverPokemon.item) item = Dex.getItem(serverPokemon.item).name;
if (serverPokemon.item) item = Dex.items.get(serverPokemon.item).name;
if (itemEffect) itemEffect = ' (' + itemEffect + ')';
if (item) itemText = '<small>Item:</small> ' + item + itemEffect;
} else if (clientPokemon) {
@@ -845,10 +845,10 @@ class BattleTooltips {
if (clientPokemon.prevItem) {
item = 'None';
if (itemEffect) itemEffect += '; ';
let prevItem = Dex.getItem(clientPokemon.prevItem).name;
let prevItem = Dex.items.get(clientPokemon.prevItem).name;
itemEffect += clientPokemon.prevItemEffect ? prevItem + ' was ' + clientPokemon.prevItemEffect : 'was ' + prevItem;
}
if (pokemon.item) item = Dex.getItem(pokemon.item).name;
if (pokemon.item) item = Dex.items.get(pokemon.item).name;
if (itemEffect) itemEffect = ' (' + itemEffect + ')';
if (item) itemText = '<small>Item:</small> ' + item + itemEffect;
}
@@ -869,7 +869,7 @@ class BattleTooltips {
text += `<p class="section">`;
const battlePokemon = clientPokemon || this.battle.findCorrespondingPokemon(pokemon);
for (const moveid of serverPokemon.moves) {
const move = Dex.getMove(moveid);
const move = Dex.moves.get(moveid);
let moveName = `&#8226; ${move.name}`;
if (battlePokemon?.moveTrack) {
for (const row of battlePokemon.moveTrack) {
@@ -890,7 +890,7 @@ class BattleTooltips {
}
if (clientPokemon.moveTrack.filter(([moveName]) => {
if (moveName.charAt(0) === '*') return false;
const move = this.battle.dex.getMove(moveName);
const move = this.battle.dex.moves.get(moveName);
return !move.isZ && !move.isMax;
}).length > 4) {
text += `(More than 4 moves is usually a sign of Illusion Zoroark/Zorua.) `;
@@ -1007,7 +1007,7 @@ class BattleTooltips {
let speedHalvingEVItems = ['machobrace', 'poweranklet', 'powerband', 'powerbelt', 'powerbracer', 'powerlens', 'powerweight'];
if (ability === 'klutz' && !speedHalvingEVItems.includes(item)) item = '' as ID;
const speciesForme = clientPokemon ? clientPokemon.getSpeciesForme() : serverPokemon.speciesForme;
let species = Dex.getSpecies(speciesForme).baseSpecies;
let species = Dex.species.get(speciesForme).baseSpecies;
let speedModifiers = [];
@@ -1117,7 +1117,7 @@ class BattleTooltips {
if (ability === 'marvelscale' && pokemon.status) {
stats.def = Math.floor(stats.def * 1.5);
}
if (item === 'eviolite' && Dex.getSpecies(pokemon.speciesForme).evos) {
if (item === 'eviolite' && Dex.species.get(pokemon.speciesForme).evos) {
stats.def = Math.floor(stats.def * 1.5);
stats.spd = Math.floor(stats.spd * 1.5);
}
@@ -1246,10 +1246,10 @@ class BattleTooltips {
let maxpp;
if (moveName.charAt(0) === '*') {
// Transformed move
move = this.battle.dex.getMove(moveName.substr(1));
move = this.battle.dex.moves.get(moveName.substr(1));
maxpp = 5;
} else {
move = this.battle.dex.getMove(moveName);
move = this.battle.dex.moves.get(moveName);
maxpp = move.noPPBoosts ? move.pp : Math.floor(move.pp * 8 / 5);
}
const bullet = moveName.charAt(0) === '*' || move.isZ ? '<span style="color:#888">&#8226;</span>' : '&#8226;';
@@ -1317,7 +1317,7 @@ class BattleTooltips {
moveType = pokemonTypes[0];
}
// Moves that require an item to change their type.
let item = Dex.getItem(value.itemName);
let item = Dex.items.get(value.itemName);
if (move.id === 'multiattack' && item.onMemory) {
if (value.itemModify(0)) moveType = item.onMemory;
}
@@ -1384,7 +1384,11 @@ class BattleTooltips {
if (value.abilityModify(0, 'Normalize')) moveType = 'Normal';
}
// There aren't any max moves with the sound flag, but if there were, Liquid Voice would make them water type
const isSound = !!(forMaxMove ? this.getMaxMoveFromType(moveType, forMaxMove !== true && forMaxMove || undefined) : move).flags['sound'];
const isSound = !!(
forMaxMove ?
this.getMaxMoveFromType(moveType, forMaxMove !== true && forMaxMove || undefined) : move
).flags['sound'];
if (allowTypeOverride && isSound && value.abilityModify(0, 'Liquid Voice')) {
moveType = 'Water';
}
@@ -1605,7 +1609,7 @@ class BattleTooltips {
}
// Moves which have base power changed due to items
if (serverPokemon.item) {
let item = Dex.getItem(serverPokemon.item);
let item = Dex.items.get(serverPokemon.item);
if (move.id === 'fling' && item.fling) {
value.itemModify(item.fling.basePower);
}
@@ -1836,7 +1840,7 @@ class BattleTooltips {
'Water Pledge',
];
getItemBoost(move: Move, value: ModifiableValue, moveType: TypeName) {
let item = this.battle.dex.getItem(value.serverPokemon.item);
let item = this.battle.dex.items.get(value.serverPokemon.item);
let itemName = item.name;
let moveName = move.name;
@@ -1860,7 +1864,7 @@ class BattleTooltips {
// Pokemon-specific items
if (item.name === 'Soul Dew' && this.battle.gen < 7) return value;
if (BattleTooltips.orbUsers[Dex.getSpecies(value.serverPokemon.speciesForme).baseSpecies] === item.name &&
if (BattleTooltips.orbUsers[Dex.species.get(value.serverPokemon.speciesForme).baseSpecies] === item.name &&
[BattleTooltips.orbTypes[item.name], 'Dragon'].includes(moveType)) {
value.itemModify(1.2);
return value;
@@ -1877,7 +1881,7 @@ class BattleTooltips {
}
getPokemonTypes(pokemon: Pokemon | ServerPokemon): ReadonlyArray<TypeName> {
if (!(pokemon as Pokemon).getTypes) {
return this.battle.dex.getSpecies(pokemon.speciesForme).types;
return this.battle.dex.species.get(pokemon.speciesForme).types;
}
return (pokemon as Pokemon).getTypeList();
@@ -1891,10 +1895,10 @@ class BattleTooltips {
}
getAllyAbility(ally: Pokemon) {
// this will only be available if the ability announced itself in some way
let allyAbility = Dex.getAbility(ally.ability).name;
let allyAbility = Dex.abilities.get(ally.ability).name;
// otherwise fall back on the original set data sent from the server
if (!allyAbility && this.battle.myAllyPokemon) {
allyAbility = Dex.getAbility(this.battle.myAllyPokemon[ally.slot].ability).name;
allyAbility = Dex.abilities.get(this.battle.myAllyPokemon[ally.slot].ability).name;
}
return allyAbility;
}
@@ -1910,7 +1914,7 @@ class BattleTooltips {
}
} else {
const speciesForme = clientPokemon.getSpeciesForme() || serverPokemon?.speciesForme || '';
const species = this.battle.dex.getSpecies(speciesForme);
const species = this.battle.dex.species.get(speciesForme);
if (species.exists && species.abilities) {
abilityData.possibilities = [species.abilities['0']];
if (species.abilities['1']) abilityData.possibilities.push(species.abilities['1']);
@@ -1938,12 +1942,12 @@ class BattleTooltips {
if (!isActive) {
// for switch tooltips, only show the original ability
const ability = abilityData.baseAbility || abilityData.ability;
if (ability) text = '<small>Ability:</small> ' + Dex.getAbility(ability).name;
if (ability) text = '<small>Ability:</small> ' + Dex.abilities.get(ability).name;
} else {
if (abilityData.ability) {
const abilityName = Dex.getAbility(abilityData.ability).name;
const abilityName = Dex.abilities.get(abilityData.ability).name;
text = '<small>Ability:</small> ' + abilityName;
const baseAbilityName = Dex.getAbility(abilityData.baseAbility).name;
const baseAbilityName = Dex.abilities.get(abilityData.baseAbility).name;
if (baseAbilityName && baseAbilityName !== abilityName) text += ' (base: ' + baseAbilityName + ')';
}
}
@@ -2051,11 +2055,11 @@ class BattleStatGuesser {
};
let hasMove: {[moveid: string]: 1} = {};
let itemid = toID(set.item);
let item = this.dex.getItem(itemid);
let item = this.dex.items.get(itemid);
let abilityid = toID(set.ability);
let species = this.dex.getSpecies(set.species || set.name!);
if (item.megaEvolves === species.name) species = this.dex.getSpecies(item.megaStone);
let species = this.dex.species.get(set.species || set.name!);
if (item.megaEvolves === species.name) species = this.dex.species.get(item.megaStone);
if (!species.exists) return '?';
let stats = species.baseStats;
@@ -2068,7 +2072,7 @@ class BattleStatGuesser {
}
for (let i = 0, len = set.moves.length; i < len; i++) {
let move = Dex.getMove(set.moves[i]);
let move = Dex.moves.get(set.moves[i]);
hasMove[move.id] = 1;
if (move.category === 'Status') {
if (['batonpass', 'healingwish', 'lunardance'].includes(move.id)) {
@@ -2337,7 +2341,7 @@ class BattleStatGuesser {
guessEVs(set: PokemonSet, role: string): Partial<StatsTable> & {plusStat?: StatName | '', minusStat?: StatName | ''} {
if (!set) return {};
if (role === '?') return {};
let species = this.dex.getSpecies(set.species || set.name!);
let species = this.dex.species.get(set.species || set.name!);
let stats = species.baseStats;
let hasMove = this.hasMove;
@@ -2555,7 +2559,7 @@ class BattleStatGuesser {
}
getStat(stat: StatName, set: PokemonSet, evOverride?: number, natureOverride?: number) {
let species = this.dex.getSpecies(set.species);
let species = this.dex.species.get(set.species);
if (!species.exists) return 0;
let level = set.level || 100;

View File

@@ -329,7 +329,7 @@ class Pokemon implements PokemonDetails, PokemonHealth {
}
rememberMove(moveName: string, pp = 1, recursionSource?: string) {
if (recursionSource === this.ident) return;
moveName = Dex.getMove(moveName).name;
moveName = Dex.moves.get(moveName).name;
if (moveName.charAt(0) === '*') return;
if (moveName === 'Struggle') return;
if (this.volatiles.transform) {
@@ -348,7 +348,7 @@ class Pokemon implements PokemonDetails, PokemonHealth {
this.moveTrack.push([moveName, pp]);
}
rememberAbility(ability: string, isNotBase?: boolean) {
ability = Dex.getAbility(ability).name;
ability = Dex.abilities.get(ability).name;
this.ability = ability;
if (!this.baseAbility && !isNotBase) {
this.baseAbility = ability;
@@ -521,10 +521,10 @@ class Pokemon implements PokemonDetails, PokemonHealth {
(serverPokemon ? serverPokemon.speciesForme : this.speciesForme);
}
getSpecies(serverPokemon?: ServerPokemon) {
return this.side.battle.dex.getSpecies(this.getSpeciesForme(serverPokemon));
return this.side.battle.dex.species.get(this.getSpeciesForme(serverPokemon));
}
getBaseSpecies() {
return this.side.battle.dex.getSpecies(this.speciesForme);
return this.side.battle.dex.species.get(this.speciesForme);
}
reset() {
this.clearVolatile();
@@ -1343,11 +1343,11 @@ class Battle {
let moveName = move.name;
if (move.isZ) {
pokemon.item = move.isZ;
let item = Dex.getItem(move.isZ);
let item = Dex.items.get(move.isZ);
if (item.zMoveFrom) moveName = item.zMoveFrom;
} else if (move.name.slice(0, 2) === 'Z-') {
moveName = moveName.slice(2);
move = Dex.getMove(moveName);
move = Dex.moves.get(moveName);
if (window.BattleItems) {
for (let item in BattleItems) {
if (BattleItems[item].zMoveType === move.type) pokemon.item = item;
@@ -1390,7 +1390,7 @@ class Battle {
return;
}
let usedMove = kwArgs.anim ? Dex.getMove(kwArgs.anim) : move;
let usedMove = kwArgs.anim ? Dex.moves.get(kwArgs.anim) : move;
if (!kwArgs.spread) {
this.scene.runMoveAnim(usedMove.id, [pokemon, target]);
return;
@@ -2034,7 +2034,7 @@ class Battle {
}
case '-item': {
let poke = this.getPokemon(args[1])!;
let item = Dex.getItem(args[2]);
let item = Dex.items.get(args[2]);
let effect = Dex.getEffect(kwArgs.from);
let ofpoke = this.getPokemon(kwArgs.of);
poke.item = item.name;
@@ -2102,7 +2102,7 @@ class Battle {
}
case '-enditem': {
let poke = this.getPokemon(args[1])!;
let item = Dex.getItem(args[2]);
let item = Dex.items.get(args[2]);
let effect = Dex.getEffect(kwArgs.from);
poke.item = '';
poke.itemEffect = '';
@@ -2164,7 +2164,7 @@ class Battle {
}
case '-ability': {
let poke = this.getPokemon(args[1])!;
let ability = Dex.getAbility(args[2]);
let ability = Dex.abilities.get(args[2]);
let effect = Dex.getEffect(kwArgs.from);
let ofpoke = this.getPokemon(kwArgs.of);
poke.rememberAbility(ability.name, effect.id && !kwArgs.fail);
@@ -2211,7 +2211,7 @@ class Battle {
// deprecated; use |-start| for Gastro Acid
// and the third arg of |-ability| for Entrainment et al
let poke = this.getPokemon(args[1])!;
let ability = Dex.getAbility(args[2]);
let ability = Dex.abilities.get(args[2]);
poke.ability = '(suppressed)';
if (ability.id) {
@@ -2235,7 +2235,7 @@ class Battle {
}
newSpeciesForme = args[2].substr(0, commaIndex);
}
let species = this.dex.getSpecies(newSpeciesForme);
let species = this.dex.species.get(newSpeciesForme);
poke.speciesForme = newSpeciesForme;
poke.ability = poke.baseAbility = (species.abilities ? species.abilities['0'] : '');
@@ -2276,7 +2276,7 @@ class Battle {
}
case '-formechange': {
let poke = this.getPokemon(args[1])!;
let species = Dex.getSpecies(args[2]);
let species = Dex.species.get(args[2]);
let fromeffect = Dex.getEffect(kwArgs.from);
let isCustomAnim = false;
poke.removeVolatile('typeadd' as ID);
@@ -2293,7 +2293,7 @@ class Battle {
}
case '-mega': {
let poke = this.getPokemon(args[1])!;
let item = Dex.getItem(args[3]);
let item = Dex.items.get(args[3]);
if (args[3]) {
poke.item = item.name;
}
@@ -2673,7 +2673,7 @@ class Battle {
case 'eeriespell':
case 'gmaxdepletion':
case 'spite':
let move = Dex.getMove(kwArgs.move).name;
let move = Dex.moves.get(kwArgs.move).name;
let pp = Number(kwArgs.number);
if (isNaN(pp)) pp = 4;
poke.rememberMove(move, pp);
@@ -2717,7 +2717,7 @@ class Battle {
break;
case 'mummy':
if (!kwArgs.ability) break; // if Mummy activated but failed, no ability will have been sent
let ability = Dex.getAbility(kwArgs.ability);
let ability = Dex.abilities.get(kwArgs.ability);
this.activateAbility(target, ability.name);
this.activateAbility(poke, "Mummy");
this.scene.wait(700);
@@ -2835,7 +2835,7 @@ class Battle {
}
case '-anim': {
let poke = this.getPokemon(args[1])!;
let move = Dex.getMove(args[2]);
let move = Dex.moves.get(args[2]);
if (this.checkActive(poke)) return;
let poke2 = this.getPokemon(args[3]);
this.scene.beforeMove(poke);
@@ -2879,7 +2879,7 @@ class Battle {
}
if (foe) siden = (siden ? 0 : 1);
let data = Dex.getSpecies(name);
let data = Dex.species.get(name);
return data.spriteData[siden];
}
*/
@@ -3338,7 +3338,7 @@ class Battle {
this.endLastTurn();
this.resetTurnsSinceMoved();
let poke = this.getPokemon(args[1])!;
let move = Dex.getMove(args[2]);
let move = Dex.moves.get(args[2]);
if (this.checkActive(poke)) return;
let poke2 = this.getPokemon(args[3]);
this.scene.beforeMove(poke);
@@ -3353,7 +3353,7 @@ class Battle {
this.resetTurnsSinceMoved();
let poke = this.getPokemon(args[1])!;
let effect = Dex.getEffect(args[2]);
let move = Dex.getMove(args[3]);
let move = Dex.moves.get(args[3]);
this.cantUseMove(poke, effect, move, kwArgs);
this.log(args, kwArgs);
break;

View File

@@ -349,7 +349,7 @@ class BattlePanel extends PSRoomPanel<BattleRoom> {
return <div class="message-error">Maxed with no max moves</div>;
}
return active.moves.map((moveData, i) => {
const move = dex.getMove(moveData.name);
const move = dex.moves.get(moveData.name);
const maxMoveData = active.maxMoves![i];
const gmaxTooltip = maxMoveData.id.startsWith('gmax') ? `|${maxMoveData.id}` : ``;
const tooltip = `maxmove|${moveData.name}|${pokemonIndex}${gmaxTooltip}`;
@@ -364,7 +364,7 @@ class BattlePanel extends PSRoomPanel<BattleRoom> {
return <div class="message-error">No Z moves</div>;
}
return active.moves.map((moveData, i) => {
const move = dex.getMove(moveData.name);
const move = dex.moves.get(moveData.name);
const zMoveData = active.zMoves![i];
if (!zMoveData) {
return <button disabled>&nbsp;</button>;
@@ -377,7 +377,7 @@ class BattlePanel extends PSRoomPanel<BattleRoom> {
}
return active.moves.map((moveData, i) => {
const move = dex.getMove(moveData.name);
const move = dex.moves.get(moveData.name);
const tooltip = `move|${moveData.name}|${pokemonIndex}`;
return <MoveButton cmd={`/move ${i + 1}`} type={move.type} tooltip={tooltip} moveData={moveData}>
{move.name}

View File

@@ -121,24 +121,24 @@ class PSTeambuilder {
set.name = parts[0];
// species
set.species = Dex.getSpecies(parts[1]).name || set.name;
set.species = Dex.species.get(parts[1]).name || set.name;
// item
set.item = Dex.getItem(parts[2]).name;
set.item = Dex.items.get(parts[2]).name;
// ability
const species = Dex.getSpecies(set.species);
const species = Dex.species.get(set.species);
set.ability = parts[3] === '-' ?
'' :
(species.baseSpecies === 'Zygarde' && parts[3] === 'H') ?
'Power Construct' :
['', '0', '1', 'H', 'S'].includes(parts[3]) ?
species.abilities[parts[3] as '0' || '0'] || (parts[3] === '' ? '' : '!!!ERROR!!!') :
Dex.getAbility(parts[3]).name;
Dex.abilities.get(parts[3]).name;
// moves
set.moves = parts[4].split(',').map(moveid =>
Dex.getMove(moveid).name
Dex.moves.get(moveid).name
);
// nature
@@ -321,10 +321,10 @@ class PSTeambuilder {
}
let parenIndex = line.lastIndexOf(' (');
if (line.charAt(line.length - 1) === ')' && parenIndex !== -1) {
set.species = Dex.getSpecies(line.slice(parenIndex + 2, -1)).name;
set.species = Dex.species.get(line.slice(parenIndex + 2, -1)).name;
set.name = line.slice(0, parenIndex);
} else {
set.species = Dex.getSpecies(line).name;
set.species = Dex.species.get(line).name;
set.name = '';
}
} else if (line.startsWith('Trait: ')) {
@@ -389,7 +389,7 @@ class PSTeambuilder {
line = 'Hidden Power ' + hpType;
if (!set.ivs && window.BattleTypeChart && window.BattleTypeChart[hpType]) {
set.ivs = {hp: 31, atk: 31, def: 31, spa: 31, spd: 31, spe: 31};
const hpIVs = Dex.getType(hpType).HPivs || {};
const hpIVs = Dex.types.get(hpType).HPivs || {};
for (let stat in hpIVs) {
set.ivs[stat as StatName] = hpIVs[stat as StatName]!;
}