@pkmn/engine 0.1.0-dev.00879b8b

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 (60) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +368 -0
  3. package/build/pkg/addon.d.ts +7 -0
  4. package/build/pkg/addon.js +111 -0
  5. package/build/pkg/addon.js.map +1 -0
  6. package/build/pkg/data/ids.json +240 -0
  7. package/build/pkg/data/layout.json +108 -0
  8. package/build/pkg/data/protocol.json +230 -0
  9. package/build/pkg/data.d.ts +91 -0
  10. package/build/pkg/data.js +150 -0
  11. package/build/pkg/data.js.map +1 -0
  12. package/build/pkg/gen1.d.ts +110 -0
  13. package/build/pkg/gen1.js +684 -0
  14. package/build/pkg/gen1.js.map +1 -0
  15. package/build/pkg/index.d.ts +387 -0
  16. package/build/pkg/index.js +122 -0
  17. package/build/pkg/index.js.map +1 -0
  18. package/build/pkg/protocol.d.ts +73 -0
  19. package/build/pkg/protocol.js +473 -0
  20. package/build/pkg/protocol.js.map +1 -0
  21. package/build/test/display.js +400 -0
  22. package/build/test/display.js.map +1 -0
  23. package/build/tools/debug.js +134 -0
  24. package/build/tools/debug.js.map +1 -0
  25. package/build.zig +363 -0
  26. package/package.json +232 -0
  27. package/src/bin/install-pkmn-engine +404 -0
  28. package/src/bin/pkmn-debug +62 -0
  29. package/src/lib/common/battle.zig +17 -0
  30. package/src/lib/common/data.zig +117 -0
  31. package/src/lib/common/debug.zig +74 -0
  32. package/src/lib/common/js.zig +118 -0
  33. package/src/lib/common/optional.zig +67 -0
  34. package/src/lib/common/options.zig +51 -0
  35. package/src/lib/common/protocol.zig +1836 -0
  36. package/src/lib/common/rational.zig +357 -0
  37. package/src/lib/common/rng.zig +243 -0
  38. package/src/lib/common/util.zig +12 -0
  39. package/src/lib/gen1/calc.zig +507 -0
  40. package/src/lib/gen1/chance.zig +1063 -0
  41. package/src/lib/gen1/data/moves.zig +1866 -0
  42. package/src/lib/gen1/data/species.zig +1105 -0
  43. package/src/lib/gen1/data/types.zig +131 -0
  44. package/src/lib/gen1/data.zig +634 -0
  45. package/src/lib/gen1/helpers.zig +866 -0
  46. package/src/lib/gen1/mechanics.zig +3156 -0
  47. package/src/lib/gen2/calc.zig +143 -0
  48. package/src/lib/gen2/chance.zig +1315 -0
  49. package/src/lib/gen2/data/items.zig +230 -0
  50. package/src/lib/gen2/data/moves.zig +2878 -0
  51. package/src/lib/gen2/data/species.zig +1798 -0
  52. package/src/lib/gen2/data/types.zig +226 -0
  53. package/src/lib/gen2/data.zig +463 -0
  54. package/src/lib/gen2/generated.zig +806 -0
  55. package/src/lib/gen2/helpers.zig +249 -0
  56. package/src/lib/gen2/mechanics.zig +3632 -0
  57. package/src/lib/node.zig +131 -0
  58. package/src/lib/pkmn.zig +128 -0
  59. package/src/lib/wasm.zig +13 -0
  60. package/src/test/display/pkmn.html.tmpl +368 -0
