@kbve/laser 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/laser.es.js +1675 -140
  2. package/package.json +1 -1
package/laser.es.js CHANGED
@@ -1,31 +1,118 @@
1
- import { createContext as e, forwardRef as t, useContext as n, useEffect as r, useImperativeHandle as i, useMemo as a, useRef as o, useState as s } from "react";
2
- import c from "phaser";
3
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
4
- import { Canvas as d, useFrame as f } from "@react-three/fiber";
5
- import { query as p } from "bitecs";
6
- import { RAPIER as m, createRapierPhysics as h } from "@phaserjs/rapier-connector";
1
+ import { createContext as e, forwardRef as t, useContext as n, useEffect as r, useImperativeHandle as i, useMemo as a, useRef as o, useState as s, useSyncExternalStore as c } from "react";
2
+ import l from "phaser";
3
+ import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
4
+ import { Canvas as ee, useFrame as p } from "@react-three/fiber";
5
+ import { query as m } from "bitecs";
6
+ import { RAPIER as h, createRapierPhysics as g } from "@phaserjs/rapier-connector";
7
7
  export * from "bitecs";
8
8
  //#region \0rolldown/runtime.js
9
- var g = class {
9
+ var _ = Object.defineProperty, v = Object.getOwnPropertyDescriptor, te = Object.getOwnPropertyNames, ne = Object.prototype.hasOwnProperty, re = (e, t) => {
10
+ let n = {};
11
+ for (var r in e) _(n, r, {
12
+ get: e[r],
13
+ enumerable: !0
14
+ });
15
+ return t || _(n, Symbol.toStringTag, { value: "Module" }), n;
16
+ }, ie = (e, t, n, r) => {
17
+ if (t && typeof t == "object" || typeof t == "function") for (var i = te(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !ne.call(e, s) && s !== n && _(e, s, {
18
+ get: ((e) => t[e]).bind(null, s),
19
+ enumerable: !(r = v(t, s)) || r.enumerable
20
+ });
21
+ return e;
22
+ }, ae = (e, t, n) => (ie(e, t, "default"), n && ie(n, t, "default")), y = class {
10
23
  handlers = /* @__PURE__ */ new Map();
24
+ errorHandlers = /* @__PURE__ */ new Set();
25
+ history = [];
26
+ trace = !1;
27
+ historySize = 0;
11
28
  on(e, t) {
12
29
  let n = this.handlers.get(e);
13
30
  return n || (n = /* @__PURE__ */ new Set(), this.handlers.set(e, n)), n.add(t), () => {
14
31
  n.delete(t);
15
32
  };
16
33
  }
34
+ once(e, t) {
35
+ let n = this.on(e, ((e) => {
36
+ n(), t(e);
37
+ }));
38
+ return n;
39
+ }
17
40
  off(e, t) {
18
41
  this.handlers.get(e)?.delete(t);
19
42
  }
20
43
  emit(e, t) {
21
- this.handlers.get(e)?.forEach((e) => {
22
- e(t);
23
- });
44
+ (this.trace || this.historySize > 0) && this.record(e, t);
45
+ let n = this.handlers.get(e);
46
+ if (n) for (let r of [...n]) try {
47
+ r(t);
48
+ } catch (n) {
49
+ this.reportError(n, String(e), t);
50
+ }
24
51
  }
25
- clear() {
26
- this.handlers.clear();
52
+ onError(e) {
53
+ return this.errorHandlers.add(e), () => {
54
+ this.errorHandlers.delete(e);
55
+ };
27
56
  }
28
- }, _ = new g(), v = class e {
57
+ setDebug(e) {
58
+ e.trace !== void 0 && (this.trace = e.trace), e.historySize !== void 0 && (this.historySize = Math.max(0, e.historySize), this.history.length > this.historySize && this.history.splice(0, this.history.length - this.historySize));
59
+ }
60
+ getHistory() {
61
+ return this.history;
62
+ }
63
+ dumpHistory() {
64
+ console.table(this.history.map((e) => ({
65
+ event: e.event,
66
+ time: new Date(e.time).toISOString().slice(11, 23),
67
+ data: e.data
68
+ })));
69
+ }
70
+ listenerCount(e) {
71
+ return this.handlers.get(e)?.size ?? 0;
72
+ }
73
+ eventNames() {
74
+ return [...this.handlers.keys()];
75
+ }
76
+ clear() {
77
+ this.handlers.clear(), this.history.length = 0;
78
+ }
79
+ record(e, t) {
80
+ this.trace && console.debug(`[laser] ${String(e)}`, t), this.historySize > 0 && (this.history.push({
81
+ event: String(e),
82
+ data: t,
83
+ time: Date.now()
84
+ }), this.history.length > this.historySize && this.history.shift());
85
+ }
86
+ reportError(e, t, n) {
87
+ if (this.errorHandlers.size > 0) for (let r of this.errorHandlers) try {
88
+ r(e, t, n);
89
+ } catch {}
90
+ else console.error(`[laser] handler for "${t}" threw:`, e);
91
+ }
92
+ }, b = new y();
93
+ typeof globalThis < "u" && (globalThis.laserEvents = b);
94
+ //#endregion
95
+ //#region packages/npm/laser/src/lib/core/invariant.ts
96
+ var oe = "laser:invariant", se = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Map(), le = 1e3;
97
+ function ue(e) {
98
+ le = Math.max(0, e);
99
+ }
100
+ function de(e, t, n) {
101
+ if (e) return !0;
102
+ let r = Date.now(), i = (se.get(t) ?? 0) + 1;
103
+ return se.set(t, i), r - (ce.get(t) ?? -Infinity) >= le && (ce.set(t, r), console.error(`[invariant] ${t}${i > 1 ? ` (x${i})` : ""}`, n), b.emit(oe, {
104
+ msg: t,
105
+ ctx: n,
106
+ count: i,
107
+ time: r
108
+ })), !1;
109
+ }
110
+ function fe() {
111
+ se.clear(), ce.clear();
112
+ }
113
+ //#endregion
114
+ //#region packages/npm/laser/src/lib/spatial/quadtree.ts
115
+ var pe = class e {
29
116
  bounds;
30
117
  capacity;
31
118
  points;
@@ -96,29 +183,29 @@ var g = class {
96
183
  isWithinRange(e, t) {
97
184
  return e.x >= t.xMin && e.x <= t.xMax && e.y >= t.yMin && e.y <= t.yMax;
98
185
  }
99
- }, y = e(null);
100
- function b() {
101
- let e = n(y);
186
+ }, x = e(null);
187
+ function me() {
188
+ let e = n(x);
102
189
  if (!e) throw Error("usePhaserGame must be used within a <PhaserGame> component");
103
190
  return e;
104
191
  }
105
192
  //#endregion
106
193
  //#region packages/npm/laser/src/lib/phaser/PhaserGame.tsx
107
- var x = t(function({ config: e, onReady: t, onDestroy: n, className: d, style: f, children: p }, m) {
108
- let h = o(null), g = o(null), v = o(null), [b, x] = s("idle");
109
- i(m, () => ({
110
- game: g.current,
111
- status: b
112
- }), [b]), r(() => {
113
- if (!h.current) return;
114
- let r = h.current;
115
- if (v.current !== null && (window.clearTimeout(v.current), v.current = null), g.current) {
116
- let e = g.current.canvas;
117
- return e && e.parentElement !== r && r.appendChild(e), x(g.current.isBooted ? "running" : "booting"), o;
194
+ var he = t(function({ config: e, onReady: t, onDestroy: n, className: c, style: u, children: ee }, p) {
195
+ let m = o(null), h = o(null), g = o(null), [_, v] = s("idle");
196
+ i(p, () => ({
197
+ game: h.current,
198
+ status: _
199
+ }), [_]), r(() => {
200
+ if (!m.current) return;
201
+ let r = m.current;
202
+ if (g.current !== null && (window.clearTimeout(g.current), g.current = null), h.current) {
203
+ let e = h.current.canvas;
204
+ return e && e.parentElement !== r && r.appendChild(e), v(h.current.isBooted ? "running" : "booting"), o;
118
205
  }
119
- x("booting");
206
+ v("booting");
120
207
  let i = {
121
- type: c.AUTO,
208
+ type: l.AUTO,
122
209
  width: e.width ?? 800,
123
210
  height: e.height ?? 600,
124
211
  parent: r,
@@ -138,15 +225,15 @@ var x = t(function({ config: e, onReady: t, onDestroy: n, className: d, style: f
138
225
  ...e.audio && { audio: e.audio },
139
226
  ...e.callbacks && { callbacks: e.callbacks },
140
227
  ...e.fps && { fps: e.fps }
141
- }, a = new c.Game(i);
142
- return g.current = a, a.events.once("ready", () => {
143
- g.current === a && (x("running"), _.emit("game:ready", { game: a }), t?.(a));
228
+ }, a = new l.Game(i);
229
+ return h.current = a, a.events.once("ready", () => {
230
+ h.current === a && (v("running"), b.emit("game:ready", { game: a }), t?.(a));
144
231
  }), o;
145
232
  function o() {
146
- v.current = window.setTimeout(() => {
147
- v.current = null;
148
- let e = g.current;
149
- e && (x("destroyed"), _.emit("game:destroy", void 0), n?.(), e.destroy(!0), g.current = null);
233
+ g.current = window.setTimeout(() => {
234
+ g.current = null;
235
+ let e = h.current;
236
+ e && (v("destroyed"), b.emit("game:destroy", void 0), n?.(), e.destroy(!0), h.current = null);
150
237
  }, 0);
151
238
  }
152
239
  }, [
@@ -154,23 +241,23 @@ var x = t(function({ config: e, onReady: t, onDestroy: n, className: d, style: f
154
241
  t,
155
242
  n
156
243
  ]);
157
- let S = a(() => ({
158
- game: g.current,
159
- status: b
160
- }), [b]);
161
- return /* @__PURE__ */ u(y.Provider, {
162
- value: S,
163
- children: [/* @__PURE__ */ l("div", {
164
- ref: h,
165
- className: d,
166
- style: f
167
- }), p]
244
+ let te = a(() => ({
245
+ game: h.current,
246
+ status: _
247
+ }), [_]);
248
+ return /* @__PURE__ */ f(x.Provider, {
249
+ value: te,
250
+ children: [/* @__PURE__ */ d("div", {
251
+ ref: m,
252
+ className: c,
253
+ style: u
254
+ }), ee]
168
255
  });
169
256
  });
170
257
  //#endregion
171
258
  //#region packages/npm/laser/src/lib/phaser/use-phaser-event.ts
172
- function S(e, t, n) {
173
- let { game: i } = b(), a = o(t);
259
+ function ge(e, t, n) {
260
+ let { game: i } = me(), a = o(t);
174
261
  a.current = t, r(() => {
175
262
  if (!i) return;
176
263
  let t = (...e) => a.current(...e);
@@ -190,7 +277,7 @@ function S(e, t, n) {
190
277
  }
191
278
  //#endregion
192
279
  //#region packages/npm/laser/src/lib/phaser/virtual-joystick.ts
193
- var C = class {
280
+ var _e = class {
194
281
  scene;
195
282
  base;
196
283
  thumb;
@@ -243,7 +330,7 @@ var C = class {
243
330
  destroy() {
244
331
  this.base.destroy(), this.thumb.destroy();
245
332
  }
246
- }, w = class {
333
+ }, ve = class {
247
334
  scene;
248
335
  gridEngine;
249
336
  quadtree;
@@ -259,21 +346,21 @@ var C = class {
259
346
  backgroundColor: "#000000"
260
347
  }).setDepth(4).setPadding(3, 2, 2, 3).setVisible(!1), r?.joystick) {
261
348
  let t = typeof r.joystick == "object" ? r.joystick : void 0;
262
- this.joystick = new C(e, t);
349
+ this.joystick = new _e(e, t);
263
350
  }
264
351
  }
265
352
  initializeWASDKeys() {
266
353
  let e = this.scene.input.keyboard;
267
354
  e && (this.wasdKeys = {
268
- W: e.addKey(c.Input.Keyboard.KeyCodes.W),
269
- A: e.addKey(c.Input.Keyboard.KeyCodes.A),
270
- S: e.addKey(c.Input.Keyboard.KeyCodes.S),
271
- D: e.addKey(c.Input.Keyboard.KeyCodes.D)
355
+ W: e.addKey(l.Input.Keyboard.KeyCodes.W),
356
+ A: e.addKey(l.Input.Keyboard.KeyCodes.A),
357
+ S: e.addKey(l.Input.Keyboard.KeyCodes.S),
358
+ D: e.addKey(l.Input.Keyboard.KeyCodes.D)
272
359
  });
273
360
  }
274
361
  checkForNearbyObjects() {
275
362
  let e = this.gridEngine.getPosition(this.playerId), t = e.x * this.tileSize, n = e.y * this.tileSize, r = this.quadtree.query(e);
276
- r.length > 0 ? (this.tooltip.setPosition(t, n - 60).setVisible(!0), _.emit("player:nearby", {
363
+ r.length > 0 ? (this.tooltip.setPosition(t, n - 60).setVisible(!0), b.emit("player:nearby", {
277
364
  position: e,
278
365
  ranges: r
279
366
  })) : this.tooltip.setVisible(!1);
@@ -285,7 +372,7 @@ var C = class {
285
372
  if (this.scene.input.keyboard?.addKey("F").isDown) {
286
373
  let e = this.gridEngine.getPosition(this.playerId), t = this.quadtree.query(e);
287
374
  if (t.length > 0) {
288
- _.emit("player:interact", {
375
+ b.emit("player:interact", {
289
376
  position: e,
290
377
  ranges: t
291
378
  });
@@ -306,12 +393,12 @@ var C = class {
306
393
  };
307
394
  //#endregion
308
395
  //#region packages/npm/laser/src/lib/phaser/entity-fx.ts
309
- function T(e, t, n = 16739179) {
310
- t.setTint(16777215).setTintMode(c.TintModes.FILL), e.time.delayedCall(60, () => t.setTint(n)), e.time.delayedCall(180, () => {
311
- t.clearTint(), t.setTintMode(c.TintModes.MULTIPLY);
396
+ function ye(e, t, n = 16739179) {
397
+ t.setTint(16777215).setTintMode(l.TintModes.FILL), e.time.delayedCall(60, () => t.setTint(n)), e.time.delayedCall(180, () => {
398
+ t.clearTint(), t.setTintMode(l.TintModes.MULTIPLY);
312
399
  });
313
400
  }
314
- function E(e, t, n, r, i, a) {
401
+ function be(e, t, n, r, i, a) {
315
402
  let o = e.add.text(t, n, r, {
316
403
  fontFamily: "monospace",
317
404
  fontSize: "14px",
@@ -328,20 +415,175 @@ function E(e, t, n, r, i, a) {
328
415
  onComplete: () => o.destroy()
329
416
  }), o;
330
417
  }
331
- function ee(e, t, n, r, i, a = 26) {
418
+ function xe(e, t, n, r, i, a = 26) {
332
419
  let o = Math.max(0, Math.min(1, r / i));
333
420
  e.clear(), e.fillStyle(0, .6), e.fillRect(t - a / 2, n, a, 4), e.fillStyle(o > .5 ? 4906624 : o > .25 ? 16498468 : 16281969, 1), e.fillRect(t - a / 2 + .5, n + .5, (a - 1) * o, 3);
334
421
  }
335
- function te(e, { min: t = .6, max: n = 2.2, step: r = .2 } = {}) {
422
+ function Se(e, t, n, r, i, a, o = 26) {
423
+ return e.setPosition(t, n), a && a.hp === r && a.maxHp === i ? {
424
+ drawn: !1,
425
+ cache: a
426
+ } : (xe(e, 0, 0, r, i, o), {
427
+ drawn: !0,
428
+ cache: {
429
+ hp: r,
430
+ maxHp: i
431
+ }
432
+ });
433
+ }
434
+ function Ce(e, { min: t = .6, max: n = 2.2, step: r = .2 } = {}) {
336
435
  let i = (r) => {
337
436
  let i = e.cameras.main;
338
- i.setZoom(c.Math.Clamp(i.zoom + r, t, n));
437
+ i.setZoom(l.Math.Clamp(i.zoom + r, t, n));
339
438
  };
340
439
  e.input.keyboard?.on("keydown-PLUS", () => i(r)), e.input.keyboard?.on("keydown-MINUS", () => i(-r)), e.input.on("wheel", (e, t, n, a) => i(a > 0 ? -r * .75 : r * .75));
341
440
  }
342
441
  //#endregion
442
+ //#region packages/npm/laser/src/lib/webgl/context-guard.ts
443
+ function we() {
444
+ try {
445
+ if (typeof window > "u" || !window.WebGLRenderingContext) return !1;
446
+ let e = document.createElement("canvas"), t = e.getContext("webgl2") || e.getContext("webgl");
447
+ return t ? (t.getExtension("WEBGL_lose_context")?.loseContext(), !0) : !1;
448
+ } catch {
449
+ return !1;
450
+ }
451
+ }
452
+ function S(e, t) {
453
+ let n = {
454
+ kind: e,
455
+ ...t
456
+ };
457
+ e === "restored" ? console.info("[laser/webgl] context restored", n) : console.warn(`[laser/webgl] context ${e}`, n);
458
+ try {
459
+ window.dispatchEvent(new CustomEvent("kbve:webgl", { detail: n }));
460
+ } catch {}
461
+ }
462
+ function C(e, { onLost: t, onRestored: n }) {
463
+ let r = (e) => {
464
+ e.preventDefault(), S("lost"), t();
465
+ }, i = () => {
466
+ S("restored"), n();
467
+ };
468
+ return e.addEventListener("webglcontextlost", r, !1), e.addEventListener("webglcontextrestored", i, !1), () => {
469
+ e.removeEventListener("webglcontextlost", r), e.removeEventListener("webglcontextrestored", i);
470
+ };
471
+ }
472
+ //#endregion
473
+ //#region packages/npm/laser/src/lib/phaser/gpu-sprite-layer.ts
474
+ function w(e, t, n) {
475
+ if (e.renderer.type !== l.WEBGL) return null;
476
+ let r = e.add.spriteGPULayer(t, n.size);
477
+ n.depth !== void 0 && r.setDepth(n.depth), n.alpha !== void 0 && r.setAlpha(n.alpha), n.blendMode !== void 0 && r.setBlendMode(n.blendMode), n.visible !== void 0 && r.setVisible(n.visible);
478
+ let i = C(e.game.canvas, {
479
+ onLost: () => void 0,
480
+ onRestored: () => r.setAllSegmentsNeedUpdate()
481
+ });
482
+ return {
483
+ layer: r,
484
+ dispose() {
485
+ i(), r.destroy();
486
+ }
487
+ };
488
+ }
489
+ function T(e, t, n) {
490
+ let r = {};
491
+ for (let i = 0; i < t; i++) n(r, i), e.layer.addMember(r);
492
+ }
493
+ //#endregion
494
+ //#region packages/npm/laser/src/lib/phaser/ambient-dust.ts
495
+ function E(e, t, n) {
496
+ let r = n() * t.width, i = n() * t.height, a = 4 + n() * 10, o = 4e3 + n() * 5e3, s = .5 + n() * 1.1, c = .35 + n() * .35, l = 2500 + n() * 3500, u = {
497
+ x: r,
498
+ y: {
499
+ base: i,
500
+ amplitude: a,
501
+ duration: o,
502
+ ease: "Sine.easeInOut",
503
+ loop: !0,
504
+ yoyo: !0
505
+ },
506
+ scaleX: s,
507
+ scaleY: s,
508
+ alpha: {
509
+ base: c,
510
+ amplitude: .25,
511
+ duration: l,
512
+ ease: "Sine.easeInOut",
513
+ loop: !0,
514
+ yoyo: !0
515
+ }
516
+ };
517
+ return t.scrollFactor !== void 0 && (u.scrollFactorX = t.scrollFactor, u.scrollFactorY = t.scrollFactor), u;
518
+ }
519
+ function Te(e, t, n, r) {
520
+ if (e.textures.exists(t)) return;
521
+ let i = n * 2, a = e.make.graphics({
522
+ x: 0,
523
+ y: 0
524
+ }, !1);
525
+ a.fillStyle(r, 1), a.fillCircle(n, n, n), a.generateTexture(t, i, i), a.destroy();
526
+ }
527
+ function Ee(e, t, n = Math.random) {
528
+ if (e.renderer.type !== l.WEBGL) return null;
529
+ let r = t.textureKey ?? "laser-dust-mote";
530
+ Te(e, r, t.radius ?? 2, t.color ?? 16777215);
531
+ let i = w(e, r, {
532
+ size: t.count,
533
+ depth: t.depth,
534
+ alpha: t.alpha,
535
+ blendMode: t.blendMode
536
+ });
537
+ return i ? (T(i, t.count, (e, r) => Object.assign(e, E(r, t, n))), i) : null;
538
+ }
539
+ //#endregion
540
+ //#region packages/npm/laser/src/lib/phaser/object-pool.ts
541
+ var D = class {
542
+ idle = [];
543
+ constructor(e) {
544
+ this.make = e;
545
+ }
546
+ acquire() {
547
+ let e = this.idle.pop() ?? this.make();
548
+ return e.setActive(!0).setVisible(!0), e;
549
+ }
550
+ release(e) {
551
+ e.setActive(!1).setVisible(!1), this.idle.push(e);
552
+ }
553
+ };
554
+ //#endregion
555
+ //#region packages/npm/laser/src/lib/phaser/keyboard-map.ts
556
+ function De(e, t) {
557
+ let n = e.input.keyboard;
558
+ if (!n) return null;
559
+ let r = n.createCursorKeys(), i = {};
560
+ for (let e of Object.keys(t)) i[e] = n.addKey(t[e], !1);
561
+ return {
562
+ cursors: r,
563
+ keys: i
564
+ };
565
+ }
566
+ //#endregion
567
+ //#region packages/npm/laser/src/lib/phaser/arrow-projectile.ts
568
+ function Oe(e, { width: t = 7, height: n = 2, depth: r = 0 } = {}) {
569
+ return new D(() => {
570
+ let i = e.add.rectangle(0, 0, t, n, 16777215);
571
+ return i.setOrigin(.5, .5), i.setDepth(r), i;
572
+ });
573
+ }
574
+ function ke(e, t, n) {
575
+ let r = t.acquire();
576
+ return r.setPosition(n.fromX, n.fromY), r.setFillStyle(n.color), r.setRotation(Math.atan2(n.toY - n.fromY, n.toX - n.fromX)), e.tweens.add({
577
+ targets: r,
578
+ x: n.toX,
579
+ y: n.toY,
580
+ duration: n.duration ?? 140,
581
+ onComplete: () => t.release(r)
582
+ }), r;
583
+ }
584
+ //#endregion
343
585
  //#region packages/npm/laser/src/lib/tile/path.ts
344
- function ne(e, t, n, r = 64) {
586
+ function Ae(e, t, n, r = 64) {
345
587
  if (e.x === t.x && e.y === t.y || n(t.x, t.y)) return [];
346
588
  let i = (e, t) => `${e},${t}`, a = /* @__PURE__ */ new Map();
347
589
  a.set(i(e.x, e.y), null);
@@ -379,13 +621,13 @@ function ne(e, t, n, r = 64) {
379
621
  }
380
622
  //#endregion
381
623
  //#region packages/npm/laser/src/lib/phaser/monsters/bird.ts
382
- function re(e) {
624
+ function je(e) {
383
625
  return +e[e.length - 1];
384
626
  }
385
- function ie(e) {
627
+ function Me(e) {
386
628
  return e.startsWith("monster_bird_") && !e.startsWith("monster_bird_shadow");
387
629
  }
388
- function D(e, t, n, r, i) {
630
+ function Ne(e, t, n, r, i) {
389
631
  let a = [];
390
632
  for (let o = 0; o < 10; o++) {
391
633
  let o = e.add.sprite(0, 0, "monster_bird");
@@ -393,13 +635,13 @@ function D(e, t, n, r, i) {
393
635
  }
394
636
  return a;
395
637
  }
396
- function O(e) {
397
- return D(e, 0, 0, 61, 47);
638
+ function Pe(e) {
639
+ return Ne(e, 0, 0, 61, 47);
398
640
  }
399
- function k(e) {
400
- return D(e, 22, 47, 16, 10);
641
+ function Fe(e) {
642
+ return Ne(e, 22, 47, 16, 10);
401
643
  }
402
- function A(e) {
644
+ function Ie(e) {
403
645
  e.anims.create({
404
646
  key: "bird",
405
647
  frames: e.anims.generateFrameNumbers("monster_bird", {
@@ -413,7 +655,7 @@ function A(e) {
413
655
  }
414
656
  //#endregion
415
657
  //#region packages/npm/laser/src/lib/r3f/components/Stage.tsx
416
- var j = ({ children: e, className: t, ...n }) => /* @__PURE__ */ u(d, {
658
+ var Le = ({ children: e, className: t, ...n }) => /* @__PURE__ */ f(ee, {
417
659
  camera: { position: [
418
660
  0,
419
661
  0,
@@ -421,34 +663,42 @@ var j = ({ children: e, className: t, ...n }) => /* @__PURE__ */ u(d, {
421
663
  ] },
422
664
  ...n,
423
665
  className: t,
424
- children: [/* @__PURE__ */ l("ambientLight", { intensity: 1.5 }), e]
666
+ children: [/* @__PURE__ */ d("ambientLight", { intensity: 1.5 }), e]
425
667
  });
426
668
  //#endregion
427
669
  //#region packages/npm/laser/src/lib/r3f/hooks/use-game-loop.ts
428
- function M(e) {
670
+ function Re(e) {
429
671
  let t = o(e);
430
- t.current = e, f((e, n) => {
672
+ t.current = e, p((e, n) => {
431
673
  t.current(n, e.clock.elapsedTime);
432
674
  });
433
675
  }
434
676
  //#endregion
677
+ //#region packages/npm/laser/src/lib/ecs/bitecs.ts
678
+ var O = /* @__PURE__ */ re({});
679
+ import * as ze from "bitecs";
680
+ ae(O, ze);
681
+ //#endregion
435
682
  //#region packages/npm/laser/src/lib/ecs/helpers.ts
436
- function* N(e, t, n, r, i, a) {
683
+ function k(e, t) {
684
+ return (e & 65535) * 65536 + (t & 65535);
685
+ }
686
+ function* A(e, t, n, r, i, a) {
437
687
  let o = a * a;
438
- for (let a of p(e, t)) {
688
+ for (let a of m(e, t)) {
439
689
  let e = n.x[a] - r, t = n.y[a] - i;
440
690
  e * e + t * t <= o && (yield a);
441
691
  }
442
692
  }
443
- function P(e, t, n, r, i, a) {
693
+ function Be(e, t, n, r, i, a) {
444
694
  let o = a * a, s = -1, c = o;
445
- for (let a of p(e, t)) {
695
+ for (let a of m(e, t)) {
446
696
  let e = n.x[a] - r, t = n.y[a] - i, o = e * e + t * t;
447
697
  o <= c && (c = o, s = a);
448
698
  }
449
699
  return s >= 0 ? s : null;
450
700
  }
451
- var F = class {
701
+ var j = class {
452
702
  map = /* @__PURE__ */ new Map();
453
703
  set(e, t) {
454
704
  this.map.set(e, t);
@@ -475,12 +725,229 @@ var F = class {
475
725
  get size() {
476
726
  return this.map.size;
477
727
  }
478
- }, I = 1e3, L = 15e3;
479
- function R(e, t, n) {
728
+ }, M = 4096, N = {
729
+ x: new Int32Array(M),
730
+ y: new Int32Array(M)
731
+ }, P = {
732
+ hp: new Float32Array(M),
733
+ maxHp: new Float32Array(M)
734
+ }, F = { value: new Int32Array(M) }, I = { slot: new Int32Array(M) }, L = { value: new Uint8Array(M) }, R = {
735
+ host: new Int32Array(M),
736
+ kind: new Uint8Array(M)
737
+ }, Ve = {}, He = {}, Ue = {}, We = {}, z = {}, B = {
738
+ Player: 0,
739
+ Npc: 1,
740
+ Item: 2,
741
+ Env: 3
742
+ }, Ge = [], Ke = class {
743
+ world = (0, O.createWorld)();
744
+ toEid = /* @__PURE__ */ new Map();
745
+ toServer = /* @__PURE__ */ new Map();
746
+ sideRefs = new j();
747
+ effectsMap = /* @__PURE__ */ new Map();
748
+ byTile = /* @__PURE__ */ new Map();
749
+ indexAdd(e, t, n) {
750
+ let r = k(t, n), i = this.byTile.get(r);
751
+ i || this.byTile.set(r, i = /* @__PURE__ */ new Set()), i.add(e);
752
+ }
753
+ indexRemove(e, t, n) {
754
+ let r = k(t, n), i = this.byTile.get(r);
755
+ i && (i.delete(e), i.size === 0 && this.byTile.delete(r));
756
+ }
757
+ tagFor(e) {
758
+ return e === B.Player ? Ve : e === B.Npc ? He : e === B.Env ? We : Ue;
759
+ }
760
+ has(e) {
761
+ return this.toEid.has(e);
762
+ }
763
+ size() {
764
+ return this.toEid.size;
765
+ }
766
+ spawn(e, t, n) {
767
+ let r = (0, O.addEntity)(this.world);
768
+ return (0, O.addComponent)(this.world, r, N), (0, O.addComponent)(this.world, r, P), (0, O.addComponent)(this.world, r, F), (0, O.addComponent)(this.world, r, I), (0, O.addComponent)(this.world, r, L), (0, O.addComponent)(this.world, r, R), (0, O.addComponent)(this.world, r, this.tagFor(t.cat)), t.hostile && (0, O.addComponent)(this.world, r, z), N.x[r] = t.tile.x, N.y[r] = t.tile.y, P.hp[r] = t.hp, P.maxHp[r] = t.maxHp, F.value[r] = t.kind, I.slot[r] = t.owner, L.value[r] = 1, R.host[r] = 0, R.kind[r] = 0, this.toEid.set(e, r), this.toServer.set(r, e), this.sideRefs.set(r, n), this.indexAdd(r, t.tile.x, t.tile.y), t.effects && this.effectsMap.set(e, t.effects), r;
769
+ }
770
+ update(e, t) {
771
+ let n = this.toEid.get(e);
772
+ if (n !== void 0) {
773
+ if (t.tile) {
774
+ let e = N.x[n], r = N.y[n];
775
+ (t.tile.x !== e || t.tile.y !== r) && (this.indexRemove(n, e, r), this.indexAdd(n, t.tile.x, t.tile.y)), N.x[n] = t.tile.x, N.y[n] = t.tile.y;
776
+ }
777
+ t.hp !== void 0 && (P.hp[n] = t.hp), t.maxHp !== void 0 && (P.maxHp[n] = t.maxHp), t.effects !== void 0 && (t.effects.length ? this.effectsMap.set(e, t.effects) : this.effectsMap.delete(e));
778
+ }
779
+ }
780
+ despawn(e) {
781
+ let t = this.toEid.get(e);
782
+ if (t === void 0) return;
783
+ let n = this.sideRefs.delete(t);
784
+ return this.indexRemove(t, N.x[t], N.y[t]), R.host[t] = 0, R.kind[t] = 0, (0, O.removeEntity)(this.world, t), this.toEid.delete(e), this.toServer.delete(t), this.effectsMap.delete(e), n;
785
+ }
786
+ refs(e) {
787
+ let t = this.toEid.get(e);
788
+ return t === void 0 ? void 0 : this.sideRefs.get(t);
789
+ }
790
+ eid(e) {
791
+ return this.toEid.get(e);
792
+ }
793
+ tile(e) {
794
+ let t = this.toEid.get(e);
795
+ return t === void 0 ? null : {
796
+ x: N.x[t],
797
+ y: N.y[t]
798
+ };
799
+ }
800
+ hp(e) {
801
+ let t = this.toEid.get(e);
802
+ return t === void 0 ? 0 : P.hp[t];
803
+ }
804
+ maxHp(e) {
805
+ let t = this.toEid.get(e);
806
+ return t === void 0 ? 0 : P.maxHp[t];
807
+ }
808
+ kind(e) {
809
+ let t = this.toEid.get(e);
810
+ return t === void 0 ? -1 : F.value[t];
811
+ }
812
+ owner(e) {
813
+ let t = this.toEid.get(e);
814
+ return t === void 0 ? -1 : I.slot[t];
815
+ }
816
+ setPossession(e, t, n) {
817
+ let r = this.toEid.get(e);
818
+ r !== void 0 && (R.host[r] = t, R.kind[r] = n);
819
+ }
820
+ possessionHost(e) {
821
+ let t = this.toEid.get(e);
822
+ return t === void 0 ? 0 : R.host[t];
823
+ }
824
+ possessionKind(e) {
825
+ let t = this.toEid.get(e);
826
+ return t === void 0 ? 0 : R.kind[t];
827
+ }
828
+ effects(e) {
829
+ return this.effectsMap.get(e) ?? Ge;
830
+ }
831
+ *entries() {
832
+ for (let [e, t] of this.toEid) {
833
+ let n = this.sideRefs.get(t);
834
+ n !== void 0 && (yield [
835
+ e,
836
+ t,
837
+ n
838
+ ]);
839
+ }
840
+ }
841
+ at(e, t, n) {
842
+ let r = this.byTile.get(k(e, t));
843
+ if (!r) return null;
844
+ for (let e of r) {
845
+ let t = this.toServer.get(e);
846
+ if (t === void 0 || t === n) continue;
847
+ let r = this.sideRefs.get(e);
848
+ if (r !== void 0) return {
849
+ serverEid: t,
850
+ eid: e,
851
+ refs: r
852
+ };
853
+ }
854
+ return null;
855
+ }
856
+ hostilesInRange(e, t, n) {
857
+ let r = 0;
858
+ for (let i of A(this.world, [N, z], N, e, t, n)) r += 1;
859
+ return r;
860
+ }
861
+ serverIdsWith(e) {
862
+ let t = this.tagFor(e), n = [];
863
+ for (let e of (0, O.query)(this.world, [t])) {
864
+ let t = this.toServer.get(e);
865
+ t !== void 0 && n.push(t);
866
+ }
867
+ return n;
868
+ }
869
+ };
870
+ //#endregion
871
+ //#region packages/npm/laser/src/lib/determ/index.ts
872
+ function V(e) {
873
+ return (e.charCodeAt(0) << 24 | e.charCodeAt(1) << 16 | e.charCodeAt(2) << 8 | e.charCodeAt(3)) >>> 0;
874
+ }
875
+ var qe = {
876
+ COMBAT: V("COMB"),
877
+ DUNGEON: V("DUNG"),
878
+ WANDER: V("WAND"),
879
+ LOOT: V("LOOT"),
880
+ TREE: V("TREE"),
881
+ BUSH: V("BUSH")
882
+ };
883
+ function Je(e) {
884
+ let t = e >>> 0;
885
+ return () => {
886
+ t = t + 1831565813 >>> 0;
887
+ let e = t;
888
+ return e = Math.imul(e ^ e >>> 15, e | 1) >>> 0, e = (e ^ e + (Math.imul(e ^ e >>> 7, e | 61) >>> 0)) >>> 0, (e ^ e >>> 14) >>> 0;
889
+ };
890
+ }
891
+ function Ye(e) {
892
+ let t = 2166136261;
893
+ for (let n of e) {
894
+ let e = n >>> 0;
895
+ for (let n = 0; n < 32; n += 8) t = (t ^ e >>> n & 255) >>> 0, t = Math.imul(t, 16777619) >>> 0;
896
+ }
897
+ return t >>> 0;
898
+ }
899
+ function Xe(e, t, n = []) {
900
+ return Je(Ye([
901
+ e,
902
+ t,
903
+ ...n
904
+ ]));
905
+ }
906
+ function Ze(e, t, n = []) {
907
+ return Xe(e, t, n)() % 100;
908
+ }
909
+ //#endregion
910
+ //#region packages/npm/laser/src/lib/combat/index.ts
911
+ var Qe = {
912
+ Adjacent: 0,
913
+ Line: 1,
914
+ Aoe: 2
915
+ }, $e = 1, et = 8;
916
+ function tt(e, t) {
917
+ return Math.max(Math.abs(e.x - t.x), Math.abs(e.y - t.y));
918
+ }
919
+ function nt(e, t, n) {
920
+ return tt(e, t) <= n;
921
+ }
922
+ function rt(e, t, n, r) {
923
+ let i = [], a = e.x, o = e.y, s = Math.abs(t.x - a), c = -Math.abs(t.y - o), l = a < t.x ? 1 : -1, u = o < t.y ? 1 : -1, d = s + c, f = 0;
924
+ for (; !(a === t.x && o === t.y);) {
925
+ let e = 2 * d;
926
+ e >= c && (d += c, a += l), e <= s && (d += s, o += u), f++;
927
+ let t = {
928
+ x: a,
929
+ y: o
930
+ };
931
+ if (i.push(t), r(t) || f >= n) break;
932
+ }
933
+ return i;
934
+ }
935
+ function it(e, t) {
936
+ let n = [];
937
+ for (let r = -t; r <= t; r++) for (let i = -t; i <= t; i++) n.push({
938
+ x: e.x + i,
939
+ y: e.y + r
940
+ });
941
+ return n;
942
+ }
943
+ //#endregion
944
+ //#region packages/npm/laser/src/lib/net/connection.ts
945
+ var at = 1e3, ot = 15e3;
946
+ function st(e, t, n) {
480
947
  let r = t.trim();
481
948
  return n ? e === 1e3 ? "disconnected" : r || `server dropped connection (code ${e})` : e === 1006 ? "cannot reach server — down or rejected" : r || `connection refused (code ${e})`;
482
949
  }
483
- var z = class {
950
+ var H = class {
484
951
  ws = null;
485
952
  closed = !1;
486
953
  attempts = 0;
@@ -495,9 +962,9 @@ var z = class {
495
962
  constructor(e, t) {
496
963
  this.opts = {
497
964
  maxAttempts: 0,
498
- baseDelayMs: I,
499
- maxDelayMs: L,
500
- closeReason: R,
965
+ baseDelayMs: at,
966
+ maxDelayMs: ot,
967
+ closeReason: st,
501
968
  ...e
502
969
  }, this.handlers = t;
503
970
  }
@@ -511,14 +978,14 @@ var z = class {
511
978
  this.isOpen() && this.ws.send(e);
512
979
  }
513
980
  connect() {
514
- if (this.ws || this.closed) return;
515
- this.everOpened = !1, this.setState({
981
+ if (this.ws) return;
982
+ this.closed = !1, this.everOpened = !1, this.setState({
516
983
  status: this.attempts === 0 ? "connecting" : "reconnecting",
517
984
  attempts: this.attempts,
518
985
  reason: this.state.reason
519
986
  });
520
987
  let e = typeof this.opts.url == "function" ? this.opts.url() : this.opts.url, t = new WebSocket(e);
521
- this.ws = t, t.addEventListener("open", () => {
988
+ t.binaryType = "arraybuffer", this.ws = t, t.addEventListener("open", () => {
522
989
  this.attempts = 0, this.everOpened = !0, this.setState({
523
990
  status: "connected",
524
991
  attempts: 0
@@ -567,12 +1034,25 @@ var z = class {
567
1034
  setState(e) {
568
1035
  this.state = e, this.handlers.onState?.(e);
569
1036
  }
570
- }, B = 10, V = 1, H = 2, U = 1, W = 2, G = 3, K = 5, ae = 6, q = 7, J = 8, oe = 9, se = 10, ce = 11, le = 0, ue = 1, de = 2, fe = [
1037
+ }, ct = 15, lt = 1, ut = 2, dt = 3, ft = 4, pt = 1, mt = 2, ht = 3, gt = 5, _t = 6, vt = 7, yt = 8, bt = 9, xt = 10, St = 11, Ct = 12, wt = 13, Tt = 0, Et = 1, Dt = 2, Ot = 3, kt = 0, At = 1, jt = 2, Mt = 3, Nt = 4, Pt = 5, Ft = 6, It = 7, Lt = 8, Rt = 9, zt = 10, Bt = 11, Vt = 12, Ht = [
1038
+ "none",
1039
+ "fire",
1040
+ "ice",
1041
+ "lightning",
1042
+ "poison",
1043
+ "shadow",
1044
+ "holy",
1045
+ "arcane",
1046
+ "earth",
1047
+ "wind",
1048
+ "nature",
1049
+ "light"
1050
+ ], Ut = 3, Wt = 4, Gt = 0, Kt = 1, qt = 2, Jt = [
571
1051
  "spades",
572
1052
  "hearts",
573
1053
  "diamonds",
574
1054
  "clubs"
575
- ], pe = [
1055
+ ], Yt = [
576
1056
  "A",
577
1057
  "2",
578
1058
  "3",
@@ -586,7 +1066,7 @@ var z = class {
586
1066
  "J",
587
1067
  "Q",
588
1068
  "K"
589
- ], me = [
1069
+ ], Xt = [
590
1070
  11,
591
1071
  2,
592
1072
  3,
@@ -601,74 +1081,633 @@ var z = class {
601
1081
  10,
602
1082
  10
603
1083
  ];
604
- function he(e) {
1084
+ function Zt(e) {
605
1085
  let t = e & 15, n = e >> 4 & 3;
606
1086
  return {
607
- suit: fe[n],
608
- rank: pe[t],
609
- points: me[t],
1087
+ suit: Jt[n],
1088
+ rank: Yt[t],
1089
+ points: Xt[t],
610
1090
  red: n === 1 || n === 2
611
1091
  };
612
1092
  }
613
- var Y = (1n << 64n) - 1n;
614
- function ge(e) {
615
- return e = (e ^ e >> 30n) * 13787848793156543929n & Y, e = (e ^ e >> 27n) * 10723151780598845931n & Y, e ^ e >> 31n;
1093
+ var U = (1n << 64n) - 1n;
1094
+ function Qt(e) {
1095
+ return e = (e ^ e >> 30n) * 13787848793156543929n & U, e = (e ^ e >> 27n) * 10723151780598845931n & U, e ^ e >> 31n;
616
1096
  }
617
- function X(e) {
1097
+ function $t(e) {
618
1098
  let t = [];
619
1099
  for (let e = 0; e < 4; e++) for (let e = 0; e < 4; e++) for (let n = 0; n < 13; n++) t.push(e << 4 | n);
620
- let n = BigInt(e) & Y;
1100
+ let n = BigInt(e) & U;
621
1101
  for (let e = t.length - 1; e > 0; e--) {
622
- n = n + 11400714819323198485n & Y;
623
- let r = Number(ge(n) % BigInt(e + 1)), i = t[e];
1102
+ n = n + 11400714819323198485n & U;
1103
+ let r = Number(Qt(n) % BigInt(e + 1)), i = t[e];
624
1104
  t[e] = t[r], t[r] = i;
625
1105
  }
626
1106
  return t;
627
1107
  }
628
- async function _e(e, t) {
629
- let n = BigInt(e) & Y, r = new Uint8Array(8);
1108
+ async function en(e, t) {
1109
+ let n = BigInt(e) & U, r = new Uint8Array(8);
630
1110
  for (let e = 0; e < 8; e++) r[e] = Number(n & 255n), n >>= 8n;
631
1111
  let i = await crypto.subtle.digest("SHA-256", r);
632
1112
  return Array.from(new Uint8Array(i)).map((e) => e.toString(16).padStart(2, "0")).join("") === t;
633
1113
  }
634
- var ve = 65535;
635
- function Z(e) {
1114
+ var tn = 65535;
1115
+ function nn(e) {
636
1116
  try {
637
1117
  return JSON.parse(new TextDecoder().decode(Uint8Array.from(e)));
638
1118
  } catch {
639
1119
  return null;
640
1120
  }
641
1121
  }
642
- function Q(e, t) {
1122
+ function rn(e, t) {
643
1123
  return { JoinMatch: {
644
- protocol: 10,
1124
+ protocol: 15,
645
1125
  jwt: e,
646
1126
  kbve_username: t
647
1127
  } };
648
1128
  }
649
- function $(e, t) {
1129
+ function an(e, t) {
650
1130
  return { Frame: {
651
1131
  client_tick: e,
652
1132
  inputs: t
653
1133
  } };
654
1134
  }
655
1135
  //#endregion
1136
+ //#region packages/npm/laser/src/lib/net/postcard.ts
1137
+ var on = class {
1138
+ buf = [];
1139
+ u8(e) {
1140
+ this.buf.push(e & 255);
1141
+ }
1142
+ i8(e) {
1143
+ this.buf.push(e & 255);
1144
+ }
1145
+ bool(e) {
1146
+ this.buf.push(+!!e);
1147
+ }
1148
+ varU32(e) {
1149
+ let t = e >>> 0;
1150
+ for (; t >= 128;) this.buf.push(t & 127 | 128), t >>>= 7;
1151
+ this.buf.push(t);
1152
+ }
1153
+ varU64(e) {
1154
+ let t = BigInt.asUintN(64, e);
1155
+ for (; t >= 128n;) this.buf.push(Number(t & 127n | 128n)), t >>= 7n;
1156
+ this.buf.push(Number(t));
1157
+ }
1158
+ varI32(e) {
1159
+ this.varU32((e << 1 ^ e >> 31) >>> 0);
1160
+ }
1161
+ varI64(e) {
1162
+ this.varU64(BigInt.asUintN(64, e << 1n ^ e >> 63n));
1163
+ }
1164
+ u16(e) {
1165
+ this.varU32(e & 65535);
1166
+ }
1167
+ u32(e) {
1168
+ this.varU32(e);
1169
+ }
1170
+ i16(e) {
1171
+ this.varI32(e);
1172
+ }
1173
+ i32(e) {
1174
+ this.varI32(e);
1175
+ }
1176
+ string(e) {
1177
+ let t = new TextEncoder().encode(e);
1178
+ this.varU32(t.length);
1179
+ for (let e of t) this.buf.push(e);
1180
+ }
1181
+ seqLen(e) {
1182
+ this.varU32(e);
1183
+ }
1184
+ option(e) {
1185
+ this.buf.push(+!!e);
1186
+ }
1187
+ variant(e) {
1188
+ this.varU32(e);
1189
+ }
1190
+ bytes() {
1191
+ return Uint8Array.from(this.buf);
1192
+ }
1193
+ }, W = class {
1194
+ off = 0;
1195
+ constructor(e) {
1196
+ this.data = e;
1197
+ }
1198
+ next() {
1199
+ return this.data[this.off++];
1200
+ }
1201
+ u8() {
1202
+ return this.next();
1203
+ }
1204
+ i8() {
1205
+ let e = this.next();
1206
+ return e < 128 ? e : e - 256;
1207
+ }
1208
+ bool() {
1209
+ return this.next() !== 0;
1210
+ }
1211
+ varU32() {
1212
+ let e = 0, t = 0, n;
1213
+ do
1214
+ n = this.next(), e |= (n & 127) << t, t += 7;
1215
+ while (n & 128);
1216
+ return e >>> 0;
1217
+ }
1218
+ varU64() {
1219
+ let e = 0n, t = 0n, n;
1220
+ do
1221
+ n = this.next(), e |= BigInt(n & 127) << t, t += 7n;
1222
+ while (n & 128);
1223
+ return e;
1224
+ }
1225
+ varI32() {
1226
+ let e = this.varU32();
1227
+ return e >>> 1 ^ -(e & 1);
1228
+ }
1229
+ varI64() {
1230
+ let e = this.varU64();
1231
+ return e >> 1n ^ -(e & 1n);
1232
+ }
1233
+ u16() {
1234
+ return this.varU32();
1235
+ }
1236
+ u32() {
1237
+ return this.varU32();
1238
+ }
1239
+ i16() {
1240
+ return this.varI32();
1241
+ }
1242
+ i32() {
1243
+ return this.varI32();
1244
+ }
1245
+ string() {
1246
+ let e = this.varU32(), t = this.data.subarray(this.off, this.off + e);
1247
+ return this.off += e, new TextDecoder().decode(t);
1248
+ }
1249
+ seqLen() {
1250
+ return this.varU32();
1251
+ }
1252
+ option() {
1253
+ return this.next() !== 0;
1254
+ }
1255
+ variant() {
1256
+ return this.varU32();
1257
+ }
1258
+ remaining() {
1259
+ return this.data.length - this.off;
1260
+ }
1261
+ };
1262
+ function sn(e) {
1263
+ let t = [], n = t.length;
1264
+ t.push(0);
1265
+ let r = 1;
1266
+ for (let i of e) i === 0 ? (t[n] = r, n = t.length, t.push(0), r = 1) : (t.push(i), r += 1, r === 255 && (t[n] = r, n = t.length, t.push(0), r = 1));
1267
+ return t[n] = r, t.push(0), Uint8Array.from(t);
1268
+ }
1269
+ function cn(e) {
1270
+ let t = [], n = 0;
1271
+ for (; n < e.length;) {
1272
+ let r = e[n++];
1273
+ if (r === 0) break;
1274
+ for (let i = 1; i < r && n < e.length; i++) t.push(e[n++]);
1275
+ r !== 255 && n < e.length && e[n] !== 0 && t.push(0);
1276
+ }
1277
+ return Uint8Array.from(t);
1278
+ }
1279
+ //#endregion
1280
+ //#region packages/npm/laser/src/lib/net/postcard-wire.ts
1281
+ var ln = {
1282
+ Up: 0,
1283
+ Down: 1,
1284
+ Left: 2,
1285
+ Right: 3
1286
+ }, un = {
1287
+ Down: 0,
1288
+ Up: 1,
1289
+ Left: 2,
1290
+ Right: 3
1291
+ }, dn = {
1292
+ Hit: 0,
1293
+ Stand: 1,
1294
+ Double: 2,
1295
+ Split: 3,
1296
+ Surrender: 4
1297
+ };
1298
+ function G(e, t) {
1299
+ e.i32(t.x), e.i32(t.y);
1300
+ }
1301
+ function fn(e, t) {
1302
+ t == null ? e.option(!1) : (e.option(!0), e.u32(t));
1303
+ }
1304
+ function pn(e, t) {
1305
+ if (typeof t == "string") {
1306
+ switch (t) {
1307
+ case "Leave": return e.variant(13);
1308
+ case "TradeAccept": return e.variant(15);
1309
+ case "TradeCancel": return e.variant(16);
1310
+ case "LeaveTable": return e.variant(20);
1311
+ case "ExitShip": return e.variant(26);
1312
+ case "LaunchSpace": return e.variant(29);
1313
+ case "ReturnSpace": return e.variant(30);
1314
+ case "SimPetBattle": return e.variant(31);
1315
+ }
1316
+ return;
1317
+ }
1318
+ if ("Step" in t) e.variant(0), e.variant(ln[t.Step.dir]);
1319
+ else if ("Move" in t) {
1320
+ let n = t.Move;
1321
+ e.variant(1), e.u32(n.seq), e.i8(n.mx), e.i8(n.my), e.bool(n.run), e.u32(n.tick);
1322
+ } else if ("MoveTo" in t) e.variant(2), G(e, t.MoveTo.tile);
1323
+ else if ("Face" in t) e.variant(3), e.variant(un[t.Face.facing]);
1324
+ else if ("Action" in t) e.variant(4), e.u16(t.Action.id), fn(e, t.Action.target);
1325
+ else if ("CastSpell" in t) e.variant(5), e.string(t.CastSpell.spell_ref), fn(e, t.CastSpell.target);
1326
+ else if ("UseItem" in t) e.variant(6), e.string(t.UseItem.item_ref);
1327
+ else if ("DropItem" in t) e.variant(7), e.string(t.DropItem.item_ref), e.u32(t.DropItem.qty);
1328
+ else if ("MoveItem" in t) e.variant(8), e.u32(t.MoveItem.from), e.u32(t.MoveItem.to);
1329
+ else if ("EquipItem" in t) e.variant(9), e.string(t.EquipItem.item_ref);
1330
+ else if ("PlaceItem" in t) e.variant(10), e.string(t.PlaceItem.item_ref), G(e, t.PlaceItem.tile), e.u8(t.PlaceItem.rot & 3);
1331
+ else if ("PickupObject" in t) e.variant(11), G(e, t.PickupObject.tile);
1332
+ else if ("Heartbeat" in t) e.variant(12), e.u32(t.Heartbeat.client_tick);
1333
+ else if ("TradeOffer" in t) {
1334
+ e.variant(14), e.u32(t.TradeOffer.target), e.seqLen(t.TradeOffer.items.length);
1335
+ for (let [n, r] of t.TradeOffer.items) e.string(n), e.u32(r);
1336
+ } else "BuyItem" in t ? (e.variant(17), e.u32(t.BuyItem.npc), e.string(t.BuyItem.item_ref), e.u32(t.BuyItem.qty)) : "SellItem" in t ? (e.variant(18), e.u32(t.SellItem.npc), e.string(t.SellItem.item_ref), e.u32(t.SellItem.qty)) : "JoinTable" in t ? (e.variant(19), e.string(t.JoinTable.table_ref)) : "PlaceBet" in t ? (e.variant(21), e.u32(t.PlaceBet.amount)) : "BjAction" in t ? (e.variant(22), e.variant(dn[t.BjAction.kind])) : "Insure" in t ? (e.variant(23), e.u32(t.Insure.amount)) : "Fell" in t ? (e.variant(24), G(e, t.Fell.tile)) : "EnterShip" in t ? (e.variant(25), e.u32(t.EnterShip.ship)) : "ExitShip" in t ? e.variant(26) : "OpenCorpse" in t ? (e.variant(27), e.u32(t.OpenCorpse.corpse)) : "TakeFromCorpse" in t ? (e.variant(28), e.u32(t.TakeFromCorpse.corpse), e.u32(t.TakeFromCorpse.slot)) : "PetTurn" in t && (e.variant(32), e.u8(t.PetTurn.action), e.u8(t.PetTurn.arg));
1337
+ }
1338
+ var mn = [
1339
+ "Down",
1340
+ "Up",
1341
+ "Left",
1342
+ "Right"
1343
+ ], hn = [
1344
+ "Poison",
1345
+ "Regen",
1346
+ "Haste",
1347
+ "Burn"
1348
+ ];
1349
+ function K(e) {
1350
+ return {
1351
+ x: e.i32(),
1352
+ y: e.i32()
1353
+ };
1354
+ }
1355
+ function gn(e) {
1356
+ return {
1357
+ kind: e.u16(),
1358
+ ref: e.string(),
1359
+ cat: e.u8()
1360
+ };
1361
+ }
1362
+ function _n(e) {
1363
+ return {
1364
+ kind: hn[e.variant()],
1365
+ remaining: e.u16()
1366
+ };
1367
+ }
1368
+ function vn(e) {
1369
+ return {
1370
+ slot: e.u16(),
1371
+ kbve_username: e.string(),
1372
+ connected: e.bool()
1373
+ };
1374
+ }
1375
+ function yn(e) {
1376
+ let t = e.u32(), n = e.u16(), r = e.u16(), i = K(e), a = mn[e.variant()], o = e.u8(), s = e.i32(), c = e.i32(), l = e.i16(), u = e.i16(), d = e.u32(), f = e.i32(), ee = e.i32(), p = e.bool(), m = e.i32(), h = [];
1377
+ for (let t = e.seqLen(); t > 0; t--) h.push(_n(e));
1378
+ return {
1379
+ eid: t,
1380
+ kind: n,
1381
+ owner: r,
1382
+ tile: i,
1383
+ facing: a,
1384
+ sub: o,
1385
+ qx: s,
1386
+ qy: c,
1387
+ qvx: l,
1388
+ qvy: u,
1389
+ input_ack: d,
1390
+ hp: f,
1391
+ max_hp: ee,
1392
+ destroyed: p,
1393
+ z: m,
1394
+ effects: h,
1395
+ piloting: e.u32()
1396
+ };
1397
+ }
1398
+ function bn(e) {
1399
+ let t = e.u32(), n = e.u32(), r = e.u32(), i = [];
1400
+ for (let t = e.seqLen(); t > 0; t--) i.push(vn(e));
1401
+ let a = [];
1402
+ for (let t = e.seqLen(); t > 0; t--) a.push(yn(e));
1403
+ return {
1404
+ tick: t,
1405
+ server_time_ms: n,
1406
+ input_ack: r,
1407
+ players: i,
1408
+ entities: a,
1409
+ keyframe: e.bool()
1410
+ };
1411
+ }
1412
+ function xn(e) {
1413
+ let t = new W(cn(e)), n = t.variant();
1414
+ switch (n) {
1415
+ case 0: {
1416
+ let e = t.u32(), n = t.u16(), r = Number(t.varU64()), i = [];
1417
+ for (let e = t.seqLen(); e > 0; e--) i.push(gn(t));
1418
+ return { Welcome: {
1419
+ protocol: e,
1420
+ your_slot: n,
1421
+ seed: r,
1422
+ registry: i
1423
+ } };
1424
+ }
1425
+ case 1: return { Snapshot: bn(t) };
1426
+ case 2: {
1427
+ let e = t.u16(), n = t.u16(), r = [];
1428
+ for (let e = t.seqLen(); e > 0; e--) r.push(t.u8());
1429
+ return { Ephemeral: {
1430
+ kind: e,
1431
+ to: n,
1432
+ payload: r
1433
+ } };
1434
+ }
1435
+ case 3: return { Reject: { reason: t.string() } };
1436
+ default: throw Error(`postcard: unknown ServerEvent variant ${n}`);
1437
+ }
1438
+ }
1439
+ function Sn(e) {
1440
+ return {
1441
+ attacker: e.u32(),
1442
+ from: K(e),
1443
+ to: K(e),
1444
+ kind: e.string(),
1445
+ hit: e.bool()
1446
+ };
1447
+ }
1448
+ function Cn(e) {
1449
+ return Sn(new W(Uint8Array.from(e)));
1450
+ }
1451
+ function wn(e) {
1452
+ return {
1453
+ z: e.i32(),
1454
+ tile: K(e)
1455
+ };
1456
+ }
1457
+ function Tn(e) {
1458
+ return wn(new W(Uint8Array.from(e)));
1459
+ }
1460
+ function En(e) {
1461
+ return {
1462
+ item_ref: e.string(),
1463
+ count: e.u32()
1464
+ };
1465
+ }
1466
+ function Dn(e) {
1467
+ return En(new W(Uint8Array.from(e)));
1468
+ }
1469
+ function q(e) {
1470
+ return {
1471
+ species_ref: e.string(),
1472
+ nickname: e.string(),
1473
+ level: e.u32(),
1474
+ hp: e.i32(),
1475
+ max_hp: e.i32()
1476
+ };
1477
+ }
1478
+ function On(e) {
1479
+ return {
1480
+ kind: e.u8(),
1481
+ side: e.u8(),
1482
+ value: e.i32(),
1483
+ hp: e.i32(),
1484
+ flag: e.u8(),
1485
+ text: e.string()
1486
+ };
1487
+ }
1488
+ function kn(e) {
1489
+ let t = new W(Uint8Array.from(e)), n = [];
1490
+ for (let e = t.seqLen(); e > 0; e--) n.push(q(t));
1491
+ let r = [];
1492
+ for (let e = t.seqLen(); e > 0; e--) r.push(q(t));
1493
+ let i = [];
1494
+ for (let e = t.seqLen(); e > 0; e--) i.push(On(t));
1495
+ return {
1496
+ player: n,
1497
+ enemy: r,
1498
+ events: i,
1499
+ outcome: t.string()
1500
+ };
1501
+ }
1502
+ function An(e) {
1503
+ return {
1504
+ slot: e.u8(),
1505
+ name: e.string(),
1506
+ element: e.string(),
1507
+ category: e.u8(),
1508
+ power: e.i32(),
1509
+ accuracy: e.u32(),
1510
+ pp: e.u32(),
1511
+ max_pp: e.u32()
1512
+ };
1513
+ }
1514
+ function jn(e) {
1515
+ let t = new W(Uint8Array.from(e)), n = [];
1516
+ for (let e = t.seqLen(); e > 0; e--) n.push(q(t));
1517
+ let r = [];
1518
+ for (let e = t.seqLen(); e > 0; e--) r.push(q(t));
1519
+ let i = t.u8(), a = t.u8(), o = [];
1520
+ for (let e = t.seqLen(); e > 0; e--) o.push(An(t));
1521
+ let s = [];
1522
+ for (let e = t.seqLen(); e > 0; e--) s.push(On(t));
1523
+ return {
1524
+ player: n,
1525
+ enemy: r,
1526
+ p_active: i,
1527
+ e_active: a,
1528
+ moves: o,
1529
+ events: s,
1530
+ outcome: t.string(),
1531
+ awaiting: t.bool(),
1532
+ can_run: t.bool()
1533
+ };
1534
+ }
1535
+ function Mn(e) {
1536
+ let t = new W(Uint8Array.from(e)), n = t.u32(), r = [];
1537
+ for (let e = t.seqLen(); e > 0; e--) r.push([t.string(), t.u32()]);
1538
+ return {
1539
+ corpse: n,
1540
+ items: r
1541
+ };
1542
+ }
1543
+ function Nn(e) {
1544
+ return {
1545
+ item_ref: e.string(),
1546
+ heal: e.i32()
1547
+ };
1548
+ }
1549
+ function Pn(e) {
1550
+ return Nn(new W(Uint8Array.from(e)));
1551
+ }
1552
+ function J(e) {
1553
+ return e.option() ? e.string() : null;
1554
+ }
1555
+ function Fn(e) {
1556
+ return {
1557
+ attacker: e.u32(),
1558
+ target: e.u32(),
1559
+ target_ref: J(e),
1560
+ dmg: e.i32(),
1561
+ crit: e.bool(),
1562
+ died: e.bool()
1563
+ };
1564
+ }
1565
+ function In(e) {
1566
+ return Fn(new W(Uint8Array.from(e)));
1567
+ }
1568
+ function Ln(e) {
1569
+ return {
1570
+ item_ref: J(e),
1571
+ slot: e.string(),
1572
+ attack: e.i32(),
1573
+ defense: e.i32()
1574
+ };
1575
+ }
1576
+ function Rn(e) {
1577
+ return Ln(new W(Uint8Array.from(e)));
1578
+ }
1579
+ function zn(e) {
1580
+ return {
1581
+ level: e.i32(),
1582
+ xp: e.i32(),
1583
+ xp_next: e.i32(),
1584
+ max_hp: e.i32(),
1585
+ attack: e.i32(),
1586
+ kills: e.u32(),
1587
+ mp: e.i32(),
1588
+ max_mp: e.i32()
1589
+ };
1590
+ }
1591
+ function Bn(e) {
1592
+ return zn(new W(Uint8Array.from(e)));
1593
+ }
1594
+ function Vn(e) {
1595
+ return {
1596
+ item_ref: e.string(),
1597
+ tile: K(e),
1598
+ ok: e.bool(),
1599
+ reason: J(e) ?? void 0
1600
+ };
1601
+ }
1602
+ function Hn(e) {
1603
+ return Vn(new W(Uint8Array.from(e)));
1604
+ }
1605
+ function Un(e) {
1606
+ let t = [];
1607
+ for (let n = e.seqLen(); n > 0; n--) {
1608
+ let n = e.string(), r = e.string(), i = e.u32();
1609
+ t.push({
1610
+ id: n,
1611
+ ref: r,
1612
+ count: i
1613
+ });
1614
+ }
1615
+ return { items: t };
1616
+ }
1617
+ function Wn(e) {
1618
+ return Un(new W(Uint8Array.from(e)));
1619
+ }
1620
+ function Gn(e) {
1621
+ return {
1622
+ action: e.string(),
1623
+ item_ref: e.string(),
1624
+ qty: e.u32(),
1625
+ ok: e.bool(),
1626
+ reason: e.string(),
1627
+ balance: e.u32()
1628
+ };
1629
+ }
1630
+ function Kn(e) {
1631
+ return Gn(new W(Uint8Array.from(e)));
1632
+ }
1633
+ function qn(e) {
1634
+ let t = [];
1635
+ for (let n = e.seqLen(); n > 0; n--) t.push(e.u8());
1636
+ return {
1637
+ cards: t,
1638
+ bet: e.u32(),
1639
+ value: e.u32(),
1640
+ soft: e.bool(),
1641
+ doubled: e.bool(),
1642
+ surrendered: e.bool(),
1643
+ done: e.bool(),
1644
+ outcome: J(e)
1645
+ };
1646
+ }
1647
+ function Jn(e) {
1648
+ let t = e.u16(), n = e.string(), r = e.u32(), i = e.u32(), a = [];
1649
+ for (let t = e.seqLen(); t > 0; t--) a.push(qn(e));
1650
+ return {
1651
+ slot: t,
1652
+ username: n,
1653
+ bet: r,
1654
+ insurance: i,
1655
+ hands: a,
1656
+ disconnected: e.bool()
1657
+ };
1658
+ }
1659
+ function Yn(e) {
1660
+ let t = e.string(), n = e.string(), r = [];
1661
+ for (let t = e.seqLen(); t > 0; t--) r.push(Jn(e));
1662
+ let i = [];
1663
+ for (let t = e.seqLen(); t > 0; t--) i.push(e.u8());
1664
+ return {
1665
+ table_ref: t,
1666
+ phase: n,
1667
+ seats: r,
1668
+ dealer_hand: i,
1669
+ dealer_hidden: e.bool(),
1670
+ active_slot: e.option() ? e.u16() : null,
1671
+ active_hand: e.option() ? e.u32() : null,
1672
+ your_balance: e.u32(),
1673
+ deadline_ms: e.u32(),
1674
+ commitment: e.string(),
1675
+ seed: J(e)
1676
+ };
1677
+ }
1678
+ function Xn(e) {
1679
+ return Yn(new W(Uint8Array.from(e)));
1680
+ }
1681
+ function Zn(e) {
1682
+ let t = new on();
1683
+ if ("JoinMatch" in e) t.variant(0), t.u32(e.JoinMatch.protocol), t.string(e.JoinMatch.jwt), t.string(e.JoinMatch.kbve_username);
1684
+ else {
1685
+ t.variant(1);
1686
+ let n = e.Frame;
1687
+ t.u32(n.client_tick), t.seqLen(n.inputs.length);
1688
+ for (let e of n.inputs) pn(t, e);
1689
+ }
1690
+ return sn(t.bytes());
1691
+ }
1692
+ //#endregion
656
1693
  //#region packages/npm/laser/src/lib/net/game-client.ts
657
- var ye = class {
1694
+ var Qn = class {
658
1695
  clientTick = 0;
1696
+ moveSeq = 0;
1697
+ unackedMoves = [];
659
1698
  terminal = !1;
660
- bus = new g();
1699
+ bus = new y();
661
1700
  opts;
662
1701
  socket;
663
1702
  constructor(e) {
664
- this.opts = e, this.socket = new z({
1703
+ this.opts = e, this.socket = new H({
665
1704
  url: e.url,
666
1705
  maxAttempts: e.maxReconnects ?? 3,
667
1706
  baseDelayMs: 1500,
668
1707
  shouldReconnect: () => !this.terminal
669
1708
  }, {
670
1709
  onOpen: () => {
671
- this.send(Q(this.opts.jwt, this.opts.kbveUsername)), this.bus.emit("open", void 0);
1710
+ this.send(rn(this.opts.jwt, this.opts.kbveUsername)), this.bus.emit("open", void 0);
672
1711
  },
673
1712
  onMessage: (e) => this.handleMessage(e),
674
1713
  onState: (e) => {
@@ -689,9 +1728,10 @@ var ye = class {
689
1728
  this.terminal = !0;
690
1729
  }
691
1730
  handleMessage(e) {
1731
+ if (!(e.data instanceof ArrayBuffer)) return;
692
1732
  let t;
693
1733
  try {
694
- t = JSON.parse(typeof e.data == "string" ? e.data : String(e.data));
1734
+ t = xn(new Uint8Array(e.data));
695
1735
  } catch {
696
1736
  return;
697
1737
  }
@@ -699,42 +1739,73 @@ var ye = class {
699
1739
  }
700
1740
  handleEphemeral(e) {
701
1741
  if (this.bus.emit("ephemeral", e), e.kind === 1) {
702
- let t = Z(e.payload);
1742
+ let t = Wn(e.payload);
703
1743
  t && this.bus.emit("inventory", t);
704
1744
  } else if (e.kind === 2) {
705
- let t = Z(e.payload);
1745
+ let t = In(e.payload);
706
1746
  t && this.bus.emit("combat", t);
1747
+ } else if (e.kind === 12) {
1748
+ let t = Cn(e.payload);
1749
+ t && this.bus.emit("projectile", t);
1750
+ } else if (e.kind === 13) {
1751
+ let t = Tn(e.payload);
1752
+ t && this.bus.emit("floor", t);
707
1753
  } else if (e.kind === 3) {
708
- let t = Z(e.payload);
1754
+ let t = Dn(e.payload);
709
1755
  t && this.bus.emit("pickup", t);
1756
+ } else if (e.kind === 16) {
1757
+ let t = Mn(e.payload);
1758
+ t && this.bus.emit("corpse", t);
710
1759
  } else if (e.kind === 5) {
711
- let t = Z(e.payload);
1760
+ let t = Pn(e.payload);
712
1761
  t && this.bus.emit("itemUsed", t);
1762
+ } else if (e.kind === 14) {
1763
+ let t = Hn(e.payload);
1764
+ t && this.bus.emit("itemPlaced", t);
713
1765
  } else if (e.kind === 6) {
714
- let t = Z(e.payload);
1766
+ let t = Rn(e.payload);
715
1767
  t && this.bus.emit("equipped", t);
716
1768
  } else if (e.kind === 7) {
717
- let t = Z(e.payload);
1769
+ let t = Bn(e.payload);
718
1770
  t && this.bus.emit("stats", t);
719
1771
  } else if (e.kind === 10) {
720
- let t = Z(e.payload);
1772
+ let t = Kn(e.payload);
721
1773
  t && this.bus.emit("shop", t);
722
1774
  } else if (e.kind === 11) {
723
- let t = Z(e.payload);
1775
+ let t = Xn(e.payload);
724
1776
  t && this.bus.emit("blackjackState", t);
1777
+ } else if (e.kind === 18) {
1778
+ let t = kn(e.payload);
1779
+ t && this.bus.emit("petBattleReplay", t);
1780
+ } else if (e.kind === 19) {
1781
+ let t = jn(e.payload);
1782
+ t && this.bus.emit("petBattleState", t);
725
1783
  }
726
1784
  }
727
1785
  send(e) {
728
- this.socket.send(JSON.stringify(e));
1786
+ this.socket.send(Zn(e));
729
1787
  }
730
1788
  sendInputs(e) {
731
- !this.socket.isOpen() || e.length === 0 || (this.clientTick += 1, this.send($(this.clientTick, e)));
732
- }
733
- step(e) {
734
- this.sendInputs([{ Step: { dir: e } }]);
735
- }
736
- moveTo(e) {
737
- this.sendInputs([{ MoveTo: { tile: e } }]);
1789
+ !this.socket.isOpen() || e.length === 0 || (this.clientTick += 1, this.send(an(this.clientTick, e)));
1790
+ }
1791
+ move(e, t, n, r) {
1792
+ this.moveSeq += 1;
1793
+ let i = this.moveSeq;
1794
+ return this.unackedMoves.push({
1795
+ seq: i,
1796
+ mx: e,
1797
+ my: t,
1798
+ run: n
1799
+ }), this.unackedMoves.length > 256 && this.unackedMoves.shift(), this.sendInputs([{ Move: {
1800
+ seq: i,
1801
+ mx: e,
1802
+ my: t,
1803
+ run: n,
1804
+ tick: r
1805
+ } }]), i;
1806
+ }
1807
+ ackMoves(e) {
1808
+ return e > 0 && (this.unackedMoves = this.unackedMoves.filter((t) => t.seq > e)), this.unackedMoves;
738
1809
  }
739
1810
  action(e, t) {
740
1811
  this.sendInputs([{ Action: {
@@ -748,9 +1819,70 @@ var ye = class {
748
1819
  useItem(e) {
749
1820
  this.sendInputs([{ UseItem: { item_ref: e } }]);
750
1821
  }
1822
+ simPetBattle() {
1823
+ this.sendInputs(["SimPetBattle"]);
1824
+ }
1825
+ petTurn(e, t) {
1826
+ this.sendInputs([{ PetTurn: {
1827
+ action: e,
1828
+ arg: t
1829
+ } }]);
1830
+ }
1831
+ castSpell(e, t) {
1832
+ this.sendInputs([{ CastSpell: {
1833
+ spell_ref: e,
1834
+ target: t
1835
+ } }]);
1836
+ }
1837
+ dropItem(e, t) {
1838
+ this.sendInputs([{ DropItem: {
1839
+ item_ref: e,
1840
+ qty: t
1841
+ } }]);
1842
+ }
1843
+ moveItem(e, t) {
1844
+ this.sendInputs([{ MoveItem: {
1845
+ from: e,
1846
+ to: t
1847
+ } }]);
1848
+ }
751
1849
  equipItem(e) {
752
1850
  this.sendInputs([{ EquipItem: { item_ref: e } }]);
753
1851
  }
1852
+ enterShip(e) {
1853
+ this.sendInputs([{ EnterShip: { ship: e } }]);
1854
+ }
1855
+ exitShip() {
1856
+ this.sendInputs(["ExitShip"]);
1857
+ }
1858
+ launchSpace() {
1859
+ this.sendInputs(["LaunchSpace"]);
1860
+ }
1861
+ returnSpace() {
1862
+ this.sendInputs(["ReturnSpace"]);
1863
+ }
1864
+ placeItem(e, t, n = 0) {
1865
+ this.sendInputs([{ PlaceItem: {
1866
+ item_ref: e,
1867
+ tile: t,
1868
+ rot: n
1869
+ } }]);
1870
+ }
1871
+ openCorpse(e) {
1872
+ this.sendInputs([{ OpenCorpse: { corpse: e } }]);
1873
+ }
1874
+ takeFromCorpse(e, t) {
1875
+ this.sendInputs([{ TakeFromCorpse: {
1876
+ corpse: e,
1877
+ slot: t
1878
+ } }]);
1879
+ }
1880
+ pickupObject(e) {
1881
+ this.sendInputs([{ PickupObject: { tile: e } }]);
1882
+ }
1883
+ fell(e) {
1884
+ this.sendInputs([{ Fell: { tile: e } }]);
1885
+ }
754
1886
  buyItem(e, t, n) {
755
1887
  this.sendInputs([{ BuyItem: {
756
1888
  npc: e,
@@ -786,12 +1918,12 @@ var ye = class {
786
1918
  close() {
787
1919
  this.sendInputs(["Leave"]), this.socket.close();
788
1920
  }
789
- }, be = "chat", xe = class {
790
- bus = new g();
1921
+ }, $n = "chat", er = class {
1922
+ bus = new y();
791
1923
  opts;
792
1924
  socket;
793
1925
  constructor(e) {
794
- this.opts = e, this.socket = new z({
1926
+ this.opts = e, this.socket = new H({
795
1927
  url: () => {
796
1928
  let e = this.opts.url.includes("?") ? "&" : "?";
797
1929
  return `${this.opts.url}${e}game=${encodeURIComponent(this.opts.game)}&token=${encodeURIComponent(this.opts.jwt)}`;
@@ -838,17 +1970,420 @@ var ye = class {
838
1970
  let t = e.trim().slice(0, 200);
839
1971
  if (!t || !this.socket.isOpen()) return;
840
1972
  let n = {
841
- kind: be,
1973
+ kind: $n,
842
1974
  sender: "",
843
1975
  platform: "",
844
1976
  channel: this.opts.channel,
845
1977
  content: t
846
1978
  };
847
- this.socket.send(JSON.stringify(n));
1979
+ this.socket.send(JSON.stringify(n)), this.bus.emit("message", {
1980
+ from: this.opts.nick || "you",
1981
+ text: t
1982
+ });
848
1983
  }
849
1984
  close() {
850
1985
  this.socket.close();
851
1986
  }
852
1987
  };
853
1988
  //#endregion
854
- export { V as ACTION_ATTACK, H as ACTION_PICKUP, ce as EPHEMERAL_BLACKJACK, W as EPHEMERAL_COMBAT, ae as EPHEMERAL_EQUIPPED, U as EPHEMERAL_INVENTORY, K as EPHEMERAL_ITEM_USED, G as EPHEMERAL_PICKUP, se as EPHEMERAL_SHOP, q as EPHEMERAL_STATS, J as EPHEMERAL_STATUS, oe as EPHEMERAL_TRADE, ye as GameClient, de as KIND_CAT_ITEM, ue as KIND_CAT_NPC, le as KIND_CAT_PLAYER, g as LaserEventBus, ve as OWNER_NONE, B as PROTOCOL_VERSION, y as PhaserContext, x as PhaserGame, w as PlayerController, v as Quadtree, m as RAPIER, xe as RealmChatClient, z as ReconnectingSocket, F as SideMap, j as Stage, C as VirtualJoystick, te as attachCameraZoom, X as bjShoeOrder, A as createBirdAnimation, O as createBirdSprites, h as createRapierPhysics, k as createShadowSprites, he as decodeCard, Z as decodeEphemeralPayload, R as defaultCloseReason, ee as drawHealthBar, ne as findTilePath, T as flashEntity, E as floatingText, re as getBirdNum, $ as inputFrame, ie as isBird, Q as joinFrame, _ as laserEvents, P as nearestInRange, N as queryInRange, M as useGameLoop, S as usePhaserEvent, b as usePhaserGame, _e as verifyBlackjackCommitment };
1989
+ //#region packages/npm/laser/src/lib/auth/game-auth.ts
1990
+ function Y(e) {
1991
+ try {
1992
+ let t = e.split(".")[1], n = atob(t.replace(/-/g, "+").replace(/_/g, "/"));
1993
+ return JSON.parse(n).kbve_username ?? "";
1994
+ } catch {
1995
+ return "";
1996
+ }
1997
+ }
1998
+ function tr(e) {
1999
+ let t = null;
2000
+ return {
2001
+ get() {
2002
+ return t;
2003
+ },
2004
+ set(e) {
2005
+ t = e;
2006
+ },
2007
+ clear() {
2008
+ t = null;
2009
+ },
2010
+ async build() {
2011
+ let n = (await e.source.getSession())?.access_token ?? "";
2012
+ return n ? (t = {
2013
+ wsUrl: e.resolveWsUrl(),
2014
+ jwt: n,
2015
+ username: Y(n)
2016
+ }, t) : null;
2017
+ }
2018
+ };
2019
+ }
2020
+ function nr(e, t) {
2021
+ return () => {
2022
+ let n = typeof e == "string" ? e : void 0;
2023
+ return n && n.length > 0 ? n : t;
2024
+ };
2025
+ }
2026
+ function rr(e, t) {
2027
+ return t ? new er({
2028
+ url: e.resolveUrl(),
2029
+ jwt: t,
2030
+ game: e.game,
2031
+ channel: e.channel,
2032
+ nick: Y(t)
2033
+ }) : null;
2034
+ }
2035
+ //#endregion
2036
+ //#region packages/npm/laser/src/lib/embed/external.ts
2037
+ var X = null;
2038
+ function ir(e) {
2039
+ X = e;
2040
+ }
2041
+ function ar() {
2042
+ return X;
2043
+ }
2044
+ function or(e) {
2045
+ if (X) {
2046
+ X(e);
2047
+ return;
2048
+ }
2049
+ typeof window < "u" && window.open(e, "_blank", "noopener,noreferrer");
2050
+ }
2051
+ function sr(e) {
2052
+ return (t) => {
2053
+ X && (t.preventDefault(), X(e));
2054
+ };
2055
+ }
2056
+ //#endregion
2057
+ //#region packages/npm/laser/src/lib/embed/discord-external.ts
2058
+ function cr(e) {
2059
+ ir((t) => {
2060
+ e.commands.openExternalLink({ url: t }).catch(() => void 0);
2061
+ });
2062
+ }
2063
+ function lr(e) {
2064
+ e.commands.encourageHardwareAcceleration().catch(() => void 0);
2065
+ }
2066
+ //#endregion
2067
+ //#region packages/npm/laser/src/lib/ads/AdCard.tsx
2068
+ var ur = "#6ea8ff";
2069
+ function dr({ creative: e, onOpen: t, style: n, className: r }) {
2070
+ let i = e.accent ?? ur;
2071
+ return /* @__PURE__ */ f("a", {
2072
+ href: e.url,
2073
+ target: "_blank",
2074
+ rel: "noopener noreferrer",
2075
+ className: r,
2076
+ onClick: t ? (n) => {
2077
+ n.preventDefault(), t(e);
2078
+ } : void 0,
2079
+ style: {
2080
+ display: "flex",
2081
+ alignItems: "center",
2082
+ gap: "12px",
2083
+ maxWidth: "320px",
2084
+ padding: "10px 14px",
2085
+ borderRadius: "8px",
2086
+ border: `1px solid ${i}59`,
2087
+ background: "linear-gradient(135deg, rgba(20,26,40,0.9), rgba(34,24,48,0.9))",
2088
+ textDecoration: "none",
2089
+ color: "#e6ebf5",
2090
+ boxShadow: "0 4px 18px rgba(0,0,0,0.45)",
2091
+ ...n
2092
+ },
2093
+ children: [/* @__PURE__ */ d("span", {
2094
+ "aria-hidden": "true",
2095
+ style: {
2096
+ flex: "0 0 auto",
2097
+ width: "38px",
2098
+ height: "38px",
2099
+ borderRadius: "8px",
2100
+ overflow: "hidden",
2101
+ display: "flex",
2102
+ alignItems: "center",
2103
+ justifyContent: "center",
2104
+ fontSize: "20px",
2105
+ background: `radial-gradient(120% 120% at 30% 20%, ${i}, #7c3aed)`
2106
+ },
2107
+ children: e.imageUrl ? /* @__PURE__ */ d("img", {
2108
+ src: e.imageUrl,
2109
+ alt: "",
2110
+ style: {
2111
+ width: "100%",
2112
+ height: "100%",
2113
+ objectFit: "cover"
2114
+ },
2115
+ onError: (e) => {
2116
+ e.currentTarget.style.display = "none";
2117
+ }
2118
+ }) : e.icon ?? "★"
2119
+ }), /* @__PURE__ */ f("span", {
2120
+ style: {
2121
+ display: "flex",
2122
+ flexDirection: "column",
2123
+ gap: "2px",
2124
+ minWidth: 0
2125
+ },
2126
+ children: [
2127
+ e.eyebrow ? /* @__PURE__ */ d("span", {
2128
+ style: {
2129
+ fontSize: "9px",
2130
+ letterSpacing: 1.4,
2131
+ textTransform: "uppercase",
2132
+ color: "#9fb3d8"
2133
+ },
2134
+ children: e.eyebrow
2135
+ }) : null,
2136
+ /* @__PURE__ */ f("span", {
2137
+ style: {
2138
+ fontSize: "13px",
2139
+ fontWeight: 700
2140
+ },
2141
+ children: [e.title, e.highlight ? /* @__PURE__ */ f(u, { children: [" ", /* @__PURE__ */ d("span", {
2142
+ style: { color: i === ur ? "#fcd34d" : i },
2143
+ children: e.highlight
2144
+ })] }) : null]
2145
+ }),
2146
+ e.body ? /* @__PURE__ */ d("span", {
2147
+ style: {
2148
+ fontSize: "11px",
2149
+ color: "#9fb3d8"
2150
+ },
2151
+ children: e.body
2152
+ }) : null
2153
+ ]
2154
+ })]
2155
+ });
2156
+ }
2157
+ //#endregion
2158
+ //#region packages/npm/laser/src/lib/ads/registry.ts
2159
+ function Z(e, t = Math.random) {
2160
+ if (e.length === 0) return null;
2161
+ let n = e.map((e) => e.weight == null ? 1 : Math.max(0, e.weight)), r = n.reduce((e, t) => e + t, 0);
2162
+ if (r <= 0) return null;
2163
+ let i = t() * r;
2164
+ for (let t = 0; t < e.length; t++) if (i -= n[t], i < 0) return e[t];
2165
+ return e[e.length - 1];
2166
+ }
2167
+ var fr = class {
2168
+ ads = /* @__PURE__ */ new Map();
2169
+ register(...e) {
2170
+ for (let t of e) this.ads.set(t.id, t);
2171
+ return this;
2172
+ }
2173
+ remove(e) {
2174
+ return this.ads.delete(e), this;
2175
+ }
2176
+ clear() {
2177
+ return this.ads.clear(), this;
2178
+ }
2179
+ list() {
2180
+ return [...this.ads.values()];
2181
+ }
2182
+ pick(e = Math.random) {
2183
+ return Z(this.list(), e);
2184
+ }
2185
+ }, pr = new fr(), mr = /\{(\w+)\}/g;
2186
+ function hr(e, t) {
2187
+ return t ? e.replace(mr, (e, n) => {
2188
+ let r = t[n];
2189
+ return r === void 0 ? e : String(r);
2190
+ }) : e;
2191
+ }
2192
+ var Q = class {
2193
+ locale;
2194
+ fallback;
2195
+ bundles = /* @__PURE__ */ new Map();
2196
+ listeners = /* @__PURE__ */ new Set();
2197
+ constructor(e = {}) {
2198
+ if (this.locale = e.locale ?? "en", this.fallback = e.fallbackLocale ?? "en", e.messages) for (let [t, n] of Object.entries(e.messages)) this.bundles.set(t, { ...n });
2199
+ }
2200
+ getLocale() {
2201
+ return this.locale;
2202
+ }
2203
+ setLocale(e) {
2204
+ e !== this.locale && (this.locale = e, this.emit());
2205
+ }
2206
+ getLocales() {
2207
+ return [...this.bundles.keys()];
2208
+ }
2209
+ add(e, t) {
2210
+ let n = this.bundles.get(e);
2211
+ this.bundles.set(e, n ? {
2212
+ ...n,
2213
+ ...t
2214
+ } : { ...t }), this.emit();
2215
+ }
2216
+ has(e, t = this.locale) {
2217
+ return this.bundles.get(t)?.[e] !== void 0 || this.bundles.get(this.fallback)?.[e] !== void 0;
2218
+ }
2219
+ t(e, t) {
2220
+ let n = this.bundles.get(this.locale)?.[e];
2221
+ if (n !== void 0) return hr(n, t);
2222
+ let r = this.bundles.get(this.fallback)?.[e];
2223
+ return r === void 0 ? e : hr(r, t);
2224
+ }
2225
+ subscribe(e) {
2226
+ return this.listeners.add(e), () => {
2227
+ this.listeners.delete(e);
2228
+ };
2229
+ }
2230
+ emit() {
2231
+ this.listeners.forEach((e) => e());
2232
+ }
2233
+ }, $ = new Q(), gr = e($);
2234
+ function _r({ store: e = $, children: t }) {
2235
+ return /* @__PURE__ */ d(gr.Provider, {
2236
+ value: e,
2237
+ children: t
2238
+ });
2239
+ }
2240
+ function vr() {
2241
+ let e = n(gr), t = c((t) => e.subscribe(t), () => e.getLocale(), () => e.getLocale());
2242
+ return a(() => ({
2243
+ t: (t, n) => e.t(t, n),
2244
+ locale: t,
2245
+ setLocale: (t) => e.setLocale(t),
2246
+ store: e
2247
+ }), [e, t]);
2248
+ }
2249
+ ae(/* @__PURE__ */ re({
2250
+ ACTION_ATTACK: () => 1,
2251
+ ACTION_LOOT: () => 4,
2252
+ ACTION_PICKUP: () => 2,
2253
+ ACTION_SHOOT: () => 3,
2254
+ Active: () => L,
2255
+ AdCard: () => dr,
2256
+ AdRegistry: () => fr,
2257
+ AttackShape: () => Qe,
2258
+ BOW_RANGE: () => 8,
2259
+ Cat: () => B,
2260
+ Domain: () => qe,
2261
+ ELEMENT_NAMES: () => Ht,
2262
+ EPHEMERAL_BLACKJACK: () => 11,
2263
+ EPHEMERAL_COMBAT: () => 2,
2264
+ EPHEMERAL_EQUIPPED: () => 6,
2265
+ EPHEMERAL_FLOOR: () => 13,
2266
+ EPHEMERAL_INVENTORY: () => 1,
2267
+ EPHEMERAL_ITEM_USED: () => 5,
2268
+ EPHEMERAL_PICKUP: () => 3,
2269
+ EPHEMERAL_PROJECTILE: () => 12,
2270
+ EPHEMERAL_SHOP: () => 10,
2271
+ EPHEMERAL_STATS: () => 7,
2272
+ EPHEMERAL_STATUS: () => 8,
2273
+ EPHEMERAL_TRADE: () => 9,
2274
+ EntityStore: () => Ke,
2275
+ EnvTag: () => We,
2276
+ GameClient: () => Qn,
2277
+ GameObjectPool: () => D,
2278
+ Health: () => P,
2279
+ I18nProvider: () => _r,
2280
+ I18nStore: () => Q,
2281
+ INVARIANT_EVENT: () => oe,
2282
+ ItemTag: () => Ue,
2283
+ KIND_CAT_ITEM: () => 2,
2284
+ KIND_CAT_NPC: () => 1,
2285
+ KIND_CAT_PLAYER: () => 0,
2286
+ Kind: () => F,
2287
+ LaserEventBus: () => y,
2288
+ MAX_ENTITIES: () => M,
2289
+ MELEE_RANGE: () => 1,
2290
+ MonsterTag: () => z,
2291
+ NpcTag: () => He,
2292
+ OWNER_NONE: () => tn,
2293
+ Owner: () => I,
2294
+ PB_DAMAGE: () => 1,
2295
+ PB_FAINT: () => 3,
2296
+ PB_HEAL: () => 7,
2297
+ PB_INFO: () => 12,
2298
+ PB_MISS: () => 2,
2299
+ PB_NOPP: () => 9,
2300
+ PB_PARALYZED: () => 10,
2301
+ PB_STAT: () => 8,
2302
+ PB_STATUS: () => 5,
2303
+ PB_STATUS_DMG: () => 6,
2304
+ PB_SWAP: () => 4,
2305
+ PB_TURN: () => 11,
2306
+ PB_USED: () => 0,
2307
+ PB_USED_CATEGORY_MASK: () => 3,
2308
+ PB_USED_RANGED: () => 4,
2309
+ PET_ACT_ITEM: () => 2,
2310
+ PET_ACT_MOVE: () => 0,
2311
+ PET_ACT_RUN: () => 3,
2312
+ PET_ACT_SWAP: () => 1,
2313
+ PROTOCOL_VERSION: () => 15,
2314
+ PhaserContext: () => x,
2315
+ PhaserGame: () => he,
2316
+ PlayerController: () => ve,
2317
+ PlayerTag: () => Ve,
2318
+ Position: () => N,
2319
+ Possession: () => R,
2320
+ Quadtree: () => pe,
2321
+ RAPIER: () => h,
2322
+ RealmChatClient: () => er,
2323
+ ReconnectingSocket: () => H,
2324
+ SideMap: () => j,
2325
+ Stage: () => Le,
2326
+ VirtualJoystick: () => _e,
2327
+ animateArrowProjectile: () => ke,
2328
+ aoeTiles: () => it,
2329
+ attachCameraZoom: () => Ce,
2330
+ bjShoeOrder: () => $t,
2331
+ createArrowPool: () => Oe,
2332
+ createBirdAnimation: () => Ie,
2333
+ createBirdSprites: () => Pe,
2334
+ createChatClient: () => rr,
2335
+ createDustMoteLayer: () => Ee,
2336
+ createGpuSpriteLayer: () => w,
2337
+ createNetConfig: () => tr,
2338
+ createRapierPhysics: () => g,
2339
+ createShadowSprites: () => Fe,
2340
+ decodeCard: () => Zt,
2341
+ decodeEphemeralPayload: () => nn,
2342
+ defaultCloseReason: () => st,
2343
+ drawHealthBar: () => xe,
2344
+ drawHealthBarCached: () => Se,
2345
+ dustMemberAt: () => E,
2346
+ encourageHardwareAcceleration: () => lr,
2347
+ findTilePath: () => Ae,
2348
+ flashEntity: () => ye,
2349
+ floatingText: () => be,
2350
+ getBirdNum: () => je,
2351
+ getExternalOpener: () => ar,
2352
+ inRangeAdjacent: () => nt,
2353
+ inputFrame: () => an,
2354
+ installDiscordExternal: () => cr,
2355
+ installWebGLContextGuard: () => C,
2356
+ invariant: () => de,
2357
+ isBird: () => Me,
2358
+ isWebGLAvailable: () => we,
2359
+ joinFrame: () => rn,
2360
+ laserAds: () => pr,
2361
+ laserEvents: () => b,
2362
+ laserI18n: () => $,
2363
+ lineCast: () => rt,
2364
+ makeWsResolver: () => nr,
2365
+ mix32: () => Ye,
2366
+ mulberry32: () => Je,
2367
+ nearestInRange: () => Be,
2368
+ onExternalClick: () => sr,
2369
+ openExternal: () => or,
2370
+ packTile: () => k,
2371
+ pickAd: () => Z,
2372
+ populateGpuSpriteLayer: () => T,
2373
+ queryInRange: () => A,
2374
+ reportWebGLEvent: () => S,
2375
+ resetInvariants: () => fe,
2376
+ rollPct: () => Ze,
2377
+ setExternalOpener: () => ir,
2378
+ setInvariantThrottle: () => ue,
2379
+ setupKeyboardMap: () => De,
2380
+ stream: () => Xe,
2381
+ useGameLoop: () => Re,
2382
+ usePhaserEvent: () => ge,
2383
+ usePhaserGame: () => me,
2384
+ useTranslation: () => vr,
2385
+ usernameFromToken: () => Y,
2386
+ verifyBlackjackCommitment: () => en
2387
+ }), O);
2388
+ //#endregion
2389
+ export { lt as ACTION_ATTACK, ft as ACTION_LOOT, ut as ACTION_PICKUP, dt as ACTION_SHOOT, L as Active, dr as AdCard, fr as AdRegistry, Qe as AttackShape, et as BOW_RANGE, B as Cat, qe as Domain, Ht as ELEMENT_NAMES, St as EPHEMERAL_BLACKJACK, mt as EPHEMERAL_COMBAT, _t as EPHEMERAL_EQUIPPED, wt as EPHEMERAL_FLOOR, pt as EPHEMERAL_INVENTORY, gt as EPHEMERAL_ITEM_USED, ht as EPHEMERAL_PICKUP, Ct as EPHEMERAL_PROJECTILE, xt as EPHEMERAL_SHOP, vt as EPHEMERAL_STATS, yt as EPHEMERAL_STATUS, bt as EPHEMERAL_TRADE, Ke as EntityStore, We as EnvTag, Qn as GameClient, D as GameObjectPool, P as Health, _r as I18nProvider, Q as I18nStore, oe as INVARIANT_EVENT, Ue as ItemTag, qt as KIND_CAT_ITEM, Kt as KIND_CAT_NPC, Gt as KIND_CAT_PLAYER, F as Kind, y as LaserEventBus, M as MAX_ENTITIES, $e as MELEE_RANGE, z as MonsterTag, He as NpcTag, tn as OWNER_NONE, I as Owner, At as PB_DAMAGE, Mt as PB_FAINT, It as PB_HEAL, Vt as PB_INFO, jt as PB_MISS, Rt as PB_NOPP, zt as PB_PARALYZED, Lt as PB_STAT, Pt as PB_STATUS, Ft as PB_STATUS_DMG, Nt as PB_SWAP, Bt as PB_TURN, kt as PB_USED, Ut as PB_USED_CATEGORY_MASK, Wt as PB_USED_RANGED, Dt as PET_ACT_ITEM, Tt as PET_ACT_MOVE, Ot as PET_ACT_RUN, Et as PET_ACT_SWAP, ct as PROTOCOL_VERSION, x as PhaserContext, he as PhaserGame, ve as PlayerController, Ve as PlayerTag, N as Position, R as Possession, pe as Quadtree, h as RAPIER, er as RealmChatClient, H as ReconnectingSocket, j as SideMap, Le as Stage, _e as VirtualJoystick, ke as animateArrowProjectile, it as aoeTiles, Ce as attachCameraZoom, $t as bjShoeOrder, Oe as createArrowPool, Ie as createBirdAnimation, Pe as createBirdSprites, rr as createChatClient, Ee as createDustMoteLayer, w as createGpuSpriteLayer, tr as createNetConfig, g as createRapierPhysics, Fe as createShadowSprites, Zt as decodeCard, nn as decodeEphemeralPayload, st as defaultCloseReason, xe as drawHealthBar, Se as drawHealthBarCached, E as dustMemberAt, lr as encourageHardwareAcceleration, Ae as findTilePath, ye as flashEntity, be as floatingText, je as getBirdNum, ar as getExternalOpener, nt as inRangeAdjacent, an as inputFrame, cr as installDiscordExternal, C as installWebGLContextGuard, de as invariant, Me as isBird, we as isWebGLAvailable, rn as joinFrame, pr as laserAds, b as laserEvents, $ as laserI18n, rt as lineCast, nr as makeWsResolver, Ye as mix32, Je as mulberry32, Be as nearestInRange, sr as onExternalClick, or as openExternal, k as packTile, Z as pickAd, T as populateGpuSpriteLayer, A as queryInRange, S as reportWebGLEvent, fe as resetInvariants, Ze as rollPct, ir as setExternalOpener, ue as setInvariantThrottle, De as setupKeyboardMap, Xe as stream, Re as useGameLoop, ge as usePhaserEvent, me as usePhaserGame, vr as useTranslation, Y as usernameFromToken, en as verifyBlackjackCommitment };