@pkmn/engine 0.1.0-dev.32adfe77 → 0.1.0-dev.3393edb3

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 (62) hide show
  1. package/README.md +15 -11
  2. package/build/pkg/addon/browser.d.ts +3 -0
  3. package/build/pkg/addon/browser.js +43 -0
  4. package/build/pkg/addon/browser.js.map +1 -0
  5. package/build/pkg/addon/node.d.ts +3 -0
  6. package/build/pkg/addon/node.js +96 -0
  7. package/build/pkg/addon/node.js.map +1 -0
  8. package/build/pkg/addon.d.ts +2 -0
  9. package/build/pkg/addon.js +35 -58
  10. package/build/pkg/addon.js.map +1 -1
  11. package/build/pkg/data.d.ts +25 -4
  12. package/build/pkg/data.js.map +1 -1
  13. package/build/pkg/gen1.js +1 -1
  14. package/build/pkg/gen1.js.map +1 -1
  15. package/build/pkg/index.d.ts +22 -9
  16. package/build/pkg/index.js +15 -10
  17. package/build/pkg/index.js.map +1 -1
  18. package/build/pkg/protocol.d.ts +20 -1
  19. package/build/pkg/protocol.js +109 -107
  20. package/build/pkg/protocol.js.map +1 -1
  21. package/build/tools/debug.js +36 -70
  22. package/build/tools/debug.js.map +1 -1
  23. package/build/tools/display/debug.jsx +141 -0
  24. package/build/tools/display/debug.jsx.map +1 -0
  25. package/build/tools/display/index.js +132 -0
  26. package/build/tools/display/index.js.map +1 -0
  27. package/build/tools/display/ui.jsx +349 -0
  28. package/build/tools/display/ui.jsx.map +1 -0
  29. package/build/tools/display/util.js +18 -0
  30. package/build/tools/display/util.js.map +1 -0
  31. package/build.zig +186 -65
  32. package/package.json +46 -29
  33. package/src/bin/install-pkmn-engine +17 -7
  34. package/src/bin/pkmn-debug +1 -1
  35. package/src/lib/common/array.zig +77 -0
  36. package/src/lib/common/data.zig +8 -8
  37. package/src/lib/common/debug.zig +32 -6
  38. package/src/lib/common/js.zig +4 -2
  39. package/src/lib/common/optional.zig +13 -9
  40. package/src/lib/common/options.zig +4 -0
  41. package/src/lib/common/protocol.zig +46 -36
  42. package/src/lib/common/rational.zig +114 -24
  43. package/src/lib/common/rng.zig +4 -4
  44. package/src/lib/common/util.zig +50 -1
  45. package/src/lib/gen1/calc.zig +663 -130
  46. package/src/lib/gen1/chance.zig +384 -275
  47. package/src/lib/gen1/data.zig +31 -30
  48. package/src/lib/gen1/helpers.zig +89 -538
  49. package/src/lib/gen1/mechanics.zig +275 -197
  50. package/src/lib/gen2/calc.zig +34 -16
  51. package/src/lib/gen2/chance.zig +90 -502
  52. package/src/lib/gen2/data.zig +15 -14
  53. package/src/lib/gen2/helpers.zig +41 -13
  54. package/src/lib/gen2/mechanics.zig +158 -103
  55. package/src/lib/pkmn.zig +10 -16
  56. package/src/tools/display/dom.ts +96 -0
  57. package/src/tools/display/ui.css +351 -0
  58. package/build/test/display.js +0 -400
  59. package/build/test/display.js.map +0 -1
  60. package/src/lib/gen1/README.md +0 -894
  61. package/src/lib/gen2/README.md +0 -329
  62. 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,29 @@ 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
398
  export type { ParsedLine, PokemonInfo } from './protocol';
386
399
  export { Info, SideInfo, Log } from './protocol';
