@pkmn/data 0.6.4 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -1,647 +1,582 @@
1
- "use strict";
2
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
3
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
4
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
6
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
7
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
8
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
9
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
10
- function fulfill(value) { resume("next", value); }
11
- function reject(value) { resume("throw", value); }
12
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
+ var DEFAULT_EXISTS = (d) => {
3
+ if (!d.exists)
4
+ return false;
5
+ if ("isNonstandard" in d && d.isNonstandard)
6
+ return false;
7
+ if (d.kind === "Ability" && d.id === "noability")
8
+ return false;
9
+ return !("tier" in d && ["Illegal", "Unreleased"].includes(d.tier));
13
10
  };
14
- var __asyncValues = (this && this.__asyncValues) || function (o) {
15
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
16
- var m = o[Symbol.asyncIterator], i;
17
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
18
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
19
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.Stats = exports.Learnsets = exports.Type = exports.Types = exports.Natures = exports.Conditions = exports.Specie = exports.Species = exports.Moves = exports.Items = exports.Abilities = exports.Generation = exports.Generations = exports.toID = void 0;
23
- const DEFAULT_EXISTS = (d) => {
24
- if (!d.exists)
25
- return false;
26
- if ('isNonstandard' in d && d.isNonstandard)
27
- return false;
28
- if (d.kind === 'Ability' && d.id === 'noability')
29
- return false;
30
- return !('tier' in d && ['Illegal', 'Unreleased'].includes(d.tier));
31
- };
32
- const tr = (num, bits = 0) => bits ? (num >>> 0) % (2 ** bits) : num >>> 0;
11
+ var tr = (num, bits = 0) => bits ? (num >>> 0) % 2 ** bits : num >>> 0;
33
12
  function assignWithout(a, b, exclude) {
34
- for (const key in b) {
35
- if (Object.prototype.hasOwnProperty.call(b, key) && !exclude.has(key)) {
36
- a[key] = b[key];
37
- }
13
+ for (const key in b) {
14
+ if (Object.prototype.hasOwnProperty.call(b, key) && !exclude.has(key)) {
15
+ a[key] = b[key];
38
16
  }
39
- return a;
17
+ }
18
+ return a;
40
19
  }
41
20
  function toID(text) {
42
- if (text === null || text === void 0 ? void 0 : text.id)
43
- text = text.id;
44
- if (typeof text !== 'string' && typeof text !== 'number')
45
- return '';
46
- return ('' + text).toLowerCase().replace(/[^a-z0-9]+/g, '');
47
- }
48
- exports.toID = toID;
49
- class Generations {
50
- constructor(dex, exists = Generations.DEFAULT_EXISTS) {
51
- this.cache = Object.create(null);
52
- this.dex = dex;
53
- this.exists = exists;
54
- }
55
- get(g) {
56
- if (isNaN(+g))
57
- throw new Error(`Invalid gen ${g}`);
58
- const gen = g; // validated by forGen
59
- if (this.cache[gen])
60
- return this.cache[gen];
61
- return (this.cache[gen] = new Generation(this.dex.forGen(gen), d => this.exists(d, gen)));
62
- }
63
- *[Symbol.iterator]() {
64
- for (let gen = 1; gen <= 8; gen++) {
65
- yield this.get(gen);
66
- }
67
- }
21
+ if (text == null ? void 0 : text.id)
22
+ text = text.id;
23
+ if (typeof text !== "string" && typeof text !== "number")
24
+ return "";
25
+ return ("" + text).toLowerCase().replace(/[^a-z0-9]+/g, "");
68
26
  }
69
- exports.Generations = Generations;
27
+ var _Generations = class {
28
+ constructor(dex, exists = _Generations.DEFAULT_EXISTS) {
29
+ this.cache = /* @__PURE__ */ Object.create(null);
30
+ this.dex = dex;
31
+ this.exists = exists;
32
+ }
33
+ get(g) {
34
+ if (isNaN(+g))
35
+ throw new Error(`Invalid gen ${g}`);
36
+ const gen = g;
37
+ if (this.cache[gen])
38
+ return this.cache[gen];
39
+ return this.cache[gen] = new Generation(this.dex.forGen(gen), (d) => this.exists(d, gen));
40
+ }
41
+ *[Symbol.iterator]() {
42
+ for (let gen = 1; gen <= 9; gen++) {
43
+ yield this.get(gen);
44
+ }
45
+ }
46
+ };
47
+ var Generations = _Generations;
70
48
  Generations.DEFAULT_EXISTS = DEFAULT_EXISTS;
71
- class Generation {
72
- constructor(dex, exists) {
73
- this.dex = dex;
74
- this.exists = exists;
75
- this.abilities = new Abilities(this.dex, this.exists);
76
- this.items = new Items(this.dex, this.exists);
77
- this.moves = new Moves(this.dex, this.exists);
78
- this.species = new Species(this.dex, this.exists);
79
- this.natures = new Natures(this.dex, this.exists);
80
- this.types = new Types(this.dex, this.exists);
81
- this.learnsets = new Learnsets(this, this.dex, this.exists);
82
- this.conditions = new Conditions(this.dex, this.exists);
83
- this.stats = new Stats(this.dex);
84
- }
85
- static get(dex, g, exists = DEFAULT_EXISTS) {
86
- return new Generations(dex, exists).get(g);
87
- }
88
- get num() {
89
- return this.dex.gen;
90
- }
91
- toString() {
92
- return `[Generation:${this.num}]`;
93
- }
94
- toJSON() {
95
- return this.toString();
96
- }
97
- }
98
- exports.Generation = Generation;
99
- class Abilities {
100
- constructor(dex, exists) {
101
- this.dex = dex;
102
- this.exists = exists;
103
- }
104
- get(name) {
105
- const ability = this.dex.abilities.get(name);
106
- return this.exists(ability) ? ability : undefined;
107
- }
108
- *[Symbol.iterator]() {
109
- for (const ability in this.dex.data.Abilities) {
110
- const a = this.get(ability);
111
- if (a)
112
- yield a;
113
- }
114
- }
115
- }
116
- exports.Abilities = Abilities;
117
- class Items {
118
- constructor(dex, exists) {
119
- this.dex = dex;
120
- this.exists = exists;
121
- }
122
- get(name) {
123
- const item = this.dex.items.get(name);
124
- return this.exists(item) ? item : undefined;
125
- }
126
- *[Symbol.iterator]() {
127
- for (const item in this.dex.data.Items) {
128
- const i = this.get(item);
129
- if (i)
130
- yield i;
131
- }
132
- }
133
- }
134
- exports.Items = Items;
135
- class Moves {
136
- constructor(dex, exists) {
137
- this.dex = dex;
138
- this.exists = exists;
139
- }
140
- get(name) {
141
- const move = this.dex.moves.get(name);
142
- return this.exists(move) ? move : undefined;
143
- }
144
- *[Symbol.iterator]() {
145
- for (const move in this.dex.data.Moves) {
146
- const m = this.get(move);
147
- if (m)
148
- yield m;
149
- }
150
- }
151
- }
152
- exports.Moves = Moves;
153
- class Species {
154
- constructor(dex, exists) {
155
- this.cache = Object.create(null);
156
- this.dex = dex;
157
- this.exists = exists;
158
- }
159
- get(name) {
160
- const species = this.dex.species.get(name);
161
- if (!this.exists(species))
162
- return undefined;
163
- const id = species.speciesid || species.id; // FIXME Event-only ability hack
164
- const cached = this.cache[id];
165
- if (cached)
166
- return cached;
167
- return (this.cache[id] = new Specie(this.dex, this.exists, species));
168
- }
169
- *[Symbol.iterator]() {
170
- for (const species in this.dex.data.Species) {
171
- const s = this.get(species);
172
- if (s)
173
- yield s;
174
- }
175
- }
176
- }
177
- exports.Species = Species;
178
- class Specie {
179
- constructor(dex, exists, species) {
180
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
181
- assignWithout(this, species, Specie.EXCLUDE);
182
- this.dex = dex;
183
- if (this.dex.gen >= 2) {
184
- this.gender = species.gender;
185
- this.genderRatio = species.genderRatio;
186
- }
187
- else {
188
- this.genderRatio = { M: 0, F: 0 };
189
- }
190
- if (this.dex.gen >= 3) {
191
- this.abilities = { 0: species.abilities[0] };
192
- // "because PS", Pokemon have the abilities that were added in Gen 4 in Gen 3 :bigthonk:
193
- if (species.abilities[1] &&
194
- this.dex.abilities.get(species.abilities[1]).gen <= this.dex.gen) {
195
- this.abilities[1] = species.abilities[1];
196
- }
197
- if (this.dex.gen >= 5 && species.abilities.H)
198
- this.abilities.H = species.abilities.H;
199
- if (this.dex.gen >= 7 && species.abilities.S)
200
- this.abilities.S = species.abilities.S;
201
- }
202
- else {
203
- this.abilities = { 0: '' };
204
- }
205
- this.evos = (_a = species.evos) === null || _a === void 0 ? void 0 : _a.filter(s => exists(this.dex.species.get(s)));
206
- this.nfe = !!((_b = this.evos) === null || _b === void 0 ? void 0 : _b.length);
207
- if (!this.nfe)
208
- this.evos = undefined;
209
- this.cosmeticFormes = (_c = species.cosmeticFormes) === null || _c === void 0 ? void 0 : _c.filter(s => exists(this.dex.species.get(s)));
210
- if (!((_d = this.cosmeticFormes) === null || _d === void 0 ? void 0 : _d.length))
211
- this.cosmeticFormes = undefined;
212
- this.otherFormes = (_e = species.otherFormes) === null || _e === void 0 ? void 0 : _e.filter(s => exists(this.dex.species.get(s)));
213
- if (!((_f = this.otherFormes) === null || _f === void 0 ? void 0 : _f.length))
214
- this.otherFormes = undefined;
215
- this.formeOrder = (_g = species.formeOrder) === null || _g === void 0 ? void 0 : _g.filter(s => exists(this.dex.species.get(s)));
216
- if (!((_h = this.formeOrder) === null || _h === void 0 ? void 0 : _h.length))
217
- this.formeOrder = undefined;
218
- this.formes = (_j = this.formeOrder) === null || _j === void 0 ? void 0 : _j.filter(s => this.dex.species.get(s).isNonstandard !== 'Gigantamax');
219
- this.prevo =
220
- species.prevo && exists(this.dex.species.get(species.prevo)) ? species.prevo : undefined;
221
- }
222
- get formeNum() {
223
- return (this.baseSpecies === this.name
224
- ? this.formeOrder ? this.formeOrder.findIndex(name => name === this.name) : 0
225
- : this.dex.species.get(this.baseSpecies).formeOrder.findIndex(name => name === (this.isNonstandard === 'Gigantamax' ? this.baseSpecies : this.name)));
226
- }
227
- toString() {
228
- return this.name;
229
- }
230
- toJSON() {
231
- return assignWithout({}, this, new Set(['dex']));
232
- }
233
- }
234
- exports.Specie = Specie;
235
- Specie.EXCLUDE = new Set([
236
- 'abilities',
237
- 'cosmeticFormes',
238
- 'evos',
239
- 'gender',
240
- 'genderRatio',
241
- 'nfe',
242
- 'otherFormes',
243
- 'prevo',
49
+ var Generation = class {
50
+ static get(dex, g, exists = DEFAULT_EXISTS) {
51
+ return new Generations(dex, exists).get(g);
52
+ }
53
+ constructor(dex, exists) {
54
+ this.dex = dex;
55
+ this.exists = exists;
56
+ this.abilities = new Abilities(this.dex, this.exists);
57
+ this.items = new Items(this.dex, this.exists);
58
+ this.moves = new Moves(this.dex, this.exists);
59
+ this.species = new Species(this.dex, this.exists);
60
+ this.natures = new Natures(this.dex, this.exists);
61
+ this.types = new Types(this.dex, this.exists);
62
+ this.learnsets = new Learnsets(this, this.dex, this.exists);
63
+ this.conditions = new Conditions(this.dex, this.exists);
64
+ this.stats = new Stats(this.dex);
65
+ }
66
+ get num() {
67
+ return this.dex.gen;
68
+ }
69
+ toString() {
70
+ return `[Generation:${this.num}]`;
71
+ }
72
+ toJSON() {
73
+ return this.toString();
74
+ }
75
+ };
76
+ var Abilities = class {
77
+ constructor(dex, exists) {
78
+ this.dex = dex;
79
+ this.exists = exists;
80
+ }
81
+ get(name) {
82
+ const ability = this.dex.abilities.get(name);
83
+ return this.exists(ability) ? ability : void 0;
84
+ }
85
+ *[Symbol.iterator]() {
86
+ for (const ability in this.dex.data.Abilities) {
87
+ const a = this.get(ability);
88
+ if (a)
89
+ yield a;
90
+ }
91
+ }
92
+ };
93
+ var Items = class {
94
+ constructor(dex, exists) {
95
+ this.dex = dex;
96
+ this.exists = exists;
97
+ }
98
+ get(name) {
99
+ const item = this.dex.items.get(name);
100
+ return this.exists(item) ? item : void 0;
101
+ }
102
+ *[Symbol.iterator]() {
103
+ for (const item in this.dex.data.Items) {
104
+ const i = this.get(item);
105
+ if (i)
106
+ yield i;
107
+ }
108
+ }
109
+ };
110
+ var Moves = class {
111
+ constructor(dex, exists) {
112
+ this.dex = dex;
113
+ this.exists = exists;
114
+ }
115
+ get(name) {
116
+ const move = this.dex.moves.get(name);
117
+ return this.exists(move) ? move : void 0;
118
+ }
119
+ *[Symbol.iterator]() {
120
+ for (const move in this.dex.data.Moves) {
121
+ const m = this.get(move);
122
+ if (m)
123
+ yield m;
124
+ }
125
+ }
126
+ };
127
+ var Species = class {
128
+ constructor(dex, exists) {
129
+ this.cache = /* @__PURE__ */ Object.create(null);
130
+ this.dex = dex;
131
+ this.exists = exists;
132
+ }
133
+ get(name) {
134
+ const species = this.dex.species.get(name);
135
+ if (!this.exists(species))
136
+ return void 0;
137
+ const id = species.speciesid || species.id;
138
+ const cached = this.cache[id];
139
+ if (cached)
140
+ return cached;
141
+ return this.cache[id] = new Specie(this.dex, this.exists, species);
142
+ }
143
+ *[Symbol.iterator]() {
144
+ for (const species in this.dex.data.Species) {
145
+ const s = this.get(species);
146
+ if (s)
147
+ yield s;
148
+ }
149
+ }
150
+ };
151
+ var _Specie = class {
152
+ constructor(dex, exists, species) {
153
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
154
+ assignWithout(this, species, _Specie.EXCLUDE);
155
+ this.dex = dex;
156
+ if (this.dex.gen >= 2) {
157
+ this.gender = species.gender;
158
+ this.genderRatio = species.genderRatio;
159
+ } else {
160
+ this.genderRatio = { M: 0, F: 0 };
161
+ }
162
+ if (this.dex.gen >= 3) {
163
+ this.abilities = { 0: species.abilities[0] };
164
+ if (species.abilities[1] && this.dex.abilities.get(species.abilities[1]).gen <= this.dex.gen) {
165
+ this.abilities[1] = species.abilities[1];
166
+ }
167
+ if (this.dex.gen >= 5 && species.abilities.H)
168
+ this.abilities.H = species.abilities.H;
169
+ if (this.dex.gen >= 7 && species.abilities.S)
170
+ this.abilities.S = species.abilities.S;
171
+ } else {
172
+ this.abilities = { 0: "" };
173
+ }
174
+ this.evos = (_a = species.evos) == null ? void 0 : _a.filter((s) => exists(this.dex.species.get(s)));
175
+ this.nfe = !!((_b = this.evos) == null ? void 0 : _b.length);
176
+ if (!this.nfe)
177
+ this.evos = void 0;
178
+ this.cosmeticFormes = (_c = species.cosmeticFormes) == null ? void 0 : _c.filter((s) => exists(this.dex.species.get(s)));
179
+ if (!((_d = this.cosmeticFormes) == null ? void 0 : _d.length))
180
+ this.cosmeticFormes = void 0;
181
+ this.otherFormes = (_e = species.otherFormes) == null ? void 0 : _e.filter((s) => exists(this.dex.species.get(s)));
182
+ if (!((_f = this.otherFormes) == null ? void 0 : _f.length))
183
+ this.otherFormes = void 0;
184
+ this.formeOrder = (_g = species.formeOrder) == null ? void 0 : _g.filter((s) => exists(this.dex.species.get(s)));
185
+ if (!((_h = this.formeOrder) == null ? void 0 : _h.length))
186
+ this.formeOrder = void 0;
187
+ this.formes = (_i = this.formeOrder) == null ? void 0 : _i.filter((s) => this.dex.species.get(s).isNonstandard !== "Gigantamax");
188
+ this.prevo = species.prevo && exists(this.dex.species.get(species.prevo)) ? species.prevo : void 0;
189
+ }
190
+ get formeNum() {
191
+ return this.baseSpecies === this.name ? this.formeOrder ? this.formeOrder.findIndex((name) => name === this.name) : 0 : this.dex.species.get(this.baseSpecies).formeOrder.findIndex(
192
+ (name) => name === (this.isNonstandard === "Gigantamax" ? this.baseSpecies : this.name)
193
+ );
194
+ }
195
+ toString() {
196
+ return this.name;
197
+ }
198
+ toJSON() {
199
+ return assignWithout({}, this, /* @__PURE__ */ new Set(["dex"]));
200
+ }
201
+ };
202
+ var Specie = _Specie;
203
+ Specie.EXCLUDE = /* @__PURE__ */ new Set([
204
+ "abilities",
205
+ "cosmeticFormes",
206
+ "evos",
207
+ "gender",
208
+ "genderRatio",
209
+ "nfe",
210
+ "otherFormes",
211
+ "prevo"
244
212
  ]);
245
- class Conditions {
246
- constructor(dex, exists) {
247
- this.dex = dex;
248
- this.exists = exists;
249
- }
250
- get(name) {
251
- const condition = this.dex.conditions.get(name);
252
- return this.exists(condition) ? condition : undefined;
253
- }
254
- }
255
- exports.Conditions = Conditions;
256
- class Natures {
257
- constructor(dex, exists) {
258
- this.dex = dex;
259
- this.exists = exists;
260
- }
261
- get(name) {
262
- if (this.dex.gen < 3)
263
- return undefined;
264
- const nature = this.dex.natures.get(name);
265
- return this.exists(nature) ? nature : undefined;
266
- }
267
- *[Symbol.iterator]() {
268
- for (const nature in this.dex.data.Natures) {
269
- const n = this.get(nature);
270
- if (n)
271
- yield n;
272
- }
273
- }
274
- }
275
- exports.Natures = Natures;
276
- const EFFECTIVENESS = {
277
- '-3': 0.125,
278
- '-2': 0.25,
279
- '-1': 0.5,
280
- '0': 1,
281
- '1': 2,
282
- '2': 4,
283
- '3': 8,
213
+ var Conditions = class {
214
+ constructor(dex, exists) {
215
+ this.dex = dex;
216
+ this.exists = exists;
217
+ }
218
+ get(name) {
219
+ const condition = this.dex.conditions.get(name);
220
+ return this.exists(condition) ? condition : void 0;
221
+ }
284
222
  };
285
- class Types {
286
- constructor(dex, exists) {
287
- this.cache = Object.create(null);
288
- this.dex = dex;
289
- this.exists = exists;
290
- // PS doesn't contain data for the '???' type
291
- this.unknown = new Type({
292
- effectType: 'Type',
293
- kind: 'Type',
294
- // Regrettably PS ID's can't represent '???'
295
- id: '',
296
- name: '???',
297
- // Technically this only exists as a true type in Gens 2-4, but there are moves dealing
298
- // typeless damage in Gen 1 so we include it there.
299
- exists: dex.gen <= 4,
300
- gen: 1,
301
- // This gets filled in for us by Type's constructor
302
- damageTaken: {},
303
- HPivs: {},
304
- HPdvs: {},
305
- }, dex, this);
306
- }
307
- get(name) {
308
- if (name === '???')
309
- return this.unknown;
310
- const type = this.dex.types.get(name);
311
- if (!this.exists(type))
312
- return undefined;
313
- const cached = this.cache[type.id];
314
- if (cached)
315
- return cached;
316
- return (this.cache[type.id] = new Type(type, this.dex, this));
317
- }
318
- *[Symbol.iterator]() {
319
- for (const type in this.dex.data.Types) {
320
- const t = this.get(type);
321
- if (t)
322
- yield t;
323
- }
324
- if (this.dex.gen >= 2 && this.dex.gen <= 4) {
325
- yield this.unknown;
326
- }
327
- }
328
- getHiddenPower(ivs) {
329
- return this.dex.getHiddenPower(ivs);
330
- }
331
- canDamage(source, target) {
332
- return this.dex.getImmunity(source, target);
333
- }
334
- totalEffectiveness(source, target) {
335
- if (!this.canDamage(source, target))
336
- return 0;
337
- const e = `${this.dex.getEffectiveness(source, target)}`;
338
- // convert from PS's ridiculous encoding to something usable
339
- return EFFECTIVENESS[e];
340
- }
341
- }
342
- exports.Types = Types;
343
- const DAMAGE_TAKEN = [1, 2, 0.5, 0];
344
- const SPECIAL = ['Fire', 'Water', 'Grass', 'Electric', 'Ice', 'Psychic', 'Dark', 'Dragon'];
345
- class Type {
346
- constructor(type, dex, types) {
347
- Object.assign(this, type);
348
- this.types = types;
349
- this.category =
350
- this.name === 'Fairy' ? undefined : SPECIAL.includes(this.name) ? 'Special' : 'Physical';
351
- // convert from PS's ridiculous encoding to something usable (plus damage taken -> dealt)
352
- this.effectiveness = { '???': 1 };
353
- for (const k in dex.data.Types) {
354
- const t = k.charAt(0).toUpperCase() + k.slice(1);
355
- this.effectiveness[t] = DAMAGE_TAKEN[dex.data.Types[k].damageTaken[this.name] || 0];
356
- }
357
- }
358
- canDamage(target) {
359
- return this.types.canDamage(this.name, target);
360
- }
361
- totalEffectiveness(target) {
362
- return this.types.totalEffectiveness(this.name, target);
363
- }
364
- toString() {
365
- return this.name;
366
- }
367
- toJSON() {
368
- return assignWithout({}, this, new Set(['types']));
369
- }
370
- }
371
- exports.Type = Type;
372
- const GEN3_HMS = new Set(['cut', 'fly', 'surf', 'strength', 'flash', 'rocksmash', 'waterfall', 'dive']);
373
- // NOTE: Whirlpool and Defog are Gen 4 HMs but the HMs differ in DPPt vs. HGSS
374
- const GEN4_HMS = new Set(['cut', 'fly', 'surf', 'strength', 'rocksmash', 'waterfall', 'rockclimb']);
375
- class Learnsets {
376
- constructor(gen, dex, exists) {
377
- this.cache = Object.create(null);
378
- this.gen = gen;
379
- this.dex = dex;
380
- this.exists = exists;
381
- }
382
- async get(name) {
383
- const learnset = await this.dex.learnsets.get(toID(name));
384
- return this.exists(learnset) ? learnset : undefined;
385
- }
386
- [Symbol.iterator]() {
387
- return __asyncGenerator(this, arguments, function* _a() {
388
- if (!this.dex.data.Learnsets)
389
- yield __await(this.dex.learnsets.get('LOAD'));
390
- for (const id in this.dex.data.Learnsets) {
391
- const l = yield __await(this.get(id));
392
- if (l)
393
- yield yield __await(l);
394
- }
395
- });
396
- }
397
- all(species) {
398
- return __asyncGenerator(this, arguments, function* all_1() {
399
- let id = species.id;
400
- let learnset = yield __await(this.get(id));
401
- if (!learnset) {
402
- id = typeof species.battleOnly === 'string' && species.battleOnly !== species.baseSpecies
403
- ? toID(species.battleOnly)
404
- : toID(species.baseSpecies);
405
- learnset = yield __await(this.get(id));
406
- }
407
- while (learnset) {
408
- yield yield __await(learnset);
409
- if (id === 'lycanrocdusk' || (species.id === 'rockruff' && id === 'rockruff')) {
410
- id = 'rockruffdusk';
411
- }
412
- else if (species.id === 'gastrodoneast') {
413
- id = 'gastrodon';
414
- }
415
- else if (species.id === 'pumpkaboosuper') {
416
- id = 'pumpkaboo';
417
- }
418
- else {
419
- id = toID(species.battleOnly || species.changesFrom || species.prevo);
420
- }
421
- if (!id)
422
- break;
423
- const s = this.gen.species.get(id);
424
- if (!s)
425
- break;
426
- species = s;
427
- learnset = yield __await(this.get(id));
428
- }
429
- });
430
- }
431
- // BUG: this only covers what Pokémon Showdown deems "teambuilder legality" - proper legality
432
- // checks/restriction enforcement requires @pkmn/sim's TeamValidator.
433
- async learnable(name, restriction) {
434
- var e_1, _a;
435
- const species = this.gen.species.get(name);
436
- if (!species)
437
- return undefined;
438
- if (!restriction) {
439
- const cached = this.cache[species.id];
440
- if (cached)
441
- return cached;
442
- }
443
- const moves = {};
444
- try {
445
- for (var _b = __asyncValues(this.all(species)), _c; _c = await _b.next(), !_c.done;) {
446
- const learnset = _c.value;
447
- if (learnset.learnset) {
448
- for (const moveid in learnset.learnset) {
449
- const move = this.gen.moves.get(moveid);
450
- if (move) {
451
- const sources = learnset.learnset[moveid];
452
- if (this.isLegal(move, sources, restriction || this.gen)) {
453
- const filtered = sources.filter(s => +s.charAt(0) <= this.gen.num);
454
- if (!filtered.length)
455
- continue;
456
- if (moves[move.id]) {
457
- // If we simply add filtered to moves[move.id] we may end up with some duplicates or
458
- // situations where we have mixed learnset information. We assume that while
459
- // moves[move.id] and filtered are already deduped, their union might not be, and
460
- // thus iterate through looking for unique prefixes. For efficiency, instead of
461
- // appending each deduped source from filtered to moves[move.id] immediately and
462
- // making each subsequent iteration longer we make a list of the unique sources to
463
- // add at the end. This is only safe given our assumption that filtered is unique
464
- // internally to begin with.
465
- const unique = [];
466
- // These lists are all expected to be short arrays so this O(n^2) linear searching
467
- // is still expected to be faster runtime-wise than a more sophisticated approach
468
- loop: for (const source of filtered) {
469
- const prefix = source.slice(0, 2);
470
- // sadly Babel chokes on using an .every(...) here due to throwIfClosureRequired
471
- for (const s of moves[move.id])
472
- if (s.startsWith(prefix))
473
- continue loop;
474
- unique.push(source);
475
- }
476
- moves[move.id].push(...unique);
477
- }
478
- else {
479
- moves[move.id] = filtered;
480
- }
481
- }
482
- }
483
- }
484
- }
485
- }
486
- }
487
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
488
- finally {
489
- try {
490
- if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
491
- }
492
- finally { if (e_1) throw e_1.error; }
493
- }
494
- if (!restriction)
495
- this.cache[species.id] = moves;
496
- return moves;
497
- }
498
- // BUG: this only covers what Pokémon Showdown deems "teambuilder legality" - proper legality
499
- // checks/restriction enforcement requires @pkmn/sim's TeamValidator.
500
- async canLearn(name, move, restriction) {
501
- var e_2, _a;
502
- var _b;
503
- const species = this.gen.species.get(name);
504
- if (!species)
505
- return false;
506
- move = typeof move === 'string' && this.gen.moves.get(move) || move;
507
- if (typeof move === 'string')
508
- return false;
509
- try {
510
- for (var _c = __asyncValues(this.all(species)), _d; _d = await _c.next(), !_d.done;) {
511
- const learnset = _d.value;
512
- if (this.isLegal(move, (_b = learnset.learnset) === null || _b === void 0 ? void 0 : _b[move.id], restriction || this.gen)) {
513
- return true;
514
- }
515
- }
516
- }
517
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
518
- finally {
519
- try {
520
- if (_d && !_d.done && (_a = _c.return)) await _a.call(_c);
521
- }
522
- finally { if (e_2) throw e_2.error; }
523
- }
524
- return false;
525
- }
526
- // BUG: this only covers what Pokémon Showdown deems "teambuilder legality" - proper legality
527
- // checks/restriction enforcement requires @pkmn/sim's TeamValidator.
528
- isLegal(move, sources, gen) {
529
- if (!sources)
530
- return undefined;
531
- const gens = sources.map(x => Number(x[0]));
532
- const minGen = Math.min(...gens);
533
- const vcOnly = (minGen === 7 && sources.every(x => x[0] !== '7' || x === '7V') ||
534
- minGen === 8 && sources.every(x => x[0] !== '8' || x === '8V'));
535
- if (gen === 'Pentagon')
536
- return gens.includes(6);
537
- if (gen === 'Plus')
538
- return gens.includes(7) && !vcOnly;
539
- if (gen === 'Galar')
540
- return gens.includes(8) && !vcOnly;
541
- if (this.gen.num >= 3 && minGen <= 4 && (GEN3_HMS.has(move.id) || GEN4_HMS.has(move.id))) {
542
- let legalGens = '';
543
- let available = false;
544
- if (minGen === 3) {
545
- legalGens += '3';
546
- available = true;
547
- }
548
- if (available)
549
- available = !GEN3_HMS.has(move.id);
550
- if (available || gens.includes(4)) {
551
- legalGens += '4';
552
- available = true;
553
- }
554
- if (available)
555
- available = !GEN4_HMS.has(move.id);
556
- const minUpperGen = available ? 5 : Math.min(...gens.filter(g => g > 4));
557
- legalGens += '012345678'.slice(minUpperGen);
558
- return legalGens.includes(`${gen.num}`);
559
- }
560
- else {
561
- return '012345678'.slice(minGen).includes(`${gen.num}`);
562
- }
563
- }
564
- }
565
- exports.Learnsets = Learnsets;
566
- const STATS = ['hp', 'atk', 'def', 'spe', 'spa', 'spd'];
567
- const NAMES = {
568
- HP: 'hp', hp: 'hp',
569
- Attack: 'atk', Atk: 'atk', atk: 'atk',
570
- Defense: 'def', Def: 'def', def: 'def',
571
- 'Special Attack': 'spa', SpA: 'spa', SAtk: 'spa', SpAtk: 'spa', spa: 'spa',
572
- Special: 'spa', spc: 'spa', Spc: 'spa',
573
- 'Special Defense': 'spd', SpD: 'spd', SDef: 'spd', SpDef: 'spd', spd: 'spd',
574
- Speed: 'spe', Spe: 'spe', Spd: 'spe', spe: 'spe',
223
+ var Natures = class {
224
+ constructor(dex, exists) {
225
+ this.dex = dex;
226
+ this.exists = exists;
227
+ }
228
+ get(name) {
229
+ if (this.dex.gen < 3)
230
+ return void 0;
231
+ const nature = this.dex.natures.get(name);
232
+ return this.exists(nature) ? nature : void 0;
233
+ }
234
+ *[Symbol.iterator]() {
235
+ for (const nature in this.dex.data.Natures) {
236
+ const n = this.get(nature);
237
+ if (n)
238
+ yield n;
239
+ }
240
+ }
575
241
  };
576
- const DISPLAY = {
577
- hp: ['HP', 'HP'],
578
- atk: ['Atk', 'Attack'],
579
- def: ['Def', 'Defense'],
580
- spa: ['SpA', 'Special Attack'],
581
- spd: ['SpD', 'Special Defense'],
582
- spe: ['Spe', 'Speed'],
583
- spc: ['Spc', 'Special'],
242
+ var EFFECTIVENESS = {
243
+ "-3": 0.125,
244
+ "-2": 0.25,
245
+ "-1": 0.5,
246
+ "0": 1,
247
+ "1": 2,
248
+ "2": 4,
249
+ "3": 8
584
250
  };
585
- class Stats {
586
- constructor(dex) {
587
- this.dex = dex;
588
- }
589
- calc(stat, base, iv = 31, ev, level = 100, nature) {
590
- if (ev === undefined)
591
- ev = this.dex.gen < 3 ? 252 : 0;
592
- if (this.dex.gen < 3) {
593
- iv = this.toDV(iv) * 2;
594
- nature = undefined;
595
- }
596
- if (stat === 'hp') {
597
- return base === 1 ? base : tr(tr(2 * base + iv + tr(ev / 4) + 100) * level / 100 + 10);
598
- }
599
- else {
600
- const val = tr(tr(2 * base + iv + tr(ev / 4)) * level / 100 + 5);
601
- if (nature !== undefined) {
602
- if (nature.plus === stat)
603
- return tr(tr(val * 110, 16) / 100);
604
- if (nature.minus === stat)
605
- return tr(tr(val * 90, 16) / 100);
251
+ var Types = class {
252
+ constructor(dex, exists) {
253
+ this.cache = /* @__PURE__ */ Object.create(null);
254
+ this.dex = dex;
255
+ this.exists = exists;
256
+ this.unknown = new Type({
257
+ effectType: "Type",
258
+ kind: "Type",
259
+ id: "",
260
+ name: "???",
261
+ exists: dex.gen <= 4,
262
+ gen: 1,
263
+ damageTaken: {},
264
+ HPivs: {},
265
+ HPdvs: {}
266
+ }, dex, this);
267
+ }
268
+ get(name) {
269
+ if (name === "???")
270
+ return this.unknown;
271
+ const type = this.dex.types.get(name);
272
+ if (!this.exists(type))
273
+ return void 0;
274
+ const cached = this.cache[type.id];
275
+ if (cached)
276
+ return cached;
277
+ return this.cache[type.id] = new Type(type, this.dex, this);
278
+ }
279
+ *[Symbol.iterator]() {
280
+ for (const type in this.dex.data.Types) {
281
+ const t = this.get(type);
282
+ if (t)
283
+ yield t;
284
+ }
285
+ if (this.dex.gen >= 2 && this.dex.gen <= 4) {
286
+ yield this.unknown;
287
+ }
288
+ }
289
+ getHiddenPower(ivs) {
290
+ return this.dex.getHiddenPower(ivs);
291
+ }
292
+ canDamage(source, target) {
293
+ return this.dex.getImmunity(source, target);
294
+ }
295
+ totalEffectiveness(source, target) {
296
+ if (!this.canDamage(source, target))
297
+ return 0;
298
+ const e = `${this.dex.getEffectiveness(source, target)}`;
299
+ return EFFECTIVENESS[e];
300
+ }
301
+ };
302
+ var DAMAGE_TAKEN = [1, 2, 0.5, 0];
303
+ var SPECIAL = ["Fire", "Water", "Grass", "Electric", "Ice", "Psychic", "Dark", "Dragon"];
304
+ var Type = class {
305
+ constructor(type, dex, types) {
306
+ Object.assign(this, type);
307
+ this.types = types;
308
+ this.category = this.name === "Fairy" ? void 0 : SPECIAL.includes(this.name) ? "Special" : "Physical";
309
+ this.effectiveness = { "???": 1 };
310
+ for (const k in dex.data.Types) {
311
+ const t = k.charAt(0).toUpperCase() + k.slice(1);
312
+ this.effectiveness[t] = DAMAGE_TAKEN[dex.data.Types[k].damageTaken[this.name] || 0];
313
+ }
314
+ }
315
+ canDamage(target) {
316
+ return this.types.canDamage(this.name, target);
317
+ }
318
+ totalEffectiveness(target) {
319
+ return this.types.totalEffectiveness(this.name, target);
320
+ }
321
+ toString() {
322
+ return this.name;
323
+ }
324
+ toJSON() {
325
+ return assignWithout({}, this, /* @__PURE__ */ new Set(["types"]));
326
+ }
327
+ };
328
+ var GEN3_HMS = /* @__PURE__ */ new Set(["cut", "fly", "surf", "strength", "flash", "rocksmash", "waterfall", "dive"]);
329
+ var GEN4_HMS = /* @__PURE__ */ new Set(["cut", "fly", "surf", "strength", "rocksmash", "waterfall", "rockclimb"]);
330
+ var Learnsets = class {
331
+ constructor(gen, dex, exists) {
332
+ this.cache = /* @__PURE__ */ Object.create(null);
333
+ this.gen = gen;
334
+ this.dex = dex;
335
+ this.exists = exists;
336
+ }
337
+ async get(name) {
338
+ const learnset = await this.dex.learnsets.get(toID(name));
339
+ return this.exists(learnset) ? learnset : void 0;
340
+ }
341
+ async *[Symbol.iterator]() {
342
+ if (!this.dex.data.Learnsets)
343
+ await this.dex.learnsets.get("LOAD");
344
+ for (const id in this.dex.data.Learnsets) {
345
+ const l = await this.get(id);
346
+ if (l)
347
+ yield l;
348
+ }
349
+ }
350
+ async *all(species) {
351
+ let id = species.id;
352
+ let learnset = await this.get(id);
353
+ if (!learnset) {
354
+ id = typeof species.battleOnly === "string" && species.battleOnly !== species.baseSpecies ? toID(species.battleOnly) : toID(species.baseSpecies);
355
+ learnset = await this.get(id);
356
+ }
357
+ while (learnset) {
358
+ yield learnset;
359
+ if (id === "lycanrocdusk" || species.id === "rockruff" && id === "rockruff") {
360
+ id = "rockruffdusk";
361
+ } else if (species.id === "gastrodoneast") {
362
+ id = "gastrodon";
363
+ } else if (species.id === "pumpkaboosuper") {
364
+ id = "pumpkaboo";
365
+ } else {
366
+ id = toID(species.battleOnly || species.changesFrom || species.prevo);
367
+ }
368
+ if (!id)
369
+ break;
370
+ const s = this.gen.species.get(id);
371
+ if (!s)
372
+ break;
373
+ species = s;
374
+ learnset = await this.get(id);
375
+ }
376
+ }
377
+ async learnable(name, restriction) {
378
+ const species = this.gen.species.get(name);
379
+ if (!species)
380
+ return void 0;
381
+ if (!restriction) {
382
+ const cached = this.cache[species.id];
383
+ if (cached)
384
+ return cached;
385
+ }
386
+ const moves = {};
387
+ for await (const learnset of this.all(species)) {
388
+ if (learnset.learnset) {
389
+ for (const moveid in learnset.learnset) {
390
+ const move = this.gen.moves.get(moveid);
391
+ if (move) {
392
+ const sources = learnset.learnset[moveid];
393
+ if (this.isLegal(move, sources, restriction || this.gen)) {
394
+ const filtered = sources.filter((s) => +s.charAt(0) <= this.gen.num);
395
+ if (!filtered.length)
396
+ continue;
397
+ if (moves[move.id]) {
398
+ const unique = [];
399
+ loop:
400
+ for (const source of filtered) {
401
+ const prefix = source.slice(0, 2);
402
+ for (const s of moves[move.id])
403
+ if (s.startsWith(prefix))
404
+ continue loop;
405
+ unique.push(source);
406
+ }
407
+ moves[move.id].push(...unique);
408
+ } else {
409
+ moves[move.id] = filtered;
410
+ }
606
411
  }
607
- return val;
412
+ }
608
413
  }
609
- }
610
- get(s) {
611
- return NAMES[s];
612
- }
613
- display(str, full = false) {
614
- let s = NAMES[str];
615
- if (s === undefined)
616
- return str;
617
- if (this.dex.gen === 1 && s === 'spa')
618
- s = 'spc';
619
- return DISPLAY[s][+full];
620
- }
621
- fill(stats, val) {
622
- for (const stat of STATS) {
623
- if (!(stat in stats))
624
- stats[stat] = val;
625
- }
626
- return stats;
627
- }
628
- getHPDV(ivs) {
629
- return ((this.toDV(ivs.atk === undefined ? 31 : ivs.atk) % 2) * 8 +
630
- (this.toDV(ivs.def === undefined ? 31 : ivs.def) % 2) * 4 +
631
- (this.toDV(ivs.spe === undefined ? 31 : ivs.spe) % 2) * 2 +
632
- (this.toDV(ivs.spa === undefined ? 31 : ivs.spa) % 2));
633
- }
634
- *[Symbol.iterator]() {
635
- for (const s of STATS) {
636
- yield s;
637
- }
638
- }
639
- toDV(iv) {
640
- return Math.floor(iv / 2);
641
- }
642
- toIV(dv) {
643
- return dv * 2 + 1;
644
- }
645
- }
646
- exports.Stats = Stats;
414
+ }
415
+ }
416
+ if (!restriction)
417
+ this.cache[species.id] = moves;
418
+ return moves;
419
+ }
420
+ async canLearn(name, move, restriction) {
421
+ var _a;
422
+ const species = this.gen.species.get(name);
423
+ if (!species)
424
+ return false;
425
+ move = typeof move === "string" && this.gen.moves.get(move) || move;
426
+ if (typeof move === "string")
427
+ return false;
428
+ for await (const learnset of this.all(species)) {
429
+ if (this.isLegal(move, (_a = learnset.learnset) == null ? void 0 : _a[move.id], restriction || this.gen)) {
430
+ return true;
431
+ }
432
+ }
433
+ return false;
434
+ }
435
+ isLegal(move, sources, gen) {
436
+ if (!sources)
437
+ return void 0;
438
+ const gens = sources.map((x) => Number(x[0]));
439
+ const minGen = Math.min(...gens);
440
+ const vcOnly = minGen === 7 && sources.every((x) => x[0] !== "7" || x === "7V") || minGen === 8 && sources.every((x) => x[0] !== "8" || x === "8V");
441
+ if (gen === "Pentagon")
442
+ return gens.includes(6);
443
+ if (gen === "Plus")
444
+ return gens.includes(7) && !vcOnly;
445
+ if (gen === "Galar")
446
+ return gens.includes(8) && !vcOnly;
447
+ if (gen === "Paldea")
448
+ return gens.includes(9);
449
+ if (this.gen.num >= 3 && minGen <= 4 && (GEN3_HMS.has(move.id) || GEN4_HMS.has(move.id))) {
450
+ let legalGens = "";
451
+ let available = false;
452
+ if (minGen === 3) {
453
+ legalGens += "3";
454
+ available = true;
455
+ }
456
+ if (available)
457
+ available = !GEN3_HMS.has(move.id);
458
+ if (available || gens.includes(4)) {
459
+ legalGens += "4";
460
+ available = true;
461
+ }
462
+ if (available)
463
+ available = !GEN4_HMS.has(move.id);
464
+ const minUpperGen = available ? 5 : Math.min(...gens.filter((g) => g > 4));
465
+ legalGens += "0123456789".slice(minUpperGen);
466
+ return legalGens.includes(`${gen.num}`);
467
+ } else {
468
+ return "0123456789".slice(minGen).includes(`${gen.num}`);
469
+ }
470
+ }
471
+ };
472
+ var STATS = ["hp", "atk", "def", "spe", "spa", "spd"];
473
+ var NAMES = {
474
+ HP: "hp",
475
+ hp: "hp",
476
+ Attack: "atk",
477
+ Atk: "atk",
478
+ atk: "atk",
479
+ Defense: "def",
480
+ Def: "def",
481
+ def: "def",
482
+ "Special Attack": "spa",
483
+ SpA: "spa",
484
+ SAtk: "spa",
485
+ SpAtk: "spa",
486
+ spa: "spa",
487
+ Special: "spa",
488
+ spc: "spa",
489
+ Spc: "spa",
490
+ "Special Defense": "spd",
491
+ SpD: "spd",
492
+ SDef: "spd",
493
+ SpDef: "spd",
494
+ spd: "spd",
495
+ Speed: "spe",
496
+ Spe: "spe",
497
+ Spd: "spe",
498
+ spe: "spe"
499
+ };
500
+ var DISPLAY = {
501
+ hp: ["HP", "HP"],
502
+ atk: ["Atk", "Attack"],
503
+ def: ["Def", "Defense"],
504
+ spa: ["SpA", "Special Attack"],
505
+ spd: ["SpD", "Special Defense"],
506
+ spe: ["Spe", "Speed"],
507
+ spc: ["Spc", "Special"]
508
+ };
509
+ var Stats = class {
510
+ constructor(dex) {
511
+ this.dex = dex;
512
+ }
513
+ calc(stat, base, iv = 31, ev, level = 100, nature) {
514
+ if (ev === void 0)
515
+ ev = this.dex.gen < 3 ? 252 : 0;
516
+ if (this.dex.gen < 3) {
517
+ iv = this.toDV(iv) * 2;
518
+ nature = void 0;
519
+ }
520
+ if (stat === "hp") {
521
+ return base === 1 ? base : tr(tr(2 * base + iv + tr(ev / 4) + 100) * level / 100 + 10);
522
+ } else {
523
+ const val = tr(tr(2 * base + iv + tr(ev / 4)) * level / 100 + 5);
524
+ if (nature !== void 0) {
525
+ if (nature.plus === stat)
526
+ return tr(tr(val * 110, 16) / 100);
527
+ if (nature.minus === stat)
528
+ return tr(tr(val * 90, 16) / 100);
529
+ }
530
+ return val;
531
+ }
532
+ }
533
+ get(s) {
534
+ return NAMES[s];
535
+ }
536
+ display(str, full = false) {
537
+ let s = NAMES[str];
538
+ if (s === void 0)
539
+ return str;
540
+ if (this.dex.gen === 1 && s === "spa")
541
+ s = "spc";
542
+ return DISPLAY[s][+full];
543
+ }
544
+ fill(stats, val) {
545
+ for (const stat of STATS) {
546
+ if (!(stat in stats))
547
+ stats[stat] = val;
548
+ }
549
+ return stats;
550
+ }
551
+ getHPDV(ivs) {
552
+ return this.toDV(ivs.atk === void 0 ? 31 : ivs.atk) % 2 * 8 + this.toDV(ivs.def === void 0 ? 31 : ivs.def) % 2 * 4 + this.toDV(ivs.spe === void 0 ? 31 : ivs.spe) % 2 * 2 + this.toDV(ivs.spa === void 0 ? 31 : ivs.spa) % 2;
553
+ }
554
+ *[Symbol.iterator]() {
555
+ for (const s of STATS) {
556
+ yield s;
557
+ }
558
+ }
559
+ toDV(iv) {
560
+ return Math.floor(iv / 2);
561
+ }
562
+ toIV(dv) {
563
+ return dv * 2 + 1;
564
+ }
565
+ };
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+ exports.Abilities = Abilities; exports.Conditions = Conditions; exports.Generation = Generation; exports.Generations = Generations; exports.Items = Items; exports.Learnsets = Learnsets; exports.Moves = Moves; exports.Natures = Natures; exports.Specie = Specie; exports.Species = Species; exports.Stats = Stats; exports.Type = Type; exports.Types = Types; exports.toID = toID;
647
582
  //# sourceMappingURL=index.js.map