@robsonbittencourt/calc 0.10.0

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.
Files changed (144) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +12 -0
  3. package/bundle +107 -0
  4. package/dist/adaptable.d.ts +6 -0
  5. package/dist/adaptable.js +28 -0
  6. package/dist/adaptable.js.map +1 -0
  7. package/dist/calc.d.ts +6 -0
  8. package/dist/calc.js +26 -0
  9. package/dist/calc.js.map +1 -0
  10. package/dist/data/abilities.d.ts +15 -0
  11. package/dist/data/abilities.js +448 -0
  12. package/dist/data/abilities.js.map +1 -0
  13. package/dist/data/index.d.ts +2 -0
  14. package/dist/data/index.js +30 -0
  15. package/dist/data/index.js.map +1 -0
  16. package/dist/data/interface.d.ts +150 -0
  17. package/dist/data/interface.js +3 -0
  18. package/dist/data/interface.js.map +1 -0
  19. package/dist/data/items.d.ts +24 -0
  20. package/dist/data/items.js +708 -0
  21. package/dist/data/items.js.map +1 -0
  22. package/dist/data/moves.d.ts +86 -0
  23. package/dist/data/moves.js +5014 -0
  24. package/dist/data/moves.js.map +1 -0
  25. package/dist/data/natures.d.ts +17 -0
  26. package/dist/data/natures.js +127 -0
  27. package/dist/data/natures.js.map +1 -0
  28. package/dist/data/production.min.js +1 -0
  29. package/dist/data/species.d.ts +48 -0
  30. package/dist/data/species.js +10126 -0
  31. package/dist/data/species.js.map +1 -0
  32. package/dist/data/types.d.ts +23 -0
  33. package/dist/data/types.js +538 -0
  34. package/dist/data/types.js.map +1 -0
  35. package/dist/desc.d.ts +65 -0
  36. package/dist/desc.js +866 -0
  37. package/dist/desc.js.map +1 -0
  38. package/dist/field.d.ts +49 -0
  39. package/dist/field.js +111 -0
  40. package/dist/field.js.map +1 -0
  41. package/dist/index.d.ts +44 -0
  42. package/dist/index.js +99 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/items.d.ts +13 -0
  45. package/dist/items.js +434 -0
  46. package/dist/items.js.map +1 -0
  47. package/dist/mechanics/gen12.d.ts +6 -0
  48. package/dist/mechanics/gen12.js +271 -0
  49. package/dist/mechanics/gen12.js.map +1 -0
  50. package/dist/mechanics/gen3.d.ts +11 -0
  51. package/dist/mechanics/gen3.js +371 -0
  52. package/dist/mechanics/gen3.js.map +1 -0
  53. package/dist/mechanics/gen4.d.ts +11 -0
  54. package/dist/mechanics/gen4.js +596 -0
  55. package/dist/mechanics/gen4.js.map +1 -0
  56. package/dist/mechanics/gen56.d.ts +13 -0
  57. package/dist/mechanics/gen56.js +836 -0
  58. package/dist/mechanics/gen56.js.map +1 -0
  59. package/dist/mechanics/gen789.d.ts +14 -0
  60. package/dist/mechanics/gen789.js +1325 -0
  61. package/dist/mechanics/gen789.js.map +1 -0
  62. package/dist/mechanics/util.d.ts +39 -0
  63. package/dist/mechanics/util.js +675 -0
  64. package/dist/mechanics/util.js.map +1 -0
  65. package/dist/move.d.ts +50 -0
  66. package/dist/move.js +324 -0
  67. package/dist/move.js.map +1 -0
  68. package/dist/pokemon.d.ts +55 -0
  69. package/dist/pokemon.js +240 -0
  70. package/dist/pokemon.js.map +1 -0
  71. package/dist/production.min.js +1 -0
  72. package/dist/result.d.ts +34 -0
  73. package/dist/result.js +94 -0
  74. package/dist/result.js.map +1 -0
  75. package/dist/state.d.ts +77 -0
  76. package/dist/state.js +3 -0
  77. package/dist/state.js.map +1 -0
  78. package/dist/stats.d.ts +26 -0
  79. package/dist/stats.js +183 -0
  80. package/dist/stats.js.map +1 -0
  81. package/dist/test/calc.test.d.ts +1 -0
  82. package/dist/test/calc.test.js +1297 -0
  83. package/dist/test/calc.test.js.map +1 -0
  84. package/dist/test/data.test.d.ts +1 -0
  85. package/dist/test/data.test.js +368 -0
  86. package/dist/test/data.test.js.map +1 -0
  87. package/dist/test/gen.d.ts +135 -0
  88. package/dist/test/gen.js +636 -0
  89. package/dist/test/gen.js.map +1 -0
  90. package/dist/test/helper.d.ts +55 -0
  91. package/dist/test/helper.js +174 -0
  92. package/dist/test/helper.js.map +1 -0
  93. package/dist/test/move.test.d.ts +1 -0
  94. package/dist/test/move.test.js +14 -0
  95. package/dist/test/move.test.js.map +1 -0
  96. package/dist/test/pokemon.test.d.ts +1 -0
  97. package/dist/test/pokemon.test.js +102 -0
  98. package/dist/test/pokemon.test.js.map +1 -0
  99. package/dist/test/stats.test.d.ts +1 -0
  100. package/dist/test/stats.test.js +64 -0
  101. package/dist/test/stats.test.js.map +1 -0
  102. package/dist/test/utils.test.d.ts +1 -0
  103. package/dist/test/utils.test.js +19 -0
  104. package/dist/test/utils.test.js.map +1 -0
  105. package/dist/util.d.ts +17 -0
  106. package/dist/util.js +115 -0
  107. package/dist/util.js.map +1 -0
  108. package/jest.config.js +11 -0
  109. package/package.json +40 -0
  110. package/src/adaptable.ts +12 -0
  111. package/src/calc.ts +40 -0
  112. package/src/data/abilities.ts +383 -0
  113. package/src/data/index.ts +36 -0
  114. package/src/data/interface.ts +176 -0
  115. package/src/data/items.ts +632 -0
  116. package/src/data/moves.ts +5028 -0
  117. package/src/data/natures.ts +65 -0
  118. package/src/data/species.ts +10098 -0
  119. package/src/data/types.ts +478 -0
  120. package/src/desc.ts +1063 -0
  121. package/src/field.ts +124 -0
  122. package/src/index.ts +156 -0
  123. package/src/items.ts +423 -0
  124. package/src/mechanics/gen12.ts +297 -0
  125. package/src/mechanics/gen3.ts +444 -0
  126. package/src/mechanics/gen4.ts +702 -0
  127. package/src/mechanics/gen56.ts +1134 -0
  128. package/src/mechanics/gen789.ts +1788 -0
  129. package/src/mechanics/util.ts +676 -0
  130. package/src/move.ts +337 -0
  131. package/src/pokemon.ts +244 -0
  132. package/src/result.ts +106 -0
  133. package/src/state.ts +81 -0
  134. package/src/stats.ts +213 -0
  135. package/src/test/calc.test.ts +1588 -0
  136. package/src/test/data.test.ts +129 -0
  137. package/src/test/gen.ts +514 -0
  138. package/src/test/helper.ts +185 -0
  139. package/src/test/move.test.ts +13 -0
  140. package/src/test/pokemon.test.ts +121 -0
  141. package/src/test/stats.test.ts +84 -0
  142. package/src/test/utils.test.ts +18 -0
  143. package/src/util.ts +153 -0
  144. package/tsconfig.json +10 -0