@@ -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,6CA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AAC,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 };
@@ -100,81 +105,81 @@ class Log {
100
105
  }
101
106
  exports.Log = Log;
102
107
  const GENDERS = ['M', 'F', 'N'];
103
- const CANT = new Array(data_1.PROTOCOL.Cant.length);
104
- CANT[data_1.PROTOCOL.Cant.Sleep] = 'slp';
105
- CANT[data_1.PROTOCOL.Cant.Freeze] = 'frz';
106
- CANT[data_1.PROTOCOL.Cant.Paralysis] = 'par';
107
- CANT[data_1.PROTOCOL.Cant.Bound] = 'partiallytrapped';
108
- CANT[data_1.PROTOCOL.Cant.Flinch] = 'flinch';
109
- CANT[data_1.PROTOCOL.Cant.Recharge] = 'recharge';
110
- CANT[data_1.PROTOCOL.Cant.PP] = 'nopp';
111
- const DAMAGE = new Array(data_1.PROTOCOL.Damage.length);
112
- DAMAGE[data_1.PROTOCOL.Damage.Poison] = 'psn';
113
- DAMAGE[data_1.PROTOCOL.Damage.Burn] = 'brn';
114
- DAMAGE[data_1.PROTOCOL.Damage.Confusion] = 'confusion';
115
- DAMAGE[data_1.PROTOCOL.Damage.LeechSeed] = 'Leech Seed';
116
- DAMAGE[data_1.PROTOCOL.Damage.RecoilOf] = 'Recoil';
117
- const BOOSTS = new Array(data_1.PROTOCOL.Boost.length);
118
- BOOSTS[data_1.PROTOCOL.Boost.Rage] = 'atk';
119
- BOOSTS[data_1.PROTOCOL.Boost.Attack] = 'atk';
120
- BOOSTS[data_1.PROTOCOL.Boost.Defense] = 'def';
121
- BOOSTS[data_1.PROTOCOL.Boost.Speed] = 'spe';
122
- BOOSTS[data_1.PROTOCOL.Boost.SpecialAttack] = 'spa';
123
- BOOSTS[data_1.PROTOCOL.Boost.SpecialDefense] = 'spd';
124
- BOOSTS[data_1.PROTOCOL.Boost.Accuracy] = 'accuracy';
125
- BOOSTS[data_1.PROTOCOL.Boost.Evasion] = 'evasion';
126
- const FAIL = new Array(data_1.PROTOCOL.Fail.length);
127
- FAIL[data_1.PROTOCOL.Fail.Sleep] = 'slp';
128
- FAIL[data_1.PROTOCOL.Fail.Poison] = 'psn';
129
- FAIL[data_1.PROTOCOL.Fail.Burn] = 'brn';
130
- FAIL[data_1.PROTOCOL.Fail.Freeze] = 'frz';
131
- FAIL[data_1.PROTOCOL.Fail.Paralysis] = 'par';
132
- FAIL[data_1.PROTOCOL.Fail.Toxic] = 'tox';
133
- const ACTIVATE = [new Array(data_1.PROTOCOL.Activate.length)];
134
- ACTIVATE[0][data_1.PROTOCOL.Activate.Bide] = 'Bide';
135
- ACTIVATE[0][data_1.PROTOCOL.Activate.Confusion] = 'confusion';
136
- ACTIVATE[0][data_1.PROTOCOL.Activate.Haze] = 'move: Haze';
137
- ACTIVATE[0][data_1.PROTOCOL.Activate.Mist] = 'move: Mist';
138
- ACTIVATE[0][data_1.PROTOCOL.Activate.Struggle] = 'move: Struggle';
139
- ACTIVATE[0][data_1.PROTOCOL.Activate.Substitute] = 'Substitute';
140
- ACTIVATE[0][data_1.PROTOCOL.Activate.Splash] = 'move: Splash';
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';
141
146
  ACTIVATE[1] = ACTIVATE[0].slice(0);
