@pkmn/engine 0.1.0-dev.d716e940 → 0.1.0-dev.d952b7c9

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 (79) hide show
  1. package/LICENSE +1 -3
  2. package/README.md +97 -59
  3. package/build/pkg/addon/browser.d.ts +3 -0
  4. package/build/pkg/addon/browser.js +43 -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 +96 -0
  8. package/build/pkg/addon/node.js.map +1 -0
  9. package/build/pkg/addon.d.ts +2 -0
  10. package/build/pkg/addon.js +35 -57
  11. package/build/pkg/addon.js.map +1 -1
  12. package/build/pkg/data/ids.json +12 -12
  13. package/build/pkg/data/layout.json +26 -4
  14. package/build/pkg/data/protocol.json +69 -12
  15. package/build/pkg/data.d.ts +27 -5
  16. package/build/pkg/data.js.map +1 -1
  17. package/build/pkg/gen1.js +16 -19
  18. package/build/pkg/gen1.js.map +1 -1
  19. package/build/pkg/index.d.ts +24 -10
  20. package/build/pkg/index.js +15 -10
  21. package/build/pkg/index.js.map +1 -1
  22. package/build/pkg/protocol.d.ts +20 -1
  23. package/build/pkg/protocol.js +123 -102
  24. package/build/pkg/protocol.js.map +1 -1
  25. package/build/tools/debug.js +36 -68
  26. package/build/tools/debug.js.map +1 -1
  27. package/build/tools/display/debug.jsx +128 -0
  28. package/build/tools/display/debug.jsx.map +1 -0
  29. package/build/tools/display/index.js +132 -0
  30. package/build/tools/display/index.js.map +1 -0
  31. package/build/tools/display/ui.jsx +349 -0
  32. package/build/tools/display/ui.jsx.map +1 -0
  33. package/build/tools/display/util.js +18 -0
  34. package/build/tools/display/util.js.map +1 -0
  35. package/build.zig +286 -131
  36. package/package.json +73 -31
  37. package/src/bin/install-pkmn-engine +39 -24
  38. package/src/bin/pkmn-debug +1 -1
  39. package/src/lib/common/array.zig +77 -0
  40. package/src/lib/common/battle.zig +17 -0
  41. package/src/lib/common/data.zig +19 -31
  42. package/src/lib/common/debug.zig +30 -16
  43. package/src/lib/common/js.zig +120 -0
  44. package/src/lib/common/optional.zig +71 -0
  45. package/src/lib/common/options.zig +13 -0
  46. package/src/lib/common/protocol.zig +911 -367
  47. package/src/lib/common/rational.zig +447 -0
  48. package/src/lib/common/rng.zig +31 -22
  49. package/src/lib/common/util.zig +61 -0
  50. package/src/lib/gen1/calc.zig +950 -0
  51. package/src/lib/gen1/chance.zig +1169 -0
  52. package/src/lib/gen1/data/moves.zig +202 -190
  53. package/src/lib/gen1/data/species.zig +5 -5
  54. package/src/lib/gen1/data/types.zig +10 -10
  55. package/src/lib/gen1/data.zig +92 -79
  56. package/src/lib/gen1/helpers.zig +141 -28
  57. package/src/lib/gen1/mechanics.zig +1118 -773
  58. package/src/lib/gen2/calc.zig +161 -0
  59. package/src/lib/gen2/chance.zig +902 -0
  60. package/src/lib/gen2/data/items.zig +14 -20
  61. package/src/lib/gen2/data/moves.zig +664 -570
  62. package/src/lib/gen2/data/species.zig +2 -2
  63. package/src/lib/gen2/data/types.zig +137 -34
  64. package/src/lib/gen2/data.zig +125 -86
  65. package/src/lib/gen2/generated.zig +806 -0
  66. package/src/lib/gen2/helpers.zig +54 -32
  67. package/src/lib/gen2/mechanics.zig +3564 -15
  68. package/src/lib/node.zig +131 -0
  69. package/src/lib/pkmn.zig +81 -5
  70. package/src/lib/wasm.zig +13 -0
  71. package/src/tools/display/dom.ts +96 -0
  72. package/src/tools/display/ui.css +351 -0
  73. package/build/test/display.js +0 -400
  74. package/build/test/display.js.map +0 -1
  75. package/src/lib/binding/node.zig +0 -229
  76. package/src/lib/binding/wasm.zig +0 -10
  77. package/src/lib/gen1/README.md +0 -812
  78. package/src/lib/gen2/README.md +0 -309
  79. package/src/test/display/pkmn.html.tmpl +0 -368
