@pkmn/engine 0.1.0-dev.10889360 → 0.1.0-dev.115ecc94
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 +0 -2
- package/README.md +13 -11
- package/build/pkg/addon.js +6 -7
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +2 -3
- package/build/pkg/protocol.js +4 -4
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +2 -2
- package/build/test/display.js.map +1 -1
- package/build/tools/debug.js +2 -3
- package/build/tools/debug.js.map +1 -1
- package/build.zig +32 -50
- package/package.json +24 -17
- package/src/bin/install-pkmn-engine +13 -5
- package/src/lib/common/debug.zig +2 -2
- package/src/lib/common/options.zig +2 -0
- package/src/lib/common/protocol.zig +10 -8
- package/src/lib/common/rational.zig +102 -12
- package/src/lib/common/rng.zig +6 -6
- package/src/lib/gen1/calc.zig +266 -97
- package/src/lib/gen1/chance.zig +114 -148
- package/src/lib/gen1/data/species.zig +1 -1
- package/src/lib/gen1/data.zig +3 -3
- package/src/lib/gen1/helpers.zig +184 -199
- package/src/lib/gen1/mechanics.zig +91 -54
- package/src/lib/gen2/chance.zig +193 -103
- package/src/lib/gen2/helpers.zig +37 -7
- package/src/lib/gen2/mechanics.zig +112 -27
- package/src/lib/pkmn.zig +4 -12
- package/src/test/display/pkmn.html.tmpl +5 -5
- package/src/lib/gen1/README.md +0 -894
- package/src/lib/gen2/README.md +0 -329
|
@@ -1304,14 +1304,32 @@ pub const Effects = struct {
|
|
|
1304
1304
|
}
|
|
1305
1305
|
|
|
1306
1306
|
pub fn bellyDrum(battle: anytype, player: Player, state: *State, options: anytype) !void {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1307
|
+
assert(!state.miss);
|
|
1308
|
+
var side = battle.side(player);
|
|
1309
|
+
|
|
1310
|
+
const ident = battle.active(player);
|
|
1311
|
+
|
|
1312
|
+
assert(side.active.boosts.atk >= -6 and side.active.boosts.atk <= 6);
|
|
1313
|
+
if (side.active.boosts.atk == 6 or side.active.boosts.atk == MAX_STAT_VALUE) {
|
|
1314
|
+
return options.log.fail(.{ ident, .None });
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
const hp = @max(side.stored().stats.hp / 2, 1);
|
|
1318
|
+
if (side.stored().hp <= hp) {
|
|
1319
|
+
try boostStat(battle, side, &side.active.stats, &side.active.boosts, "atk", 2);
|
|
1320
|
+
try options.log.boost(.{ ident, .Attack, @as(i8, 2), .Silent });
|
|
1321
|
+
return options.log.fail(.{ ident, .None });
|
|
1322
|
+
} else {
|
|
1323
|
+
side.stored().hp -= hp;
|
|
1324
|
+
try options.log.damage(.{ ident, side.stored(), .None });
|
|
1325
|
+
|
|
1326
|
+
const before = side.active.boosts.atk;
|
|
1327
|
+
var i: usize = 0;
|
|
1328
|
+
while (i < 6 and side.active.stats.atk < MAX_STAT_VALUE) : (i += 1) {
|
|
1329
|
+
try boostStat(battle, side, &side.active.stats, &side.active.boosts, "atk", 2);
|
|
1330
|
+
}
|
|
1331
|
+
try options.log.boost(.{ ident, .Attack, @as(i8, side.active.boosts.atk - before) });
|
|
1332
|
+
}
|
|
1315
1333
|
}
|
|
1316
1334
|
|
|
1317
1335
|
pub const bide = struct {
|
|
@@ -1596,8 +1614,16 @@ pub const Effects = struct {
|
|
|
1596
1614
|
try options.log.start(.{ foe_ident, .Encore, move.id });
|
|
1597
1615
|
}
|
|
1598
1616
|
|
|
1599
|
-
pub fn explode(battle: anytype, player: Player,
|
|
1600
|
-
|
|
1617
|
+
pub fn explode(battle: anytype, player: Player, _: *State, _: anytype) !void {
|
|
1618
|
+
var side = battle.side(player);
|
|
1619
|
+
var stored = side.stored();
|
|
1620
|
+
|
|
1621
|
+
stored.hp = 0;
|
|
1622
|
+
// Pokémon Showdown sets the status to 0 on faint(), and we need to do the same to be able
|
|
1623
|
+
// to correctly implement Pokémon Showdown's dumb speed-based switch mechanics
|
|
1624
|
+
if (!showdown) stored.status = 0;
|
|
1625
|
+
side.active.volatiles.LeechSeed = false;
|
|
1626
|
+
side.active.volatiles.DestinyBond = false;
|
|
1601
1627
|
}
|
|
1602
1628
|
|
|
1603
1629
|
pub fn falseSwipe(battle: anytype, player: Player, state: *State, _: anytype) !void {
|
|
@@ -1723,8 +1749,26 @@ pub const Effects = struct {
|
|
|
1723
1749
|
foe.active.volatiles.frozen = true;
|
|
1724
1750
|
}
|
|
1725
1751
|
|
|
1726
|
-
|
|
1727
|
-
|
|
1752
|
+
// TODO FIXME showdown calls this before calcDamage (after checkHit) and modifies state.bp!
|
|
1753
|
+
pub fn furyCutter(battle: anytype, player: Player, state: *State, _: anytype) !void {
|
|
1754
|
+
var side = battle.side(player);
|
|
1755
|
+
var volatiles = &side.active.volatiles;
|
|
1756
|
+
|
|
1757
|
+
if (state.miss) {
|
|
1758
|
+
volatiles.fury_cutter = 0;
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
assert(volatiles.fury_cutter >= 0 and volatiles.fury_cutter <= 5);
|
|
1763
|
+
if (volatiles.fury_cutter == 5) return;
|
|
1764
|
+
volatiles.fury_cutter += 1;
|
|
1765
|
+
|
|
1766
|
+
if (showdown) {
|
|
1767
|
+
state.bp *= 2;
|
|
1768
|
+
assert(state.bp <= 160);
|
|
1769
|
+
} else {
|
|
1770
|
+
state.damage *|= 2;
|
|
1771
|
+
}
|
|
1728
1772
|
}
|
|
1729
1773
|
|
|
1730
1774
|
pub fn futureSight(battle: anytype, player: Player, state: *State, options: anytype) !void {
|
|
@@ -1885,7 +1929,29 @@ pub const Effects = struct {
|
|
|
1885
1929
|
}
|
|
1886
1930
|
|
|
1887
1931
|
pub fn mimic(battle: anytype, player: Player, state: *State, options: anytype) !void {
|
|
1888
|
-
|
|
1932
|
+
var side = battle.side(player);
|
|
1933
|
+
|
|
1934
|
+
if (state.miss) {
|
|
1935
|
+
if (!showdown) return options.log.fail(.{ battle.active(player.foe()), .None });
|
|
1936
|
+
try options.log.lastmiss(.{});
|
|
1937
|
+
return options.log.miss(.{battle.active(player)});
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
const move = battle.foe(player).lastMove(false);
|
|
1941
|
+
if (move == .None or move == .Struggle) {
|
|
1942
|
+
return options.log.fail(.{ battle.active(player.foe()), .None });
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
var slot: u4 = 0;
|
|
1946
|
+
for (side.active.moves, 0..) |m, i| {
|
|
1947
|
+
if (m.id == move) return options.log.fail(.{ battle.active(player.foe()), .None });
|
|
1948
|
+
if (m.id == .Mimic) slot = @intCast(i + 1);
|
|
1949
|
+
}
|
|
1950
|
+
assert(slot != 0 and slot == state.mslot);
|
|
1951
|
+
|
|
1952
|
+
side.active.move(slot).id = move;
|
|
1953
|
+
side.active.move(slot).pp = 5;
|
|
1954
|
+
try options.log.start(.{ battle.active(player), .Mimic, move });
|
|
1889
1955
|
}
|
|
1890
1956
|
|
|
1891
1957
|
pub fn mirrorMove(
|
|
@@ -2393,17 +2459,37 @@ pub const Effects = struct {
|
|
|
2393
2459
|
}
|
|
2394
2460
|
|
|
2395
2461
|
pub fn spite(battle: anytype, player: Player, state: *State, options: anytype) !void {
|
|
2396
|
-
|
|
2397
|
-
// var foe = battle.foe(player);
|
|
2462
|
+
var foe = battle.foe(player);
|
|
2398
2463
|
|
|
2399
|
-
|
|
2464
|
+
const last = foe.lastMove(false);
|
|
2465
|
+
if (state.miss or last == .None or last == .Struggle) {
|
|
2466
|
+
return options.log.fail(.{ battle.active(player.foe()), .None });
|
|
2467
|
+
}
|
|
2400
2468
|
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
//
|
|
2406
|
-
|
|
2469
|
+
var slot: u4 = 0;
|
|
2470
|
+
for (foe.active.moves, 0..) |m, i| {
|
|
2471
|
+
if (m.id == last) slot = @intCast(i + 1);
|
|
2472
|
+
}
|
|
2473
|
+
// If the move was called via Metronome it might not exist
|
|
2474
|
+
if (slot == 0 or foe.active.move(slot).pp == 0) {
|
|
2475
|
+
return options.log.fail(.{ battle.active(player.foe()), .None });
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
// Pokémon Showdown always deducts 4 instead of randomizing
|
|
2479
|
+
const pp = @min(
|
|
2480
|
+
foe.active.move(slot).pp,
|
|
2481
|
+
if (showdown) 4 else try Rolls.spite(battle, player, options),
|
|
2482
|
+
);
|
|
2483
|
+
foe.active.move(slot).pp -= pp;
|
|
2484
|
+
if (!foe.active.volatiles.Transform) {
|
|
2485
|
+
var move_slot = foe.stored().move(slot);
|
|
2486
|
+
assert(move_slot.pp > 0);
|
|
2487
|
+
|
|
2488
|
+
move_slot.pp = @as(u6, @intCast(move_slot.pp)) -% 1;
|
|
2489
|
+
assert(foe.active.move(slot).pp == foe.stored().move(slot).pp);
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
try options.log.activate(.{ battle.active(player.foe()), .Spite, last, pp });
|
|
2407
2493
|
}
|
|
2408
2494
|
|
|
2409
2495
|
pub fn splash(battle: anytype, player: Player, _: *State, options: anytype) !void {
|
|
@@ -3009,13 +3095,12 @@ pub const Rolls = struct {
|
|
|
3009
3095
|
return hits;
|
|
3010
3096
|
}
|
|
3011
3097
|
|
|
3012
|
-
fn spite(battle: anytype, player: Player, options: anytype) !
|
|
3013
|
-
|
|
3098
|
+
fn spite(battle: anytype, player: Player, options: anytype) !u3 {
|
|
3099
|
+
assert(!showdown);
|
|
3100
|
+
const pp: u3 = if (options.calc.overridden(player, .spite)) |val|
|
|
3014
3101
|
val + 1
|
|
3015
|
-
else if (showdown)
|
|
3016
|
-
battle.rng.range(u8, 2, 6)
|
|
3017
3102
|
else
|
|
3018
|
-
(battle.rng.next() & 3) + 2;
|
|
3103
|
+
@intCast((battle.rng.next() & 3) + 2);
|
|
3019
3104
|
|
|
3020
3105
|
assert(pp >= 2 and pp <= 5);
|
|
3021
3106
|
try options.chance.spite(player, pp);
|
package/src/lib/pkmn.zig
CHANGED
|
@@ -26,9 +26,7 @@ pub const Result = @import("common/data.zig").Result;
|
|
|
26
26
|
pub const PSRNG = @import("common/rng.zig").PSRNG;
|
|
27
27
|
|
|
28
28
|
/// Namespace for helpers related to protocol message logging.
|
|
29
|
-
pub const protocol = if (options.internal) struct {
|
|
30
|
-
pub usingnamespace @import("common/protocol.zig");
|
|
31
|
-
} else struct {
|
|
29
|
+
pub const protocol = if (options.internal) @import("common/protocol.zig") else struct {
|
|
32
30
|
/// Logs protocol information to its `Writer` during a battle update when
|
|
33
31
|
/// `options.log` is enabled.
|
|
34
32
|
pub const Log = @import("common/protocol.zig").Log;
|
|
@@ -82,9 +80,7 @@ pub const gen1 = struct {
|
|
|
82
80
|
/// via `overrides` and tracks `summaries` of information relevant to damage calculation.
|
|
83
81
|
pub const Calc = @import("gen1/calc.zig").Calc;
|
|
84
82
|
/// Namespace for types associated with supported Generation I Pokémon damage calc features.
|
|
85
|
-
pub const calc = if (options.internal) struct {
|
|
86
|
-
pub usingnamespace @import("gen1/calc.zig");
|
|
87
|
-
} else struct {
|
|
83
|
+
pub const calc = if (options.internal) @import("gen1/calc.zig") else struct {
|
|
88
84
|
/// TODO
|
|
89
85
|
pub const Overrides = @import("gen1/calc.zig").Overrides;
|
|
90
86
|
/// Information relevant to damage calculation that occured during a Generation I
|
|
@@ -114,9 +110,7 @@ pub const gen2 = struct {
|
|
|
114
110
|
pub const NULL = @import("gen2/chance.zig").NULL;
|
|
115
111
|
};
|
|
116
112
|
pub const Calc = @import("gen2/calc.zig").Calc;
|
|
117
|
-
pub const calc = if (options.internal) struct {
|
|
118
|
-
pub usingnamespace @import("gen2/calc.zig");
|
|
119
|
-
} else struct {
|
|
113
|
+
pub const calc = if (options.internal) @import("gen2/calc.zig") else struct {
|
|
120
114
|
pub const Overrides = @import("gen2/calc.zig").Overrides;
|
|
121
115
|
pub const Summaries = @import("gen2/calc.zig").Summaries;
|
|
122
116
|
pub const Summary = @import("gen2/calc.zig").Summary;
|
|
@@ -127,9 +121,7 @@ pub const gen2 = struct {
|
|
|
127
121
|
|
|
128
122
|
// Internal APIs used by other pkmn libraries, not actually part of the public API.
|
|
129
123
|
// NOTE: `pub usingnamespace struct { ... }` here results in a (false?) dependency loop
|
|
130
|
-
pub const js = if (options.internal) struct {
|
|
131
|
-
pub usingnamespace @import("common/js.zig");
|
|
132
|
-
} else struct {};
|
|
124
|
+
pub const js = if (options.internal) @import("common/js.zig") else struct {};
|
|
133
125
|
pub const bindings = if (options.internal) struct {
|
|
134
126
|
pub const node = @import("node.zig");
|
|
135
127
|
pub const wasm = @import("wasm.zig");
|
|
@@ -218,8 +218,9 @@
|
|
|
218
218
|
border-radius: 0 4px 4px 0;
|
|
219
219
|
}
|
|
220
220
|
.moves ul {
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
display: grid;
|
|
222
|
+
grid-template-columns: repeat(2, auto);
|
|
223
|
+
gap: 0 2em;
|
|
223
224
|
}
|
|
224
225
|
.left {
|
|
225
226
|
padding-right: 32px;
|
|
@@ -268,7 +269,7 @@
|
|
|
268
269
|
}
|
|
269
270
|
@media(max-width: 1200px) {
|
|
270
271
|
.moves ul {
|
|
271
|
-
|
|
272
|
+
grid-template-columns: repeat(1, auto);
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
275
|
@media(max-width: 1100px) {
|
|
@@ -283,7 +284,7 @@
|
|
|
283
284
|
margin-left: 5px;
|
|
284
285
|
}
|
|
285
286
|
.moves ul {
|
|
286
|
-
|
|
287
|
+
grid-template-columns: repeat(2, auto);
|
|
287
288
|
}
|
|
288
289
|
.left {
|
|
289
290
|
padding-right: 0;
|
|
@@ -309,7 +310,6 @@
|
|
|
309
310
|
justify-content: center;
|
|
310
311
|
}
|
|
311
312
|
.moves ul {
|
|
312
|
-
column-count: 1;
|
|
313
313
|
display: inline-block;
|
|
314
314
|
padding: 0;
|
|
315
315
|
}
|