142
- ACTIVATE[1][data_1.PROTOCOL.Activate.Bide] = 'move: Bide';
143
- const START = [new Array(data_1.PROTOCOL.Start.length)];
144
- START[0][data_1.PROTOCOL.Start.Bide] = 'Bide';
145
- START[0][data_1.PROTOCOL.Start.Confusion] = 'confusion';
146
- START[0][data_1.PROTOCOL.Start.ConfusionSilent] = 'confusion';
147
- START[0][data_1.PROTOCOL.Start.FocusEnergy] = 'move: Focus Energy';
148
- START[0][data_1.PROTOCOL.Start.LeechSeed] = 'move: Leech Seed';
149
- START[0][data_1.PROTOCOL.Start.LightScreen] = 'Light Screen';
150
- START[0][data_1.PROTOCOL.Start.Mist] = 'Mist';
151
- START[0][data_1.PROTOCOL.Start.Reflect] = 'Reflect';
152
- START[0][data_1.PROTOCOL.Start.Substitute] = 'Substitute';
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';
153
158
  START[1] = START[0].slice(0);
154
- START[1][data_1.PROTOCOL.Start.Bide] = 'move: Bide';
155
- const END = [new Array(data_1.PROTOCOL.End.length)];
156
- END[0][data_1.PROTOCOL.End.Disable] = 'Disable';
157
- END[0][data_1.PROTOCOL.End.Confusion] = 'confusion';
158
- END[0][data_1.PROTOCOL.End.Bide] = 'Bide';
159
- END[0][data_1.PROTOCOL.End.Substitute] = 'Substitute';
160
- END[0][data_1.PROTOCOL.End.DisableSilent] = 'Disable';
161
- END[0][data_1.PROTOCOL.End.ConfusionSilent] = 'confusion';
162
- END[0][data_1.PROTOCOL.End.MistSilent] = 'Mist';
163
- END[0][data_1.PROTOCOL.End.FocusEnergySilent] = 'move: Focus Energy';
164
- END[0][data_1.PROTOCOL.End.LeechSeedSilent] = 'move: Leech Seed';
165
- END[0][data_1.PROTOCOL.End.ToxicSilent] = 'Toxic counter';
166
- END[0][data_1.PROTOCOL.End.LightScreenSilent] = 'Light Screen';
167
- END[0][data_1.PROTOCOL.End.ReflectSilent] = 'Reflect';
168
- END[0][data_1.PROTOCOL.End.BideSilent] = 'move: Bide';
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';
169
174
  END[1] = END[0].slice(0);
170
- END[1][data_1.PROTOCOL.End.Disable] = 'move: Disable';
171
- END[1][data_1.PROTOCOL.End.Bide] = 'move: Bide';
172
- END[1][data_1.PROTOCOL.End.LeechSeed] = 'Leech Seed';
173
- const SIDE = new Array(data_1.PROTOCOL.Side.length);
174
- SIDE[data_1.PROTOCOL.Side.Safeguard] = 'Safeguard';
175
- SIDE[data_1.PROTOCOL.Side.Reflect] = 'Reflect';
176
- SIDE[data_1.PROTOCOL.Side.LightScreen] = 'move: Light Screen';
177
- SIDE[data_1.PROTOCOL.Side.Spikes] = 'Spikes';
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';
178
183
  const DECODERS = new Array(ArgType.length);