@@ -0,0 +1,478 @@
1
+ import type * as I from './interface';
2
+ import {toID, extend} from '../util';
3
+
4
+ export type TypeChart = {
5
+ [type in I.TypeName]?: {[type in I.TypeName]?: number};
6
+ };
7
+
8
+ const RBY: TypeChart = {
9
+ '???': {
10
+ Normal: 1,
11
+ Grass: 1,
12
+ Fire: 1,
13
+ Water: 1,
14
+ Electric: 1,
15
+ Ice: 1,
16
+ Flying: 1,
17
+ Bug: 1,
18
+ Poison: 1,
19
+ Ground: 1,
20
+ Rock: 1,
21
+ Fighting: 1,
22
+ Psychic: 1,
23
+ Ghost: 1,
24
+ Dragon: 1,
25
+ },
26
+ Normal: {
27
+ '???': 1,
28
+ Normal: 1,
29
+ Grass: 1,
30
+ Fire: 1,
31
+ Water: 1,
32
+ Electric: 1,
33
+ Ice: 1,
34
+ Flying: 1,
35
+ Bug: 1,
36
+ Poison: 1,
37
+ Ground: 1,
38
+ Rock: 0.5,
39
+ Fighting: 1,
40
+ Psychic: 1,
41
+ Ghost: 0,
42
+ Dragon: 1,
43
+ },
44
+ Grass: {
45
+ '???': 1,
46
+ Normal: 1,
47
+ Grass: 0.5,
48
+ Fire: 0.5,
49
+ Water: 2,
50
+ Electric: 1,
51
+ Ice: 1,
52
+ Flying: 0.5,
53
+ Bug: 0.5,
54
+ Poison: 0.5,
55
+ Ground: 2,
56
+ Rock: 2,
57
+ Fighting: 1,
58
+ Psychic: 1,
59
+ Ghost: 1,
60
+ Dragon: 0.5,
61
+ },
62
+ Fire: {
63
+ '???': 1,
64
+ Normal: 1,
65
+ Grass: 2,
66
+ Fire: 0.5,
67
+ Water: 0.5,
68
+ Electric: 1,
69
+ Ice: 2,
70
+ Flying: 1,
71
+ Bug: 2,
72
+ Poison: 1,
73
+ Ground: 1,
74
+ Rock: 0.5,
75
+ Fighting: 1,
76
+ Psychic: 1,
77
+ Ghost: 1,
78
+ Dragon: 0.5,
79
+ },
80
+ Water: {
81
+ '???': 1,
82
+ Normal: 1,
83
+ Grass: 0.5,
84
+ Fire: 2,
85
+ Water: 0.5,
86
+ Electric: 1,
87
+ Ice: 1,
88
+ Flying: 1,
89
+ Bug: 1,
90
+ Poison: 1,
91
+ Ground: 2,
92
+ Rock: 2,
93
+ Fighting: 1,
94
+ Psychic: 1,
95
+ Ghost: 1,
96
+ Dragon: 0.5,
97
+ },
98
+ Electric: {
99
+ '???': 1,
100
+ Normal: 1,
101
+ Grass: 0.5,
102
+ Fire: 1,
103
+ Water: 2,
104
+ Electric: 0.5,
105
+ Ice: 1,
106
+ Flying: 2,
107
+ Bug: 1,
108
+ Poison: 1,
109
+ Ground: 0,
110
+ Rock: 1,
111
+ Fighting: 1,
112
+ Psychic: 1,
113
+ Ghost: 1,
114
+ Dragon: 0.5,
115
+ },
116
+ Ice: {
117
+ '???': 1,
118
+ Normal: 1,
119
+ Grass: 2,
120
+ Fire: 1,
121
+ Water: 0.5,
122
+ Electric: 1,
123
+ Ice: 0.5,
124
+ Flying: 2,
125
+ Bug: 1,
126
+ Poison: 1,
127
+ Ground: 2,
128
+ Rock: 1,
129
+ Fighting: 1,
130
+ Psychic: 1,
131
+ Ghost: 1,
132
+ Dragon: 2,
133
+ },
134
+ Flying: {
135
+ '???': 1,
136
+ Normal: 1,
137
+ Grass: 2,
138
+ Fire: 1,
139
+ Water: 1,
140
+ Electric: 0.5,
141
+ Ice: 1,
142
+ Flying: 1,
143
+ Bug: 2,
144
+ Poison: 1,
145
+ Ground: 1,
146
+ Rock: 0.5,
147
+ Fighting: 2,
148
+ Psychic: 1,
149
+ Ghost: 1,
150
+ Dragon: 1,
151
+ },
152
+ Bug: {
153
+ '???': 1,
154
+ Normal: 1,
155
+ Grass: 2,
156
+ Fire: 0.5,
157
+ Water: 1,
158
+ Electric: 1,
159
+ Ice: 1,
160
+ Flying: 0.5,
161
+ Bug: 1,
162
+ Poison: 2,
163
+ Ground: 1,
164
+ Rock: 1,
165
+ Fighting: 0.5,
166
+ Psychic: 2,
167
+ Ghost: 0.5,
168
+ Dragon: 1,
169
+ },
170
+ Poison: {
171
+ '???': 1,
172
+ Normal: 1,
173
+ Grass: 2,
174
+ Fire: 1,
175
+ Water: 1,
176
+ Electric: 1,
177
+ Ice: 1,
178
+ Flying: 1,
179
+ Bug: 2,
180
+ Poison: 0.5,
181
+ Ground: 0.5,
182
+ Rock: 0.5,
183
+ Fighting: 1,
184
+ Psychic: 1,
185
+ Ghost: 0.5,
186
+ Dragon: 1,
187
+ },
188
+ Ground: {
189
+ '???': 1,
190
+ Normal: 1,
191
+ Grass: 0.5,
192
+ Fire: 2,
193
+ Water: 1,
194
+ Electric: 2,
195
+ Ice: 1,
196
+ Flying: 0,
197
+ Bug: 0.5,
198
+ Poison: 2,
199
+ Ground: 1,
200
+ Rock: 2,
201
+ Fighting: 1,
202
+ Psychic: 1,
203
+ Ghost: 1,
204
+ Dragon: 1,
205
+ },
206
+ Rock: {
207
+ '???': 1,
208
+ Normal: 1,
209
+ Grass: 1,
210
+ Fire: 2,
211
+ Water: 1,
212
+ Electric: 1,
213
+ Ice: 2,
214
+ Flying: 2,
215
+ Bug: 2,
216
+ Poison: 1,
217
+ Ground: 0.5,
218
+ Rock: 1,
219
+ Fighting: 0.5,
220
+ Psychic: 1,
221
+ Ghost: 1,
222
+ Dragon: 1,
223
+ },
224
+ Fighting: {
225
+ '???': 1,
226
+ Normal: 2,
227
+ Grass: 1,
228
+ Fire: 1,
229
+ Water: 1,
230
+ Electric: 1,
231
+ Ice: 2,
232
+ Flying: 0.5,
233
+ Bug: 0.5,
234
+ Poison: 0.5,
235
+ Ground: 1,
236
+ Rock: 2,
237
+ Fighting: 1,
238
+ Psychic: 0.5,
239
+ Ghost: 0,
240
+ Dragon: 1,
241
+ },
242
+ Psychic: {
243
+ '???': 1,
244
+ Normal: 1,
245
+ Grass: 1,
246
+ Fire: 1,
247
+ Water: 1,
248
+ Electric: 1,
249
+ Ice: 1,
250
+ Flying: 1,
251
+ Bug: 1,
252
+ Poison: 2,
253
+ Ground: 1,
254
+ Rock: 1,
255
+ Fighting: 2,
256
+ Psychic: 0.5,
257
+ Ghost: 1,
258
+ Dragon: 1,
259
+ },
260
+ Ghost: {
261
+ '???': 1,
262
+ Normal: 0,
263
+ Grass: 1,
264
+ Fire: 1,
265
+ Water: 1,
266
+ Electric: 1,
267
+ Ice: 1,
268
+ Flying: 1,
269
+ Bug: 1,
270
+ Poison: 1,
271
+ Ground: 1,
272
+ Rock: 1,
273
+ Fighting: 1,
274
+ Psychic: 0,
275
+ Ghost: 2,
276
+ Dragon: 1,
277
+ },
278
+ Dragon: {
279
+ '???': 1,
280
+ Normal: 1,
281
+ Grass: 1,
282
+ Fire: 1,
283
+ Water: 1,
284
+ Electric: 1,
285
+ Ice: 1,
286
+ Flying: 1,
287
+ Bug: 1,
288
+ Poison: 1,
289
+ Ground: 1,
290
+ Rock: 1,
291
+ Fighting: 1,
292
+ Psychic: 1,
293
+ Ghost: 1,
294
+ Dragon: 2,
295
+ },
296
+ };
297
+
298
+ const GSC: TypeChart = extend(true, {}, RBY, {
299
+ '???': {Dark: 1, Steel: 1},
300
+ Normal: {Dark: 1, Steel: 0.5},
301
+ Grass: {Dark: 1, Steel: 0.5},
302
+ Fire: {Dark: 1, Steel: 2},
303
+ Water: {Dark: 1, Steel: 1},
304
+ Electric: {Dark: 1, Steel: 1},
305
+ Ice: {Fire: 0.5, Dark: 1, Steel: 0.5},
306
+ Flying: {Dark: 1, Steel: 0.5},
307
+ Bug: {Poison: 0.5, Dark: 2, Steel: 0.5},
308
+ Poison: {Bug: 1, Dark: 1, Steel: 0},
309
+ Ground: {Dark: 1, Steel: 2},
310
+ Rock: {Dark: 1, Steel: 0.5},
311
+ Fighting: {Dark: 2, Steel: 2},
312
+ Psychic: {Dark: 0, Steel: 0.5},
313
+ Ghost: {Psychic: 2, Dark: 0.5, Steel: 0.5},
314
+ Dragon: {Dark: 1, Steel: 0.5},
315
+ Dark: {
316
+ '???': 1,
317
+ Normal: 1,
318
+ Grass: 1,
319
+ Fire: 1,
320
+ Water: 1,
321
+ Electric: 1,
322
+ Ice: 1,
323
+ Flying: 1,
324
+ Bug: 1,
325
+ Poison: 1,
326
+ Ground: 1,
327
+ Rock: 1,
328
+ Fighting: 0.5,
329
+ Psychic: 2,
330
+ Ghost: 2,
331
+ Dragon: 1,
332
+ Dark: 0.5,
333
+ Steel: 0.5,
334
+ },
335
+ Steel: {
336
+ '???': 1,
337
+ Normal: 1,
338
+ Grass: 1,
339
+ Fire: 0.5,
340
+ Water: 0.5,
341
+ Electric: 0.5,
342
+ Ice: 2,
343
+ Flying: 1,
344
+ Bug: 1,
345
+ Poison: 1,
346
+ Ground: 1,
347
+ Rock: 2,
348
+ Fighting: 1,
349
+ Psychic: 1,
350
+ Ghost: 1,
351
+ Dragon: 1,
352
+ Dark: 1,
353
+ Steel: 0.5,
354
+ },
355
+ });
356
+
357
+ const ADV = GSC;
358
+
359
+ const DPP = GSC;
360
+
361
+ const BW = GSC;
362
+
363
+ const XY: TypeChart = extend(true, {}, GSC, {
364
+ '???': {Fairy: 1},
365
+ Normal: {Fairy: 1},
366
+ Grass: {Fairy: 1},
367
+ Fire: {Fairy: 1},
368
+ Water: {Fairy: 1},
369
+ Electric: {Fairy: 1},
370
+ Ice: {Fairy: 1},
371
+ Flying: {Fairy: 1},
372
+ Bug: {Fairy: 0.5},
373
+ Poison: {Fairy: 2},
374
+ Ground: {Fairy: 1},
375
+ Rock: {Fairy: 1},
376
+ Fighting: {Fairy: 0.5},
377
+ Psychic: {Fairy: 1},
378
+ Ghost: {Steel: 1, Fairy: 1},
379
+ Dragon: {Fairy: 0},
380
+ Dark: {Steel: 1, Fairy: 0.5},
381
+ Steel: {Fairy: 2},
382
+ Fairy: {
383
+ '???': 1,
384
+ Normal: 1,
385
+ Grass: 1,
386
+ Fire: 0.5,
387
+ Water: 1,
388
+ Electric: 1,
389
+ Ice: 1,
390
+ Flying: 1,
391
+ Bug: 1,
392
+ Poison: 0.5,
393
+ Ground: 1,
394
+ Rock: 1,
395
+ Fighting: 2,
396
+ Psychic: 1,
397
+ Ghost: 1,
398
+ Dragon: 2,
399
+ Dark: 2,
400
+ Steel: 0.5,
401
+ Fairy: 1,
402
+ },
403
+ });
404
+
405
+ const SM = XY;
406
+
407
+ const SS = SM;
408
+
409
+ const SV: TypeChart = extend(true, {}, SS, {
410
+ '???': {Stellar: 1},
411
+ Normal: {Stellar: 1},
412
+ Grass: {Stellar: 1},
413
+ Fire: {Stellar: 1},
414
+ Water: {Stellar: 1},
415
+ Electric: {Stellar: 1},
416
+ Ice: {Stellar: 1},
417
+ Flying: {Stellar: 1},
418
+ Bug: {Stellar: 1},
419
+ Poison: {Stellar: 1},
420
+ Ground: {Stellar: 1},
421
+ Rock: {Stellar: 1},
422
+ Fighting: {Stellar: 1},
423
+ Psychic: {Stellar: 1},
424
+ Ghost: {Stellar: 1},
425
+ Dragon: {Stellar: 1},
426
+ Dark: {Stellar: 1},
427
+ Steel: {Stellar: 1},
428
+ Fairy: {Stellar: 1},
429
+ Stellar: {
430
+ '???': 1,
431
+ },
432
+ });
433
+
434
+ export const TYPE_CHART = [{}, RBY, GSC, ADV, DPP, BW, XY, SM, SS, SV];
435
+
436
+ export class Types implements I.Types {
437
+ private readonly gen: I.GenerationNum;
438
+
439
+ constructor(gen: I.GenerationNum) {
440
+ this.gen = gen;
441
+ }
442
+
443
+ get(id: I.ID) {
444
+ // toID('???') => '', as do many other things, but returning the '???' type seems appropriate :)
445
+ return TYPES_BY_ID[this.gen][id];
446
+ }
447
+
448
+ *[Symbol.iterator]() {
449
+ for (const id in TYPES_BY_ID[this.gen]) {
450
+ yield this.get(id as I.ID)!;
451
+ }
452
+ }
453
+ }
454
+
455
+ class Type implements I.Type {
456
+ readonly kind: 'Type';
457
+ readonly id: I.ID;
458
+ readonly name: I.TypeName;
459
+ readonly effectiveness: Readonly<{[type in I.TypeName]?: I.TypeEffectiveness}>;
460
+
461
+ constructor(name: string, effectiveness: TypeChart[I.TypeName]) {
462
+ this.kind = 'Type';
463
+ this.id = toID(name);
464
+ this.name = name as I.TypeName;
465
+ this.effectiveness = effectiveness! as {[type in I.TypeName]?: I.TypeEffectiveness};
466
+ }
467
+ }
468
+
469
+ const TYPES_BY_ID: Array<{[id: string]: Type}> = [];
470
+
471
+ for (const typeChart of TYPE_CHART) {
472
+ const map: {[id: string]: Type} = {};
473
+ for (const type in typeChart) {
474
+ const t = new Type(type, {...typeChart[type as I.TypeName]!});
475
+ map[t.id] = t;
476
+ }
477
+ TYPES_BY_ID.push(map);
478
+ }