@pkmn/engine 0.1.0-dev.fb5bf955 → 0.1.0-dev.fb6653d6

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 (85) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +115 -76
  3. package/build/pkg/addon/browser.d.ts +3 -0
  4. package/build/pkg/addon/browser.js +44 -0
  5. package/build/pkg/addon/browser.js.map +1 -0
  6. package/build/pkg/addon/node.d.ts +3 -0
  7. package/build/pkg/addon/node.js +97 -0
  8. package/build/pkg/addon/node.js.map +1 -0
  9. package/build/pkg/addon/wasm.d.ts +2 -0
  10. package/build/pkg/addon/wasm.js +53 -0
  11. package/build/pkg/addon/wasm.js.map +1 -0
  12. package/build/pkg/addon.d.ts +27 -5
  13. package/build/pkg/addon.js +42 -73
  14. package/build/pkg/addon.js.map +1 -1
  15. package/build/pkg/data/ids.json +12 -12
  16. package/build/pkg/data/layout.json +40 -5
  17. package/build/pkg/data/protocol.json +84 -13
  18. package/build/pkg/data.d.ts +27 -5
  19. package/build/pkg/data.js.map +1 -1
  20. package/build/pkg/gen1.d.ts +16 -19
  21. package/build/pkg/gen1.js +54 -42
  22. package/build/pkg/gen1.js.map +1 -1
  23. package/build/pkg/index.d.ts +55 -103
  24. package/build/pkg/index.js +6 -63
  25. package/build/pkg/index.js.map +1 -1
  26. package/build/pkg/protocol.d.ts +24 -3
  27. package/build/pkg/protocol.js +127 -104
  28. package/build/pkg/protocol.js.map +1 -1
  29. package/build/tools/debug.js +36 -69
  30. package/build/tools/debug.js.map +1 -1
  31. package/build/tools/display/debug.jsx +141 -0
  32. package/build/tools/display/debug.jsx.map +1 -0
  33. package/build/tools/display/index.js +142 -0
  34. package/build/tools/display/index.js.map +1 -0
  35. package/build/tools/display/ui.jsx +349 -0
  36. package/build/tools/display/ui.jsx.map +1 -0
  37. package/build/tools/display/util.js +18 -0
  38. package/build/tools/display/util.js.map +1 -0
  39. package/build.zig +373 -152
  40. package/package.json +68 -120
  41. package/src/bin/install-pkmn-engine +41 -26
  42. package/src/bin/pkmn-debug +29 -6
  43. package/src/lib/bindings/node.zig +121 -0
  44. package/src/lib/bindings/wasm.zig +58 -0
  45. package/src/lib/common/array.zig +77 -0
  46. package/src/lib/common/battle.zig +17 -0
  47. package/src/lib/common/data.zig +19 -31
  48. package/src/lib/common/debug.zig +58 -17
  49. package/src/lib/common/js.zig +120 -0
  50. package/src/lib/common/optional.zig +71 -0
  51. package/src/lib/common/options.zig +18 -3
  52. package/src/lib/common/protocol.zig +947 -407
  53. package/src/lib/common/rational.zig +449 -0
  54. package/src/lib/common/rng.zig +31 -24
  55. package/src/lib/common/util.zig +61 -0
  56. package/src/lib/gen1/calc.zig +953 -0
  57. package/src/lib/gen1/chance.zig +1185 -0
  58. package/src/lib/gen1/data/moves.zig +203 -193
  59. package/src/lib/gen1/data/species.zig +6 -8
  60. package/src/lib/gen1/data/types.zig +11 -12
  61. package/src/lib/gen1/data.zig +100 -89
  62. package/src/lib/gen1/helpers.zig +139 -50
  63. package/src/lib/gen1/mechanics.zig +1344 -907
  64. package/src/lib/gen2/calc.zig +153 -0
  65. package/src/lib/gen2/chance.zig +902 -0
  66. package/src/lib/gen2/data/items.zig +15 -23
  67. package/src/lib/gen2/data/moves.zig +665 -573
  68. package/src/lib/gen2/data/species.zig +3 -5
  69. package/src/lib/gen2/data/types.zig +138 -36
  70. package/src/lib/gen2/data.zig +134 -99
  71. package/src/lib/gen2/generated.zig +801 -0
  72. package/src/lib/gen2/helpers.zig +59 -44
  73. package/src/lib/gen2/mechanics.zig +3582 -30
  74. package/src/lib/node.zig +18 -0
  75. package/src/lib/pkmn.zig +93 -12
  76. package/src/lib/wasm.zig +17 -0
  77. package/src/tools/display/dom.ts +96 -0
  78. package/src/tools/display/ui.css +354 -0
  79. package/build/test/display.js +0 -382
  80. package/build/test/display.js.map +0 -1
  81. package/src/lib/binding/node.zig +0 -229
  82. package/src/lib/binding/wasm.zig +0 -10
  83. package/src/lib/gen1/README.md +0 -784
  84. package/src/lib/gen2/README.md +0 -309
  85. package/src/test/display/pkmn.html.tmpl +0 -368
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Lookup = exports.Log = exports.SideInfo = exports.Info = exports.Result = exports.Choice = exports.Battle = void 0;
26
+ exports.Lookup = exports.Log = exports.SideInfo = exports.Info = exports.Result = exports.Choice = exports.initialize = exports.Battle = void 0;
27
27
  const addon = __importStar(require("./addon"));