@@ -242,6 +242,8 @@ export type CreateOptions = {
242
242
  * that the engine be built in a specific compatibility mode).
243
243
  */
244
244
  showdown?: boolean;
245
+ /** Whether the battle should be initialized without functionality afforded by native code. */
246
+ inert?: true;
245
247
  } & ({
246
248
  /** Player 1's options. */
247
249
  p1: PlayerOptions;
@@ -344,16 +346,18 @@ export declare const Battle: {
344
346
  * Restore a (possibly in-progress) `Battle` in the given generation with the
345
347
  * provided options.
346
348
  */
347
- restore(gen: Generation, battle: Battle, options: RestoreOptions): Battle;
349
+ restore(gen: Generation, battle: Data<Battle>, options: RestoreOptions): Battle;
348
350
  };
349
351
  /** Utilities for working with `Choice` objects. */
350
352
  export declare class Choice {
351
- /** All valid choices types. */
352
- static Types: readonly ["pass", "move", "switch"];
353
- protected static PASS: {
354
- readonly type: "pass";
355
- readonly data: 0;
353
+ /** Encoded values of the various choice types. */
354
+ static Encoding: {
355
+ readonly pass: 0;
356
+ readonly move: 1;
357
+ readonly switch: 2;
356
358
  };
359
+ /** All valid choices types. */
360
+ static Types: readonly Choice["type"][];
357
361
  protected static MATCH: RegExp;
358
362
  private constructor();
359
363
  /** Decode a choice from its binary representation. */
@@ -367,20 +371,30 @@ export declare class Choice {
367
371
  static parse(choice: string): Choice;
368
372
  /** Formats a `Choice` into a Pokémon Showdown compatible choice string. */
369
373
  static format(choice: Choice): string;
370
- /** Returns the "pass" `Choice`. */
371
- static pass(): Choice;
374
+ /** The canonical "pass" `Choice`. */
375
+ static pass: Choice;
372
376
  /** Returns a "move" `Choice` with the provided data. */
373
377
  static move(data: 0 | 1 | 2 | 3 | 4): Choice;
374
378
  /** Returns a "switch" `Choice` with the provided data. */
375
379
  static switch(data: 2 | 3 | 4 | 5 | 6): Choice;
376
380
  }
377
- /** Utilities for working with `Result` objects */
381
+ /** Utilities for working with `Result` objects. */
378
382
  export declare class Result {
383
+ /** Encoded values of non-empty various result types. */
384
+ static Encoding: {
385
+ readonly win: 1;
386
+ readonly lose: 2;
387
+ readonly tie: 3;
388
+ readonly error: 4;
389
+ };
379
390
  /** All valid result types. */
380
391
  static Types: readonly [undefined, "win", "lose", "tie", "error"];
381
392
  private constructor();
382
393
  /** Decode a `Result` from its binary representation. */
383
394
  static decode(byte: number): Result;
395
+ /** Encode a `Result`` to its binary representation. */
396
+ static encode(result: Result): number;
384
397
  }
385
- export { ParsedLine, Info, SideInfo, PokemonInfo, Log } from './protocol';
398
+ export type { ParsedLine, PokemonInfo } from './protocol';
399
+ export { Info, SideInfo, Log } from './protocol';
386
400
  export { Lookup } from './data';
@@ -53,9 +53,10 @@ exports.Battle = new class {
53
53
  };
54
54
  /** Utilities for working with `Choice` objects. */
55
55
  class Choice {
56
+ /** Encoded values of the various choice types. */
57
+ static Encoding = { pass: 0, move: 1, switch: 2 };
56
58
  /** All valid choices types. */
57
- static Types = ['pass', 'move', 'switch'];
58
- static PASS = { type: 'pass', data: 0 };
59
+ static Types = Object.keys(Choice.Encoding);
59
60
  static MATCH = /^(?:(pass)|((move) ([0-4]))|((switch) ([2-6])))$/;
60
61
  constructor() { }
61
62
  /** Decode a choice from its binary representation. */
@@ -64,9 +65,7 @@ class Choice {
64
65
  }
65
66
  /** Encode a choice to its binary representation. */
66
67
  static encode(choice) {
67
- return (choice
68
- ? (choice.data << 2 | (choice.type === 'pass' ? 0 : choice.type === 'move' ? 1 : 2))
69
- : 0);
68
+ return (choice ? (choice.data << 2 | Choice.Encoding[choice.type]) : 0);
70
69
  }
71
70
  /**
72
71
  * Parse a Pokémon Showdown choice string into a `Choice`.
@@ -84,10 +83,8 @@ class Choice {
84
83
  static format(choice) {
85
84
  return choice.type === 'pass' ? choice.type : `${choice.type} ${choice.data}`;
86
85
  }
87
- /** Returns the "pass" `Choice`. */
88
- static pass() {
89
- return Choice.PASS;
90
- }
86
+ /** The canonical "pass" `Choice`. */
87
+ static pass = { type: 'pass', data: 0 };
91
88
  /** Returns a "move" `Choice` with the provided data. */
92
89
  static move(data) {
93
90
  return { type: 'move', data };
@@ -98,8 +95,10 @@ class Choice {
98
95
  }
99
96
  }
100
97
  exports.Choice = Choice;
101
- /** Utilities for working with `Result` objects */
98
+ /** Utilities for working with `Result` objects. */
102
99
  class Result {
100
+ /** Encoded values of non-empty various result types. */
101
+ static Encoding = { win: 1, lose: 2, tie: 3, error: 4 };
103
102
  /** All valid result types. */
104
103
  static Types = [undefined, 'win', 'lose', 'tie', 'error'];
105
104
  constructor() { }
@@ -111,6 +110,12 @@ class Result {
111
110
  p2: Choice.Types[byte >> 6],
112
111
  };
113
112
  }
113
+ /** Encode a `Result`` to its binary representation. */
114
+ static encode(result) {
115
+ return ((result.type ? Result.Encoding[result.type] : 0) |
116
+ Choice.Encoding[result.p1] << 4 |
117
+ Choice.Encoding[result.p2] << 6);
118
+ }
114
119
  }
115
120
  exports.Result = Result;
116
121
  var protocol_1 = require("./protocol");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pkg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,+CAAiC;AACjC,iCAA8B;AAC9B,6CAA+B;AAiW/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,KAAK,CAAC,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;SACtD;IACH,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,GAAe,EAAE,MAAc,EAAE,OAAuB;QAC9D,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,aAA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AM,EAAE,KAAK,EAAE,OAAO,CAAU,CAAC;IAEnE,gBAAuB,CAAC;IAExB,wDAAwD;IACxD,MAAM,CAAC,MAAM,CAAC,IAAY;QACxB,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC;YACjC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;YACpC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC;SAC5B,CAAC;IACJ,CAAC;IAED,uDAAuD;IACvD,MAAM,CAAC,MAAM,CAAC,MAAc;QAC1B,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACpD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;YAC/B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC;;AAtBH,wBAuBC;AAGD,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. */
@@ -71,3 +89,4 @@ export declare function decodeIdentRaw(byte: number): {
71
89
  };
72
90
  export declare function decodeStatus(val: number): StatusName | undefined;
73
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,67 +104,82 @@ 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++));
@@ -169,17 +189,17 @@ DECODERS[ArgType.Move] = function (offset, data) {
169
189
  const target = id === 0
170
190
  ? '' : `${player}a: ${(set.name || set.species)}`;
171
191
  const reason = data.getUint8(offset++);
172
- const move = reason === data_1.PROTOCOL.Move.Recharge
192
+ const move = reason === data_2.PROTOCOL.Move.Recharge
173
193
  ? 'recharge' : this.gen.moves.get(this.lookup.moveByNum(m)).name;
174
194
  const args = ['move', source, move, target];
175
- const kwArgs = reason === data_1.PROTOCOL.Move.From
195
+ const kwArgs = reason === data_2.PROTOCOL.Move.From
176
196
  ? { from: this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name } : {};
177
197
  return { offset, line: { args, kwArgs } };
178
198
  };
179
199
  DECODERS[ArgType.Switch] = function (offset, data) {
180
200
  const ident = decodeIdent(this.info, data.getUint8(offset++));
181
201
  const details = decodeDetails(offset, data, this.gen, this.lookup);
182
- offset += 2;
202
+ offset += this.gen.num > 1 ? 3 : 2;
183
203
  const hpStatus = decodeHPStatus(offset, data);
184
204
  offset += 5;
185
205
  const args = ['switch', ident, details, hpStatus];
@@ -189,7 +209,7 @@ DECODERS[ArgType.Cant] = function (offset, data) {
189
209
  const ident = decodeIdent(this.info, data.getUint8(offset++));
190
210
  const reason = data.getUint8(offset++);
191
211
  let args;
192
- if (reason === data_1.PROTOCOL.Cant.Disable) {
212
+ if (reason === data_2.PROTOCOL.Cant.Disable) {
193
213
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
194
214
  args = ['cant', ident, 'Disable', move];
195
215
  }
@@ -202,7 +222,7 @@ DECODERS[ArgType.Faint] = function (offset, data) {
202
222
  return decodeProtocol('faint', offset, data, this.info);
203
223
  };
204
224
  DECODERS[ArgType.Turn] = function (offset, data) {
205
- const turn = data.getUint16(offset, data_1.LE).toString();
225
+ const turn = data.getUint16(offset, data_2.LE).toString();
206
226
  offset += 2;
207
227
  return { offset, line: { args: ['turn', turn], kwArgs: {} } };
208
228
  };
@@ -221,9 +241,9 @@ DECODERS[ArgType.Damage] = function (offset, data) {
221
241
  offset += 5;
222
242
  const reason = data.getUint8(offset++);
223
243
  const kwArgs = {};
224
- if (reason > data_1.PROTOCOL.Damage.None)
244
+ if (reason > data_2.PROTOCOL.Damage.None)
225
245
  kwArgs.from = DAMAGE[reason];
226
- if (reason === data_1.PROTOCOL.Damage.RecoilOf) {
246
+ if (reason === data_2.PROTOCOL.Damage.RecoilOf) {
227
247
  kwArgs.of = decodeIdent(this.info, data.getUint8(offset++));
228
248
  }
229
249
  const args = ['-damage', ident, hpStatus];
@@ -235,11 +255,11 @@ DECODERS[ArgType.Heal] = function (offset, data) {
235
255
  offset += 5;
236
256
  const reason = data.getUint8(offset++);
237
257
  const kwArgs = {};
238
- if (reason === data_1.PROTOCOL.Heal.Drain) {
258
+ if (reason === data_2.PROTOCOL.Heal.Drain) {
239
259
  kwArgs.from = 'drain';
240
260
  kwArgs.of = decodeIdent(this.info, data.getUint8(offset++));
241
261
  }
242
- else if (reason === data_1.PROTOCOL.Heal.Silent) {
262
+ else if (reason === data_2.PROTOCOL.Heal.Silent) {
243
263
  kwArgs.silent = true;
244
264
  }
245
265
  const args = ['-heal', ident, hpStatus];
@@ -250,10 +270,10 @@ DECODERS[ArgType.Status] = function (offset, data) {
250
270
  const status = decodeStatus(data.getUint8(offset++));
251
271
  const reason = data.getUint8(offset++);
252
272
  const kwArgs = {};
253
- if (reason === data_1.PROTOCOL.CureStatus.Silent) {
273
+ if (reason === data_2.PROTOCOL.Status.Silent) {
254
274
  kwArgs.silent = true;
255
275
  }
256
- else if (reason === data_1.PROTOCOL.Status.From) {
276
+ else if (reason === data_2.PROTOCOL.Status.From) {
257
277
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
258
278
  kwArgs.from = `move: ${move}`;
259
279
  }
@@ -265,10 +285,10 @@ DECODERS[ArgType.CureStatus] = function (offset, data) {
265
285
  const status = decodeStatus(data.getUint8(offset++));
266
286
  const reason = data.getUint8(offset++);
267
287
  const kwArgs = {};
268
- if (reason === data_1.PROTOCOL.CureStatus.Message) {
288
+ if (reason === data_2.PROTOCOL.CureStatus.Message) {
269
289
  kwArgs.msg = true;
270
290
  }
271
- else if (reason === data_1.PROTOCOL.CureStatus.Silent) {
291
+ else if (reason === data_2.PROTOCOL.CureStatus.Silent) {
272
292
  kwArgs.silent = true;
273
293
  }
274
294
  const args = ['-curestatus', ident, status];
@@ -279,7 +299,7 @@ DECODERS[ArgType.Boost] = function (offset, data) {
279
299
  const reason = data.getUint8(offset++);
280
300
  const boost = BOOSTS[reason];
281
301
  const kwArgs = {};
282
- if (reason === data_1.PROTOCOL.Boost.Rage) {
302
+ if (reason === data_2.PROTOCOL.Boost.Rage) {
283
303
  kwArgs.from = 'Rage';
284
304
  }
285
305
  const n = data.getUint8(offset++) - 6;
@@ -298,13 +318,13 @@ DECODERS[ArgType.Fail] = function (offset, data) {
298
318
  const reason = data.getUint8(offset++);
299
319
  let args;
300
320
  const kwArgs = {};
301
- const weak = reason === data_1.PROTOCOL.Fail.Weak;
302
- 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) {
303
323
  args = ['-fail', ident, 'move: Substitute'];
304
324
  if (weak)
305
325
  kwArgs.weak = true;
306
326
  }
307
- else if (reason !== data_1.PROTOCOL.Fail.None) {
327
+ else if (reason !== data_2.PROTOCOL.Fail.None) {
308
328
  args = ['-fail', ident, FAIL[reason]];
309
329
  }
310
330
  else {
@@ -333,11 +353,12 @@ DECODERS[ArgType.MustRecharge] = function (offset, data) {
333
353
  DECODERS[ArgType.Activate] = function (offset, data) {
334
354
  const ident = decodeIdent(this.info, data.getUint8(offset++));
335
355
  const reason = data.getUint8(offset++);
336
- const type = reason === data_1.PROTOCOL.Activate.Mist ? '-block' : '-activate';
337
- const args = reason === data_1.PROTOCOL.Activate.Splash
338
- ? [type, '', ACTIVATE[reason]]
339
- : [type, ident, ACTIVATE[reason], ''];
340
- 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 } : {};
341
362
  return { offset, line: { args, kwArgs } };
342
363
  };
343
364
  DECODERS[ArgType.FieldActivate] = function (offset) {
@@ -350,12 +371,12 @@ DECODERS[ArgType.Start] = function (offset, data) {
350
371
  const reason = data.getUint8(offset++);
351
372
  let args;
352
373
  const kwArgs = {};
353
- if (reason < data_1.PROTOCOL.Start.TypeChange) {
354
- args = ['-start', ident, START[reason]];
355
- 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)
356
377
  kwArgs.silent = true;
357
378
  }
358
- else if (reason === data_1.PROTOCOL.Start.TypeChange) {
379
+ else if (reason === data_2.PROTOCOL.Start.TypeChange) {
359
380
  const types = decodeTypes(this.lookup, data.getUint8(offset++));
360
381
  const t = types[0] === types[1] ? types[0] : types.join('/');
361
382
  args = ['-start', ident, 'typechange', t];
@@ -364,7 +385,7 @@ DECODERS[ArgType.Start] = function (offset, data) {
364
385
  }
365
386
  else {
366
387
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
367
- const effect = reason === data_1.PROTOCOL.Start.Disable ? 'Disable' : 'Mimic';
388
+ const effect = reason === data_2.PROTOCOL.Start.Disable ? 'Disable' : 'Mimic';
368
389
  args = ['-start', ident, effect, move];
369
390
  }
370
391
  return { offset, line: { args, kwArgs } };
@@ -372,8 +393,8 @@ DECODERS[ArgType.Start] = function (offset, data) {
372
393
  DECODERS[ArgType.End] = function (offset, data) {
373
394
  const ident = decodeIdent(this.info, data.getUint8(offset++));
374
395
  const reason = data.getUint8(offset++);
375
- const args = ['-end', ident, END[reason]];
376
- 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 } : {};
377
398
  return { offset, line: { args, kwArgs } };
378
399
  };
379
400
  DECODERS[ArgType.OHKO] = function (offset) {
@@ -391,7 +412,7 @@ DECODERS[ArgType.Resisted] = function (offset, data) {
391
412
  DECODERS[ArgType.Immune] = function (offset, data) {
392
413
  const ident = decodeIdent(this.info, data.getUint8(offset++));
393
414
  const reason = data.getUint8(offset++);
394
- const kwArgs = reason === data_1.PROTOCOL.Immune.OHKO ? { ohko: true } : {};
415
+ const kwArgs = reason === data_2.PROTOCOL.Immune.OHKO ? { ohko: true } : {};
395
416
  return { offset, line: { args: ['-immune', ident], kwArgs } };
396
417
  };
397
418
  DECODERS[ArgType.Transform] = function (offset, data) {
@@ -411,13 +432,16 @@ function decodeIdent(info, byte) {
411
432
  }
412
433
  function decodeDetails(offset, data, gen, lookup) {
413
434
  const species = gen.species.get(lookup.speciesByNum(data.getUint8(offset++))).name;
435
+ const gender = gen.num > 1 ? GENDERS[data.getUint8(offset++)] : 'N';
414
436
  const level = data.getUint8(offset);
415
- 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}`;
416
440
  }
417
441
  function decodeHPStatus(offset, data) {
418
- const hp = data.getUint16(offset, data_1.LE);
442
+ const hp = data.getUint16(offset, data_2.LE);
419
443
  offset += 2;
420
- const maxhp = data.getUint16(offset, data_1.LE);
444
+ const maxhp = data.getUint16(offset, data_2.LE);
421
445
  offset += 2;
422
446
  if (hp === 0)
423
447
  return '0 fnt';
@@ -430,7 +454,6 @@ function decodeIdentRaw(byte) {
430
454
  id: byte & 0b111,
431
455
  };
432
456
  }
433
- exports.decodeIdentRaw = decodeIdentRaw;
434
457
  function decodeStatus(val) {
435
458
  if (val & 0b111)
436
459
  return 'slp';
@@ -446,9 +469,7 @@ function decodeStatus(val) {
446
469
  return 'psn';
447
470
  return undefined;
448
471
  }
449
- exports.decodeStatus = decodeStatus;
450
472
  function decodeTypes(lookup, val) {
451
473
  return [lookup.typeByNum(val & 0x0F), lookup.typeByNum(val >> 4)];
452
474
  }
453
- exports.decodeTypes = decodeTypes;
454
475
  //# sourceMappingURL=protocol.js.map