@korial29/tiny-fps 0.130.2 → 0.132.0

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/dist/server.js CHANGED
@@ -370,6 +370,7 @@ var BODY = {
370
370
  MALE: 0,
371
371
  FEMALE: 1
372
372
  };
373
+ var HAIRS_N = [4, 5];
373
374
  /** Bits of Input.keys. Keys are read by KeyboardEvent.code, so WASD is ZQSD on AZERTY. */
374
375
  var KEY = {
375
376
  FORWARD: 1,
@@ -511,6 +512,63 @@ var TEX = {
511
512
  /** Dark basalt: mottled, speckled with pits and light flecks, a few fine cracks. The moon's boulders. */
512
513
  ROCK: 12
513
514
  };
515
+ // src/shared/kit.ts
516
+ var ROLE = {
517
+ MARINE: 0,
518
+ NINJA: 1,
519
+ ASTRONAUT: 2
520
+ };
521
+ var MARINE = {
522
+ run: 6,
523
+ sprint: 9,
524
+ jump: 7,
525
+ double: 6,
526
+ wallrun: 60,
527
+ dashes: 1,
528
+ haste: 1,
529
+ ammo: 60,
530
+ rail: 240,
531
+ rifle: 240,
532
+ cool: 7,
533
+ rifleCool: 3,
534
+ mag: 15,
535
+ cap: 80,
536
+ clip: 60,
537
+ damage: 1,
538
+ slow: 1
539
+ };
540
+ /** By ROLE. The astronaut moves and fights as the marine: the moon's gravity is the map's. */
541
+ var KITS = [
542
+ MARINE,
543
+ {
544
+ run: 6 * 1.2,
545
+ sprint: 9 * 1.2,
546
+ jump: 7 * 1.15,
547
+ double: 6 * 1.15,
548
+ wallrun: 120,
549
+ dashes: 3,
550
+ haste: 2,
551
+ ammo: 30,
552
+ rail: 120,
553
+ rifle: 120,
554
+ cool: 14,
555
+ rifleCool: 6,
556
+ mag: Math.ceil(15 / 2),
557
+ cap: 40,
558
+ clip: 30,
559
+ damage: .5,
560
+ slow: .55
561
+ },
562
+ MARINE
563
+ ];
564
+ /** The classes a map offers, the first one the default: the astronaut alone on a map with space helmets. */
565
+ var rolesOf = (def) => def.helmets ? [ROLE.ASTRONAUT] : [ROLE.MARINE, ROLE.NINJA];
566
+ /** The class a player plays on the map: his `role` when the map offers it, else the map's default. */
567
+ var roleOf = (role, def) => {
568
+ const all = rolesOf(def);
569
+ return all.includes(role ?? -1) ? role : all[0];
570
+ };
571
+ var kitOf = (role, def) => KITS[roleOf(role, def)];
514
572
  // src/shared/world.ts
515
573
  /** Metres per grid cell: about the size of the player's reach, so a query touches 1 to 4 cells. */
516
574
  var CELL = 4;
@@ -1073,7 +1131,7 @@ var unwalled = (p, w, c, h) => {
1073
1131
  * Ground control: speed toward the wished direction (a vector of length 0 to 1), up to `top` times
1074
1132
  * its length; friction with none.
1075
1133
  */
1076
- var steer = (p, wish, top) => {
1134
+ var steer = (p, wish, top, run = 6) => {
1077
1135
  const m = len$1(wish[0], wish[1]);
1078
1136
  if (m < EPS) {
1079
1137
  const s = len$1(p.vx, p.vz);
@@ -1091,7 +1149,7 @@ var steer = (p, wish, top) => {
1091
1149
  [px, pz] = [px * k, pz * k];
1092
1150
  }
1093
1151
  top *= m;
1094
- par = par < top ? Math.min(top, par + (par >= 6 ? 3 : 50) * DT$2) : Math.max(top, par - 12 * DT$2);
1152
+ par = par < top ? Math.min(top, par + (par >= run ? 3 : 50) * DT$2) : Math.max(top, par - 12 * DT$2);
1095
1153
  p.vx = px + par * wx;
1096
1154
  p.vz = pz + par * wz;
1097
1155
  };
@@ -1210,11 +1268,11 @@ var run = (p, w, c) => {
1210
1268
  p.vz = tz - nz * 5;
1211
1269
  leap(p, WALL_KICK_UP);
1212
1270
  p.jumps = 1;
1213
- p.dashes = 1;
1271
+ p.dashes = c.kit.dashes;
1214
1272
  p.ev |= EV.WALLRUN_END;
1215
1273
  } else {
1216
1274
  const gap = wallGap(p, w, p.wall);
1217
- if (gap === void 0 || !c.fwd || s < 3.5 || p.t >= 60) {
1275
+ if (gap === void 0 || !c.fwd || s < 3.5 || p.t >= c.kit.wallrun) {
1218
1276
  enter(p, MODE.AIR);
1219
1277
  p.ev |= EV.WALLRUN_END;
1220
1278
  return;
@@ -1249,7 +1307,7 @@ var startRun = (p, w, c) => {
1249
1307
  [p.vx, p.vz] = [tx * k, tz * k];
1250
1308
  p.vy = clamp$2(p.vy, 2, 3);
1251
1309
  p.jumps = 1;
1252
- p.dashes = 1;
1310
+ p.dashes = c.kit.dashes;
1253
1311
  p.coyote = 0;
1254
1312
  p.ev |= EV.WALLRUN_START;
1255
1313
  return;
@@ -1257,7 +1315,7 @@ var startRun = (p, w, c) => {
1257
1315
  }
1258
1316
  };
1259
1317
  /** Takes hold of a ledge: hang there. */
1260
- var grab = (p, l) => {
1318
+ var grab = (p, l, dashes) => {
1261
1319
  enter(p, MODE.HANG);
1262
1320
  p.wall = l.side;
1263
1321
  p.edge = f32$2(l.top);
@@ -1265,7 +1323,7 @@ var grab = (p, l) => {
1265
1323
  else p.z = l.hang;
1266
1324
  p.vx = p.vy = p.vz = 0;
1267
1325
  p.jumps = 1;
1268
- p.dashes = 1;
1326
+ p.dashes = dashes;
1269
1327
  p.coyote = 0;
1270
1328
  p.buffer = 0;
1271
1329
  p.ev |= EV.GRAB;
@@ -1273,8 +1331,11 @@ var grab = (p, l) => {
1273
1331
  /** The modes that move freely: everything but the hang and the climb. */
1274
1332
  var free$1 = (p, w, c) => {
1275
1333
  const ground = p.mode === MODE.GROUND;
1276
- if (c.dash && p.dash === 0 && (ground || (p.mode === MODE.AIR || p.mode === MODE.WALLRUN) && p.dashes > 0)) {
1334
+ const chain = c.kit.dashes > 1;
1335
+ if (chain && ground && p.dash === 0) p.dashes = c.kit.dashes;
1336
+ if (c.dash && (p.dash === 0 || chain && p.dashes > 0 && p.dash <= 44) && (ground ? !chain || p.dashes > 0 : (p.mode === MODE.AIR || p.mode === MODE.WALLRUN) && p.dashes > 0)) {
1277
1337
  const [dx, dz] = c.wx || c.wz ? [c.wx, c.wz] : [c.fx, c.fz];
1338
+ p.dashes -= +(ground && chain);
1278
1339
  if (!ground) {
1279
1340
  p.dashes--;
1280
1341
  p.vy = 0;
@@ -1300,7 +1361,7 @@ var free$1 = (p, w, c) => {
1300
1361
  p.ev |= EV.LAND | (p.mode === MODE.WALLRUN ? EV.WALLRUN_END : 0);
1301
1362
  p.fall = hit;
1302
1363
  p.jumps = 1;
1303
- p.dashes = 1;
1364
+ p.dashes = c.kit.dashes;
1304
1365
  p.wall = SIDE.NONE;
1305
1366
  if (c.keys & KEY.CROUCH) {
1306
1367
  const slide = len$1(p.vx, p.vz) >= SLIDE_MIN_SPEED;
@@ -1315,7 +1376,7 @@ var free$1 = (p, w, c) => {
1315
1376
  }
1316
1377
  if (p.mode === MODE.AIR) {
1317
1378
  const ledge = ledgeAt(p, w);
1318
- if (ledge) grab(p, ledge);
1379
+ if (ledge) grab(p, ledge, c.kit.dashes);
1319
1380
  else startRun(p, w, c);
1320
1381
  }
1321
1382
  };
@@ -1325,7 +1386,7 @@ var onGround = (p, w, c, burst) => {
1325
1386
  if (p.buffer > 0 && (p.mode === MODE.GROUND || canStand(p, w))) {
1326
1387
  p.ev |= p.mode === MODE.SLIDE ? EV.SLIDE_END : 0;
1327
1388
  enter(p, MODE.AIR);
1328
- leap(p, 7);
1389
+ leap(p, c.kit.jump);
1329
1390
  return;
1330
1391
  }
1331
1392
  const speed = len$1(p.vx, p.vz);
@@ -1354,16 +1415,17 @@ var onGround = (p, w, c, burst) => {
1354
1415
  } else if (p.mode === MODE.CROUCH) steer(p, unwalled(p, w, c, LOW_H), 3);
1355
1416
  else {
1356
1417
  const sprint = (c.keys & KEY.SPRINT) !== 0 && c.fwd;
1357
- steer(p, unwalled(p, w, c, PLAYER_H), sprint ? 9 : 6);
1418
+ const run = c.kit.run * c.pace;
1419
+ steer(p, unwalled(p, w, c, PLAYER_H), sprint ? c.kit.sprint * c.pace : run, run);
1358
1420
  }
1359
1421
  };
1360
1422
  /** In the air: the extra jump, a jump just after an edge (coyote), and air control. */
1361
1423
  var air = (p, w, c, burst) => {
1362
1424
  if (p.buffer > 0) {
1363
- if (p.coyote > 0) leap(p, 7);
1425
+ if (p.coyote > 0) leap(p, c.kit.jump);
1364
1426
  else if (p.jumps > 0 && !landingSoon(p, w)) {
1365
1427
  p.jumps--;
1366
- leap(p, 6);
1428
+ leap(p, c.kit.double);
1367
1429
  p.ev = p.ev & ~EV.JUMP | EV.DOUBLE;
1368
1430
  }
1369
1431
  }
@@ -1379,7 +1441,7 @@ var air = (p, w, c, burst) => {
1379
1441
  * kill floor put the player back at a spawn of his `team` (EV.RESPAWN). `bodies` are the rovers'
1380
1442
  * (hull(), rover.ts) as they stand when the step runs: walls and floors for this step alone.
1381
1443
  */
1382
- var move = (p, i, w, team = 0, bodies = []) => {
1444
+ var move = (p, i, w, team = 0, bodies = [], kit = KITS[0]) => {
1383
1445
  p.yaw = norm(i.yaw);
1384
1446
  p.pitch = Math.max(-MAX_PITCH, Math.min(MAX_PITCH, i.pitch));
1385
1447
  const f = (i.keys & KEY.FORWARD ? 1 : 0) - (i.keys & KEY.BACK ? 1 : 0);
@@ -1399,7 +1461,9 @@ var move = (p, i, w, team = 0, bodies = []) => {
1399
1461
  wz: (fz * f + fx * s) / n,
1400
1462
  fx,
1401
1463
  fz,
1402
- bodies
1464
+ bodies,
1465
+ kit,
1466
+ pace: !p.wield && (p.ammo >= 0 || (p.rail ?? -1) >= 0 || (p.rifle ?? -1) >= 0) ? kit.slow : 1
1403
1467
  };
1404
1468
  const before = p.mode;
1405
1469
  p.ev = 0;
@@ -1848,7 +1912,7 @@ var STRIKE = {
1848
1912
  * stays in hand for the length of a swing. `wield` is the katana in hand, `railed` the rail gun.
1849
1913
  * - The gun fires from its battery (`mag`), the rail gun from its capsule (`cap`). An empty one, or
1850
1914
  * KEY.RELOAD with room in it, swaps it for a full one from what he carries: `reload` ticks
1851
- * without firing, then it holds GUN_MAG (RAIL_CAP) or what is left. A switch of weapon drops it.
1915
+ * without firing, then it holds the kit's `mag` (`cap`, `clip`) or what is left. A switch of weapon drops it.
1852
1916
  * The racks fill both.
1853
1917
  * - The rail gun throws its bolt on every step FIRE is held, spending a tick of it (`zapping`),
1854
1918
  * unless it is `hot`: its `heat` rises while it fires and falls when it does not (HEAT_MAX).
@@ -1865,13 +1929,13 @@ var STRIKE = {
1865
1929
  * its swing. The look is the input's, so both go where the player sees.
1866
1930
  * `armed` is false while the match is over: no weapon, no rack. `bodies` are move()'s.
1867
1931
  */
1868
- var step = (p, i, w, team, armed = true, bodies = []) => {
1932
+ var step = (p, i, w, team, armed = true, bodies = [], kit = KITS[0]) => {
1869
1933
  const down = p.down > 0;
1870
1934
  const locked = !down && (p.lock ?? 0) > 0;
1871
1935
  move(p, down || locked ? {
1872
1936
  ...i,
1873
1937
  keys: 0
1874
- } : i, w, team, bodies);
1938
+ } : i, w, team, bodies, kit);
1875
1939
  p.heat = Math.max(0, (p.heat ?? 0) - (p.zapping ? 0 : p.hot ? 1 : 2));
1876
1940
  p.hot = !!p.hot && p.heat > 0;
1877
1941
  p.zapping = false;
@@ -1883,19 +1947,27 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
1883
1947
  if (locked) return duel(p, i);
1884
1948
  const { rack, blade, rail, rifle } = w.def.teams[team];
1885
1949
  const inside = !!rack && within(p, rack, 1.2);
1886
- if (armed && inside && !p.rack) [p.ammo, p.mag] = [60, 15];
1950
+ if (armed && inside && !p.rack) [p.ammo, p.mag] = [kit.ammo, kit.mag];
1887
1951
  p.rack = inside;
1888
1952
  p.blade = !!p.blade || armed && !!blade && within(p, blade, 1.2);
1889
1953
  const inRail = !!rail && within(p, rail, 1.2);
1890
- if (armed && inRail && !p.inRail) [p.rail, p.cap] = [240, 80];
1954
+ if (armed && inRail && !p.inRail) [p.rail, p.cap] = [kit.rail, kit.cap];
1891
1955
  p.inRail = inRail;
1892
1956
  const inRifle = !!rifle && within(p, rifle, 1.2);
1893
1957
  if (armed && inRifle && !p.inRifle) [p.rifle, p.clip, p.nades] = [
1894
- 240,
1895
- 60,
1958
+ kit.rifle,
1959
+ kit.clip,
1896
1960
  3
1897
1961
  ];
1898
1962
  p.inRifle = inRifle;
1963
+ p.ammo = Math.min(p.ammo, kit.ammo);
1964
+ p.rail = p.rail === void 0 ? p.rail : Math.min(p.rail, kit.rail);
1965
+ p.rifle = p.rifle === void 0 ? p.rifle : Math.min(p.rifle, kit.rifle);
1966
+ [p.mag, p.cap, p.clip] = [
1967
+ Math.min(p.mag ?? 0, kit.mag),
1968
+ Math.min(p.cap ?? 0, kit.cap),
1969
+ Math.min(p.clip ?? 0, kit.clip)
1970
+ ];
1899
1971
  p.cool = Math.max(0, p.cool - 1);
1900
1972
  p.lob = Math.max(0, (p.lob ?? 0) - 1);
1901
1973
  const busy = p.mode === MODE.HANG || p.mode === MODE.CLIMB;
@@ -1907,7 +1979,10 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
1907
1979
  p.swing = swingOf(p).ticks;
1908
1980
  } else {
1909
1981
  p.charge = top ? 0 : p.charge;
1910
- p.swing = Math.max(0, (p.swing ?? 0) - 1);
1982
+ const s = p.swing ?? 0;
1983
+ const c = swingOf(p);
1984
+ const stop = (v) => v == s - 1 && (v == c.ticks - c.strike || v == PUNCH.ticks - PUNCH.strike || !p.heavy && v == ticks - hold);
1985
+ p.swing = Math.max(0, kit.haste > 1 && stop(s - 1) ? s - 1 : s - kit.haste);
1911
1986
  p.heavy = !!p.swing && !!p.heavy;
1912
1987
  }
1913
1988
  p.mag = Math.min(p.mag ?? 0, Math.max(p.ammo, 0));
@@ -1932,17 +2007,17 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
1932
2007
  }
1933
2008
  const [key, size, carried, ticks2] = hand == 3 ? [
1934
2009
  "clip",
1935
- 60,
2010
+ kit.clip,
1936
2011
  p.rifle,
1937
2012
  96
1938
2013
  ] : hand == 2 ? [
1939
2014
  "cap",
1940
- 80,
2015
+ kit.cap,
1941
2016
  p.rail,
1942
2017
  90
1943
2018
  ] : [
1944
2019
  "mag",
1945
- 15,
2020
+ kit.mag,
1946
2021
  p.ammo,
1947
2022
  78
1948
2023
  ];
@@ -1977,7 +2052,7 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
1977
2052
  if (!p.cool && p.clip && !p.reload) {
1978
2053
  p.rifle--;
1979
2054
  p.clip--;
1980
- p.cool = 3;
2055
+ p.cool = kit.rifleCool;
1981
2056
  p.shots = p.shots + 1 & 255;
1982
2057
  return STRIKE.LASER;
1983
2058
  }
@@ -2000,7 +2075,7 @@ var step = (p, i, w, team, armed = true, bodies = []) => {
2000
2075
  p.ammo -= p.power;
2001
2076
  p.mag = p.mag - p.power;
2002
2077
  p.shots = p.shots + 1 & 255;
2003
- p.cool = 7;
2078
+ p.cool = kit.cool;
2004
2079
  return STRIKE.SHOT;
2005
2080
  }
2006
2081
  return STRIKE.NONE;
@@ -4927,12 +5002,12 @@ var encodeSnapshot = (s) => {
4927
5002
  v.setUint16(o + 29, toTurn(p.yaw));
4928
5003
  v.setInt16(o + 31, toPitch(p.pitch));
4929
5004
  v.setUint16(o + 33, p.ack & 65535);
4930
- v.setUint8(o + 35, p.mode & 7 | (p.wall & 7) << 3 | (p.jumps & 1) << 6 | p.dashes << 7);
5005
+ v.setUint8(o + 35, p.mode & 7 | (p.wall & 7) << 3 | (p.jumps & 1) << 6 | (p.dashes & 1) << 7);
4931
5006
  v.setUint8(o + 36, p.t);
4932
5007
  v.setUint8(o + 37, p.dash | (p.by >> 2 & 3) << 6);
4933
5008
  v.setUint8(o + 38, p.coyote & 7 | (p.buffer & 7) << 3 | (p.held & KEY.JUMP ? 64 : 0) | (p.held & KEY.DASH ? 128 : 0));
4934
5009
  v.setUint8(o + 39, p.stun | (p.by & 3) << 6);
4935
- const gun = p.hp | p.cool << 3 | (p.ammo < 0 ? NO_GUN : p.ammo) << 6 | p.down << 13 | +!!p.rack << 20 | +!!p.blade << 21 | +!!p.wield << 22 | +!!p.zap << 23;
5010
+ const gun = p.hp | (p.cool & 7) << 3 | (p.ammo < 0 ? NO_GUN : p.ammo) << 6 | p.down << 13 | +!!p.rack << 20 | +!!p.blade << 21 | +!!p.wield << 22 | +!!p.zap << 23;
4936
5011
  v.setUint8(o + 40, gun >> 16);
4937
5012
  v.setUint16(o + 41, gun & 65535);
4938
5013
  v.setUint8(o + 43, p.shots);
@@ -4941,11 +5016,11 @@ var encodeSnapshot = (s) => {
4941
5016
  v.setUint8(o + 46, (p.lost ?? 0) & 7 | ((p.cut ?? 0) & 4) << 1 | (p.fried ? 16 : 0) | (p.heavy ? 32 : 0));
4942
5017
  v.setUint8(o + 47, p.charge ?? 0);
4943
5018
  v.setUint8(o + 48, p.lock ?? 0);
4944
- v.setUint8(o + 49, (p.foe ?? 0) & 15 | (p.pressed ? 128 : 0));
5019
+ v.setUint8(o + 49, (p.foe ?? 0) & 15 | (p.dashes & 2) << 3 | (p.pressed ? 128 : 0));
4945
5020
  v.setUint8(o + 50, p.pushes ?? 0);
4946
5021
  v.setUint8(o + 51, p.away ?? 0);
4947
5022
  v.setUint8(o + 52, (p.rail ?? -1) + 1);
4948
- v.setUint8(o + 53, +!!p.railed | +!!p.inRail << 1 | +!!p.zapping << 2 | +!!p.rifled << 3 | +!!p.inRifle << 4 | +!!p.hot << 5 | (p.held & KEY.USE ? 64 : 0));
5023
+ v.setUint8(o + 53, +!!p.railed | +!!p.inRail << 1 | +!!p.zapping << 2 | +!!p.rifled << 3 | +!!p.inRifle << 4 | +!!p.hot << 5 | (p.held & KEY.USE ? 64 : 0) | (p.cool & 8) << 4);
4949
5024
  v.setUint8(o + 54, p.slow ?? 0);
4950
5025
  v.setUint8(o + 55, p.mag ?? 0);
4951
5026
  v.setUint8(o + 56, p.cap ?? 0);
@@ -6237,6 +6312,26 @@ var SPAWN_CLEAR = 2;
6237
6312
  var SPLAT_COOLDOWN = 30;
6238
6313
  /** The two seats of a rover, the driver's first. */
6239
6314
  var SEATS = ["driver", "rider"];
6315
+ /** An index in [0, n), or undefined. */
6316
+ var index = (v, n) => Number.isInteger(v) && v >= 0 && v < n ? v : void 0;
6317
+ /**
6318
+ * What a player picked, only what the game knows: the woman's body (the man's is no field, so an old
6319
+ * roster is unchanged), a skin, a haircut of that body and a class (ROLE: the map says which it offers).
6320
+ */
6321
+ var chosen = (m) => {
6322
+ const body = m.body === BODY.FEMALE ? BODY.FEMALE : void 0;
6323
+ const [tone, hair, role] = [
6324
+ index(m.tone, 6),
6325
+ index(m.hair, HAIRS_N[body ?? 0]),
6326
+ index(m.role, 3)
6327
+ ];
6328
+ return {
6329
+ ...body !== void 0 ? { body } : {},
6330
+ ...tone !== void 0 ? { tone } : {},
6331
+ ...hair !== void 0 ? { hair } : {},
6332
+ ...role !== void 0 ? { role } : {}
6333
+ };
6334
+ };
6240
6335
  /** First n characters (code points) of s, trimmed. */
6241
6336
  var cut = (s, n) => Array.from(s).slice(0, n).join("").trim();
6242
6337
  var cleanName = (raw) => cut((typeof raw === "string" ? raw : "").replace(/\s+/g, " ").replace(/\p{Cc}/gu, "").trim(), 16);
@@ -6396,14 +6491,23 @@ var Room = class {
6396
6491
  const p = this.peers.get(conn);
6397
6492
  if (typeof data === "string") {
6398
6493
  const msg = parseText(data);
6399
- if (p === null && msg?.t === "join") this.join(conn, msg.name, msg.body);
6494
+ if (p === null && msg?.t === "join") this.join(conn, msg.name, msg);
6400
6495
  else if (p && msg?.t === "map" && p === this.host() && Object.hasOwn(MAPS, msg.map)) {
6401
6496
  this.next = msg.map === this.mapName ? void 0 : msg.map;
6402
6497
  this.roster();
6403
- } else if (p && msg?.t === "body" && msg.body === BODY.FEMALE !== !!p.info.body) {
6404
- if (msg.body === BODY.FEMALE) p.info.body = BODY.FEMALE;
6405
- else delete p.info.body;
6406
- this.roster();
6498
+ } else if (p && msg?.t === "body") {
6499
+ const { id, name, team, color } = p.info;
6500
+ const info = {
6501
+ id,
6502
+ name,
6503
+ team,
6504
+ color,
6505
+ ...chosen(msg)
6506
+ };
6507
+ if (JSON.stringify(info) !== JSON.stringify(p.info)) {
6508
+ p.info = info;
6509
+ this.roster();
6510
+ }
6407
6511
  }
6408
6512
  return;
6409
6513
  }
@@ -6424,7 +6528,7 @@ var Room = class {
6424
6528
  this.lase(p, r, input);
6425
6529
  }
6426
6530
  } else {
6427
- const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over, solid(this.rovers, p.state));
6531
+ const struck = step(p.state, input, this.world, p.info.team, !this.ctf.over, solid(this.rovers, p.state), kitOf(p.info.role, this.world.def));
6428
6532
  this.ctf.moved(p.state);
6429
6533
  this.tackle(p, input.view);
6430
6534
  const here = spot(p.state);
@@ -6658,13 +6762,23 @@ var Room = class {
6658
6762
  });
6659
6763
  }
6660
6764
  /**
6765
+ * `hp` of a gun's damage to `foe` from `by`: as his class deals it (Kit.damage, a ninja's half), the
6766
+ * half points kept on `foe` toward the next. True when he went down.
6767
+ */
6768
+ shot(foe, hp, by) {
6769
+ const bank = (foe.halves ?? 0) + hp * 2 * (by ? kitOf(by.info.role, this.world.def).damage : 1);
6770
+ foe.halves = bank % 2;
6771
+ return bank >= 2 && this.harm(foe, Math.floor(bank / 2));
6772
+ }
6773
+ /**
6661
6774
  * `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
6662
6775
  * the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
6663
6776
  * True when he went down.
6664
6777
  */
6665
6778
  harm(foe, hp) {
6666
6779
  if ((foe.state.hp -= hp) > 0) return false;
6667
- [foe.graze, foe.bruise, foe.blows] = [
6780
+ [foe.graze, foe.bruise, foe.blows, foe.halves] = [
6781
+ 0,
6668
6782
  0,
6669
6783
  0,
6670
6784
  0
@@ -6754,8 +6868,8 @@ var Room = class {
6754
6868
  if (by) by.state.hits = by.state.hits + 1 & 255;
6755
6869
  if (b.power === 0 || b.power === 6) {
6756
6870
  foe.graze = ((foe.graze ?? 0) + 1) % 2;
6757
- if (!foe.graze) this.harm(foe, 1);
6758
- } else if (!b.arc) this.harm(foe, b.power ?? 1);
6871
+ if (!foe.graze) this.shot(foe, 1, by);
6872
+ } else if (!b.arc) this.shot(foe, b.power ?? 1, by);
6759
6873
  else if (this.harm(foe, CUTS[b.arc].hp)) {
6760
6874
  const from = by && {
6761
6875
  ...by.state,
@@ -6893,14 +7007,14 @@ var Room = class {
6893
7007
  foe.state.slow = 180;
6894
7008
  if (fresh) {
6895
7009
  p.state.hits = p.state.hits + 1 & 255;
6896
- foe.burn = 0;
7010
+ [foe.burn, foe.railer] = [0, p];
6897
7011
  this.fry(foe);
6898
7012
  }
6899
7013
  }
6900
7014
  }
6901
- /** 1 hp of the bolt's drain to `foe`; if it puts him down he is disintegrated (`fried`). */
7015
+ /** 1 hp of the bolt's drain to `foe`, as his railer deals it; if it puts him down he is disintegrated (`fried`). */
6902
7016
  fry(foe) {
6903
- foe.state.fried = this.harm(foe, 1);
7017
+ foe.state.fried = this.shot(foe, 1, foe.railer);
6904
7018
  }
6905
7019
  /**
6906
7020
  * A saber lock of `p`, after his input: it ends when a side leads by LOCK_WIN presses (the other
@@ -6956,19 +7070,23 @@ var Room = class {
6956
7070
  return;
6957
7071
  }
6958
7072
  const kind = +(k >= packs.length) + +(k >= packs.length + ammo.length);
6959
- const wants = (q) => [
6960
- q.hp < 5,
6961
- q.ammo >= 0 && q.ammo < 60 || (q.rifle ?? -1) >= 0 && q.rifle < 240,
6962
- (q.rail ?? -1) >= 0 && q.rail < 240
6963
- ][kind];
6964
- const p = players.find(({ state: q }) => !q.down && wants(q) && within(q, at, .9));
7073
+ const wants = ({ state: q, info }) => {
7074
+ const kit = kitOf(info.role, this.world.def);
7075
+ return [
7076
+ q.hp < 5,
7077
+ q.ammo >= 0 && q.ammo < kit.ammo || (q.rifle ?? -1) >= 0 && q.rifle < kit.rifle,
7078
+ (q.rail ?? -1) >= 0 && q.rail < kit.rail
7079
+ ][kind];
7080
+ };
7081
+ const p = players.find((o) => !o.state.down && wants(o) && within(o.state, at, .9));
6965
7082
  if (p) {
6966
7083
  const q = p.state;
7084
+ const kit = kitOf(p.info.role, this.world.def);
6967
7085
  if (kind == 0) q.hp = Math.min(5, q.hp + 2);
6968
7086
  else if (kind == 1) {
6969
- q.ammo = q.ammo < 0 ? -1 : Math.min(60, q.ammo + 20);
6970
- q.rifle = (q.rifle ?? -1) < 0 ? -1 : Math.min(240, q.rifle + 60);
6971
- } else q.rail = Math.min(240, q.rail + 80);
7087
+ q.ammo = q.ammo < 0 ? -1 : Math.min(kit.ammo, q.ammo + 20);
7088
+ q.rifle = (q.rifle ?? -1) < 0 ? -1 : Math.min(kit.rifle, q.rifle + 60);
7089
+ } else q.rail = Math.min(kit.rail, q.rail + 80);
6972
7090
  this.gone[k] = (kind == 1 ? 10 : 20) * 60;
6973
7091
  }
6974
7092
  });
@@ -7208,7 +7326,7 @@ var Room = class {
7208
7326
  const own = q.info.id === by;
7209
7327
  const hp = !q.state.down && q.state.mode !== MODE.RIDE && (own || q.info.team !== team) ? blast(this.world, c, q.state) : 0;
7210
7328
  if (hp) {
7211
- this.harm(q, hp);
7329
+ this.shot(q, hp, this.players().find((o) => o.info.id === by));
7212
7330
  hit ||= !own;
7213
7331
  }
7214
7332
  }
@@ -7281,7 +7399,7 @@ var Room = class {
7281
7399
  players() {
7282
7400
  return [...this.peers.values()].filter((p) => p !== null);
7283
7401
  }
7284
- join(conn, name, body) {
7402
+ join(conn, name, picked = {}) {
7285
7403
  const players = this.players();
7286
7404
  if (players.length >= this.rules.maxPlayers) {
7287
7405
  conn.send(JSON.stringify({ t: "full" }));
@@ -7298,7 +7416,7 @@ var Room = class {
7298
7416
  name: unique(cleanName(name) || `Player ${id}`, players.map((p) => p.info.name)),
7299
7417
  team,
7300
7418
  color: TEAM_COLOR[team],
7301
- ...body === BODY.FEMALE ? { body } : {}
7419
+ ...chosen(picked)
7302
7420
  },
7303
7421
  state: this.place(id, team, players.map((p) => p.state)),
7304
7422
  since: this.joins++,
@@ -25,6 +25,8 @@ interface Region {
25
25
  round?: [number, number, number];
26
26
  /** Moulded: a smooth shell round the trunk rather than the skin's facets (moulding()). */
27
27
  mould?: boolean;
28
+ /** The ninja's own armour (the user, 2026-11-13), worn by him alone; he wears no other plate. */
29
+ alone?: boolean;
28
30
  }
29
31
  /**
30
32
  * The chest plate's pecs (the user, 2026-11-10: fuller toward the bottom, then the round part too
@@ -92,6 +94,18 @@ export declare const BAND: {
92
94
  };
93
95
  /** The gap the user asked between the chest plate and the belly's plates, and between those. */
94
96
  export declare const GAP = 0.02;
97
+ /**
98
+ * The ninja's vest: the bottom of its chest piece at the sides, how far its chevron dips at the
99
+ * middle (and the lames' under it), the bottom of the V at its neck, the lames' height and the gap
100
+ * between two pieces.
101
+ */
102
+ export declare const VEST: {
103
+ y: number;
104
+ dip: number;
105
+ neck: number;
106
+ lame: number;
107
+ gap: number;
108
+ };
95
109
  export declare const REGIONS: Region[];
96
110
  /** A corner being clipped: its place at rest, its weights of its skin triangle's corners, its normal at rest, then the limits it lies on (BITS). */
97
111
  type Corner = number[];
@@ -112,7 +126,7 @@ export declare const DOME: {
112
126
  * Appends the armour cut out of the skin `s` drawn into `out` from the float `from` on (skin()
113
127
  * writes three vertices per triangle of s.t, in order). Not `fine` (a runner not close by), curved
114
128
  * outlines follow the skin's own triangles, unrefined, and there are no scratches. `plate` is the
115
- * plates' colour (their walls a shade darker): white when absent.
129
+ * plates' colour (their walls a shade darker): white when absent. The `ninja` wears his own armour.
116
130
  */
117
- export declare const armor: (out: number[], from: number, s: Skin, fine?: boolean, plate?: number[]) => void;
131
+ export declare const armor: (out: number[], from: number, s: Skin, fine?: boolean, plate?: number[], ninja?: boolean) => void;
118
132
  export {};
@@ -25,8 +25,8 @@ export interface Body {
25
25
  pose(eye: Vec3, yaw: number, pitch: number, roll?: number): Solved | undefined;
26
26
  /** Appends the body's vertices (see STRIDE) in the jacket `color`; nothing when pose() has none. */
27
27
  draw(out: number[], eye: Vec3, yaw: number, pitch: number, roll?: number, color?: number[]): void;
28
- /** The own player's character (BUILD in rig.ts, PlayerInfo.body): the woman's arms are slimmer and her hands smaller, on the same grips. */
29
- wear(build: number): void;
28
+ /** The own player's character (BUILD in rig.ts, PlayerInfo.body): the woman's arms are slimmer and her hands smaller, on the same grips; `tone` the skin he picked (the default's when absent). */
29
+ wear(build: number, tone?: number[], ninja?: boolean): void;
30
30
  }
31
31
  export declare const inv: ([x, y, z, w]: Quat) => Quat;
32
32
  /**
@@ -96,6 +96,10 @@ export declare const hash: (id: number, salt: number) => number;
96
96
  export declare const TONES: number[][];
97
97
  /** A skin tone for the runner `id`, the same for everyone who sees him. */
98
98
  export declare const toneOf: (id: number) => number[];
99
+ /** The skin tone the player picked (`c.tone`, an index of TONES), else his id's. */
100
+ export declare const toneFor: (id: number, c?: {
101
+ tone?: number;
102
+ }) => number[];
99
103
  /**
100
104
  * The face of the runner `id`: the weights of the trait channels (the expressions' are 0), the
101
105
  * same for everyone who sees him. Each trait is the mean of two draws, so most faces are near the
@@ -8,8 +8,10 @@ export declare const STYLE: {
8
8
  readonly UNDERCUT: 4;
9
9
  };
10
10
  export declare const STYLES: number;
11
- /** The hair style of the woman `id`: the same for everyone who sees her. */
12
- export declare const styleOf: (id: number) => number;
11
+ /** The hair style of the woman `id`: the one she picked (`c.hair`), else her id's, the same for everyone who sees her. */
12
+ export declare const styleOf: (id: number, c?: {
13
+ hair?: number;
14
+ }) => number;
13
15
  /** The woman's head to the man's (SCALE in skin.ts), and the lowest a style may hang on the man's head at rest, metres: the chin's height. */
14
16
  export declare const HEAD_SCALE: number, LOWEST: number;
15
17
  /** The style's rest mesh (make()), built once per style and fineness. */
@@ -1,13 +1,21 @@
1
1
  import type { Result } from '../shared/protocol';
2
- import type { PlayerState, Rover, Snapshot } from '../shared/types';
2
+ import type { Choice, PlayerState, Rover, Snapshot } from '../shared/types';
3
3
  import type { Mark } from './marks';
4
4
  export declare const rim: () => [number, number][];
5
5
  export declare const HUD_CSS: string;
6
+ /** The menu of a game paused by Escape (the user, 2026-11-12): play on, then the two parts of the title screen it opens, then leave. */
7
+ export declare const PAUSE: string[];
6
8
  /** The tabs of the title screen's menu, the first one shown first. */
7
9
  export declare const TABS: string[];
8
- /** The characters' first names (the user, 2026-11-11: names, not "man" and "woman"), in BODY's order, and the size of a card's picture in pixels. */
10
+ /** The characters' first names (the user, 2026-11-11: names, not "man" and "woman"), in BODY's order, and the size of the character's picture in pixels. */
9
11
  export declare const CAST: string[];
10
12
  export declare const SHOT: number[];
13
+ /** The size of a haircut's picture, pixels. */
14
+ export declare const HEAD_PX = 112;
15
+ /** The haircuts of each body, in HAIRS_N's order: the man's by length (LENGTHS, soldier.ts), the woman's STYLE (hair.ts). */
16
+ export declare const HAIR_NAMES: string[][];
17
+ /** The classes, in ROLE's order (kit.ts): the name, what it does, and where it plays. */
18
+ export declare const ROLES: [name: string, does: string, where: string][];
11
19
  /** Capture the flag in a few lines, with the room's default rules. */
12
20
  export declare const GOAL: string[];
13
21
  /**
@@ -39,16 +47,22 @@ export interface Hud {
39
47
  */
40
48
  title(status: string, name: string, tag?: string, lore?: string): void;
41
49
  /**
42
- * The character cards of the title screen: `pick` is told the BODY of the card the player
43
- * chooses. Returns the cards' canvases, in BODY's order, for their pictures (SHOT pixels).
50
+ * Whether the player has been in the game: then the title screen opens on the pause menu (PAUSE)
51
+ * rather than the whole panel, until he plays again.
44
52
  */
45
- cast(pick: (body: number) => void): HTMLCanvasElement[];
53
+ paused(on: boolean): void;
46
54
  /**
47
- * The maps in the title screen's Game panel, [key, name] each: the one the next match plays (`next`, else
48
- * `played`) stands out. They are buttons that `pick` when the own player is the host (`mine`),
49
- * read-only for the others; `host` is his name.
55
+ * The character on the title screen: `pick` is told the whole choice (the body, the skin, the
56
+ * haircut, the class) each time the player changes a part of it. Returns the canvas of his live
57
+ * picture (SHOT pixels).
50
58
  */
51
- maps(list: [string, string][], played: string, next: string | undefined, host: string, mine: boolean, pick: (key: string) => void): void;
59
+ cast(pick: (c: Choice & {
60
+ body: number;
61
+ }) => void): HTMLCanvasElement;
62
+ /** The pictures of the haircuts on offer, in their order (HEAD_PX square): the own head with each. */
63
+ heads(): HTMLCanvasElement[];
64
+ /** The own player's magazines, as his class holds them (Kit's mag, cap, clip): the spare ones counted by them. */
65
+ magazines(sizes: number[]): void;
52
66
  /** Shows or hides the muted mark. */
53
67
  mute(on: boolean): void;
54
68
  /**
@@ -78,8 +92,12 @@ export interface Hud {
78
92
  hit(): void;
79
93
  /** The face over the health, frame `n` of face.ts (-1 hides it). */
80
94
  face(n: number): void;
81
- /** The own player's character (BODY): the face is hers when she is the woman, and her card is the chosen one. */
82
- wear(body: number): void;
95
+ /**
96
+ * The own player's character (BODY): the face is hers when she is the woman. `c` is what the
97
+ * roster says he picked, shown chosen on the title screen, and `roles` the classes the map offers
98
+ * (ROLE): the others are greyed out.
99
+ */
100
+ wear(body: number, c?: Choice, roles?: number[]): void;
83
101
  /**
84
102
  * A saber lock: the gauge of the tug of war under the crosshair, with `lead` the own side's, -1
85
103
  * (the foe wins) to 1 (he wins); undefined hides it.
@@ -129,4 +147,4 @@ export declare const clock: (s: number) => string;
129
147
  * Appends the HUD to `screen`, whose stylesheet has HUD_CSS. `play` is the title screen's button:
130
148
  * the click that starts the game (the panel takes its other clicks, the view round it plays too).
131
149
  */
132
- export declare const createHud: (screen: HTMLElement, play?: () => void) => Hud;
150
+ export declare const createHud: (screen: HTMLElement, play?: () => void, quit?: () => void) => Hud;