Skip to content

Commit

Permalink
Update Dex API
Browse files Browse the repository at this point in the history
This is the change that renames:

- `Dex.getMove` -> `Dex.moves.get`
- `Dex.getAbility` -> `Dex.abilities.get`
- `Dex.getItem` -> `Dex.items.get`
- `Dex.getSpecies` -> `Dex.species.get`
- `Dex.getEffect` -> `Dex.conditions.get`
- `Dex.getEffectByID` -> `Dex.conditions.getByID`
- `Dex.getNature` -> `Dex.natures.get`
- `Dex.getType` -> `Dex.types.get`
- `Dex.getFormat` -> `Dex.formats.get`
- `Dex.data.Formats` -> `Dex.data.Rulesets`
- `Dex.formats` -> now an array `Dex.formats.all()`
- `Dex.getRuleTable` -> `Dex.formats.getRuleTable`
- `Dex.validateFormat` -> `Dex.formats.validate`

`getByID` methods have also been added to every other table.
  • Loading branch information
Zarel committed Apr 7, 2021
1 parent 4f32736 commit 5261b70
Show file tree
Hide file tree
Showing 121 changed files with 1,975 additions and 1,853 deletions.
116 changes: 58 additions & 58 deletions config/formats.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions data/FORMES.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Cosmetic formes are not listed in the `otherFormes` array, only in the `cosmetic

`{name: "Gastrodon", baseForme: "West", cosmeticFormes: ["gastodoneast"]}`

You will still be able to get a data entry for a cosmetic forme with `getSpecies` as normal, though:
You will still be able to get a data entry for a cosmetic forme with `species.get` as normal, though:

`{name: "Gastodon-East", forme: "East", baseSpecies: "Gastrodon"}`

Expand Down Expand Up @@ -192,6 +192,6 @@ Dynamax and Gigantamax are not considered formes by the games themselves. PS imp
`pokedex.js`
------------

All the data shown here is information available from `Dex.getSpecies`. Data in `pokedex.js` will not necessarily contain the same information.
All the data shown here is information available from `Dex.species.get`. Data in `pokedex.js` will not necessarily contain the same information.

Most importantly, note that cosmetic formes are not listed in `pokedex.js`, but generated automatically from their base forme entry.
26 changes: 13 additions & 13 deletions data/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
onStart(pokemon) {
for (const target of pokemon.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
const move = this.dex.moves.get(moveSlot.move);
if (move.category === 'Status') continue;
const moveType = move.id === 'hiddenpower' ? target.hpType : move.type;
if (
Expand Down Expand Up @@ -191,7 +191,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
onSourceAfterFaint(length, target, source, effect) {
if (effect && effect.effectType === 'Move') {
this.boost({atk: length}, source, source, this.dex.getAbility('chillingneigh'));
this.boost({atk: length}, source, source, this.dex.abilities.get('chillingneigh'));
}
},
isPermanent: true,
Expand All @@ -213,7 +213,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
onSourceAfterFaint(length, target, source, effect) {
if (effect && effect.effectType === 'Move') {
this.boost({spa: length}, source, source, this.dex.getAbility('grimneigh'));
this.boost({spa: length}, source, source, this.dex.abilities.get('grimneigh'));
}
},
isPermanent: true,
Expand Down Expand Up @@ -789,7 +789,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
if (['mimikyu', 'mimikyutotem'].includes(pokemon.species.id) && this.effectData.busted) {
const speciesid = pokemon.species.id === 'mimikyutotem' ? 'Mimikyu-Busted-Totem' : 'Mimikyu-Busted';
pokemon.formeChange(speciesid, this.effect, true);
this.damage(pokemon.baseMaxhp / 8, pokemon, pokemon, this.dex.getSpecies(speciesid));
this.damage(pokemon.baseMaxhp / 8, pokemon, pokemon, this.dex.species.get(speciesid));
}
},
isPermanent: true,
Expand Down Expand Up @@ -1140,7 +1140,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
let warnBp = 1;
for (const target of pokemon.foes()) {
for (const moveSlot of target.moveSlots) {
const move = this.dex.getMove(moveSlot.move);
const move = this.dex.moves.get(moveSlot.move);
let bp = move.basePower;
if (move.ohko) bp = 150;
if (move.id === 'counter' || move.id === 'metalburst' || move.id === 'mirrorcoat') bp = 120;
Expand Down Expand Up @@ -1371,7 +1371,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
onResidualSubOrder: 1,
onResidual(pokemon) {
if (this.field.isWeather(['sunnyday', 'desolateland']) || this.randomChance(1, 2)) {
if (pokemon.hp && !pokemon.item && this.dex.getItem(pokemon.lastItem).isBerry) {
if (pokemon.hp && !pokemon.item && this.dex.items.get(pokemon.lastItem).isBerry) {
pokemon.setItem(pokemon.lastItem);
pokemon.lastItem = '';
this.add('-item', pokemon, pokemon.getItem(), '[from] ability: Harvest');
Expand Down Expand Up @@ -1586,7 +1586,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
},
onDamagingHit(damage, target, source, move) {
if (target.illusion) {
this.singleEvent('End', this.dex.getAbility('Illusion'), target.abilityData, target, source, move);
this.singleEvent('End', this.dex.abilities.get('Illusion'), target.abilityData, target, source, move);
}
},
onEnd(pokemon) {
Expand Down Expand Up @@ -1636,7 +1636,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
// fortunately, side.foe already takes care of all that
const target = pokemon.side.foe.active[pokemon.side.foe.active.length - 1 - pokemon.position];
if (target) {
pokemon.transformInto(target, this.dex.getAbility('imposter'));
pokemon.transformInto(target, this.dex.abilities.get('imposter'));
}
this.effectData.switchingIn = false;
},
Expand Down Expand Up @@ -2206,7 +2206,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
if (move.flags['contact']) {
const oldAbility = source.setAbility('mummy', target);
if (oldAbility) {
this.add('-activate', target, 'ability: Mummy', this.dex.getAbility(oldAbility).name, '[of] ' + source);
this.add('-activate', target, 'ability: Mummy', this.dex.abilities.get(oldAbility).name, '[of] ' + source);
}
}
},
Expand Down Expand Up @@ -2315,7 +2315,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
pokemon.abilityData.ending = false;
for (const target of this.getAllActive()) {
if (target.illusion) {
this.singleEvent('End', this.dex.getAbility('Illusion'), target.abilityData, target, pokemon, 'neutralizinggas');
this.singleEvent('End', this.dex.abilities.get('Illusion'), target.abilityData, target, pokemon, 'neutralizinggas');
}
if (target.volatiles['slowstart']) {
delete target.volatiles['slowstart'];
Expand Down Expand Up @@ -2587,7 +2587,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
const randomTarget = this.sample(pickupTargets);
const item = randomTarget.lastItem;
randomTarget.lastItem = '';
this.add('-item', pokemon, this.dex.getItem(item), '[from] ability: Pickup');
this.add('-item', pokemon, this.dex.items.get(item), '[from] ability: Pickup');
pokemon.setItem(item);
},
name: "Pickup",
Expand Down Expand Up @@ -2660,7 +2660,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
move.secondaries.push({
chance: 30,
status: 'psn',
ability: this.dex.getAbility('poisontouch'),
ability: this.dex.abilities.get('poisontouch'),
});
},
name: "Poison Touch",
Expand Down Expand Up @@ -4152,7 +4152,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
if (target.isAlly(source)) {
this.add('-activate', target, 'Skill Swap', '', '', '[of] ' + source);
} else {
this.add('-activate', target, 'ability: Wandering Spirit', this.dex.getAbility(sourceAbility).name, 'Wandering Spirit', '[of] ' + source);
this.add('-activate', target, 'ability: Wandering Spirit', this.dex.abilities.get(sourceAbility).name, 'Wandering Spirit', '[of] ' + source);
}
target.setAbility(sourceAbility);
}
Expand Down
4 changes: 2 additions & 2 deletions data/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export const Conditions: {[k: string]: ConditionData} = {
this.effectData.move = effect.id;
target.addVolatile(effect.id);
let moveTarget: Pokemon | null = source;
if (effect.sourceEffect && this.dex.getMove(effect.id).target === 'normal') {
if (effect.sourceEffect && this.dex.moves.get(effect.id).target === 'normal') {
// this move was called by another move such as metronome and needs a random target to be determined now
// won't randomly choose an empty slot if there's at least one valid target
moveTarget = this.getRandomTarget(target, effect.id);
Expand Down Expand Up @@ -355,7 +355,7 @@ export const Conditions: {[k: string]: ConditionData} = {
onEnd(target) {
const data = this.effectData;
// time's up; time to hit! :D
const move = this.dex.getMove(data.move);
const move = this.dex.moves.get(data.move);
if (target.fainted || target === data.source) {
this.hint(`${move.name} did not hit because the target is ${(target.fainted ? 'fainted' : 'the user')}.`);
return;
Expand Down
8 changes: 4 additions & 4 deletions data/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ export const Items: {[itemid: string]: ItemData} = {
this.add('-enditem', target, 'Air Balloon');
target.item = '';
target.itemData = {id: '', target};
this.runEvent('AfterUseItem', target, null, null, this.dex.getItem('airballoon'));
this.runEvent('AfterUseItem', target, null, null, this.dex.items.get('airballoon'));
},
onAfterSubDamage(damage, target, source, effect) {
this.debug('effect: ' + effect.id);
if (effect.effectType === 'Move') {
this.add('-enditem', target, 'Air Balloon');
target.item = '';
target.itemData = {id: '', target};
this.runEvent('AfterUseItem', target, null, null, this.dex.getItem('airballoon'));
this.runEvent('AfterUseItem', target, null, null, this.dex.items.get('airballoon'));
}
},
num: 541,
Expand Down Expand Up @@ -275,7 +275,7 @@ export const Items: {[itemid: string]: ItemData} = {
},
onDisableMove(pokemon) {
for (const moveSlot of pokemon.moveSlots) {
if (this.dex.getMove(moveSlot.move).category === 'Status') {
if (this.dex.moves.get(moveSlot.move).category === 'Status') {
pokemon.disableMove(moveSlot.id);
}
}
Expand Down Expand Up @@ -2910,7 +2910,7 @@ export const Items: {[itemid: string]: ItemData} = {
},
onAfterMoveSecondarySelf(source, target, move) {
if (source && source !== target && move && move.category !== 'Status') {
this.damage(source.baseMaxhp / 10, source, source, this.dex.getItem('lifeorb'));
this.damage(source.baseMaxhp / 10, source, source, this.dex.items.get('lifeorb'));
}
},
num: 270,
Expand Down
8 changes: 4 additions & 4 deletions data/mods/gen1/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ export const Moves: {[k: string]: ModdedMoveData} = {
// - (Counter will thus desync if the target's last used move is not as counterable as the target's last selected move)
// - if Counter succeeds it will deal twice the last move damage dealt in battle (even if it's from a different pokemon because of a switch)

const lastMove = target.side.lastMove && this.dex.getMove(target.side.lastMove.id);
const lastMove = target.side.lastMove && this.dex.moves.get(target.side.lastMove.id);
const lastMoveIsCounterable = lastMove && lastMove.basePower > 0 &&
['Normal', 'Fighting'].includes(lastMove.type) && lastMove.id !== 'counter';

const lastSelectedMove = target.side.lastSelectedMove && this.dex.getMove(target.side.lastSelectedMove);
const lastSelectedMove = target.side.lastSelectedMove && this.dex.moves.get(target.side.lastSelectedMove);
const lastSelectedMoveIsCounterable = lastSelectedMove && lastSelectedMove.basePower > 0 &&
['Normal', 'Fighting'].includes(lastSelectedMove.type) && lastSelectedMove.id !== 'counter';

Expand Down Expand Up @@ -296,7 +296,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
this.effectData.duration++;
}
const moves = pokemon.moves;
const move = this.dex.getMove(this.sample(moves));
const move = this.dex.moves.get(this.sample(moves));
this.add('-start', pokemon, 'Disable', move.name);
this.effectData.move = move.id;
return;
Expand Down Expand Up @@ -558,7 +558,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
const moves = target.moves;
const moveid = this.sample(moves);
if (!moveid) return false;
const move = this.dex.getMove(moveid);
const move = this.dex.moves.get(moveid);
source.moveSlots[moveslot] = {
move: move.name,
id: move.id,
Expand Down
34 changes: 17 additions & 17 deletions data/mods/gen1/random-teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export class RandomGen1Teams extends RandomGen2Teams {
let formeCounter = 0;
for (const id in this.dex.data.Pokedex) {
if (!(this.dex.data.Pokedex[id].num in hasDexNumber)) continue;
const species = this.dex.getSpecies(id);
const lsetData = this.dex.getLearnsetData(id as ID);
if (!lsetData.learnset || species.forme) continue;
const species = this.dex.species.get(id);
const learnset = this.dex.species.getLearnset(id as ID);
if (!learnset || species.forme) continue;
formes[hasDexNumber[species.num]].push(species.name);
if (++formeCounter >= 6) {
// Gen 1 had no alternate formes, so we can break out of the loop already.
Expand All @@ -39,8 +39,8 @@ export class RandomGen1Teams extends RandomGen2Teams {
for (let i = 0; i < 6; i++) {
// Choose forme.
const poke = this.sample(formes[i]);
const species = this.dex.getSpecies(poke);
const lsetData = this.dex.getLearnsetData(species.id);
const species = this.dex.species.get(poke);
const learnset = this.dex.species.getLearnset(species.id);

// Level balance: calculate directly from stats rather than using some silly lookup table.
const mbstmin = 1307;
Expand Down Expand Up @@ -91,10 +91,10 @@ export class RandomGen1Teams extends RandomGen2Teams {
// Four random unique moves from movepool. don't worry about "attacking" or "viable".
// Since Gens 1 and 2 learnsets are shared, we need to weed out Gen 2 moves.
const pool: string[] = [];
if (lsetData.learnset) {
for (const move in lsetData.learnset) {
if (this.dex.getMove(move).gen !== 1) continue;
if (lsetData.learnset[move].some(learned => learned.startsWith('1'))) {
if (learnset) {
for (const move in learnset) {
if (this.dex.moves.get(move).gen !== 1) continue;
if (learnset[move].some(learned => learned.startsWith('1'))) {
pool.push(move);
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ export class RandomGen1Teams extends RandomGen2Teams {

const pokemonPool = [];
for (const id in this.dex.data.FormatsData) {
const species = this.dex.getSpecies(id);
const species = this.dex.species.get(id);
if (!species.isNonstandard && species.randomBattleMoves) {
pokemonPool.push(id);
}
Expand All @@ -144,7 +144,7 @@ export class RandomGen1Teams extends RandomGen2Teams {
let hasShitmon = false;

while (pokemonPool.length && pokemon.length < 6) {
const species = this.dex.getSpecies(this.sampleNoReplace(pokemonPool));
const species = this.dex.species.get(this.sampleNoReplace(pokemonPool));
if (!species.exists) continue;
// Only one Ditto is allowed per battle in Generation 1,
// as it can cause an endless battle if two Dittos are forced
Expand Down Expand Up @@ -261,8 +261,8 @@ export class RandomGen1Teams extends RandomGen2Teams {
* Random set generation for Gen 1 Random Battles.
*/
randomSet(species: string | Species): RandomTeamsTypes.RandomSet {
species = this.dex.getSpecies(species);
if (!species.exists) species = this.dex.getSpecies('pikachu'); // Because Gen 1.
species = this.dex.species.get(species);
if (!species.exists) species = this.dex.species.get('pikachu'); // Because Gen 1.

const movePool = species.randomBattleMoves ? species.randomBattleMoves.slice() : [];
const moves: string[] = [];
Expand Down Expand Up @@ -306,7 +306,7 @@ export class RandomGen1Teams extends RandomGen2Teams {
hasMove = {};
counter = {Physical: 0, Special: 0, Status: 0, physicalsetup: 0, specialsetup: 0};
for (const setMoveid of moves) {
const move = this.dex.getMove(setMoveid);
const move = this.dex.moves.get(setMoveid);
const moveid = move.id;
hasMove[moveid] = true;
if (!move.damage && !move.damageCallback) counter[move.category]++;
Expand All @@ -316,7 +316,7 @@ export class RandomGen1Teams extends RandomGen2Teams {

for (const [i, moveid] of moves.entries()) {
if (moveid === species.essentialMove) continue;
const move = this.dex.getMove(moveid);
const move = this.dex.moves.get(moveid);
if ((!species.essentialMove || moveid !== species.essentialMove) && this.shouldCullMove(move, hasMove, counter).cull) {
moves.splice(i, 1);
break;
Expand Down Expand Up @@ -369,7 +369,7 @@ export class RandomGen1Teams extends RandomGen2Teams {

for (let i = 0; i < 6; i++) {
// Choose forme
const species = this.dex.getSpecies(random6[i]);
const species = this.dex.species.get(random6[i]);
if (!hackmonsCup[species.id]) {
hackmonsCup[species.id] = {
types: [this.sample(typesPool), this.sample(typesPool)],
Expand All @@ -392,7 +392,7 @@ export class RandomGen1Teams extends RandomGen2Teams {
const moves = [];
do {
const moveid = this.sampleNoReplace(movePool);
const move = this.dex.getMove(moveid);
const move = this.dex.moves.get(moveid);
if (move.gen <= this.gen && !move.isNonstandard && !move.name.startsWith('Hidden Power ')) {
moves.push(moveid);
}
Expand Down
2 changes: 1 addition & 1 deletion data/mods/gen1/rulesets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const Formats: {[k: string]: ModdedFormatData} = {
export const Rulesets: {[k: string]: ModdedFormatData} = {
standard: {
effectType: 'ValidatorRule',
name: 'Standard',
Expand Down
6 changes: 3 additions & 3 deletions data/mods/gen1/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const Scripts: ModdedBattleScriptsData = {
// It uses the move and then deals with the effects after the move.
useMove(moveOrMoveName, pokemon, target, sourceEffect) {
if (!sourceEffect && this.battle.effect.id) sourceEffect = this.battle.effect;
const baseMove = this.battle.dex.getMove(moveOrMoveName);
const baseMove = this.battle.dex.moves.get(moveOrMoveName);
let move = this.battle.dex.getActiveMove(baseMove);
if (target === undefined) target = this.battle.getRandomTarget(pokemon, move);
if (move.target === 'self') {
Expand Down Expand Up @@ -180,7 +180,7 @@ export const Scripts: ModdedBattleScriptsData = {
return false;
}

if (sourceEffect) attrs += '|[from]' + this.battle.dex.getEffect(sourceEffect);
if (sourceEffect) attrs += '|[from]' + this.battle.dex.conditions.get(sourceEffect);
this.battle.addMove('move', pokemon, move.name, target + attrs);

if (!this.battle.singleEvent('Try', move, null, pokemon, target, move)) {
Expand Down Expand Up @@ -800,7 +800,7 @@ export const Scripts: ModdedBattleScriptsData = {
if (!source) source = this.event.source;
if (!effect) effect = this.effect;
}
if (typeof effect === 'string') effect = this.dex.getEffect(effect);
if (typeof effect === 'string') effect = this.dex.conditions.get(effect);
if (!target?.hp) return 0;
let success = null;
boost = this.runEvent('Boost', target, source, effect, {...boost});
Expand Down
2 changes: 1 addition & 1 deletion data/mods/gen1stadium/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Moves: {[k: string]: ModdedMoveData} = {
// - Counter succeeds if the target used a Counterable move earlier this turn

const lastMoveThisTurn = target.side.lastMove && target.side.lastMove.id === target.side.lastSelectedMove &&
!this.queue.willMove(target) && this.dex.getMove(target.side.lastMove.id);
!this.queue.willMove(target) && this.dex.moves.get(target.side.lastMove.id);
if (!lastMoveThisTurn) {
this.debug("Stadium 1 Counter: last move was not this turn");
this.add('-fail', pokemon);
Expand Down
2 changes: 1 addition & 1 deletion data/mods/gen1stadium/rulesets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const Formats: {[k: string]: ModdedFormatData} = {
export const Rulesets: {[k: string]: ModdedFormatData} = {
standard: {
effectType: 'ValidatorRule',
name: 'Standard',
Expand Down
2 changes: 1 addition & 1 deletion data/mods/gen2/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const Conditions: {[k: string]: ModdedConditionData} = {
delete pokemon.volatiles['lockedmove'];
},
onBeforeTurn(pokemon) {
const move = this.dex.getMove(this.effectData.move);
const move = this.dex.moves.get(this.effectData.move);
if (move.id) {
this.debug('Forcing into ' + move.id);
this.queue.changeAction(pokemon, {choice: 'move', moveid: move.id});
Expand Down

0 comments on commit 5261b70

Please sign in to comment.