@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.
- package/README.md +15 -11
- package/build/pkg/addon/browser.d.ts +3 -0
- package/build/pkg/addon/browser.js +43 -0
- package/build/pkg/addon/browser.js.map +1 -0
- package/build/pkg/addon/node.d.ts +3 -0
- package/build/pkg/addon/node.js +96 -0
- package/build/pkg/addon/node.js.map +1 -0
- package/build/pkg/addon.d.ts +2 -0
- package/build/pkg/addon.js +35 -58
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +25 -4
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +1 -1
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +22 -9
- package/build/pkg/index.js +15 -10
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +20 -1
- package/build/pkg/protocol.js +109 -107
- package/build/pkg/protocol.js.map +1 -1
- package/build/tools/debug.js +36 -70
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/debug.jsx +141 -0
- package/build/tools/display/debug.jsx.map +1 -0
- package/build/tools/display/index.js +132 -0
- package/build/tools/display/index.js.map +1 -0
- package/build/tools/display/ui.jsx +349 -0
- package/build/tools/display/ui.jsx.map +1 -0
- package/build/tools/display/util.js +18 -0
- package/build/tools/display/util.js.map +1 -0
- package/build.zig +186 -65
- package/package.json +46 -29
- package/src/bin/install-pkmn-engine +17 -7
- package/src/bin/pkmn-debug +1 -1
- package/src/lib/common/array.zig +77 -0
- package/src/lib/common/data.zig +8 -8
- package/src/lib/common/debug.zig +32 -6
- package/src/lib/common/js.zig +4 -2
- package/src/lib/common/optional.zig +13 -9
- package/src/lib/common/options.zig +4 -0
- package/src/lib/common/protocol.zig +46 -36
- package/src/lib/common/rational.zig +114 -24
- package/src/lib/common/rng.zig +4 -4
- package/src/lib/common/util.zig +50 -1
- package/src/lib/gen1/calc.zig +663 -130
- package/src/lib/gen1/chance.zig +384 -275
- package/src/lib/gen1/data.zig +31 -30
- package/src/lib/gen1/helpers.zig +89 -538
- package/src/lib/gen1/mechanics.zig +275 -197
- package/src/lib/gen2/calc.zig +34 -16
- package/src/lib/gen2/chance.zig +90 -502
- package/src/lib/gen2/data.zig +15 -14
- package/src/lib/gen2/helpers.zig +41 -13
- package/src/lib/gen2/mechanics.zig +158 -103
- package/src/lib/pkmn.zig +10 -16
- package/src/tools/display/dom.ts +96 -0
- package/src/tools/display/ui.css +351 -0
- package/build/test/display.js +0 -400
- package/build/test/display.js.map +0 -1
- package/src/lib/gen1/README.md +0 -894
- package/src/lib/gen2/README.md +0 -329
- package/src/test/display/pkmn.html.tmpl +0 -368
package/build/pkg/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
/**
|
|
352
|
-
static
|
|
353
|
-
|
|
354
|
-
readonly
|
|
355
|
-
readonly
|
|
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
|
-
/**
|
|
371
|
-
static pass
|
|
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';
|
package/build/pkg/index.js
CHANGED
|
@@ -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 =
|
|
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
|
-
/**
|
|
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");
|
package/build/pkg/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pkg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,+CAAiC;AACjC,iCAA8B;AAC9B,6CAA+B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pkg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,+CAAiC;AACjC,iCAA8B;AAC9B,6CAA+B;AAmW/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,CAAC;YAChB,KAAK,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACxD,OAAO,CAA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, 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 {};
|
package/build/pkg/protocol.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
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 ?
|
|
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(
|
|
104
|
-
CANT[
|
|
105
|
-
CANT[
|
|
106
|
-
CANT[
|
|
107
|
-
CANT[
|
|
108
|
-
CANT[
|
|
109
|
-
CANT[
|
|
110
|
-
CANT[
|
|
111
|
-
const DAMAGE = new Array(
|
|
112
|
-
DAMAGE[
|
|
113
|
-
DAMAGE[
|
|
114
|
-
DAMAGE[
|
|
115
|
-
DAMAGE[
|
|
116
|
-
DAMAGE[
|
|
117
|
-
const BOOSTS = new Array(
|
|
118
|
-
BOOSTS[
|
|
119
|
-
BOOSTS[
|
|
120
|
-
BOOSTS[
|
|
121
|
-
BOOSTS[
|
|
122
|
-
BOOSTS[
|
|
123
|
-
BOOSTS[
|
|
124
|
-
BOOSTS[
|
|
125
|
-
BOOSTS[
|
|
126
|
-
const FAIL = new Array(
|
|
127
|
-
FAIL[
|
|
128
|
-
FAIL[
|
|
129
|
-
FAIL[
|
|
130
|
-
FAIL[
|
|
131
|
-
FAIL[
|
|
132
|
-
FAIL[
|
|
133
|
-
const ACTIVATE = [new Array(
|
|
134
|
-
ACTIVATE[0][
|
|
135
|
-
ACTIVATE[0][
|
|
136
|
-
ACTIVATE[0][
|
|
137
|
-
ACTIVATE[0][
|
|
138
|
-
ACTIVATE[0][
|
|
139
|
-
ACTIVATE[0][
|
|
140
|
-
ACTIVATE[0][
|
|
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][
|
|
143
|
-
const START = [new Array(
|
|
144
|
-
START[0][
|
|
145
|
-
START[0][
|
|
146
|
-
START[0][
|
|
147
|
-
START[0][
|
|
148
|
-
START[0][
|
|
149
|
-
START[0][
|
|
150
|
-
START[0][
|
|
151
|
-
START[0][
|
|
152
|
-
START[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';
|
|
153
158
|
START[1] = START[0].slice(0);
|
|
154
|
-
START[1][
|
|
155
|
-
const END = [new Array(
|
|
156
|
-
END[0][
|
|
157
|
-
END[0][
|
|
158
|
-
END[0][
|
|
159
|
-
END[0][
|
|
160
|
-
END[0][
|
|
161
|
-
END[0][
|
|
162
|
-
END[0][
|
|
163
|
-
END[0][
|
|
164
|
-
END[0][
|
|
165
|
-
END[0][
|
|
166
|
-
END[0][
|
|
167
|
-
END[0][
|
|
168
|
-
END[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';
|
|
169
174
|
END[1] = END[0].slice(0);
|
|
170
|
-
END[1][
|
|
171
|
-
END[1][
|
|
172
|
-
END[1][
|
|
173
|
-
const SIDE = new Array(
|
|
174
|
-
SIDE[
|
|
175
|
-
SIDE[
|
|
176
|
-
SIDE[
|
|
177
|
-
SIDE[
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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,
|
|
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 >
|
|
244
|
+
if (reason > data_2.PROTOCOL.Damage.None)
|
|
240
245
|
kwArgs.from = DAMAGE[reason];
|
|
241
|
-
if (reason ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
273
|
+
if (reason === data_2.PROTOCOL.Status.Silent) {
|
|
269
274
|
kwArgs.silent = true;
|
|
270
275
|
}
|
|
271
|
-
else if (reason ===
|
|
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 ===
|
|
288
|
+
if (reason === data_2.PROTOCOL.CureStatus.Message) {
|
|
284
289
|
kwArgs.msg = true;
|
|
285
290
|
}
|
|
286
|
-
else if (reason ===
|
|
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 ===
|
|
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 ===
|
|
317
|
-
if (weak || reason ===
|
|
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 !==
|
|
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 ===
|
|
356
|
+
const type = reason === data_2.PROTOCOL.Activate.Mist ? '-block' : '-activate';
|
|
352
357
|
const activate = ACTIVATE[this.gen.num - 1];
|
|
353
|
-
const args = reason ===
|
|
358
|
+
const args = reason === data_2.PROTOCOL.Activate.Splash
|
|
354
359
|
? [type, '', activate[reason]]
|
|
355
360
|
: [type, ident, activate[reason], ''];
|
|
356
|
-
const kwArgs = reason ===
|
|
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 <
|
|
374
|
+
if (reason < data_2.PROTOCOL.Start.TypeChange) {
|
|
370
375
|
args = ['-start', ident, START[this.gen.num - 1][reason]];
|
|
371
|
-
if (reason ===
|
|
376
|
+
if (reason === data_2.PROTOCOL.Start.ConfusionSilent)
|
|
372
377
|
kwArgs.silent = true;
|
|
373
378
|
}
|
|
374
|
-
else if (reason ===
|
|
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 ===
|
|
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 >=
|
|
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 ===
|
|
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,
|
|
442
|
+
const hp = data.getUint16(offset, data_2.LE);
|
|
438
443
|
offset += 2;
|
|
439
|
-
const maxhp = data.getUint16(offset,
|
|
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
|