179
184
  DECODERS[ArgType.Move] = function (offset, data) {
180
185
  const source = decodeIdent(this.info, data.getUint8(offset++));
@@ -184,10 +189,10 @@ DECODERS[ArgType.Move] = function (offset, data) {
184
189
  const target = id === 0
185
190
  ? '' : `${player}a: ${(set.name || set.species)}`;
186
191
  const reason = data.getUint8(offset++);
187
- const move = reason === data_1.PROTOCOL.Move.Recharge
192
+ const move = reason === data_2.PROTOCOL.Move.Recharge
188
193
  ? 'recharge' : this.gen.moves.get(this.lookup.moveByNum(m)).name;
189
194
  const args = ['move', source, move, target];
190
- const kwArgs = reason === data_1.PROTOCOL.Move.From
195
+ const kwArgs = reason === data_2.PROTOCOL.Move.From
191
196
  ? { from: this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name } : {};
192
197
  return { offset, line: { args, kwArgs } };
193
198
  };
@@ -204,7 +209,7 @@ DECODERS[ArgType.Cant] = function (offset, data) {
204
209
  const ident = decodeIdent(this.info, data.getUint8(offset++));
205
210
  const reason = data.getUint8(offset++);
206
211
  let args;
207
- if (reason === data_1.PROTOCOL.Cant.Disable) {
212
+ if (reason === data_2.PROTOCOL.Cant.Disable) {
208
213
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
209
214
  args = ['cant', ident, 'Disable', move];
210
215
  }
@@ -217,7 +222,7 @@ DECODERS[ArgType.Faint] = function (offset, data) {
217
222
  return decodeProtocol('faint', offset, data, this.info);
218
223
  };
219
224
  DECODERS[ArgType.Turn] = function (offset, data) {
220
- const turn = data.getUint16(offset, data_1.LE).toString();
225
+ const turn = data.getUint16(offset, data_2.LE).toString();
221
226
  offset += 2;
222
227
  return { offset, line: { args: ['turn', turn], kwArgs: {} } };
223
228
  };
@@ -236,9 +241,9 @@ DECODERS[ArgType.Damage] = function (offset, data) {
236
241
  offset += 5;
237
242
  const reason = data.getUint8(offset++);
238
243
  const kwArgs = {};
239
- if (reason > data_1.PROTOCOL.Damage.None)
244
+ if (reason > data_2.PROTOCOL.Damage.None)
240
245
  kwArgs.from = DAMAGE[reason];
241
- if (reason === data_1.PROTOCOL.Damage.RecoilOf) {
246
+ if (reason === data_2.PROTOCOL.Damage.RecoilOf) {
242
247
  kwArgs.of = decodeIdent(this.info, data.getUint8(offset++));
243
248
  }
244
249
  const args = ['-damage', ident, hpStatus];
@@ -250,11 +255,11 @@ DECODERS[ArgType.Heal] = function (offset, data) {
250
255
  offset += 5;
251
256
  const reason = data.getUint8(offset++);
252
257
  const kwArgs = {};
253
- if (reason === data_1.PROTOCOL.Heal.Drain) {
258
+ if (reason === data_2.PROTOCOL.Heal.Drain) {
254
259
  kwArgs.from = 'drain';
255
260
  kwArgs.of = decodeIdent(this.info, data.getUint8(offset++));
256
261
  }
257
- else if (reason === data_1.PROTOCOL.Heal.Silent) {
262
+ else if (reason === data_2.PROTOCOL.Heal.Silent) {
258
263
  kwArgs.silent = true;
259
264
  }
260
265
  const args = ['-heal', ident, hpStatus];
@@ -265,10 +270,10 @@ DECODERS[ArgType.Status] = function (offset, data) {
265
270
  const status = decodeStatus(data.getUint8(offset++));
266
271
  const reason = data.getUint8(offset++);
267
272
  const kwArgs = {};
268
- if (reason === data_1.PROTOCOL.Status.Silent) {
273
+ if (reason === data_2.PROTOCOL.Status.Silent) {
269
274
  kwArgs.silent = true;
270
275
  }
271
- else if (reason === data_1.PROTOCOL.Status.From) {
276
+ else if (reason === data_2.PROTOCOL.Status.From) {
272
277
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
273
278
  kwArgs.from = `move: ${move}`;
274
279
  }
@@ -280,10 +285,10 @@ DECODERS[ArgType.CureStatus] = function (offset, data) {
280
285
  const status = decodeStatus(data.getUint8(offset++));
281
286
  const reason = data.getUint8(offset++);
282
287
  const kwArgs = {};
283
- if (reason === data_1.PROTOCOL.CureStatus.Message) {
288
+ if (reason === data_2.PROTOCOL.CureStatus.Message) {
284
289
  kwArgs.msg = true;
285
290
  }
286
- else if (reason === data_1.PROTOCOL.CureStatus.Silent) {
291
+ else if (reason === data_2.PROTOCOL.CureStatus.Silent) {
287
292
  kwArgs.silent = true;
288
293
  }
289
294
  const args = ['-curestatus', ident, status];
@@ -294,7 +299,7 @@ DECODERS[ArgType.Boost] = function (offset, data) {
294
299
  const reason = data.getUint8(offset++);
295
300
  const boost = BOOSTS[reason];
296
301
  const kwArgs = {};
297
- if (reason === data_1.PROTOCOL.Boost.Rage) {
302
+ if (reason === data_2.PROTOCOL.Boost.Rage) {
298
303
  kwArgs.from = 'Rage';
299
304
  }
300
305
  const n = data.getUint8(offset++) - 6;
@@ -313,13 +318,13 @@ DECODERS[ArgType.Fail] = function (offset, data) {
313
318
  const reason = data.getUint8(offset++);
314
319
  let args;
315
320
  const kwArgs = {};
316
- const weak = reason === data_1.PROTOCOL.Fail.Weak;
317
- 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) {
318
323
  args = ['-fail', ident, 'move: Substitute'];
319
324
  if (weak)
320
325
  kwArgs.weak = true;
321
326
  }
322
- else if (reason !== data_1.PROTOCOL.Fail.None) {
327
+ else if (reason !== data_2.PROTOCOL.Fail.None) {
323
328
  args = ['-fail', ident, FAIL[reason]];
324
329
  }
325
330
  else {
@@ -348,12 +353,12 @@ DECODERS[ArgType.MustRecharge] = function (offset, data) {
348
353
  DECODERS[ArgType.Activate] = function (offset, data) {
349
354
  const ident = decodeIdent(this.info, data.getUint8(offset++));
350
355
  const reason = data.getUint8(offset++);
351
- const type = reason === data_1.PROTOCOL.Activate.Mist ? '-block' : '-activate';
356
+ const type = reason === data_2.PROTOCOL.Activate.Mist ? '-block' : '-activate';
352
357
  const activate = ACTIVATE[this.gen.num - 1];
353
- const args = reason === data_1.PROTOCOL.Activate.Splash
358
+ const args = reason === data_2.PROTOCOL.Activate.Splash
354
359
  ? [type, '', activate[reason]]
355
360
  : [type, ident, activate[reason], ''];
356
- const kwArgs = reason === data_1.PROTOCOL.Activate.Substitute ? { damage: true } : {};
361
+ const kwArgs = reason === data_2.PROTOCOL.Activate.Substitute ? { damage: true } : {};
357
362
  return { offset, line: { args, kwArgs } };
358
363
  };
359
364
  DECODERS[ArgType.FieldActivate] = function (offset) {
@@ -366,12 +371,12 @@ DECODERS[ArgType.Start] = function (offset, data) {
366
371
  const reason = data.getUint8(offset++);
367
372
  let args;
368
373
  const kwArgs = {};
369
- if (reason < data_1.PROTOCOL.Start.TypeChange) {
374
+ if (reason < data_2.PROTOCOL.Start.TypeChange) {
370
375
  args = ['-start', ident, START[this.gen.num - 1][reason]];
371
- if (reason === data_1.PROTOCOL.Start.ConfusionSilent)
376
+ if (reason === data_2.PROTOCOL.Start.ConfusionSilent)
372
377
  kwArgs.silent = true;
373
378
  }
374
- else if (reason === data_1.PROTOCOL.Start.TypeChange) {
379
+ else if (reason === data_2.PROTOCOL.Start.TypeChange) {
375
380
  const types = decodeTypes(this.lookup, data.getUint8(offset++));
376
381
  const t = types[0] === types[1] ? types[0] : types.join('/');
377
382
  args = ['-start', ident, 'typechange', t];
@@ -380,7 +385,7 @@ DECODERS[ArgType.Start] = function (offset, data) {
380
385
  }
381
386
  else {
382
387
  const move = this.gen.moves.get(this.lookup.moveByNum(data.getUint8(offset++))).name;
383
- const effect = reason === data_1.PROTOCOL.Start.Disable ? 'Disable' : 'Mimic';
388
+ const effect = reason === data_2.PROTOCOL.Start.Disable ? 'Disable' : 'Mimic';
384
389
  args = ['-start', ident, effect, move];
385
390
  }
386
391
  return { offset, line: { args, kwArgs } };
@@ -389,7 +394,7 @@ DECODERS[ArgType.End] = function (offset, data) {
389
394
  const ident = decodeIdent(this.info, data.getUint8(offset++));
390
395
  const reason = data.getUint8(offset++);
391
396
  const args = ['-end', ident, END[this.gen.num - 1][reason]];
392
- const kwArgs = reason >= data_1.PROTOCOL.End.DisableSilent ? { silent: true } : {};
397
+ const kwArgs = reason >= data_2.PROTOCOL.End.DisableSilent ? { silent: true } : {};
393
398
  return { offset, line: { args, kwArgs } };
394
399
  };
395
400
  DECODERS[ArgType.OHKO] = function (offset) {
@@ -407,7 +412,7 @@ DECODERS[ArgType.Resisted] = function (offset, data) {
407
412
  DECODERS[ArgType.Immune] = function (offset, data) {
408
413
  const ident = decodeIdent(this.info, data.getUint8(offset++));
409
414
  const reason = data.getUint8(offset++);
410
- const kwArgs = reason === data_1.PROTOCOL.Immune.OHKO ? { ohko: true } : {};
415
+ const kwArgs = reason === data_2.PROTOCOL.Immune.OHKO ? { ohko: true } : {};
411
416
  return { offset, line: { args: ['-immune', ident], kwArgs } };
412
417
  };
413
418
  DECODERS[ArgType.Transform] = function (offset, data) {
@@ -434,9 +439,9 @@ function decodeDetails(offset, data, gen, lookup) {
434
439
  return `${species}${mf}${lvl}`;
435
440
  }
436
441
  function decodeHPStatus(offset, data) {
437
- const hp = data.getUint16(offset, data_1.LE);
442
+ const hp = data.getUint16(offset, data_2.LE);
438
443
  offset += 2;
439
- const maxhp = data.getUint16(offset, data_1.LE);
444
+ const maxhp = data.getUint16(offset, data_2.LE);
440
445
  offset += 2;
441
446
  if (hp === 0)
442
447
  return '0 fnt';
@@ -449,7 +454,6 @@ function decodeIdentRaw(byte) {
449
454
  id: byte & 0b111,
450
455
  };
451
456
  }
452
- exports.decodeIdentRaw = decodeIdentRaw;
453
457
  function decodeStatus(val) {
454
458
  if (val & 0b111)
455
459
  return 'slp';
@@ -465,9 +469,7 @@ function decodeStatus(val) {
465
469
  return 'psn';
466
470
  return undefined;
467
471
  }
468
- exports.decodeStatus = decodeStatus;
469
472
  function decodeTypes(lookup, val) {
470
473
  return [lookup.typeByNum(val & 0x0F), lookup.typeByNum(val >> 4)];
471
474
  }
472
- exports.decodeTypes = decodeTypes;
473
475
  //# sourceMappingURL=protocol.js.map