28
28
  const data_1 = require("./data");
29
29
  const gen1 = __importStar(require("./gen1"));
@@ -51,68 +51,11 @@ exports.Battle = new class {
51
51
  }
52
52
  }
53
53
  };
54
- /** Utilities for working with `Choice` objects. */
55
- class Choice {
56
- /** All valid choices types. */
57
- static Types = ['pass', 'move', 'switch'];
58
- static PASS = { type: 'pass', data: 0 };
59
- static MATCH = /^(?:(pass)|((move) ([0-4]))|((switch) ([2-6])))$/;
60
- constructor() { }
61
- /** Decode a choice from its binary representation. */
62
- static decode(byte) {
63
- return { type: Choice.Types[byte & 0b11], data: byte >> 2 };
64
- }
65
- /** Encode a choice to its binary representation. */
66
- static encode(choice) {
67
- return (choice
68
- ? (choice.data << 2 | (choice.type === 'pass' ? 0 : choice.type === 'move' ? 1 : 2))
69
- : 0);
70
- }
71
- /**
72
- * Parse a Pokémon Showdown choice string into a `Choice`.
73
- * Only numeric choice data is supported.
74
- */
75
- static parse(choice) {
76
- const m = Choice.MATCH.exec(choice);
77
- if (!m)
78
- throw new Error(`Invalid choice: '${choice}'`);
79
- const type = (m[1] ?? m[3] ?? m[6]);
80
- const data = +(m[4] ?? m[7] ?? 0);
81
- return { type, data };
82
- }
83
- /** Formats a `Choice` into a Pokémon Showdown compatible choice string. */
84
- static format(choice) {
85
- return choice.type === 'pass' ? choice.type : `${choice.type} ${choice.data}`;
86
- }
87
- /** Returns the "pass" `Choice`. */
88
- static pass() {
89
- return Choice.PASS;
90
- }
91
- /** Returns a "move" `Choice` with the provided data. */
92
- static move(data) {
93
- return { type: 'move', data };
94
- }
95
- /** Returns a "switch" `Choice` with the provided data. */
96
- static switch(data) {
97
- return { type: 'switch', data };
98
- }
99
- }
100
- exports.Choice = Choice;
101
- /** Utilities for working with `Result` objects */
102
- class Result {
103
- /** All valid result types. */
104
- static Types = [undefined, 'win', 'lose', 'tie', 'error'];
105
- constructor() { }
106
- /** Decode a `Result` from its binary representation. */
107
- static decode(byte) {
108
- return {
109
- type: Result.Types[byte & 0b1111],
110
- p1: Choice.Types[(byte >> 4) & 0b11],
111
- p2: Choice.Types[byte >> 6],
112
- };
113
- }
114
- }
115
- exports.Result = Result;
54
+ var addon_1 = require("./addon");
55
+ Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return addon_1.initialize; } });
56
+ var common_1 = require("./common");
57
+ Object.defineProperty(exports, "Choice", { enumerable: true, get: function () { return common_1.Choice; } });
58
+ Object.defineProperty(exports, "Result", { enumerable: true, get: function () { return common_1.Result; } });
116
59
  var protocol_1 = require("./protocol");
117
60
  Object.defineProperty(exports, "Info", { enumerable: true, get: function () { return protocol_1.Info; } });