@@ -0,0 +1,240 @@
1
+ [
2
+ {
3
+ "types": [
4
+ "Normal",
5
+ "Fighting",
6
+ "Flying",
7
+ "Poison",
8
+ "Ground",
9
+ "Rock",
10
+ "Bug",
11
+ "Ghost",
12
+ "Fire",
13
+ "Water",
14
+ "Grass",
15
+ "Electric",
16
+ "Psychic",
17
+ "Ice",
18
+ "Dragon"
19
+ ]
20
+ },
21
+ {
22
+ "types": [
23
+ "Ground",
24
+ "Rock",
25
+ "Steel",
26
+ "Normal",
27
+ "Fighting",
28
+ "Flying",
29
+ "Poison",
30
+ "Bug",
31
+ "Ghost",
32
+ "???",
33
+ "Fire",
34
+ "Water",
35
+ "Grass",
36
+ "Electric",
37
+ "Psychic",
38
+ "Ice",
39
+ "Dragon",
40
+ "Dark"
41
+ ],
42
+ "items": [
43
+ "softsand",
44
+ "hardstone",
45
+ "metalcoat",
46
+ "pinkbow",
47
+ "blackbelt",
48
+ "sharpbeak",
49
+ "poisonbarb",
50
+ "silverpowder",
51
+ "spelltag",
52
+ "polkadotbow",
53
+ "charcoal",
54
+ "mysticwater",
55
+ "miracleseed",
56
+ "magnet",
57
+ "twistedspoon",
58
+ "nevermeltice",
59
+ "dragonscale",
60
+ "blackglasses",
61
+ "brightpowder",
62
+ "metalpowder",
63
+ "quickclaw",
64
+ "kingsrock",
65
+ "stick",
66
+ "thickclub",
67
+ "focusband",
68
+ "scopelens",
69
+ "leftovers",
70
+ "berserkgene",
71
+ "lightball",
72
+ "berry",
73
+ "berryjuice",
74
+ "goldberry",
75
+ "mintberry",
76
+ "psncureberry",
77
+ "przcureberry",
78
+ "iceberry",
79
+ "burntberry",
80
+ "miracleberry",
81
+ "bitterberry",
82
+ "mysteryberry",
83
+ "masterball",
84
+ "ultraball",
85
+ "greatball",
86
+ "pokeball",
87
+ "moonstone",
88
+ "firestone",
89
+ "thunderstone",
90
+ "waterstone",
91
+ "luckypunch",
92
+ "leafstone",
93
+ "dragonfang",
94
+ "heavyball",
95
+ "levelball",
96
+ "lureball",
97
+ "fastball",
98
+ "friendball",
99
+ "moonball",
100
+ "loveball",
101
+ "sunstone",
102
+ "upgrade",
103
+ "flowermail",
104
+ "surfmail",
105
+ "lightbluemail",
106
+ "portrailmail",
107
+ "lovelymail",
108
+ "eonmail",
109
+ "morphmail",
110
+ "blueskymail",
111
+ "musicmail",
112
+ "miragemail",
113
+ "townmap",
114
+ "antidote",
115
+ "burnheal",
116
+ "iceheal",
117
+ "awakening",
118
+ "parylzeheal",
119
+ "fullrestore",
120
+ "maxpotion",
121
+ "hyperpotion",
122
+ "superpotion",
123
+ "potion",
124
+ "escaperope",
125
+ "repel",
126
+ "maxelixir",
127
+ "hpup",
128
+ "protein",
129
+ "iron",
130
+ "carbos",
131
+ "calcium",
132
+ "rarecandy",
133
+ "xaccuracy",
134
+ "nugget",
135
+ "pokedoll",
136
+ "fullheal",
137
+ "revive",
138
+ "maxrevive",
139
+ "guardspec",
140
+ "superrepel",
141
+ "maxrepel",
142
+ "direhit",
143
+ "freshwater",
144
+ "sodapop",
145
+ "lemonade",
146
+ "xattack",
147
+ "xdefend",
148
+ "xspeed",
149
+ "xspecial",
150
+ "pokeflute",
151
+ "expshare",
152
+ "silverleaf",
153
+ "ppup",
154
+ "ether",
155
+ "maxether",
156
+ "elixir",
157
+ "moomoomilk",
158
+ "goldleaf",
159
+ "redapricorn",
160
+ "tinymushroom",
161
+ "bigmushroom",
162
+ "blueapricorn",
163
+ "amuletcoin",
164
+ "yellowapricorn",
165
+ "greenapricorn",
166
+ "cleansetag",
167
+ "whiteapricorn",
168
+ "blackapricorn",
169
+ "pinkapricorn",
170
+ "slowpoketail",
171
+ "smokeball",
172
+ "pearl",
173
+ "bigpearl",
174
+ "everstone",
175
+ "ragecandybar",
176
+ "energypowder",
177
+ "energyroot",
178
+ "healpowder",
179
+ "revivalherb",
180
+ "luckyegg",
181
+ "stardust",
182
+ "starpiece",
183
+ "sacredash",
184
+ "normalbox",
185
+ "gorgeousbox",
186
+ "parkball",
187
+ "brickpiece",
188
+ "tm01",
189
+ "tm02",
190
+ "tm03",
191
+ "tm04",
192
+ "tm05",
193
+ "tm06",
194
+ "tm07",
195
+ "tm08",
196
+ "tm09",
197
+ "tm10",
198
+ "tm11",
199
+ "tm12",
200
+ "tm13",
201
+ "tm14",
202
+ "tm15",
203
+ "tm16",
204
+ "tm17",
205
+ "tm18",
206
+ "tm19",
207
+ "tm20",
208
+ "tm21",
209
+ "tm22",
210
+ "tm23",
211
+ "tm24",
212
+ "tm25",
213
+ "tm26",
214
+ "tm27",
215
+ "tm28",
216
+ "tm29",
217
+ "tm30",
218
+ "tm31",
219
+ "tm32",
220
+ "tm33",
221
+ "tm34",
222
+ "tm35",
223
+ "tm36",
224
+ "tm37",
225
+ "tm38",
226
+ "tm39",
227
+ "tm40",
228
+ "tm41",
229
+ "tm42",
230
+ "tm43",
231
+ "tm44",
232
+ "tm45",
233
+ "tm46",
234
+ "tm47",
235
+ "tm48",
236
+ "tm49",
237
+ "tm50"
238
+ ]
239
+ }
240
+ ]
@@ -0,0 +1,108 @@
1
+ [
2
+ {
3
+ "sizes": {
4
+ "Battle": 384,
5
+ "Side": 184,
6
+ "Pokemon": 24,
7
+ "ActivePokemon": 32,
8
+ "Actions": 16,
9
+ "Summaries": 12
10
+ },
11
+ "offsets": {
12
+ "Battle": {
13
+ "sides": 0,
14
+ "turn": 368,
15
+ "last_damage": 370,
16
+ "last_moves": 372,
17
+ "rng": 374
18
+ },
19
+ "Side": {
20
+ "pokemon": 0,
21
+ "active": 144,
22
+ "order": 176,
23
+ "last_selected_move": 182,
24
+ "last_used_move": 183
25
+ },
26
+ "Pokemon": {
27
+ "stats": 0,
28
+ "moves": 10,
29
+ "hp": 18,
30
+ "status": 20,
31
+ "species": 21,
32
+ "types": 22,
33
+ "level": 23
34
+ },
35
+ "ActivePokemon": {
36
+ "stats": 0,
37
+ "species": 10,
38
+ "types": 11,
39
+ "boosts": 12,
40
+ "volatiles": 16,
41
+ "moves": 24
42
+ },
43
+ "Stats": {
44
+ "hp": 0,
45
+ "atk": 2,
46
+ "def": 4,
47
+ "spe": 6,
48
+ "spc": 8
49
+ },
50
+ "Boosts": {
51
+ "atk": 0,
52
+ "def": 4,
53
+ "spe": 8,
54
+ "spc": 12,
55
+ "accuracy": 16,
56
+ "evasion": 20
57
+ },
58
+ "Volatiles": {
59
+ "Bide": 0,
60
+ "Thrashing": 1,
61
+ "MultiHit": 2,
62
+ "Flinch": 3,
63
+ "Charging": 4,
64
+ "Binding": 5,
65
+ "Invulnerable": 6,
66
+ "Confusion": 7,
67
+ "Mist": 8,
68
+ "FocusEnergy": 9,
69
+ "Substitute": 10,
70
+ "Recharging": 11,
71
+ "Rage": 12,
72
+ "LeechSeed": 13,
73
+ "Toxic": 14,
74
+ "LightScreen": 15,
75
+ "Reflect": 16,
76
+ "Transform": 17,
77
+ "confusion": 18,
78
+ "attacks": 21,
79
+ "state": 24,
80
+ "substitute": 40,
81
+ "transform": 48,
82
+ "disable_duration": 52,
83
+ "disable_move": 56,
84
+ "toxic": 59
85
+ },
86
+ "Action": {
87
+ "damage": 0,
88
+ "hit": 8,
89
+ "critical_hit": 10,
90
+ "secondary_chance": 12,
91
+ "speed_tie": 14,
92
+ "confused": 16,
93
+ "paralyzed": 18,
94
+ "duration": 20,
95
+ "durations": 24,
96
+ "move_slot": 40,
97
+ "multi_hit": 44,
98
+ "psywave": 48,
99
+ "metronome": 56
100
+ },
101
+ "Damage": {
102
+ "base": 0,
103
+ "final": 2,
104
+ "capped": 4
105
+ }
106
+ }
107
+ }
108
+ ]
@@ -0,0 +1,230 @@
1
+ {
2
+ "ArgType": [
3
+ "None",
4
+ "LastStill",
5
+ "LastMiss",
6
+ "Move",
7
+ "Switch",
8
+ "Cant",
9
+ "Faint",
10
+ "Turn",
11
+ "Win",
12
+ "Tie",
13
+ "Damage",
14
+ "Heal",
15
+ "Status",
16
+ "CureStatus",
17
+ "Boost",
18
+ "ClearAllBoost",
19
+ "Fail",
20
+ "Miss",
21
+ "HitCount",
22
+ "Prepare",
23
+ "MustRecharge",
24
+ "Activate",
25
+ "FieldActivate",
26
+ "Start",
27
+ "End",
28
+ "OHKO",
29
+ "Crit",
30
+ "SuperEffective",
31
+ "Resisted",
32
+ "Immune",
33
+ "Transform",
34
+ "Drag",
35
+ "Item",
36
+ "EndItem",
37
+ "CureTeam",
38
+ "SetHP",
39
+ "SetBoost",
40
+ "CopyBoost",
41
+ "SideStart",
42
+ "SideEnd",
43
+ "SingleMove",
44
+ "SingleTurn",
45
+ "Weather",
46
+ "Block",
47
+ "Ability",
48
+ "EndAbility",
49
+ "ClearNegativeBoost",
50
+ "FormeChange",
51
+ "NoTarget",
52
+ "SwapBoost",
53
+ "FieldStart",
54
+ "FieldEnd",
55
+ "DetailsChange",
56
+ "ClearPoke",
57
+ "Poke",
58
+ "TeamPreview",
59
+ "Center",
60
+ "Swap",
61
+ "Combine",
62
+ "Waiting",
63
+ "Replace",
64
+ "ClearBoost",
65
+ "Mega",
66
+ "Primal",
67
+ "InvertBoost",
68
+ "ZBroken",
69
+ "ZPower",
70
+ "Burst",
71
+ "ClearPositiveBoost",
72
+ "CanDynamax",
73
+ "SwapSideConditions",
74
+ "Terastallize"
75
+ ],
76
+ "Move": [
77
+ "None",
78
+ "From"
79
+ ],
80
+ "Cant": [
81
+ "Sleep",
82
+ "Freeze",
83
+ "Paralysis",
84
+ "Bound",
85
+ "Flinch",
86
+ "Disable",
87
+ "Recharge",
88
+ "PP",
89
+ "Attract"
90
+ ],
91
+ "Heal": [
92
+ "None",
93
+ "Silent",
94
+ "Drain",
95
+ "Leftovers"
96
+ ],
97
+ "Damage": [
98
+ "None",
99
+ "Poison",
100
+ "Burn",
101
+ "Confusion",
102
+ "LeechSeed",
103
+ "RecoilOf",
104
+ "Bind",
105
+ "Wrap",
106
+ "FireSpin",
107
+ "Clamp",
108
+ "Whirlpool",
109
+ "Spikes"
110
+ ],
111
+ "Status": [
112
+ "None",
113
+ "Silent",
114
+ "From"
115
+ ],
116
+ "CureStatus": [
117
+ "Message",
118
+ "Silent"
119
+ ],
120
+ "Boost": [
121
+ "Rage",
122
+ "Attack",
123
+ "Defense",
124
+ "Speed",
125
+ "SpecialAttack",
126
+ "SpecialDefense",
127
+ "Accuracy",
128
+ "Evasion"
129
+ ],
130
+ "Fail": [
131
+ "None",
132
+ "Sleep",
133
+ "Poison",
134
+ "Burn",
135
+ "Freeze",
136
+ "Paralysis",
137
+ "Toxic",
138
+ "Substitute",
139
+ "Weak"
140
+ ],
141
+ "Activate": [
142
+ "Bide",
143
+ "Confusion",
144
+ "Haze",
145
+ "Mist",
146
+ "Struggle",
147
+ "Substitute",
148
+ "Splash",
149
+ "Attract",
150
+ "LockOn",
151
+ "Bind",
152
+ "Wrap",
153
+ "FireSpin",
154
+ "Clamp",
155
+ "Whirlpool",
156
+ "BeatUp"
157
+ ],
158
+ "Start": [
159
+ "Bide",
160
+ "Confusion",
161
+ "ConfusionSilent",
162
+ "FocusEnergy",
163
+ "LeechSeed",
164
+ "LightScreen",
165
+ "Mist",
166
+ "Reflect",
167
+ "Substitute",
168
+ "TypeChange",
169
+ "Disable",
170
+ "Mimic",
171
+ "Nightmare",
172
+ "Curse",
173
+ "Foresight",
174
+ "Encore",
175
+ "FutureSight",
176
+ "PerishSong3Silent",
177
+ "PerishSong3",
178
+ "PerishSong2",
179
+ "PerishSong1",
180
+ "PerishSong0"
181
+ ],
182
+ "End": [
183
+ "Disable",
184
+ "Confusion",
185
+ "Bide",
186
+ "Substitute",
187
+ "Nightmare",
188
+ "Curse",
189
+ "Foresight",
190
+ "Encore",
191
+ "FutureSight",
192
+ "LeechSeed",
193
+ "Bind",
194
+ "Wrap",
195
+ "FireSpin",
196
+ "Clamp",
197
+ "Whirlpool",
198
+ "DisableSilent",
199
+ "ConfusionSilent",
200
+ "MistSilent",
201
+ "FocusEnergySilent",
202
+ "LeechSeedSilent",
203
+ "ToxicSilent",
204
+ "LightScreenSilent",
205
+ "ReflectSilent",
206
+ "BideSilent"
207
+ ],
208
+ "Immune": [
209
+ "None",
210
+ "OHKO"
211
+ ],
212
+ "EndItem": [
213
+ "None",
214
+ "Eat"
215
+ ],
216
+ "SetHP": [
217
+ "None",
218
+ "Silent"
219
+ ],
220
+ "Side": [
221
+ "Safeguard",
222
+ "Reflect",
223
+ "LightScreen",
224
+ "Spikes"
225
+ ],
226
+ "Weather": [
227
+ "None",
228
+ "Upkeep"
229
+ ]
230
+ }
@@ -0,0 +1,91 @@
1
+ import { Generation, ID, TypeName } from '@pkmn/data';
2
+ export declare const LE: boolean;
3
+ export type IDs = [
4
+ {
5
+ types: Exclude<TypeName, 'Dark' | 'Steel' | 'Fairy' | 'Stellar'>[];
6
+ },
7
+ {
8
+ items: ID[];
9
+ types: Exclude<TypeName, 'Fairy' | 'Stellar'>[];
10
+ }
11
+ ];
12
+ export declare const IDS: IDs;
13
+ export declare const PROTOCOL: {
14
+ [decl: string]: {
15
+ [name: string]: number;
16
+ };
17
+ };
18
+ export declare const LAYOUT: Array<{
19
+ sizes: {
20
+ [decl: string]: number;
21
+ };
22
+ offsets: {
23
+ [decl: string]: {
24
+ [field: string]: number;
25
+ };
26
+ };
27
+ }>;
28
+ export declare const Data: {
29
+ view(buf: number[] | Buffer): DataView;
30
+ };
31
+ /**
32
+ * Translation table for encoding/decoding Pokémon Showdown string identifiers
33
+ * to the identifiers used internally by the pkmn engine.
34
+ */
35
+ export declare class Lookup {
36
+ private readonly gen;
37
+ private readonly typesByNum;
38
+ private readonly typesByName;
39
+ private readonly species;
40
+ private readonly moves;
41
+ private readonly itemsByNum;
42
+ private readonly itemsByID;
43
+ /** Returns a `Lookup` table for a given generation. */
44
+ static get(gen: Generation): Lookup;
45
+ private constructor();
46
+ /**
47
+ * Returns the respective sizes of the various data types in the lookup table.
48
+ */
49
+ get sizes(): {
50
+ types: number;
51
+ species: number;
52
+ moves: number;
53
+ items: number;
54
+ };
55
+ /**
56
+ * Decodes the Pokémon Showdown `TypeName` for a type corresponding to the
57
+ * identifying `num` returned by the engine.
58
+ */
59
+ typeByNum(num: number): TypeName;
60
+ /**
61
+ * Encodes a `TypeName` to the number used as an identifier by the engine.
62
+ */
63
+ typeByName(name: TypeName): number;
64
+ /**
65
+ * Decodes the Pokémon Showdown `ID` for a species corresponding to the
66
+ * identifying `num` returned by the engine.
67
+ */
68
+ speciesByNum(num: number): ID;
69
+ /**
70
+ * Encodes a species `ID` to the number used as an identifier by the engine.
71
+ */
72
+ speciesByID(id: ID | undefined): number;
73
+ /**
74
+ * Decodes the Pokémon Showdown `ID` for a move corresponding to the
75
+ * identifying `num` returned by the engine.
76
+ */
77
+ moveByNum(num: number): ID;
78
+ /**
79
+ * Encodes a move `ID` to the number used as an identifier by the engine.
80
+ */
81
+ moveByID(id: ID | undefined): number;
82
+ /**
83
+ * Decodes the Pokémon Showdown `ID` for an item corresponding to the
84
+ * identifying `num` returned by the engine.
85
+ */
86
+ itemByNum(num: number): ID;
87
+ /**
88
+ * Encodes an item `ID` to the number used as an identifier by the engine.
89
+ */
90
+ itemByID(id: ID | undefined): number;
91
+ }