@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.
- package/LICENSE +1 -3
- package/README.md +115 -76
- package/build/pkg/addon/browser.d.ts +3 -0
- package/build/pkg/addon/browser.js +44 -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 +97 -0
- package/build/pkg/addon/node.js.map +1 -0
- package/build/pkg/addon/wasm.d.ts +2 -0
- package/build/pkg/addon/wasm.js +53 -0
- package/build/pkg/addon/wasm.js.map +1 -0
- package/build/pkg/addon.d.ts +27 -5
- package/build/pkg/addon.js +42 -73
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data/ids.json +12 -12
- package/build/pkg/data/layout.json +40 -5
- package/build/pkg/data/protocol.json +84 -13
- package/build/pkg/data.d.ts +27 -5
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.d.ts +16 -19
- package/build/pkg/gen1.js +54 -42
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +55 -103
- package/build/pkg/index.js +6 -63
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +24 -3
- package/build/pkg/protocol.js +127 -104
- package/build/pkg/protocol.js.map +1 -1
- package/build/tools/debug.js +36 -69
- 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 +142 -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 +373 -152
- package/package.json +68 -120
- package/src/bin/install-pkmn-engine +41 -26
- package/src/bin/pkmn-debug +29 -6
- package/src/lib/bindings/node.zig +121 -0
- package/src/lib/bindings/wasm.zig +58 -0
- package/src/lib/common/array.zig +77 -0
- package/src/lib/common/battle.zig +17 -0
- package/src/lib/common/data.zig +19 -31
- package/src/lib/common/debug.zig +58 -17
- package/src/lib/common/js.zig +120 -0
- package/src/lib/common/optional.zig +71 -0
- package/src/lib/common/options.zig +18 -3
- package/src/lib/common/protocol.zig +947 -407
- package/src/lib/common/rational.zig +449 -0
- package/src/lib/common/rng.zig +31 -24
- package/src/lib/common/util.zig +61 -0
- package/src/lib/gen1/calc.zig +953 -0
- package/src/lib/gen1/chance.zig +1185 -0
- package/src/lib/gen1/data/moves.zig +203 -193
- package/src/lib/gen1/data/species.zig +6 -8
- package/src/lib/gen1/data/types.zig +11 -12
- package/src/lib/gen1/data.zig +100 -89
- package/src/lib/gen1/helpers.zig +139 -50
- package/src/lib/gen1/mechanics.zig +1344 -907
- package/src/lib/gen2/calc.zig +153 -0
- package/src/lib/gen2/chance.zig +902 -0
- package/src/lib/gen2/data/items.zig +15 -23
- package/src/lib/gen2/data/moves.zig +665 -573
- package/src/lib/gen2/data/species.zig +3 -5
- package/src/lib/gen2/data/types.zig +138 -36
- package/src/lib/gen2/data.zig +134 -99
- package/src/lib/gen2/generated.zig +801 -0
- package/src/lib/gen2/helpers.zig +59 -44
- package/src/lib/gen2/mechanics.zig +3582 -30
- package/src/lib/node.zig +18 -0
- package/src/lib/pkmn.zig +93 -12
- package/src/lib/wasm.zig +17 -0
- package/src/tools/display/dom.ts +96 -0
- package/src/tools/display/ui.css +354 -0
- package/build/test/display.js +0 -382
- package/build/test/display.js.map +0 -1
- package/src/lib/binding/node.zig +0 -229
- package/src/lib/binding/wasm.zig +0 -10
- package/src/lib/gen1/README.md +0 -784
- package/src/lib/gen2/README.md +0 -309
- package/src/test/display/pkmn.html.tmpl +0 -368
package/build/pkg/index.js
CHANGED
|
@@ -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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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; } });
|
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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pkg/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,+CAAiC;AAEjC,iCAA8B;AAC9B,6CAA+B;AA2U/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,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"}
|
package/build/pkg/protocol.d.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 {};
|
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 };
|
|
@@ -99,86 +104,102 @@ class Log {
|
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
exports.Log = Log;
|
|
102
|
-
const
|
|
103
|
-
CANT
|
|
104
|
-
CANT[
|
|
105
|
-
CANT[
|
|
106
|
-
CANT[
|
|
107
|
-
CANT[
|
|
108
|
-
CANT[
|
|
109
|
-
CANT[
|
|
110
|
-
|
|
111
|
-
DAMAGE
|
|
112
|
-
DAMAGE[
|
|
113
|
-
DAMAGE[
|
|
114
|
-
DAMAGE[
|
|
115
|
-
DAMAGE[
|
|
116
|
-
|
|
117
|
-
BOOSTS
|
|
118
|
-
BOOSTS[
|
|
119
|
-
BOOSTS[
|
|
120
|
-
BOOSTS[
|
|
121
|
-
BOOSTS[
|
|
122
|
-
BOOSTS[
|
|
123
|
-
BOOSTS[
|
|
124
|
-
BOOSTS[
|
|
125
|
-
|
|
126
|
-
FAIL
|
|
127
|
-
FAIL[
|
|
128
|
-
FAIL[
|
|
129
|
-
FAIL[
|
|
130
|
-
FAIL[
|
|
131
|
-
FAIL[
|
|
132
|
-
|
|
133
|
-
ACTIVATE[
|
|
134
|
-
ACTIVATE[
|
|
135
|
-
ACTIVATE[
|
|
136
|
-
ACTIVATE[
|
|
137
|
-
ACTIVATE[
|
|
138
|
-
ACTIVATE[
|
|
139
|
-
ACTIVATE[
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
START[
|
|
144
|
-
START[
|
|
145
|
-
START[
|
|
146
|
-
START[
|
|
147
|
-
START[
|
|
148
|
-
START[
|
|
149
|
-
START[
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
END[
|
|
156
|
-
END[
|
|
157
|
-
END[
|
|
158
|
-
END[
|
|
159
|
-
END[
|
|
160
|
-
END[
|
|
161
|
-
END[
|
|
162
|
-
END[
|
|
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: ${
|
|
190
|
+
? '' : `${player}a: ${(set.name || set.species)}`;
|
|
170
191
|
const reason = data.getUint8(offset++);
|
|
171
|
-
const move = reason ===
|
|
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 ===
|
|
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 ===
|
|
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,
|
|
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 >
|
|
244
|
+
if (reason > data_2.PROTOCOL.Damage.None)
|
|
224
245
|
kwArgs.from = DAMAGE[reason];
|
|
225
|
-
if (reason ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
273
|
+
if (reason === data_2.PROTOCOL.Status.Silent) {
|
|
253
274
|
kwArgs.silent = true;
|
|
254
275
|
}
|
|
255
|
-
else if (reason ===
|
|
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 ===
|
|
288
|
+
if (reason === data_2.PROTOCOL.CureStatus.Message) {
|
|
268
289
|
kwArgs.msg = true;
|
|
269
290
|
}
|
|
270
|
-
else if (reason ===
|
|
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 ===
|
|
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 ===
|
|
301
|
-
if (weak || reason ===
|
|
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 !==
|
|
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 ===
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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 <
|
|
353
|
-
args = ['-start', ident, START[reason]];
|
|
354
|
-
if (reason ===
|
|
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 ===
|
|
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 ===
|
|
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 >=
|
|
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 ===
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
442
|
+
const hp = data.getUint16(offset, data_2.LE);
|
|
417
443
|
offset += 2;
|
|
418
|
-
const maxhp = data.getUint16(offset,
|
|
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
|