118
61
  Object.defineProperty(exports, "SideInfo", { enumerable: true, get: function () { return protocol_1.SideInfo; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pkg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,+CAAiC;AACjC,iCAA8B;AAC9B,6CAA+B;AA8V/B,2CAA2C;AAC9B,QAAA,MAAM,GAAG,IAAI;IACxB,2EAA2E;IAC3E,MAAM,CAAC,GAAe,EAAE,OAAsB;QAC5C,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,aAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,QAAQ,GAAG,CAAC,GAAG,EAAE;YACjB,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C,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACxD,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,GAAe,EAAE,MAAoB,EAAE,OAAuB;QACpE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,aAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC;YAChB,KAAK,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACjE,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;CACF,CAAC;AAEF,iCAAmC;AAA3B,mGAAA,UAAU,OAAA;AAClB,mCAAwC;AAAhC,gGAAA,MAAM,OAAA;AAAE,gGAAA,MAAM,OAAA;AAGtB,uCAA+C;AAAvC,gGAAA,IAAI,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAAE,+FAAA,GAAG,OAAA;AAC3B,+BAA8B;AAAtB,8FAAA,MAAM,OAAA"}
@@ -1,7 +1,25 @@
1
- import { Generation, StatusName, TypeName } from '@pkmn/data';
1
+ import { GenderName, GenerationNum, ID, MoveName, SpeciesName, StatusName, TypeName } from '@pkmn/data';
2
2
  import { Protocol } from '@pkmn/protocol';
3
3
  import { Lookup } from './data';
4
4
  import { PlayerOptions } from '.';
5
+ interface Generation {
6
+ num: GenerationNum;
7
+ species: {
8
+ get(id: ID): {
9
+ name: SpeciesName;
10
+ genderRatio: {
11
+ M: number;
12
+ F: number;
13
+ };
14
+ gender?: GenderName;
15
+ } | undefined;
16
+ };
17
+ moves: {
18
+ get(id: ID): {
19
+ name: MoveName;
20
+ } | undefined;
21
+ };
22
+ }
5
23
  /** A message logged by the engine parsed into Pokémon Showdown's protocol. */
6
24
  export interface ParsedLine {
7
25
  /** Positional protocol arguments. */
@@ -39,8 +57,10 @@ export declare class SideInfo {
39
57
  * protocol from the engine's binary protocol.
40
58
  */
41
59
  export interface PokemonInfo {
42
- /** The Pokémon's nickname. */
43
- name: string;
60
+ /** The Pokémon's nickname. Either this or species must be set. */
61
+ name?: string;
62
+ /** The Pokémon's species. Either this or name must be set. */
63
+ species?: string;
44
64
  /** The gender of the Pokémon. */
45
65
  gender?: string;
46
66
  /** Whether or not the Pokémon is shiny. */
@@ -69,3 +89,4 @@ export declare function decodeIdentRaw(byte: number): {
69
89
  };
70
90
  export declare function decodeStatus(val: number): StatusName | undefined;
71
91
  export declare function decodeTypes(lookup: Lookup, val: number): readonly [TypeName, TypeName];
92
+ export {};
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeTypes = exports.decodeStatus = exports.decodeIdentRaw = exports.Log = exports.SideInfo = exports.Info = void 0;
4
- const data_1 = require("./data");
5
- const ArgType = data_1.PROTOCOL.ArgType;
3
+ exports.Log = exports.SideInfo = exports.Info = void 0;
4
+ exports.decodeIdentRaw = decodeIdentRaw;
5
+ exports.decodeStatus = decodeStatus;
6
+ exports.decodeTypes = decodeTypes;
7
+ const data_1 = require("@pkmn/data");
8
+ const data_2 = require("./data");
9
+ const ArgType = data_2.PROTOCOL.ArgType;
6
10
  /**
7
11
  * Information related to battle required to parse the engine's binary protocol
8
12
  * into Pokémon Showdown's text protocol (e.g. Pokémon nicknames).
@@ -30,10 +34,11 @@ class SideInfo {
30
34
  constructor(gen, player) {
31
35
  this.name = player.name;
32
36
  this.team = player.team.map(p => {
33
- const species = gen.species.get(p.species);
37
+ const species = gen.species.get((0, data_1.toID)(p.species));
34
38
  const name = p.name ?? species.name;
39
+ const dv = Math.floor((p.ivs?.atk ?? 31) / 2);
35
40
  const fallback = gen.num === 1 ? undefined
36
- : gen.num === 2 ? gen.stats.toDV(p.ivs?.atk ?? 31) >= species.genderRatio.F * 16 ? 'M' : 'F'
41
+ : gen.num === 2 ? dv >= species.genderRatio.F * 16 ? 'M' : 'F'
37
42
  : 'M';
38
43
  const gender = (p.gender ?? species.gender ?? fallback);
39
44
  return { species: species.name, name, gender, shiny: p.shiny };
@@ -99,86 +104,102 @@ class Log {
99
104
  }
100
105
  }
101
106
  exports.Log = Log;
102
- const CANT = new Array(data_1.PROTOCOL.Cant.length);
103
- CANT[data_1.PROTOCOL.Cant.Sleep] = 'slp';
104
- CANT[data_1.PROTOCOL.Cant.Freeze] = 'frz';
105
- CANT[data_1.PROTOCOL.Cant.Paralysis] = 'par';
106
- CANT[data_1.PROTOCOL.Cant.Bound] = 'partiallytrapped';
107
- CANT[data_1.PROTOCOL.Cant.Flinch] = 'flinch';
108
- CANT[data_1.PROTOCOL.Cant.Recharge] = 'recharge';
109
- CANT[data_1.PROTOCOL.Cant.PP] = 'nopp';
110
- const DAMAGE = new Array(data_1.PROTOCOL.Damage.length);
111
- DAMAGE[data_1.PROTOCOL.Damage.Poison] = 'psn';
112
- DAMAGE[data_1.PROTOCOL.Damage.Burn] = 'brn';
113
- DAMAGE[data_1.PROTOCOL.Damage.Confusion] = 'confusion';
114
- DAMAGE[data_1.PROTOCOL.Damage.LeechSeed] = 'Leech Seed';
115
- DAMAGE[data_1.PROTOCOL.Damage.RecoilOf] = 'Recoil';
116
- const BOOSTS = new Array(data_1.PROTOCOL.Boost.length);
117
- BOOSTS[data_1.PROTOCOL.Boost.Rage] = 'atk';
118
- BOOSTS[data_1.PROTOCOL.Boost.Attack] = 'atk';
119
- BOOSTS[data_1.PROTOCOL.Boost.Defense] = 'def';
120
- BOOSTS[data_1.PROTOCOL.Boost.Speed] = 'spe';
121
- BOOSTS[data_1.PROTOCOL.Boost.SpecialAttack] = 'spa';
122
- BOOSTS[data_1.PROTOCOL.Boost.SpecialDefense] = 'spd';
123
- BOOSTS[data_1.PROTOCOL.Boost.Accuracy] = 'accuracy';
124
- BOOSTS[data_1.PROTOCOL.Boost.Evasion] = 'evasion';
125
- const FAIL = new Array(data_1.PROTOCOL.Fail.length);
126
- FAIL[data_1.PROTOCOL.Fail.Sleep] = 'slp';
127
- FAIL[data_1.PROTOCOL.Fail.Poison] = 'psn';
128
- FAIL[data_1.PROTOCOL.Fail.Burn] = 'brn';
129
- FAIL[data_1.PROTOCOL.Fail.Freeze] = 'frz';
130
- FAIL[data_1.PROTOCOL.Fail.Paralysis] = 'par';
131
- FAIL[data_1.PROTOCOL.Fail.Toxic] = 'tox';
132
- const ACTIVATE = new Array(data_1.PROTOCOL.Activate.length);
133
- ACTIVATE[data_1.PROTOCOL.Activate.Bide] = 'Bide';
134
- ACTIVATE[data_1.PROTOCOL.Activate.Confusion] = 'confusion';
135
- ACTIVATE[data_1.PROTOCOL.Activate.Haze] = 'move: Haze';
136
- ACTIVATE[data_1.PROTOCOL.Activate.Mist] = 'move: Mist';
137
- ACTIVATE[data_1.PROTOCOL.Activate.Struggle] = 'move: Struggle';
138
- ACTIVATE[data_1.PROTOCOL.Activate.Substitute] = 'Substitute';
139
- ACTIVATE[data_1.PROTOCOL.Activate.Splash] = 'move: Splash';
140
- const START = new Array(data_1.PROTOCOL.Start.length);
141
- START[data_1.PROTOCOL.Start.Bide] = 'Bide';
142
- START[data_1.PROTOCOL.Start.Confusion] = 'confusion';
143
- START[data_1.PROTOCOL.Start.ConfusionSilent] = 'confusion';
144
- START[data_1.PROTOCOL.Start.FocusEnergy] = 'move: Focus Energy';
145
- START[data_1.PROTOCOL.Start.LeechSeed] = 'move: Leech Seed';
146
- START[data_1.PROTOCOL.Start.LightScreen] = 'Light Screen';
147
- START[data_1.PROTOCOL.Start.Mist] = 'Mist';
148
- START[data_1.PROTOCOL.Start.Reflect] = 'Reflect';
149
- START[data_1.PROTOCOL.Start.Substitute] = 'Substitute';
150
- const END = new Array(data_1.PROTOCOL.End.length);
151
- END[data_1.PROTOCOL.End.Disable] = 'Disable';
152
- END[data_1.PROTOCOL.End.Confusion] = 'confusion';
153
- END[data_1.PROTOCOL.End.Bide] = 'Bide';
154
- END[data_1.PROTOCOL.End.Substitute] = 'Substitute';
155
- END[data_1.PROTOCOL.End.DisableSilent] = 'Disable';
156
- END[data_1.PROTOCOL.End.ConfusionSilent] = 'confusion';
157
- END[data_1.PROTOCOL.End.Mist] = 'Mist';
158
- END[data_1.PROTOCOL.End.FocusEnergy] = 'move: Focus Energy';
159
- END[data_1.PROTOCOL.End.LeechSeed] = 'move: Leech Seed';
160
- END[data_1.PROTOCOL.End.Toxic] = 'Toxic counter';
161
- END[data_1.PROTOCOL.End.LightScreen] = 'Light Screen';
162
- END[data_1.PROTOCOL.End.Reflect] = 'Reflect';
107
+ const GENDERS = ['M', 'F', 'N'];
108
+ const CANT = new Array(data_2.PROTOCOL.Cant.length);
109
+ CANT[data_2.PROTOCOL.Cant.Sleep] = 'slp';
110
+ CANT[data_2.PROTOCOL.Cant.Freeze] = 'frz';
111
+ CANT[data_2.PROTOCOL.Cant.Paralysis] = 'par';
112
+ CANT[data_2.PROTOCOL.Cant.Bound] = 'partiallytrapped';
113
+ CANT[data_2.PROTOCOL.Cant.Flinch] = 'flinch';
114
+ CANT[data_2.PROTOCOL.Cant.Recharge] = 'recharge';
115
+ CANT[data_2.PROTOCOL.Cant.PP] = 'nopp';
116
+ const DAMAGE = new Array(data_2.PROTOCOL.Damage.length);
117
+ DAMAGE[data_2.PROTOCOL.Damage.Poison] = 'psn';
118
+ DAMAGE[data_2.PROTOCOL.Damage.Burn] = 'brn';
119
+ DAMAGE[data_2.PROTOCOL.Damage.Confusion] = 'confusion';
120
+ DAMAGE[data_2.PROTOCOL.Damage.LeechSeed] = 'Leech Seed';
121
+ DAMAGE[data_2.PROTOCOL.Damage.RecoilOf] = 'Recoil';
122
+ const BOOSTS = new Array(data_2.PROTOCOL.Boost.length);
123
+ BOOSTS[data_2.PROTOCOL.Boost.Rage] = 'atk';
124
+ BOOSTS[data_2.PROTOCOL.Boost.Attack] = 'atk';
125
+ BOOSTS[data_2.PROTOCOL.Boost.Defense] = 'def';
126
+ BOOSTS[data_2.PROTOCOL.Boost.Speed] = 'spe';
127
+ BOOSTS[data_2.PROTOCOL.Boost.SpecialAttack] = 'spa';
128
+ BOOSTS[data_2.PROTOCOL.Boost.SpecialDefense] = 'spd';
129
+ BOOSTS[data_2.PROTOCOL.Boost.Accuracy] = 'accuracy';
130
+ BOOSTS[data_2.PROTOCOL.Boost.Evasion] = 'evasion';
131
+ const FAIL = new Array(data_2.PROTOCOL.Fail.length);
132
+ FAIL[data_2.PROTOCOL.Fail.Sleep] = 'slp';
133
+ FAIL[data_2.PROTOCOL.Fail.Poison] = 'psn';
134
+ FAIL[data_2.PROTOCOL.Fail.Burn] = 'brn';
135
+ FAIL[data_2.PROTOCOL.Fail.Freeze] = 'frz';
136
+ FAIL[data_2.PROTOCOL.Fail.Paralysis] = 'par';
137
+ FAIL[data_2.PROTOCOL.Fail.Toxic] = 'tox';
138
+ const ACTIVATE = [new Array(data_2.PROTOCOL.Activate.length)];
139
+ ACTIVATE[0][data_2.PROTOCOL.Activate.Bide] = 'Bide';
140
+ ACTIVATE[0][data_2.PROTOCOL.Activate.Confusion] = 'confusion';
141
+ ACTIVATE[0][data_2.PROTOCOL.Activate.Haze] = 'move: Haze';
142
+ ACTIVATE[0][data_2.PROTOCOL.Activate.Mist] = 'move: Mist';
143
+ ACTIVATE[0][data_2.PROTOCOL.Activate.Struggle] = 'move: Struggle';
144
+ ACTIVATE[0][data_2.PROTOCOL.Activate.Substitute] = 'Substitute';
145
+ ACTIVATE[0][data_2.PROTOCOL.Activate.Splash] = 'move: Splash';
146
+ ACTIVATE[1] = ACTIVATE[0].slice(0);
147
+ ACTIVATE[1][data_2.PROTOCOL.Activate.Bide] = 'move: Bide';
148
+ const START = [new Array(data_2.PROTOCOL.Start.length)];
149
+ START[0][data_2.PROTOCOL.Start.Bide] = 'Bide';
150
+ START[0][data_2.PROTOCOL.Start.Confusion] = 'confusion';
151
+ START[0][data_2.PROTOCOL.Start.ConfusionSilent] = 'confusion';
152
+ START[0][data_2.PROTOCOL.Start.FocusEnergy] = 'move: Focus Energy';
153
+ START[0][data_2.PROTOCOL.Start.LeechSeed] = 'move: Leech Seed';
154
+ START[0][data_2.PROTOCOL.Start.LightScreen] = 'Light Screen';
155
+ START[0][data_2.PROTOCOL.Start.Mist] = 'Mist';
156
+ START[0][data_2.PROTOCOL.Start.Reflect] = 'Reflect';
157
+ START[0][data_2.PROTOCOL.Start.Substitute] = 'Substitute';
158
+ START[1] = START[0].slice(0);
159
+ START[1][data_2.PROTOCOL.Start.Bide] = 'move: Bide';
160
+ const END = [new Array(data_2.PROTOCOL.End.length)];
161
+ END[0][data_2.PROTOCOL.End.Disable] = 'Disable';
162
+ END[0][data_2.PROTOCOL.End.Confusion] = 'confusion';
163
+ END[0][data_2.PROTOCOL.End.Bide] = 'Bide';
164
+ END[0][data_2.PROTOCOL.End.Substitute] = 'Substitute';
165
+ END[0][data_2.PROTOCOL.End.DisableSilent] = 'Disable';
166
+ END[0][data_2.PROTOCOL.End.ConfusionSilent] = 'confusion';
167
+ END[0][data_2.PROTOCOL.End.MistSilent] = 'Mist';
168
+ END[0][data_2.PROTOCOL.End.FocusEnergySilent] = 'move: Focus Energy';
169
+ END[0][data_2.PROTOCOL.End.LeechSeedSilent] = 'move: Leech Seed';
170
+ END[0][data_2.PROTOCOL.End.ToxicSilent] = 'Toxic counter';
171
+ END[0][data_2.PROTOCOL.End.LightScreenSilent] = 'Light Screen';
172
+ END[0][data_2.PROTOCOL.End.ReflectSilent] = 'Reflect';
173
+ END[0][data_2.PROTOCOL.End.BideSilent] = 'move: Bide';
174
+ END[1] = END[0].slice(0);
175
+ END[1][data_2.PROTOCOL.End.Disable] = 'move: Disable';
176
+ END[1][data_2.PROTOCOL.End.Bide] = 'move: Bide';
177
+ END[1][data_2.PROTOCOL.End.LeechSeed] = 'Leech Seed';
178
+ const SIDE = new Array(data_2.PROTOCOL.Side.length);
179
+ SIDE[data_2.PROTOCOL.Side.Safeguard] = 'Safeguard';
180
+ SIDE[data_2.PROTOCOL.Side.Reflect] = 'Reflect';
181
+ SIDE[data_2.PROTOCOL.Side.LightScreen] = 'move: Light Screen';
182
+ SIDE[data_2.PROTOCOL.Side.Spikes] = 'Spikes';
163
183
  const DECODERS = new Array(ArgType.length);
164
184
  DECODERS[ArgType.Move] = function (offset, data) {
165
185
  const source = decodeIdent(this.info, data.getUint8(offset++));
166
186
  const m = data.getUint8(offset++);
167
187
  const { player, id } = decodeIdentRaw(data.getUint8(offset++));
188
+ const set = this.info[player].team[id - 1];
168
189
  const target = id === 0
169
- ? '' : `${player}a: ${this.info[player].team[id - 1].name}`;
190
+ ? '' : `${player}a: ${(set.name || set.species)}`;
170
191
  const reason = data.getUint8(offset++);
171
- const move = reason === data_1.PROTOCOL.Move.Recharge
192
+ const move = reason === data_2.PROTOCOL.Move.Recharge
172
193
  ? 'recharge' : this.gen.moves.get(this.lookup.moveByNum(m)).name;
173
194
  const args = ['move', source, move, target];
174
- const kwArgs = reason === data_1.PROTOCOL.Move.From
195
+ const kwArgs = reason === data_2.PROTOCOL.Move.From
175
196
  ? { from: this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name } : {};
176
197
  return { offset, line: { args, kwArgs } };
177
198
  };
178
199
  DECODERS[ArgType.Switch] = function (offset, data) {
179
200
  const ident = decodeIdent(this.info, data.getUint8(offset++));
180
201
  const details = decodeDetails(offset, data, this.gen, this.lookup);
181
- offset += 2;
202
+ offset += this.gen.num > 1 ? 3 : 2;
182
203
  const hpStatus = decodeHPStatus(offset, data);
183
204
  offset += 5;
184
205
  const args = ['switch', ident, details, hpStatus];
@@ -188,7 +209,7 @@ DECODERS[ArgType.Cant] = function (offset, data) {
188
209
  const ident = decodeIdent(this.info, data.getUint8(offset++));
189
210
  const reason = data.getUint8(offset++);
190
211
  let args;
191
- if (reason === data_1.PROTOCOL.Cant.Disable) {
212
+ if (reason === data_2.PROTOCOL.Cant.Disable) {
192
213
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
193
214
  args = ['cant', ident, 'Disable', move];
194
215
  }
@@ -201,7 +222,7 @@ DECODERS[ArgType.Faint] = function (offset, data) {
201
222
  return decodeProtocol('faint', offset, data, this.info);
202
223
  };
203
224
  DECODERS[ArgType.Turn] = function (offset, data) {
204
- const turn = data.getUint16(offset, data_1.LE).toString();
225
+ const turn = data.getUint16(offset, data_2.LE).toString();
205
226
  offset += 2;
206
227
  return { offset, line: { args: ['turn', turn], kwArgs: {} } };
207
228
  };
@@ -220,9 +241,9 @@ DECODERS[ArgType.Damage] = function (offset, data) {
220
241
  offset += 5;
221
242
  const reason = data.getUint8(offset++);
222
243
  const kwArgs = {};
223
- if (reason > data_1.PROTOCOL.Damage.None)
244
+ if (reason > data_2.PROTOCOL.Damage.None)
224
245
  kwArgs.from = DAMAGE[reason];
225
- if (reason === data_1.PROTOCOL.Damage.RecoilOf) {
246
+ if (reason === data_2.PROTOCOL.Damage.RecoilOf) {
226
247
  kwArgs.of = decodeIdent(this.info, data.getUint8(offset++));
227
248
  }
228
249
  const args = ['-damage', ident, hpStatus];
@@ -234,11 +255,11 @@ DECODERS[ArgType.Heal] = function (offset, data) {
234
255
  offset += 5;
235
256
  const reason = data.getUint8(offset++);
236
257
  const kwArgs = {};
237
- if (reason === data_1.PROTOCOL.Heal.Drain) {
258
+ if (reason === data_2.PROTOCOL.Heal.Drain) {
238
259
  kwArgs.from = 'drain';
239
260
  kwArgs.of = decodeIdent(this.info, data.getUint8(offset++));
240
261
  }
241
- else if (reason === data_1.PROTOCOL.Heal.Silent) {
262
+ else if (reason === data_2.PROTOCOL.Heal.Silent) {
242
263
  kwArgs.silent = true;
243
264
  }
244
265
  const args = ['-heal', ident, hpStatus];
@@ -249,10 +270,10 @@ DECODERS[ArgType.Status] = function (offset, data) {
249
270
  const status = decodeStatus(data.getUint8(offset++));
250
271
  const reason = data.getUint8(offset++);
251
272
  const kwArgs = {};
252
- if (reason === data_1.PROTOCOL.CureStatus.Silent) {
273
+ if (reason === data_2.PROTOCOL.Status.Silent) {
253
274
  kwArgs.silent = true;
254
275
  }
255
- else if (reason === data_1.PROTOCOL.Status.From) {
276
+ else if (reason === data_2.PROTOCOL.Status.From) {
256
277
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
257
278
  kwArgs.from = `move: ${move}`;
258
279
  }
@@ -264,10 +285,10 @@ DECODERS[ArgType.CureStatus] = function (offset, data) {
264
285
  const status = decodeStatus(data.getUint8(offset++));
265
286
  const reason = data.getUint8(offset++);
266
287
  const kwArgs = {};
267
- if (reason === data_1.PROTOCOL.CureStatus.Message) {
288
+ if (reason === data_2.PROTOCOL.CureStatus.Message) {
268
289
  kwArgs.msg = true;
269
290
  }
270
- else if (reason === data_1.PROTOCOL.CureStatus.Silent) {
291
+ else if (reason === data_2.PROTOCOL.CureStatus.Silent) {
271
292
  kwArgs.silent = true;
272
293
  }
273
294
  const args = ['-curestatus', ident, status];
@@ -278,7 +299,7 @@ DECODERS[ArgType.Boost] = function (offset, data) {
278
299
  const reason = data.getUint8(offset++);
279
300
  const boost = BOOSTS[reason];
280
301
  const kwArgs = {};
281
- if (reason === data_1.PROTOCOL.Boost.Rage) {
302
+ if (reason === data_2.PROTOCOL.Boost.Rage) {
282
303
  kwArgs.from = 'Rage';
283
304
  }
284
305
  const n = data.getUint8(offset++) - 6;
@@ -297,13 +318,13 @@ DECODERS[ArgType.Fail] = function (offset, data) {
297
318
  const reason = data.getUint8(offset++);
298
319
  let args;
299
320
  const kwArgs = {};
300
- const weak = reason === data_1.PROTOCOL.Fail.Weak;
301
- if (weak || reason === data_1.PROTOCOL.Fail.Substitute) {
321
+ const weak = reason === data_2.PROTOCOL.Fail.Weak;
322
+ if (weak || reason === data_2.PROTOCOL.Fail.Substitute) {
302
323
  args = ['-fail', ident, 'move: Substitute'];
303
324
  if (weak)
304
325
  kwArgs.weak = true;
305
326
  }
306
- else if (reason !== data_1.PROTOCOL.Fail.None) {
327
+ else if (reason !== data_2.PROTOCOL.Fail.None) {
307
328
  args = ['-fail', ident, FAIL[reason]];
308
329
  }
309
330
  else {
@@ -332,11 +353,12 @@ DECODERS[ArgType.MustRecharge] = function (offset, data) {
332
353
  DECODERS[ArgType.Activate] = function (offset, data) {
333
354
  const ident = decodeIdent(this.info, data.getUint8(offset++));
334
355
  const reason = data.getUint8(offset++);
335
- const type = reason === data_1.PROTOCOL.Activate.Mist ? '-block' : '-activate';
336
- const args = reason === data_1.PROTOCOL.Activate.Splash
337
- ? [type, '', ACTIVATE[reason]]
338
- : [type, ident, ACTIVATE[reason], ''];
339
- const kwArgs = reason === data_1.PROTOCOL.Activate.Substitute ? { damage: true } : {};
356
+ const type = reason === data_2.PROTOCOL.Activate.Mist ? '-block' : '-activate';
357
+ const activate = ACTIVATE[this.gen.num - 1];
358
+ const args = reason === data_2.PROTOCOL.Activate.Splash
359
+ ? [type, '', activate[reason]]
360
+ : [type, ident, activate[reason], ''];
361
+ const kwArgs = reason === data_2.PROTOCOL.Activate.Substitute ? { damage: true } : {};
340
362
  return { offset, line: { args, kwArgs } };
341
363
  };
342
364
  DECODERS[ArgType.FieldActivate] = function (offset) {
@@ -349,12 +371,12 @@ DECODERS[ArgType.Start] = function (offset, data) {
349
371
  const reason = data.getUint8(offset++);
350
372
  let args;
351
373
  const kwArgs = {};
352
- if (reason < data_1.PROTOCOL.Start.TypeChange) {
353
- args = ['-start', ident, START[reason]];
354
- if (reason === data_1.PROTOCOL.Start.ConfusionSilent)
374
+ if (reason < data_2.PROTOCOL.Start.TypeChange) {
375
+ args = ['-start', ident, START[this.gen.num - 1][reason]];
376
+ if (reason === data_2.PROTOCOL.Start.ConfusionSilent)
355
377
  kwArgs.silent = true;
356
378
  }
357
- else if (reason === data_1.PROTOCOL.Start.TypeChange) {
379
+ else if (reason === data_2.PROTOCOL.Start.TypeChange) {
358
380
  const types = decodeTypes(this.lookup, data.getUint8(offset++));
359
381
  const t = types[0] === types[1] ? types[0] : types.join('/');
360
382
  args = ['-start', ident, 'typechange', t];
@@ -363,7 +385,7 @@ DECODERS[ArgType.Start] = function (offset, data) {
363
385
  }
364
386
  else {
365
387
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
366
- const effect = reason === data_1.PROTOCOL.Start.Disable ? 'Disable' : 'Mimic';
388
+ const effect = reason === data_2.PROTOCOL.Start.Disable ? 'Disable' : 'Mimic';
367
389
  args = ['-start', ident, effect, move];
368
390
  }
369
391
  return { offset, line: { args, kwArgs } };
@@ -371,8 +393,8 @@ DECODERS[ArgType.Start] = function (offset, data) {
371
393
  DECODERS[ArgType.End] = function (offset, data) {
372
394
  const ident = decodeIdent(this.info, data.getUint8(offset++));
373
395
  const reason = data.getUint8(offset++);
374
- const args = ['-end', ident, END[reason]];
375
- const kwArgs = reason >= data_1.PROTOCOL.End.DisableSilent ? { silent: true } : {};
396
+ const args = ['-end', ident, END[this.gen.num - 1][reason]];
397
+ const kwArgs = reason >= data_2.PROTOCOL.End.DisableSilent ? { silent: true } : {};
376
398
  return { offset, line: { args, kwArgs } };
377
399
  };
378
400
  DECODERS[ArgType.OHKO] = function (offset) {
@@ -390,7 +412,7 @@ DECODERS[ArgType.Resisted] = function (offset, data) {
390
412
  DECODERS[ArgType.Immune] = function (offset, data) {
391
413
  const ident = decodeIdent(this.info, data.getUint8(offset++));
392
414
  const reason = data.getUint8(offset++);
393
- const kwArgs = reason === data_1.PROTOCOL.Immune.OHKO ? { ohko: true } : {};
415
+ const kwArgs = reason === data_2.PROTOCOL.Immune.OHKO ? { ohko: true } : {};
394
416
  return { offset, line: { args: ['-immune', ident], kwArgs } };
395
417
  };
396
418
  DECODERS[ArgType.Transform] = function (offset, data) {
@@ -405,17 +427,21 @@ function decodeProtocol(type, offset, data, info) {
405
427
  }
406
428
  function decodeIdent(info, byte) {
407
429
  const { player, id } = decodeIdentRaw(byte);
408
- return `${player}a: ${info[player].team[id - 1].name}`;
430
+ const set = info[player].team[id - 1];
431
+ return `${player}a: ${(set.name || set.species)}`;
409
432
  }
410
433
  function decodeDetails(offset, data, gen, lookup) {
411
434
  const species = gen.species.get(lookup.speciesByNum(data.getUint8(offset++))).name;
435
+ const gender = gen.num > 1 ? GENDERS[data.getUint8(offset++)] : 'N';
412
436
  const level = data.getUint8(offset);
413
- return (level === 100 ? species : `${species}, L${level}`);
437
+ const mf = gender === 'N' ? '' : `, ${gender}`;
438
+ const lvl = level === 100 ? '' : `, L${level}`;
439
+ return `${species}${mf}${lvl}`;
414
440
  }
415
441
  function decodeHPStatus(offset, data) {
416
- const hp = data.getUint16(offset, data_1.LE);
442
+ const hp = data.getUint16(offset, data_2.LE);
417
443
  offset += 2;
418
- const maxhp = data.getUint16(offset, data_1.LE);
444
+ const maxhp = data.getUint16(offset, data_2.LE);
419
445
  offset += 2;
420
446
  if (hp === 0)
421
447
  return '0 fnt';
@@ -428,7 +454,6 @@ function decodeIdentRaw(byte) {
428
454
  id: byte & 0b111,
429
455
  };
430
456
  }
431
- exports.decodeIdentRaw = decodeIdentRaw;
432
457
  function decodeStatus(val) {
433
458
  if (val & 0b111)
434
459
  return 'slp';
@@ -444,9 +469,7 @@ function decodeStatus(val) {
444
469
  return 'psn';
445
470
  return undefined;
446
471
  }
447
- exports.decodeStatus = decodeStatus;
448
472
  function decodeTypes(lookup, val) {
449
473
  return [lookup.typeByNum(val & 0x0F), lookup.typeByNum(val >> 4)];
450
474
  }
451
- exports.decodeTypes = decodeTypes;
452
475
  //# sourceMappingURL=protocol.js.map