@minicode-dev/chat 0.1.14 → 0.1.15

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 (37) hide show
  1. package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js → BattleshipGameCard-8H-sBCsv.js} +3 -3
  2. package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js.map → BattleshipGameCard-8H-sBCsv.js.map} +1 -1
  3. package/dist/chunks/{ChatContext-DQtKsR6Z.js → ChatContext-CVW58bzC.js} +2 -2
  4. package/dist/chunks/{ChatContext-DQtKsR6Z.js.map → ChatContext-CVW58bzC.js.map} +1 -1
  5. package/dist/chunks/{RacingLiveGameCard-c1G7uoDI.js → RacingLiveGameCard-8j9QLnxW.js} +4 -4
  6. package/dist/chunks/{RacingLiveGameCard-c1G7uoDI.js.map → RacingLiveGameCard-8j9QLnxW.js.map} +1 -1
  7. package/dist/chunks/{TanksGameCard-CvTaF7tu.js → TanksGameCard-DnCufSH6.js} +12 -12
  8. package/dist/chunks/{TanksGameCard-CvTaF7tu.js.map → TanksGameCard-DnCufSH6.js.map} +1 -1
  9. package/dist/chunks/TanksLiveGameCard-D_27Jomp.js +1274 -0
  10. package/dist/chunks/TanksLiveGameCard-D_27Jomp.js.map +1 -0
  11. package/dist/chunks/{avalancheScene3d-Z5QyZIid.js → avalancheScene3d-CIE2WKQn.js} +51 -50
  12. package/dist/chunks/{avalancheScene3d-Z5QyZIid.js.map → avalancheScene3d-CIE2WKQn.js.map} +1 -1
  13. package/dist/chunks/cars-D1PM7mVD.js +340 -0
  14. package/dist/chunks/cars-D1PM7mVD.js.map +1 -0
  15. package/dist/chunks/{connect4Sounds-DmD-E9kX.js → connect4Sounds-BqEHULjv.js} +2 -2
  16. package/dist/chunks/{connect4Sounds-DmD-E9kX.js.map → connect4Sounds-BqEHULjv.js.map} +1 -1
  17. package/dist/chunks/createLiveScene-MTGRv8rx.js +758 -0
  18. package/dist/chunks/createLiveScene-MTGRv8rx.js.map +1 -0
  19. package/dist/chunks/{createRaceScene-C7Rw89kj.js → createRaceScene-BiEtQsVs.js} +4 -3
  20. package/dist/chunks/{createRaceScene-C7Rw89kj.js.map → createRaceScene-BiEtQsVs.js.map} +1 -1
  21. package/dist/chunks/fx-DhXerGyt.js +248 -0
  22. package/dist/chunks/fx-DhXerGyt.js.map +1 -0
  23. package/dist/chunks/{games-BvYTWgaR.js → games-Bl_8raG6.js} +1147 -574
  24. package/dist/chunks/games-Bl_8raG6.js.map +1 -0
  25. package/dist/chunks/{tanksSounds-DwjfSp3W.js → tanksSounds-DTnidbiq.js} +5 -5
  26. package/dist/chunks/{tanksSounds-DwjfSp3W.js.map → tanksSounds-DTnidbiq.js.map} +1 -1
  27. package/dist/index.js +28 -28
  28. package/dist/index.js.map +1 -1
  29. package/dist/styles.css +1 -1
  30. package/package.json +1 -1
  31. package/dist/chunks/TanksLiveGameCard-COr9Oay5.js +0 -1011
  32. package/dist/chunks/TanksLiveGameCard-COr9Oay5.js.map +0 -1
  33. package/dist/chunks/createLiveScene-CWBunxPi.js +0 -367
  34. package/dist/chunks/createLiveScene-CWBunxPi.js.map +0 -1
  35. package/dist/chunks/fx-UZwhOmdl.js +0 -584
  36. package/dist/chunks/fx-UZwhOmdl.js.map +0 -1
  37. package/dist/chunks/games-BvYTWgaR.js.map +0 -1
@@ -12,25 +12,577 @@ function p(e = globalThis.crypto) {
12
12
  let n = Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
13
13
  return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
14
14
  }
15
+ // src/games/tanks-live/logic/simulation.js
16
+ var m = Object.freeze({
17
+ speed: 16,
18
+ reverse: 9,
19
+ turn: 1.8,
20
+ acceleration: 28,
21
+ radius: 2,
22
+ reloadMs: 1500,
23
+ shellSpeed: 60,
24
+ damage: 25
25
+ }), h = (e, t, n) => Math.max(t, Math.min(n, e)), g = (e, t) => Math.atan2(Math.sin(t - e), Math.cos(t - e));
26
+ function _() {
27
+ return {
28
+ size: 120,
29
+ bounds: {
30
+ minX: 0,
31
+ maxX: 120,
32
+ minZ: 0,
33
+ maxZ: 120
34
+ },
35
+ obstacles: [
36
+ [
37
+ 42,
38
+ 35,
39
+ 4
40
+ ],
41
+ [
42
+ 78,
43
+ 85,
44
+ 4
45
+ ],
46
+ [
47
+ 60,
48
+ 30,
49
+ 3
50
+ ],
51
+ [
52
+ 60,
53
+ 90,
54
+ 3
55
+ ],
56
+ [
57
+ 35,
58
+ 65,
59
+ 3
60
+ ],
61
+ [
62
+ 85,
63
+ 55,
64
+ 3
65
+ ],
66
+ [
67
+ 60,
68
+ 60,
69
+ 5
70
+ ]
71
+ ].map(([e, t, n], r) => ({
72
+ x: e,
73
+ z: t,
74
+ r: n,
75
+ kind: r % 2 ? "tree" : "rock"
76
+ }))
77
+ };
78
+ }
79
+ function v(e, t) {
80
+ return {
81
+ id: String(e),
82
+ x: t ? 102 : 18,
83
+ z: 60,
84
+ yaw: t ? Math.PI : 0,
85
+ turretYaw: t ? Math.PI : 0,
86
+ speed: 0,
87
+ hp: 100,
88
+ alive: !0,
89
+ color: t ? "#d7463f" : "#54a34a"
90
+ };
91
+ }
92
+ var y = Object.freeze({
93
+ radius: 6,
94
+ damage: 20
95
+ }), b = (e) => !!e && e.alive !== !1 && (e.hp === void 0 || e.hp > 0);
96
+ function x(e, t, n) {
97
+ let r = t - e.x, i = n - e.z, a = Math.cos(e.rot || 0), o = Math.sin(e.rot || 0);
98
+ return [r * a + i * o, -r * o + i * a];
99
+ }
100
+ function S(e, t, n, r) {
101
+ if (r.shape !== "rect") return Math.hypot(e - r.x, t - r.z) < r.r + n;
102
+ let [i, a] = x(r, e, t), o = r.w / 2, s = r.d / 2;
103
+ return Math.hypot(i - h(i, -o, o), a - h(a, -s, s)) < n || Math.abs(i) <= o && Math.abs(a) <= s;
104
+ }
105
+ function ee(e, t, n, r = m.radius) {
106
+ let i = n.bounds;
107
+ return e >= i.minX + r && e <= i.maxX - r && t >= i.minZ + r && t <= i.maxZ - r && !n.obstacles.some((n) => S(e, t, r, n)) && !(n.destructibles || []).some((n) => b(n) && S(e, t, r, n));
108
+ }
109
+ function te(e, t, n, r) {
110
+ if (!e.alive) return;
111
+ let i = h(Number(t.throttle) || 0, -1, 1), a = h(Number(t.steer) || 0, -1, 1), o = i * (i < 0 ? m.reverse : m.speed);
112
+ e.speed += h(o - e.speed, -m.acceleration * n, m.acceleration * n), e.yaw += a * m.turn * n, Number.isFinite(t.turretYaw) && (e.turretYaw = t.turretYaw);
113
+ let s = e.x + Math.cos(e.yaw) * e.speed * n, c = e.z + Math.sin(e.yaw) * e.speed * n;
114
+ ee(s, e.z, r) ? e.x = s : e.speed = 0, ee(e.x, c, r) ? e.z = c : e.speed = 0;
115
+ }
116
+ function ne(e, t, n, r, i, a, o) {
117
+ let s = n - e, c = r - t, l = s * s + c * c, u = l ? h(((i - e) * s + (a - t) * c) / l, 0, 1) : 0;
118
+ return Math.hypot(e + s * u - i, t + c * u - a) <= o ? u : null;
119
+ }
120
+ function re(e, t, n, r, i) {
121
+ let [a, o] = x(i, e, t), [s, c] = x(i, n, r), l = [s - a, c - o], u = [a, o], d = [i.w / 2, i.d / 2], f = 0, p = 1;
122
+ for (let e = 0; e < 2; e++) {
123
+ if (Math.abs(l[e]) < 1e-12) {
124
+ if (Math.abs(u[e]) > d[e]) return null;
125
+ continue;
126
+ }
127
+ let t = (-d[e] - u[e]) / l[e], n = (d[e] - u[e]) / l[e];
128
+ if (t > n && ([t, n] = [n, t]), f = Math.max(f, t), p = Math.min(p, n), f > p) return null;
129
+ }
130
+ return f;
131
+ }
132
+ var ie = (e, t, n, r, i) => i.shape === "rect" ? re(e, t, n, r, i) : ne(e, t, n, r, i.x, i.z, i.r);
133
+ function ae(e, t, n, r) {
134
+ let i = e.x + Math.cos(e.yaw) * m.shellSpeed * t, a = e.z + Math.sin(e.yaw) * m.shellSpeed * t, o = null;
135
+ for (let t of n.obstacles) {
136
+ let n = ie(e.x, e.z, i, a, t);
137
+ n !== null && (!o || n < o.t) && (o = t.shape === "rect" ? {
138
+ t: n,
139
+ kind: "obstacle",
140
+ shape: "rect",
141
+ id: t.id,
142
+ obstacleKind: t.kind
143
+ } : {
144
+ t: n,
145
+ kind: "obstacle"
146
+ });
147
+ }
148
+ for (let t of n.destructibles || []) {
149
+ if (!b(t)) continue;
150
+ let n = ie(e.x, e.z, i, a, t);
151
+ n !== null && (!o || n < o.t) && (o = {
152
+ t: n,
153
+ kind: "destructible",
154
+ id: t.id,
155
+ destructibleKind: t.kind
156
+ });
157
+ }
158
+ for (let t of r) {
159
+ if (!t.alive || t.id === e.owner) continue;
160
+ let n = ne(e.x, e.z, i, a, t.x, t.z, m.radius);
161
+ n !== null && (!o || n < o.t) && (o = {
162
+ t: n,
163
+ kind: "tank",
164
+ target: t.id
165
+ });
166
+ }
167
+ return o ? (e.x += (i - e.x) * o.t, e.z += (a - e.z) * o.t, o) : (e.x = i, e.z = a, e.age += t, !ee(i, a, {
168
+ ...n,
169
+ obstacles: [],
170
+ destructibles: []
171
+ }, 0) || e.age > 3 ? { kind: "terrain" } : null);
172
+ }
173
+ function oe(e, t, n = 1) {
174
+ let r = (e?.destructibles || []).find((e) => e.id === t);
175
+ return b(r) ? (r.hp = Math.max(0, (r.hp ?? 1) - Math.max(0, Number(n) || 0)), r.hp === 0 && (r.alive = !1), {
176
+ destroyed: r.hp === 0,
177
+ kind: r.kind,
178
+ hp: r.hp
179
+ }) : {
180
+ destroyed: !1,
181
+ kind: r?.kind ?? null,
182
+ hp: 0
183
+ };
184
+ }
185
+ function se(e, t, n, r = y.radius, i = y.damage) {
186
+ return e.filter((e) => e.alive !== !1 && Math.hypot(e.x - t, e.z - n) <= r).map((e) => ({
187
+ id: e.id,
188
+ dmg: i
189
+ }));
190
+ }
191
+ function ce(e, t, n) {
192
+ let r = (e?.destructibles || []).find((e) => e.id === t);
193
+ if (!r) return {
194
+ hits: [],
195
+ chained: null
196
+ };
197
+ let i = [r], a = (e.destructibles || []).filter((e) => e !== r && e.kind === "barrel" && b(e) && Math.hypot(e.x - r.x, e.z - r.z) <= y.radius).sort((e, t) => Math.hypot(e.x - r.x, e.z - r.z) - Math.hypot(t.x - r.x, t.z - r.z))[0];
198
+ a && (a.hp = 0, a.alive = !1, i.push(a));
199
+ let o = /* @__PURE__ */ new Map();
200
+ for (let e of i) for (let t of se(n, e.x, e.z)) o.set(t.id, (o.get(t.id) || 0) + t.dmg);
201
+ return {
202
+ hits: [...o].map(([e, t]) => ({
203
+ id: e,
204
+ dmg: t
205
+ })),
206
+ chained: a ? {
207
+ id: a.id,
208
+ x: a.x,
209
+ z: a.z
210
+ } : null
211
+ };
212
+ }
213
+ function le(e, t, n) {
214
+ let r = h(n, 0, 1);
215
+ return {
216
+ ...t,
217
+ x: e.x + (t.x - e.x) * r,
218
+ z: e.z + (t.z - e.z) * r,
219
+ yaw: e.yaw + g(e.yaw, t.yaw) * r,
220
+ turretYaw: e.turretYaw + g(e.turretYaw, t.turretYaw) * r
221
+ };
222
+ }
223
+ // src/games/tanks-live/logic/maps.js
224
+ var ue = Object.freeze([
225
+ "meadow",
226
+ "forest",
227
+ "desert",
228
+ "ruins",
229
+ "arctic",
230
+ "random"
231
+ ]), de = [
232
+ "forest",
233
+ "desert",
234
+ "ruins",
235
+ "arctic"
236
+ ], C = 120, fe = C / 2, pe = 4, me = 12, he = 1.5, ge = 2, _e = () => [{
237
+ x: 18,
238
+ z: 60,
239
+ yaw: 0
240
+ }, {
241
+ x: 102,
242
+ z: 60,
243
+ yaw: Math.PI
244
+ }], ve = {
245
+ crate: {
246
+ r: 1.2,
247
+ hp: 2
248
+ },
249
+ barrel: {
250
+ r: .9,
251
+ hp: 1
252
+ }
253
+ };
254
+ function ye(e) {
255
+ let t = e >>> 0;
256
+ return () => {
257
+ t = t + 1831565813 >>> 0;
258
+ let e = t;
259
+ return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), ((e ^ e >>> 14) >>> 0) / 4294967296;
260
+ };
261
+ }
262
+ var w = (e) => Math.round(e * 10) / 10, T = (e, t, n) => t + e() * (n - t), be = (e, t) => t[Math.floor(e() * t.length) % t.length];
263
+ function xe(e, t) {
264
+ let n = e() * t.reduce((e, t) => e + t.w, 0);
265
+ for (let e of t) if (n -= e.w, n < 0) return e;
266
+ return t[t.length - 1];
267
+ }
268
+ var E = (e, t, n) => ({
269
+ kind: e,
270
+ make: (r) => ({
271
+ shape: "circle",
272
+ kind: e,
273
+ r: w(T(r, t, n))
274
+ })
275
+ }), D = (e, t, n, r) => ({
276
+ kind: e,
277
+ make: (i) => ({
278
+ shape: "rect",
279
+ kind: e,
280
+ w: w(T(i, ...t)),
281
+ d: w(T(i, ...n)),
282
+ rot: r ? be(i, r) : w(T(i, 0, Math.PI))
283
+ })
284
+ }), Se = [0, Math.PI / 2], Ce = {
285
+ forest: {
286
+ count: [18, 25],
287
+ destructibles: [2, 4],
288
+ decor: [
289
+ "grass",
290
+ "flower",
291
+ "bush",
292
+ "pebble"
293
+ ],
294
+ items: [
295
+ {
296
+ w: 6,
297
+ ...E("tree", 2, 3.2)
298
+ },
299
+ {
300
+ w: 2,
301
+ ...E("log", 1.6, 2.2)
302
+ },
303
+ {
304
+ w: 1,
305
+ ...E("rock", 2, 3)
306
+ }
307
+ ]
308
+ },
309
+ desert: {
310
+ count: [12, 15],
311
+ destructibles: [2, 4],
312
+ decor: [
313
+ "pebble",
314
+ "dry_grass",
315
+ "cactus",
316
+ "bones"
317
+ ],
318
+ items: [{
319
+ w: 3,
320
+ ...E("rock", 5, 7)
321
+ }, {
322
+ w: 2,
323
+ ...D("low", [8, 12], [1.8, 2.4])
324
+ }]
325
+ },
326
+ ruins: {
327
+ count: [16, 22],
328
+ destructibles: [4, 6],
329
+ decor: [
330
+ "rubble",
331
+ "pebble",
332
+ "weed"
333
+ ],
334
+ items: [
335
+ {
336
+ w: 4,
337
+ ...D("wall", [8, 14], [1.1, 1.4], Se)
338
+ },
339
+ {
340
+ w: 2,
341
+ ...D("house", [7, 9], [6, 8], Se)
342
+ },
343
+ {
344
+ w: 2,
345
+ ...D("car", [4.2, 4.6], [2, 2.3])
346
+ },
347
+ {
348
+ w: 1,
349
+ ...E("rock", 2, 3)
350
+ }
351
+ ]
352
+ },
353
+ arctic: {
354
+ count: [14, 20],
355
+ destructibles: [2, 4],
356
+ decor: [
357
+ "snow",
358
+ "ice_shard",
359
+ "pebble"
360
+ ],
361
+ items: [
362
+ {
363
+ w: 3,
364
+ ...D("ice_block", [3, 5], [3, 5])
365
+ },
366
+ {
367
+ w: 2,
368
+ ...E("ice", 2.5, 4)
369
+ },
370
+ {
371
+ w: 2,
372
+ ...E("tree", 2, 3)
373
+ }
374
+ ]
375
+ }
376
+ }, we = (e) => e.shape === "rect" ? Math.hypot(e.w, e.d) / 2 : e.r, Te = (e) => ({
377
+ ...e,
378
+ x: w(C - e.x),
379
+ z: w(C - e.z)
380
+ }), Ee = (e) => e.shape !== "rect" || e.kind !== "low";
381
+ function De(e) {
382
+ let t = we(e);
383
+ return e.x - t >= pe && e.x + t <= 116 && e.z - t >= pe && e.z + t <= 116;
384
+ }
385
+ function Oe(e, t, n) {
386
+ let r = we(e);
387
+ return !De(e) || n.some((t) => Math.hypot(e.x - t.x, e.z - t.z) - r < me) ? !1 : t.every((t) => Math.hypot(e.x - t.x, e.z - t.z) >= r + we(t) + he);
388
+ }
389
+ function ke(e, t, n) {
390
+ if (n.shape !== "rect") return Math.hypot(e - n.x, t - n.z) - n.r;
391
+ let r = Math.cos(-n.rot), i = Math.sin(-n.rot), a = e - n.x, o = t - n.z, s = Math.abs(a * r - o * i) - n.w / 2, c = Math.abs(a * i + o * r) - n.d / 2;
392
+ return Math.hypot(Math.max(s, 0), Math.max(c, 0)) + Math.min(Math.max(s, c), 0);
393
+ }
394
+ function Ae(e, t, n, r = ge) {
395
+ let i = [...e.filter(Ee), ...t], a = (e, t) => e >= r && e <= C - r && t >= r && t <= C - r && i.every((n) => ke(e, t, n) >= r), o = /* @__PURE__ */ new Uint8Array(14641), [s, c] = n.map((e) => [Math.round(e.x), Math.round(e.z)]), l = [s];
396
+ o[s[0] * 121 + s[1]] = 1;
397
+ for (let e = 0; e < l.length; e++) {
398
+ let [t, n] = l[e];
399
+ if (t === c[0] && n === c[1]) return !0;
400
+ for (let [e, r] of [
401
+ [1, 0],
402
+ [-1, 0],
403
+ [0, 1],
404
+ [0, -1]
405
+ ]) {
406
+ let i = t + e, s = n + r;
407
+ i < 0 || s < 0 || i >= 121 || s >= 121 || o[i * 121 + s] || !a(i, s) || (o[i * 121 + s] = 1, l.push([i, s]));
408
+ }
409
+ }
410
+ return !1;
411
+ }
412
+ function je(e, t, n, r, i, a = 1500) {
413
+ let o = [];
414
+ for (let s = 0; o.length < n && s < a; s++) {
415
+ let n = t(), a = we(n);
416
+ n.x = w(T(e, pe + a, 116 - a)), n.z = w(T(e, pe + a, 116 - a));
417
+ let s = Te(n);
418
+ if (Math.hypot(n.x - s.x, n.z - s.z) < 2 * a + he) continue;
419
+ let c = [...r, ...o];
420
+ Oe(n, c, i) && Oe(s, [...c, n], i) && o.push(n, s);
421
+ }
422
+ return o;
423
+ }
424
+ function Me(e, t, n) {
425
+ let [r, i] = e.count, a = r + Math.floor(t() * (i - r + 1)), o = [];
426
+ if (a % 2) {
427
+ let r = xe(t, e.items).make(t);
428
+ r.x = fe, r.z = fe, Oe(r, [], n) && o.push(r);
429
+ }
430
+ o.push(...je(t, () => xe(t, e.items).make(t), a - o.length, o, n));
431
+ let [s, c] = e.destructibles, l = je(t, () => {
432
+ let e = t() < .5 ? "crate" : "barrel";
433
+ return {
434
+ shape: "circle",
435
+ kind: e,
436
+ ...ve[e]
437
+ };
438
+ }, 2 * (s / 2 + Math.floor(t() * ((c - s) / 2 + 1))), o, n);
439
+ for (; !Ae(o, l, n);) if (l.length > 2) l.splice(-2);
440
+ else if (o.length > r) o.splice(-2);
441
+ else return null;
442
+ return o.length < r || o.length > 25 || l.length < 2 || l.length > 6 ? null : {
443
+ obstacles: o,
444
+ destructibles: l
445
+ };
446
+ }
447
+ function Ne(e, t, n) {
448
+ return Array.from({ length: n }, (n, r) => ({
449
+ id: `c${r}`,
450
+ kind: be(e, t),
451
+ x: w(T(e, 2, 118)),
452
+ z: w(T(e, 2, 118)),
453
+ s: w(T(e, .5, 1.5)),
454
+ rot: w(T(e, 0, Math.PI * 2))
455
+ }));
456
+ }
457
+ var O = (e) => (Math.round(e * 100) / 100).toFixed(2);
458
+ function Pe(e) {
459
+ let t = [e.id, e.size];
460
+ for (let n of [...e.obstacles || [], ...e.destructibles || []]) t.push(n.shape === "rect" ? `${n.id}:R:${n.kind}:${O(n.x)}:${O(n.z)}:${O(n.w)}:${O(n.d)}:${O(n.rot)}` : `${n.id}:C:${n.kind}:${O(n.x)}:${O(n.z)}:${O(n.r)}${n.hp == null ? "" : `:${n.hp}`}`);
461
+ for (let n of e.spawns || []) t.push(`S:${O(n.x)}:${O(n.z)}:${O(n.yaw)}`);
462
+ let n = t.join("|"), r = 2166136261;
463
+ for (let e = 0; e < n.length; e++) r ^= n.charCodeAt(e), r = Math.imul(r, 16777619) >>> 0;
464
+ return r.toString(16).padStart(8, "0");
465
+ }
466
+ function Fe(e = "meadow", t = 0) {
467
+ t = Number(t) >>> 0;
468
+ let n = ue.includes(e) ? e : "meadow";
469
+ n === "random" && (n = de[Math.floor(ye(t ^ 2654435769)() * de.length)]);
470
+ let r = _e(), i = {
471
+ id: n,
472
+ seed: t,
473
+ size: C,
474
+ bounds: {
475
+ minX: 0,
476
+ maxX: C,
477
+ minZ: 0,
478
+ maxZ: C
479
+ },
480
+ spawns: r
481
+ }, a;
482
+ if (n === "meadow") {
483
+ let e = _();
484
+ a = {
485
+ ...i,
486
+ obstacles: e.obstacles.map((e, t) => ({
487
+ id: `o${t}`,
488
+ shape: "circle",
489
+ ...e
490
+ })),
491
+ destructibles: [],
492
+ decor: Ne(ye(t ^ 57024), [
493
+ "grass",
494
+ "flower",
495
+ "pebble"
496
+ ], 40)
497
+ };
498
+ } else {
499
+ let e = Ce[n], o = ye(t), s = null;
500
+ for (let t = 0; !s && t < 20; t++) s = Me(e, o, r);
501
+ s || (s = {
502
+ obstacles: [],
503
+ destructibles: []
504
+ }), a = {
505
+ ...i,
506
+ obstacles: s.obstacles.map((e, t) => ({
507
+ id: `o${t}`,
508
+ ...e
509
+ })),
510
+ destructibles: s.destructibles.map((e, t) => ({
511
+ id: `d${t}`,
512
+ ...e
513
+ })),
514
+ decor: Ne(ye(t ^ 57024), e.decor, 50)
515
+ };
516
+ }
517
+ return a.hash = Pe(a), a;
518
+ }
15
519
  // src/games/tanks-live/session.js
16
- var m = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), h = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
17
- function g(e) {
18
- let t = e.data;
520
+ var Ie = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), Le = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, Re = (e) => typeof e == "object" && !!e && !Array.isArray(e), ze = (e, t) => Object.keys(e).every((e) => t.includes(e)), Be = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295, Ve = (e) => typeof e == "string" && /^[0-9a-f]{8}$/.test(e), He = Object.freeze([
521
+ 1,
522
+ 3,
523
+ 5
524
+ ]), Ue = Object.freeze(ue.filter((e) => e !== "random")), k = /* @__PURE__ */ new Map();
525
+ function We(e, t) {
526
+ let n = `${e}:${t}`;
527
+ return k.has(n) || (k.set(n, Fe(e, t).hash), k.size > 32 && k.delete(k.keys().next().value)), k.get(n);
528
+ }
529
+ var Ge = [
530
+ "map_id",
531
+ "seed",
532
+ "map_hash",
533
+ "lives"
534
+ ];
535
+ function Ke(e) {
536
+ let t = e?.data;
537
+ if (!Re(t)) return !1;
19
538
  switch (e.type) {
20
- case "game_invite": return h(t.opponent_id) && t.rules_version === 1 && (t.rematch_of === void 0 || m(t.rematch_of));
21
- case "game_accept":
22
- case "game_decline": return m(t.invite_event_id);
23
- case "game_end": return t.reason === "closed";
539
+ case "game_invite": return !ze(t, [
540
+ "opponent_id",
541
+ "rules_version",
542
+ "rematch_of",
543
+ ...Ge
544
+ ]) || !Le(t.opponent_id) || t.rematch_of !== void 0 && !Ie(t.rematch_of) ? !1 : t.rules_version === 1 ? Ge.every((e) => t[e] === void 0) : t.rules_version === 2 && Ue.includes(t.map_id) && Be(t.seed) && He.includes(t.lives) && Ve(t.map_hash) && t.map_hash === We(t.map_id, t.seed);
545
+ case "game_accept": return ze(t, ["invite_event_id", "map_hash"]) && Ie(t.invite_event_id) && (t.map_hash === void 0 || Ve(t.map_hash));
546
+ case "game_decline": return ze(t, ["invite_event_id"]) && Ie(t.invite_event_id);
547
+ case "game_end": return ze(t, ["reason"]) && t.reason === "closed";
24
548
  default: return !1;
25
549
  }
26
550
  }
27
- function _(e, t) {
551
+ var qe = () => globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0];
552
+ function Je({ opponentId: e, mapId: t = "random", lives: n = 3, seed: r = qe(), rematchOf: i } = {}) {
553
+ let a = t === null;
554
+ if (!Le(e) || i !== void 0 && !Ie(i) || !a && (!ue.includes(t) || !Be(r) || !He.includes(n))) throw TypeError("Configuración de invitación de Tanques LIVE inválida");
555
+ let o = i === void 0 ? {} : { rematch_of: i };
556
+ if (a) return {
557
+ opponent_id: e,
558
+ rules_version: 1,
559
+ ...o
560
+ };
561
+ let s = Fe(t, r);
562
+ return {
563
+ opponent_id: e,
564
+ rules_version: 2,
565
+ map_id: s.id,
566
+ seed: r,
567
+ map_hash: s.hash,
568
+ lives: n,
569
+ ...o
570
+ };
571
+ }
572
+ function Ye(e, t) {
573
+ let n = t.rules_version === 2 ? {
574
+ mapId: t.map_id,
575
+ seed: t.seed,
576
+ mapHash: t.map_hash,
577
+ lives: t.lives
578
+ } : null;
28
579
  return {
29
580
  ...e,
30
581
  game: "tanks_live",
31
582
  status: "invited",
32
583
  turnId: null,
33
584
  winnerId: null,
585
+ liveConfig: n,
34
586
  rematchOf: t.rematch_of ?? null,
35
587
  pending: !1,
36
588
  pendingEvent: null,
@@ -38,7 +590,7 @@ function _(e, t) {
38
590
  acceptEventId: null
39
591
  };
40
592
  }
41
- function v(e, t, n) {
593
+ function Xe(e, t, n) {
42
594
  return [e.hostId, e.guestId].includes(n) ? t.type === "game_end" ? ["closed", "declined"].includes(e.status) ? e : {
43
595
  ...e,
44
596
  status: "closed",
@@ -48,7 +600,7 @@ function v(e, t, n) {
48
600
  ...e,
49
601
  status: "declined",
50
602
  lastEventId: t.event_id
51
- } : t.type === "game_accept" ? {
603
+ } : t.type === "game_accept" && t.data.map_hash === (e.liveConfig?.mapHash ?? void 0) ? {
52
604
  ...e,
53
605
  status: "active",
54
606
  acceptEventId: t.event_id,
@@ -56,12 +608,12 @@ function v(e, t, n) {
56
608
  } : e : e;
57
609
  }
58
610
  // src/games/racing-live/session.js
59
- var y = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), b = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, x = (e) => typeof e == "object" && !!e && !Array.isArray(e), S = (e, t) => Object.keys(e).every((e) => t.includes(e)), ee = (e) => typeof e == "string" && /^racing-v1-[0-9a-f]{8}$/.test(e), te = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
60
- function ne(n) {
611
+ var Ze = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), Qe = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, $e = (e) => typeof e == "object" && !!e && !Array.isArray(e), et = (e, t) => Object.keys(e).every((e) => t.includes(e)), tt = (e) => typeof e == "string" && /^racing-v1-[0-9a-f]{8}$/.test(e), nt = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
612
+ function rt(n) {
61
613
  let i = n?.data;
62
- if (!x(i)) return !1;
614
+ if (!$e(i)) return !1;
63
615
  switch (n.type) {
64
- case "game_invite": return S(i, [
616
+ case "game_invite": return et(i, [
65
617
  "opponent_id",
66
618
  "rules_version",
67
619
  "mode",
@@ -71,16 +623,16 @@ function ne(n) {
71
623
  "laps",
72
624
  "speed_class",
73
625
  "rematch_of"
74
- ]) && b(i.opponent_id) && i.rules_version === 1 && i.mode === "classic" && i.map_id === "neon_city" && te(i.seed) && (i.speed_class === void 0 || t(i.speed_class) !== null) && i.laps === (t(i.speed_class)?.laps ?? e.laps) && ee(i.track_hash) && (i.rematch_of === void 0 || y(i.rematch_of)) && i.track_hash === r(i.map_id, i.seed, { speedClass: i.speed_class }).trackHash;
75
- case "game_accept": return S(i, ["invite_event_id", "track_hash"]) && y(i.invite_event_id) && ee(i.track_hash);
76
- case "game_decline": return S(i, ["invite_event_id"]) && y(i.invite_event_id);
77
- case "game_end": return S(i, ["reason"]) && i.reason === "closed";
626
+ ]) && Qe(i.opponent_id) && i.rules_version === 1 && i.mode === "classic" && i.map_id === "neon_city" && nt(i.seed) && (i.speed_class === void 0 || t(i.speed_class) !== null) && i.laps === (t(i.speed_class)?.laps ?? e.laps) && tt(i.track_hash) && (i.rematch_of === void 0 || Ze(i.rematch_of)) && i.track_hash === r(i.map_id, i.seed, { speedClass: i.speed_class }).trackHash;
627
+ case "game_accept": return et(i, ["invite_event_id", "track_hash"]) && Ze(i.invite_event_id) && tt(i.track_hash);
628
+ case "game_decline": return et(i, ["invite_event_id"]) && Ze(i.invite_event_id);
629
+ case "game_end": return et(i, ["reason"]) && i.reason === "closed";
78
630
  default: return !1;
79
631
  }
80
632
  }
81
- function re({ opponentId: i, seed: a = 0, rematchOf: o, speedClass: s = n } = {}) {
633
+ function it({ opponentId: i, seed: a = 0, rematchOf: o, speedClass: s = n } = {}) {
82
634
  let c = t(s);
83
- if (!b(i) || !te(a) || o !== void 0 && !y(o) || s !== null && !c) throw TypeError("Configuración de invitación de carrera inválida");
635
+ if (!Qe(i) || !nt(a) || o !== void 0 && !Ze(o) || s !== null && !c) throw TypeError("Configuración de invitación de carrera inválida");
84
636
  return {
85
637
  opponent_id: i,
86
638
  rules_version: 1,
@@ -93,8 +645,8 @@ function re({ opponentId: i, seed: a = 0, rematchOf: o, speedClass: s = n } = {}
93
645
  ...o === void 0 ? {} : { rematch_of: o }
94
646
  };
95
647
  }
96
- function ie(e, t) {
97
- if (!ne({
648
+ function at(e, t) {
649
+ if (!rt({
98
650
  type: "game_invite",
99
651
  data: t
100
652
  })) throw TypeError("Configuración de carrera inválida");
@@ -120,8 +672,8 @@ function ie(e, t) {
120
672
  acceptEventId: null
121
673
  };
122
674
  }
123
- function ae(e, t, n) {
124
- return !e || t?.game !== "racing_live" || t.game_id !== e.gameId || ![e.hostId, e.guestId].includes(n) || !ne(t) ? e : t.type === "game_end" ? ["closed", "declined"].includes(e.status) ? e : {
675
+ function ot(e, t, n) {
676
+ return !e || t?.game !== "racing_live" || t.game_id !== e.gameId || ![e.hostId, e.guestId].includes(n) || !rt(t) ? e : t.type === "game_end" ? ["closed", "declined"].includes(e.status) ? e : {
125
677
  ...e,
126
678
  status: "closed",
127
679
  closedBy: n,
@@ -139,29 +691,29 @@ function ae(e, t, n) {
139
691
  } : e;
140
692
  }
141
693
  // src/net/webrtc/rtcSignals.js
142
- var oe = /* @__PURE__ */ new Set(), se = {
694
+ var st = /* @__PURE__ */ new Set(), ct = {
143
695
  emit(e) {
144
- oe.forEach((t) => {
696
+ st.forEach((t) => {
145
697
  try {
146
698
  t(e);
147
699
  } catch {}
148
700
  });
149
701
  },
150
702
  subscribe(e) {
151
- return oe.add(e), () => oe.delete(e);
703
+ return st.add(e), () => st.delete(e);
152
704
  }
153
- }, ce = ({ send: e, roomId: t }) => ({
705
+ }, lt = ({ send: e, roomId: t }) => ({
154
706
  send: (n) => e(t, n),
155
- subscribe: (e) => se.subscribe((n) => {
707
+ subscribe: (e) => ct.subscribe((n) => {
156
708
  String(n.roomId) === String(t) && e(n);
157
709
  })
158
- }), le = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, ue = /^[0-9a-f]{16}$/, de = /^[0-9a-f]{32}$/, fe = /^[0-9a-f]{64}$/, pe = (e) => typeof e == "object" && !!e && !Array.isArray(e), me = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, C = (e) => typeof e == "string" && le.test(e), w = (e, t, n) => Number.isInteger(e) && e >= t && e <= n, he = Object.freeze([
710
+ }), ut = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, dt = /^[0-9a-f]{16}$/, ft = /^[0-9a-f]{32}$/, pt = /^[0-9a-f]{64}$/, mt = (e) => typeof e == "object" && !!e && !Array.isArray(e), ht = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, A = (e) => typeof e == "string" && ut.test(e), j = (e, t, n) => Number.isInteger(e) && e >= t && e <= n, gt = Object.freeze([
159
711
  "standard",
160
712
  "heavy",
161
713
  "cluster"
162
- ]), ge = (e) => w(e, 1, 120), _e = (e) => w(e.move, -16, 16) && w(e.yaw, 0, 359) && w(e.pitch, 5, 80) && w(e.power, 0, 100) && w(e.ammo, 0, he.length - 1);
163
- function ve(e) {
164
- return Array.isArray(e) ? e[0] === 1 ? e.length === 6 && _e({
714
+ ]), _t = (e) => j(e, 1, 120), vt = (e) => j(e.move, -16, 16) && j(e.yaw, 0, 359) && j(e.pitch, 5, 80) && j(e.power, 0, 100) && j(e.ammo, 0, gt.length - 1);
715
+ function yt(e) {
716
+ return Array.isArray(e) ? e[0] === 1 ? e.length === 6 && vt({
165
717
  move: e[1],
166
718
  yaw: e[2],
167
719
  pitch: e[3],
@@ -169,93 +721,93 @@ function ve(e) {
169
721
  ammo: e[5]
170
722
  }) : e[0] === 2 ? e.length === 1 : e[0] === 3 && e.length === 2 && (e[1] === 0 || e[1] === 1) : !1;
171
723
  }
172
- var ye = (e) => Array.isArray(e.log) && e.log.length <= 120 && e.log.every(ve) && C(e.head) && (e.accept_event_id === void 0 ? e.log.length === 0 && e.seed_b === void 0 && e.seed_a === void 0 : C(e.accept_event_id) && typeof e.seed_b == "string" && de.test(e.seed_b)) && (e.seed_a === void 0 ? e.log.length === 0 : de.test(e.seed_a) && C(e.seed_event_id));
173
- function be(e) {
724
+ var bt = (e) => Array.isArray(e.log) && e.log.length <= 120 && e.log.every(yt) && A(e.head) && (e.accept_event_id === void 0 ? e.log.length === 0 && e.seed_b === void 0 && e.seed_a === void 0 : A(e.accept_event_id) && typeof e.seed_b == "string" && ft.test(e.seed_b)) && (e.seed_a === void 0 ? e.log.length === 0 : ft.test(e.seed_a) && A(e.seed_event_id));
725
+ function xt(e) {
174
726
  let t = e.data;
175
727
  switch (e.type) {
176
- case "game_invite": return me(t.opponent_id) && t.rules_version === 1 && typeof t.seed_commit == "string" && fe.test(t.seed_commit) && (t.first_player_id === void 0 || me(t.first_player_id)) && (t.rematch_of === void 0 || C(t.rematch_of));
177
- case "game_accept": return C(t.invite_event_id) && typeof t.seed_b == "string" && de.test(t.seed_b);
178
- case "game_decline": return C(t.invite_event_id);
728
+ case "game_invite": return ht(t.opponent_id) && t.rules_version === 1 && typeof t.seed_commit == "string" && pt.test(t.seed_commit) && (t.first_player_id === void 0 || ht(t.first_player_id)) && (t.rematch_of === void 0 || A(t.rematch_of));
729
+ case "game_accept": return A(t.invite_event_id) && typeof t.seed_b == "string" && ft.test(t.seed_b);
730
+ case "game_decline": return A(t.invite_event_id);
179
731
  case "game_end": return t.reason === "closed";
180
- case "tk_seed": return typeof t.seed_a == "string" && de.test(t.seed_a);
181
- case "tk_turn": return ge(t.ply) && C(t.prev_event_id) && _e(t) && typeof t.hash == "string" && ue.test(t.hash);
732
+ case "tk_seed": return typeof t.seed_a == "string" && ft.test(t.seed_a);
733
+ case "tk_turn": return _t(t.ply) && A(t.prev_event_id) && vt(t) && typeof t.hash == "string" && dt.test(t.hash);
182
734
  case "tk_skip":
183
- case "tk_resign": return ge(t.ply) && C(t.prev_event_id);
184
- case "tk_sync_request": return pe(t) && ye(t);
185
- case "tk_sync_state": return pe(t) && ye(t) && C(t.request_event_id);
735
+ case "tk_resign": return _t(t.ply) && A(t.prev_event_id);
736
+ case "tk_sync_request": return mt(t) && bt(t);
737
+ case "tk_sync_state": return mt(t) && bt(t) && A(t.request_event_id);
186
738
  default: return !1;
187
739
  }
188
740
  }
189
741
  // src/games/shared/protocol.js
190
- var xe = "LIRA_GAME_V1:", Se = 4096, Ce = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, we = (e) => typeof e == "object" && !!e && !Array.isArray(e), T = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, E = (e) => typeof e == "string" && Ce.test(e), Te = (e) => Array.isArray(e) && e.length <= 42 && e.every((e) => Array.isArray(e) && e.length === 2 && Number.isInteger(e[0]) && e[0] >= 0 && e[0] < 7 && E(e[1])) && new Set(e.map((e) => e[1])).size === e.length, Ee = (e) => Te(e.moves) && e.rev === e.moves.length && (e.accept_event_id === void 0 ? e.moves.length === 0 : E(e.accept_event_id)), D = [
742
+ var St = "LIRA_GAME_V1:", Ct = 4096, wt = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, Tt = (e) => typeof e == "object" && !!e && !Array.isArray(e), M = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, N = (e) => typeof e == "string" && wt.test(e), Et = (e) => Array.isArray(e) && e.length <= 42 && e.every((e) => Array.isArray(e) && e.length === 2 && Number.isInteger(e[0]) && e[0] >= 0 && e[0] < 7 && N(e[1])) && new Set(e.map((e) => e[1])).size === e.length, Dt = (e) => Et(e.moves) && e.rev === e.moves.length && (e.accept_event_id === void 0 ? e.moves.length === 0 : N(e.accept_event_id)), Ot = [
191
743
  "carrier",
192
744
  "battleship",
193
745
  "cruiser",
194
746
  "submarine",
195
747
  "destroyer"
196
- ], O = (e) => Number.isInteger(e) && e >= 0 && e < 10, De = (e) => typeof e == "string" && /^[0-9a-f]{64}$/.test(e), Oe = (e) => Number.isInteger(e) && e >= 1 && e <= 200, ke = (e) => e === null || we(e) && D.includes(e.ship_id) && Array.isArray(e.cells) && e.cells.length >= 2 && e.cells.length <= 5 && e.cells.every((e) => Array.isArray(e) && e.length === 2 && O(e[0]) && O(e[1])), Ae = (e) => Array.isArray(e) && e.length === D.length && e.every((e) => we(e) && D.includes(e.ship_id) && O(e.row) && O(e.col) && (e.orientation === "horizontal" || e.orientation === "vertical")) && new Set(e.map((e) => e.ship_id)).size === e.length, je = (e, t) => Array.isArray(e) && O(e[0]) && O(e[1]) && (e.length === 2 && t || e.length === 3 && (e[2] === 0 || e[2] === 1) || e.length === 7 && e[2] === 2 && Number.isInteger(e[3]) && e[3] >= 0 && e[3] < D.length && O(e[4]) && O(e[5]) && (e[6] === 0 || e[6] === 1)), Me = (e) => Array.isArray(e.commits) && e.commits.length === 2 && e.commits.every((e) => e === null || De(e)) && Array.isArray(e.log) && e.log.length <= 200 && e.log.every((t, n) => je(t, n === e.log.length - 1)) && E(e.head) && (e.accept_event_id === void 0 ? e.commits.every((e) => e === null) && e.log.length === 0 : E(e.accept_event_id)) && (e.log.length === 0 || e.commits.every(Boolean));
197
- function Ne(e) {
748
+ ], P = (e) => Number.isInteger(e) && e >= 0 && e < 10, kt = (e) => typeof e == "string" && /^[0-9a-f]{64}$/.test(e), At = (e) => Number.isInteger(e) && e >= 1 && e <= 200, jt = (e) => e === null || Tt(e) && Ot.includes(e.ship_id) && Array.isArray(e.cells) && e.cells.length >= 2 && e.cells.length <= 5 && e.cells.every((e) => Array.isArray(e) && e.length === 2 && P(e[0]) && P(e[1])), Mt = (e) => Array.isArray(e) && e.length === Ot.length && e.every((e) => Tt(e) && Ot.includes(e.ship_id) && P(e.row) && P(e.col) && (e.orientation === "horizontal" || e.orientation === "vertical")) && new Set(e.map((e) => e.ship_id)).size === e.length, Nt = (e, t) => Array.isArray(e) && P(e[0]) && P(e[1]) && (e.length === 2 && t || e.length === 3 && (e[2] === 0 || e[2] === 1) || e.length === 7 && e[2] === 2 && Number.isInteger(e[3]) && e[3] >= 0 && e[3] < Ot.length && P(e[4]) && P(e[5]) && (e[6] === 0 || e[6] === 1)), Pt = (e) => Array.isArray(e.commits) && e.commits.length === 2 && e.commits.every((e) => e === null || kt(e)) && Array.isArray(e.log) && e.log.length <= 200 && e.log.every((t, n) => Nt(t, n === e.log.length - 1)) && N(e.head) && (e.accept_event_id === void 0 ? e.commits.every((e) => e === null) && e.log.length === 0 : N(e.accept_event_id)) && (e.log.length === 0 || e.commits.every(Boolean));
749
+ function Ft(e) {
198
750
  let t = e.data;
199
751
  switch (e.type) {
200
- case "game_invite": return T(t.opponent_id) && t.rules_version === 1;
752
+ case "game_invite": return M(t.opponent_id) && t.rules_version === 1;
201
753
  case "game_accept":
202
- case "game_decline": return E(t.invite_event_id);
203
- case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 || T(t.winner_id));
204
- case "bs_commit": return De(t.commitment);
205
- case "bs_fire": return Oe(t.ply) && O(t.row) && O(t.col) && E(t.prev_event_id);
206
- case "bs_result": return Oe(t.ply) && O(t.row) && O(t.col) && ["hit", "miss"].includes(t.result) && ke(t.sunk) && typeof t.defeated == "boolean" && (t.result === "hit" || t.sunk === null && !t.defeated);
207
- case "bs_reveal": return Ae(t.fleet) && typeof t.salt == "string" && /^[0-9a-f]{32}$/.test(t.salt);
208
- case "bs_sync_request": return Me(t);
209
- case "bs_sync_state": return Me(t) && E(t.request_event_id);
754
+ case "game_decline": return N(t.invite_event_id);
755
+ case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 || M(t.winner_id));
756
+ case "bs_commit": return kt(t.commitment);
757
+ case "bs_fire": return At(t.ply) && P(t.row) && P(t.col) && N(t.prev_event_id);
758
+ case "bs_result": return At(t.ply) && P(t.row) && P(t.col) && ["hit", "miss"].includes(t.result) && jt(t.sunk) && typeof t.defeated == "boolean" && (t.result === "hit" || t.sunk === null && !t.defeated);
759
+ case "bs_reveal": return Mt(t.fleet) && typeof t.salt == "string" && /^[0-9a-f]{32}$/.test(t.salt);
760
+ case "bs_sync_request": return Pt(t);
761
+ case "bs_sync_state": return Pt(t) && N(t.request_event_id);
210
762
  default: return !1;
211
763
  }
212
764
  }
213
- function Pe(e) {
765
+ function It(e) {
214
766
  return typeof e == "string" && e.startsWith("LIRA_GAME_V1:");
215
767
  }
216
- function Fe(e) {
768
+ function Lt(e) {
217
769
  let t = e.data;
218
770
  switch (e.type) {
219
- case "game_invite": return T(t.opponent_id) && t.rules_version === 1;
771
+ case "game_invite": return M(t.opponent_id) && t.rules_version === 1;
220
772
  case "game_accept":
221
- case "game_decline": return E(t.invite_event_id);
222
- case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 && E(t.prev_event_id);
773
+ case "game_decline": return N(t.invite_event_id);
774
+ case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 && N(t.prev_event_id);
223
775
  case "game_end": return [
224
776
  "closed",
225
777
  "win",
226
778
  "draw"
227
- ].includes(t.reason) && (t.winner_id === void 0 || T(t.winner_id)) && (t.final_move_event_id === void 0 || E(t.final_move_event_id)) && (t.reason !== "win" || T(t.winner_id) && E(t.final_move_event_id)) && (t.reason !== "draw" || E(t.final_move_event_id));
228
- case "game_resync_request": return Ee(t);
229
- case "game_resync_state": return Ee(t) && E(t.request_event_id);
779
+ ].includes(t.reason) && (t.winner_id === void 0 || M(t.winner_id)) && (t.final_move_event_id === void 0 || N(t.final_move_event_id)) && (t.reason !== "win" || M(t.winner_id) && N(t.final_move_event_id)) && (t.reason !== "draw" || N(t.final_move_event_id));
780
+ case "game_resync_request": return Dt(t);
781
+ case "game_resync_state": return Dt(t) && N(t.request_event_id);
230
782
  default: return !1;
231
783
  }
232
784
  }
233
- var Ie = {
234
- connect4: Fe,
235
- battleship: Ne,
236
- tanks: be,
237
- tanks_live: g,
238
- racing_live: ne
239
- }, Le = Object.freeze(Object.keys(Ie));
240
- function Re(e) {
241
- return !we(e) || e.version !== 1 || !Object.hasOwn(Ie, e.game) || !E(e.game_id) || !E(e.event_id) || !we(e.data) ? !1 : Ie[e.game](e);
242
- }
243
- function ze(e) {
244
- if (!Pe(e) || e.length > Se) return null;
785
+ var Rt = {
786
+ connect4: Lt,
787
+ battleship: Ft,
788
+ tanks: xt,
789
+ tanks_live: Ke,
790
+ racing_live: rt
791
+ }, zt = Object.freeze(Object.keys(Rt));
792
+ function Bt(e) {
793
+ return !Tt(e) || e.version !== 1 || !Object.hasOwn(Rt, e.game) || !N(e.game_id) || !N(e.event_id) || !Tt(e.data) ? !1 : Rt[e.game](e);
794
+ }
795
+ function Vt(e) {
796
+ if (!It(e) || e.length > Ct) return null;
245
797
  try {
246
798
  let t = JSON.parse(e.slice(13));
247
- return Re(t) ? t : null;
799
+ return Bt(t) ? t : null;
248
800
  } catch {
249
801
  return null;
250
802
  }
251
803
  }
252
- function Be(e) {
253
- if (!Re(e)) throw Error("Evento de juego inválido");
254
- let t = xe + JSON.stringify(e);
255
- if (t.length > Se) throw Error("Evento de juego demasiado grande");
804
+ function Ht(e) {
805
+ if (!Bt(e)) throw Error("Evento de juego inválido");
806
+ let t = St + JSON.stringify(e);
807
+ if (t.length > Ct) throw Error("Evento de juego demasiado grande");
256
808
  return t;
257
809
  }
258
- function k(e, { game_id: t, data: n, event_id: r = p(), game: i = "connect4" }) {
810
+ function F(e, { game_id: t, data: n, event_id: r = p(), game: i = "connect4" }) {
259
811
  let a = {
260
812
  version: 1,
261
813
  game: i,
@@ -264,22 +816,22 @@ function k(e, { game_id: t, data: n, event_id: r = p(), game: i = "connect4" })
264
816
  type: e,
265
817
  data: n
266
818
  };
267
- if (!Re(a)) throw Error("Evento de juego inválido");
819
+ if (!Bt(a)) throw Error("Evento de juego inválido");
268
820
  return a;
269
821
  }
270
- function Ve() {
822
+ function Ut() {
271
823
  return Array.from({ length: 6 }, () => Array(7).fill(null));
272
824
  }
273
- var He = [
825
+ var Wt = [
274
826
  [0, 1],
275
827
  [1, 0],
276
828
  [1, 1],
277
829
  [1, -1]
278
830
  ];
279
- function Ue(e) {
831
+ function Gt(e) {
280
832
  for (let t = 0; t < 6; t += 1) for (let n = 0; n < 7; n += 1) {
281
833
  let r = e[t][n];
282
- if (r != null) for (let [i, a] of He) {
834
+ if (r != null) for (let [i, a] of Wt) {
283
835
  let o = [];
284
836
  for (let s = 0; s < 4; s += 1) {
285
837
  let c = t + i * s, l = n + a * s;
@@ -291,34 +843,34 @@ function Ue(e) {
291
843
  }
292
844
  return [];
293
845
  }
294
- function We(e) {
295
- let t = Ue(e);
846
+ function Kt(e) {
847
+ let t = Gt(e);
296
848
  return t.length ? e[t[0][0]][t[0][1]] : null;
297
849
  }
298
- function Ge(e) {
850
+ function qt(e) {
299
851
  return e[0].every((e) => e !== null);
300
852
  }
301
- function Ke(e, t, n) {
302
- if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null || We(e) !== null) return null;
853
+ function Jt(e, t, n) {
854
+ if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null || Kt(e) !== null) return null;
303
855
  let r = 5;
304
856
  for (; r >= 0 && e[r][t] !== null;) --r;
305
857
  if (r < 0) return null;
306
858
  let i = e.map((e) => e.slice());
307
859
  i[r][t] = n;
308
- let a = Ue(i), o = a.length ? i[a[0][0]][a[0][1]] : null;
860
+ let a = Gt(i), o = a.length ? i[a[0][0]][a[0][1]] : null;
309
861
  return {
310
862
  board: i,
311
863
  row: r,
312
864
  column: t,
313
865
  winner: o,
314
- draw: o === null && Ge(i),
866
+ draw: o === null && qt(i),
315
867
  winningCells: a
316
868
  };
317
869
  }
318
870
  // src/games/battleship/logic/game.js
319
- var qe = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
320
- function Je({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
321
- if (!qe(e) || !Array.isArray(t) || t.length !== 2 || !t.every(qe) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
871
+ var Yt = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
872
+ function Xt({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
873
+ if (!Yt(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Yt) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
322
874
  return {
323
875
  game: "battleship",
324
876
  rulesVersion: 1,
@@ -335,7 +887,7 @@ function Je({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
335
887
  revision: 0
336
888
  };
337
889
  }
338
- function Ye(e, t) {
890
+ function Zt(e, t) {
339
891
  if (!e || !t || typeof t != "object" || e.phase === "finished" || t.gameId !== void 0 && t.gameId !== e.gameId || t.expectedRevision !== void 0 && t.expectedRevision !== e.revision) return e;
340
892
  let n = e.players.indexOf(t.playerId);
341
893
  if (n < 0) return e;
@@ -391,16 +943,16 @@ function Ye(e, t) {
391
943
  };
392
944
  }
393
945
  // src/games/battleship/net/session.js
394
- var Xe = u.reduce((e, t) => e + t.size, 0), Ze = /^[0-9a-f]{32}$/, Qe = [
946
+ var Qt = u.reduce((e, t) => e + t.size, 0), $t = /^[0-9a-f]{32}$/, en = [
395
947
  "won",
396
948
  "closed",
397
949
  "declined"
398
- ], A = "La partida perdió sincronización. Se intentará resincronizar.", $e = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", et = "El rival envió un resultado imposible para ese disparo.", tt = "Tu flota no está disponible en este dispositivo; no se pueden responder disparos.", nt = () => Array.from({ length: 10 }, () => Array(10).fill(null)), rt = (e, t, n, r) => e.map((e, i) => i === t ? e.map((e, t) => t === n ? r : e) : e), it = (e) => e.reduce((e, t) => e + t.filter((e) => e === "hit").length, 0), at = (e) => e.reduce((e, t) => e + t.filter((e) => e !== null).length, 0), ot = (e, t) => t % 2 == 1 ? e.hostId : e.guestId, st = (e, t) => t === e.hostId ? e.guestId : e.hostId, ct = (e, t) => t === e.hostId ? "hostCommitment" : "guestCommitment", j = (e, t) => ({
950
+ ], I = "La partida perdió sincronización. Se intentará resincronizar.", tn = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", nn = "El rival envió un resultado imposible para ese disparo.", rn = "Tu flota no está disponible en este dispositivo; no se pueden responder disparos.", an = () => Array.from({ length: 10 }, () => Array(10).fill(null)), on = (e, t, n, r) => e.map((e, i) => i === t ? e.map((e, t) => t === n ? r : e) : e), sn = (e) => e.reduce((e, t) => e + t.filter((e) => e === "hit").length, 0), cn = (e) => e.reduce((e, t) => e + t.filter((e) => e !== null).length, 0), ln = (e, t) => t % 2 == 1 ? e.hostId : e.guestId, un = (e, t) => t === e.hostId ? e.guestId : e.hostId, dn = (e, t) => t === e.hostId ? "hostCommitment" : "guestCommitment", L = (e, t) => ({
399
951
  ...e,
400
952
  status: "conflict",
401
953
  error: t
402
- }), lt = (e) => `${e.row},${e.col}`, ut = (e, t) => e.row - t.row || e.col - t.col, dt = (e, t) => e.length === t.length && e.map(lt).sort().join("|") === t.map(lt).sort().join("|");
403
- function ft(e) {
954
+ }), fn = (e) => `${e.row},${e.col}`, pn = (e, t) => e.row - t.row || e.col - t.col, mn = (e, t) => e.length === t.length && e.map(fn).sort().join("|") === t.map(fn).sort().join("|");
955
+ function hn(e) {
404
956
  return {
405
957
  ...e,
406
958
  game: "battleship",
@@ -409,8 +961,8 @@ function ft(e) {
409
961
  myFleet: [],
410
962
  myReady: !1,
411
963
  opponentReady: !1,
412
- incomingShots: nt(),
413
- targetShots: nt(),
964
+ incomingShots: an(),
965
+ targetShots: an(),
414
966
  sunkEnemyShips: [],
415
967
  pendingShot: null,
416
968
  lastShot: null,
@@ -432,7 +984,7 @@ function ft(e) {
432
984
  sync: e.sync ?? null
433
985
  };
434
986
  }
435
- var pt = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.status) && !e.myReady, mt = (e) => e?.status === "active" && e.turnId === e.ownId && !e.pendingShot, ht = (e) => ({
987
+ var gn = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.status) && !e.myReady, _n = (e) => e?.status === "active" && e.turnId === e.ownId && !e.pendingShot, vn = (e) => ({
436
988
  id: e.id,
437
989
  size: e.size,
438
990
  orientation: e.orientation,
@@ -440,33 +992,33 @@ var pt = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.
440
992
  row: e.row,
441
993
  col: e.col
442
994
  }))
443
- }), gt = (e) => ({
995
+ }), yn = (e) => ({
444
996
  shipId: e.id,
445
997
  row: e.cells[0].row,
446
998
  col: e.cells[0].col,
447
999
  orientation: e.orientation
448
1000
  });
449
- function _t(e) {
1001
+ function bn(e) {
450
1002
  return !e || typeof e != "object" ? null : typeof e.ship_id == "string" ? {
451
1003
  shipId: e.ship_id,
452
1004
  row: e.row,
453
1005
  col: e.col,
454
1006
  orientation: e.orientation
455
- } : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ? gt(e) : null;
1007
+ } : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ? yn(e) : null;
456
1008
  }
457
- function vt(e) {
1009
+ function xn(e) {
458
1010
  if (!Array.isArray(e)) return null;
459
1011
  let t = s();
460
1012
  for (let n of e) {
461
- let e = _t(n), r = e && l(t, e);
1013
+ let e = bn(n), r = e && l(t, e);
462
1014
  if (!r?.ok) return null;
463
1015
  t = r.board;
464
1016
  }
465
1017
  return t;
466
1018
  }
467
- function M(e) {
1019
+ function Sn(e) {
468
1020
  if (!Array.isArray(e)) return null;
469
- let t = e.map(_t);
1021
+ let t = e.map(bn);
470
1022
  return t.some((e) => !e) ? null : t.map(({ shipId: e, row: t, col: n, orientation: r }) => ({
471
1023
  ship_id: e,
472
1024
  row: t,
@@ -474,21 +1026,21 @@ function M(e) {
474
1026
  orientation: r
475
1027
  })).sort((e, t) => e.ship_id < t.ship_id ? -1 : +(e.ship_id > t.ship_id));
476
1028
  }
477
- function yt(e) {
478
- let t = vt(e);
479
- return t && i(t) ? t.ships.map(ht) : null;
1029
+ function Cn(e) {
1030
+ let t = xn(e);
1031
+ return t && i(t) ? t.ships.map(vn) : null;
480
1032
  }
481
- var bt = (e) => !!yt(e);
482
- function xt(e) {
483
- let t = vt(e?.myFleet);
1033
+ var wn = (e) => !!Cn(e);
1034
+ function Tn(e) {
1035
+ let t = xn(e?.myFleet);
484
1036
  return t && i(t) ? {
485
1037
  ...t,
486
1038
  shots: e.incomingShots.map((e) => e.slice())
487
1039
  } : null;
488
1040
  }
489
- function St(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
490
- if (!pt(e)) return e;
491
- let a = vt(e.myFleet.filter((e) => e.id !== t)), o = a && l(a, {
1041
+ function En(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
1042
+ if (!gn(e)) return e;
1043
+ let a = xn(e.myFleet.filter((e) => e.id !== t)), o = a && l(a, {
492
1044
  shipId: t,
493
1045
  row: n,
494
1046
  col: r,
@@ -496,23 +1048,23 @@ function St(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
496
1048
  });
497
1049
  return o?.ok ? {
498
1050
  ...e,
499
- myFleet: o.board.ships.map(ht)
1051
+ myFleet: o.board.ships.map(vn)
500
1052
  } : e;
501
1053
  }
502
- function Ct(e, t) {
503
- return !pt(e) || !e.myFleet.some((e) => e.id === t) ? e : {
1054
+ function Dn(e, t) {
1055
+ return !gn(e) || !e.myFleet.some((e) => e.id === t) ? e : {
504
1056
  ...e,
505
1057
  myFleet: e.myFleet.filter((e) => e.id !== t)
506
1058
  };
507
1059
  }
508
- function wt(e) {
1060
+ function On(e) {
509
1061
  let t = Math.floor(4294967296 / e) * e, n = /* @__PURE__ */ new Uint32Array(1);
510
1062
  do
511
1063
  globalThis.crypto.getRandomValues(n);
512
1064
  while (n[0] >= t);
513
1065
  return n[0] % e;
514
1066
  }
515
- function Tt(e = wt) {
1067
+ function kn(e = On) {
516
1068
  for (let t = 0; t < 50; t += 1) {
517
1069
  let t = s();
518
1070
  for (let n of u) for (let r = 0; r < 300; r += 1) {
@@ -527,31 +1079,31 @@ function Tt(e = wt) {
527
1079
  break;
528
1080
  }
529
1081
  }
530
- if (i(t)) return t.ships.map(ht);
1082
+ if (i(t)) return t.ships.map(vn);
531
1083
  }
532
1084
  throw Error("No se pudo generar una flota aleatoria.");
533
1085
  }
534
- var Et = (e, t) => pt(e) ? {
1086
+ var An = (e, t) => gn(e) ? {
535
1087
  ...e,
536
- myFleet: Tt(t)
537
- } : e, Dt = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
538
- function Ot() {
1088
+ myFleet: kn(t)
1089
+ } : e, jn = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
1090
+ function Mn() {
539
1091
  let e = /* @__PURE__ */ new Uint8Array(16);
540
- return globalThis.crypto.getRandomValues(e), Dt(e);
1092
+ return globalThis.crypto.getRandomValues(e), jn(e);
541
1093
  }
542
- function kt(e, t) {
543
- let n = M(e);
1094
+ function Nn(e, t) {
1095
+ let n = Sn(e);
544
1096
  if (!n || typeof t != "string") throw TypeError("Flota inválida");
545
1097
  return JSON.stringify({
546
1098
  fleet: n,
547
1099
  salt: t
548
1100
  });
549
1101
  }
550
- async function At(e, t) {
551
- let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(kt(e, t)));
552
- return Dt(new Uint8Array(n));
1102
+ async function Pn(e, t) {
1103
+ let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(Nn(e, t)));
1104
+ return jn(new Uint8Array(n));
553
1105
  }
554
- function jt(e, t) {
1106
+ function Fn(e, t) {
555
1107
  if (!e || !t) return null;
556
1108
  let n = c(e, {
557
1109
  row: t.row,
@@ -571,7 +1123,7 @@ function jt(e, t) {
571
1123
  defeated: n.defeated
572
1124
  };
573
1125
  }
574
- function Mt(e) {
1126
+ function In(e) {
575
1127
  let t = u.find((t) => t.id === e?.ship_id);
576
1128
  if (!t || !Array.isArray(e.cells) || e.cells.length !== t.size) return null;
577
1129
  let n = e.cells.map((e) => Array.isArray(e) ? {
@@ -579,7 +1131,7 @@ function Mt(e) {
579
1131
  col: e[1]
580
1132
  } : null);
581
1133
  if (n.some((e) => !o(e))) return null;
582
- n.sort(ut);
1134
+ n.sort(pn);
583
1135
  let r = n.every((e, t) => e.row === n[0].row && e.col === n[0].col + t), i = n.every((e, t) => e.col === n[0].col && e.row === n[0].row + t);
584
1136
  return !r && !i ? null : {
585
1137
  id: t.id,
@@ -589,43 +1141,43 @@ function Mt(e) {
589
1141
  sunk: !0
590
1142
  };
591
1143
  }
592
- function Nt(e, t) {
1144
+ function Ln(e, t) {
593
1145
  let { row: n, col: r, result: i, sunk: a } = t, o = !!t.defeated;
594
1146
  if (i !== "hit" && i !== "miss" || e.targetShots[n][r] !== null) return null;
595
- let s = rt(e.targetShots, n, r, i), c = it(s), l = null;
1147
+ let s = on(e.targetShots, n, r, i), c = sn(s), l = null;
596
1148
  if (a) {
597
- if (l = i === "hit" ? Mt(a) : null, !l || e.sunkEnemyShips.some((e) => e.id === l.id)) return null;
598
- let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(lt)));
599
- if (!l.cells.some((e) => e.row === n && e.col === r) || l.cells.some((e) => s[e.row][e.col] !== "hit" || t.has(lt(e)))) return null;
1149
+ if (l = i === "hit" ? In(a) : null, !l || e.sunkEnemyShips.some((e) => e.id === l.id)) return null;
1150
+ let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(fn)));
1151
+ if (!l.cells.some((e) => e.row === n && e.col === r) || l.cells.some((e) => s[e.row][e.col] !== "hit" || t.has(fn(e)))) return null;
600
1152
  }
601
1153
  let d = e.sunkEnemyShips.length + +!!l;
602
- return c > Xe || o !== (c === Xe) || o !== (d === u.length) || !o && Xe - c > 100 - at(s) ? null : {
1154
+ return c > Qt || o !== (c === Qt) || o !== (d === u.length) || !o && Qt - c > 100 - cn(s) ? null : {
603
1155
  shots: s,
604
1156
  ship: l
605
1157
  };
606
1158
  }
607
- function Pt(e, t) {
608
- let n = jt(xt(e), t);
1159
+ function Rn(e, t) {
1160
+ let n = Fn(Tn(e), t);
609
1161
  if (!n || n.result !== t.result || n.defeated !== !!t.defeated || !!n.sunk != !!t.sunk) return null;
610
- let r = n.sunk ? Mt(n.sunk) : null;
611
- return r && (t.sunk.ship_id !== r.id || !dt(r.cells, t.sunk.cells.map(([e, t]) => ({
1162
+ let r = n.sunk ? In(n.sunk) : null;
1163
+ return r && (t.sunk.ship_id !== r.id || !mn(r.cells, t.sunk.cells.map(([e, t]) => ({
612
1164
  row: e,
613
1165
  col: t
614
1166
  })))) ? null : {
615
- shots: rt(e.incomingShots, t.row, t.col, t.result),
1167
+ shots: on(e.incomingShots, t.row, t.col, t.result),
616
1168
  ship: r
617
1169
  };
618
1170
  }
619
- function Ft(e, t, n, r) {
620
- let i = ct(e, t);
1171
+ function zn(e, t, n, r) {
1172
+ let i = dn(e, t);
621
1173
  if (e[i]) return e[i] === n ? e : null;
622
1174
  let a = {
623
1175
  ...e,
624
1176
  [i]: n
625
1177
  };
626
1178
  if (t === e.ownId) {
627
- let t = r?.commitment === n ? yt(r.fleet) : null;
628
- t && Ze.test(r.salt ?? "") ? a = {
1179
+ let t = r?.commitment === n ? Cn(r.fleet) : null;
1180
+ t && $t.test(r.salt ?? "") ? a = {
629
1181
  ...a,
630
1182
  myFleet: t,
631
1183
  mySalt: r.salt,
@@ -635,7 +1187,7 @@ function Ft(e, t, n, r) {
635
1187
  myFleet: [],
636
1188
  mySalt: null,
637
1189
  myCommitment: n,
638
- error: tt
1190
+ error: rn
639
1191
  }), a.myReady = !0;
640
1192
  } else a.opponentReady = !0;
641
1193
  return a.hostCommitment && a.guestCommitment && (a = {
@@ -646,7 +1198,7 @@ function Ft(e, t, n, r) {
646
1198
  pendingShot: null
647
1199
  }), a;
648
1200
  }
649
- function It(e, t, { row: n, col: r, ply: i }, a) {
1201
+ function Bn(e, t, { row: n, col: r, ply: i }, a) {
650
1202
  let s = t === e.ownId ? e.targetShots : e.incomingShots;
651
1203
  return !o({
652
1204
  row: n,
@@ -662,8 +1214,8 @@ function It(e, t, { row: n, col: r, ply: i }, a) {
662
1214
  lastEventId: a ?? e.lastEventId
663
1215
  };
664
1216
  }
665
- function Lt(e, t, n, r) {
666
- let i = e.pendingShot, a = t === e.ownId, o = a ? Pt(e, n) : Nt(e, n);
1217
+ function Vn(e, t, n, r) {
1218
+ let i = e.pendingShot, a = t === e.ownId, o = a ? Rn(e, n) : Ln(e, n);
667
1219
  if (!o) return null;
668
1220
  let s = !!n.defeated, c = {
669
1221
  ply: i.ply,
@@ -693,21 +1245,21 @@ function Lt(e, t, n, r) {
693
1245
  verification: s ? "pending" : e.verification
694
1246
  };
695
1247
  }
696
- function Rt(e, t, n) {
1248
+ function Hn(e, t, n) {
697
1249
  let { ply: r, row: i, col: a, prev_event_id: o } = t.data;
698
- return n === ot(e, r) ? e.status === "active" ? r <= e.ply ? e : e.pendingShot ? r === e.pendingShot.ply ? e : j(e, A) : r > e.ply + 1 ? j(e, A) : n === e.turnId ? o === e.lastEventId ? It(e, n, {
1250
+ return n === ln(e, r) ? e.status === "active" ? r <= e.ply ? e : e.pendingShot ? r === e.pendingShot.ply ? e : L(e, I) : r > e.ply + 1 ? L(e, I) : n === e.turnId ? o === e.lastEventId ? Bn(e, n, {
699
1251
  row: i,
700
1252
  col: a,
701
1253
  ply: r
702
- }, t.event_id) ?? e : j(e, A) : e : j(e, e.status === "invited" ? $e : A) : e;
1254
+ }, t.event_id) ?? e : L(e, I) : e : L(e, e.status === "invited" ? tn : I) : e;
703
1255
  }
704
- function zt(e, t, n) {
1256
+ function Un(e, t, n) {
705
1257
  let { ply: r, row: i, col: a } = t.data;
706
- if (e.status !== "active") return e.status === "placement" ? j(e, A) : e;
1258
+ if (e.status !== "active") return e.status === "placement" ? L(e, I) : e;
707
1259
  let o = e.pendingShot;
708
- return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e : j(e, "El rival respondió a un disparo distinto.") : Lt(e, n, t.data, t.event_id) || (n === e.ownId ? e : j(e, et)) : r < o.ply ? e : j(e, A) : r <= e.ply ? e : j(e, A);
1260
+ return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e : L(e, "El rival respondió a un disparo distinto.") : Vn(e, n, t.data, t.event_id) || (n === e.ownId ? e : L(e, nn)) : r < o.ply ? e : L(e, I) : r <= e.ply ? e : L(e, I);
709
1261
  }
710
- function Bt(e, t, n) {
1262
+ function Wn(e, t, n) {
711
1263
  return !e.winnerId || !["won", "closed"].includes(e.status) ? e : n === e.ownId ? e.myRevealSent ? e : {
712
1264
  ...e,
713
1265
  myRevealSent: !0
@@ -720,7 +1272,7 @@ function Bt(e, t, n) {
720
1272
  verification: "pending"
721
1273
  };
722
1274
  }
723
- function Vt(e, t, n, r = {}) {
1275
+ function Gn(e, t, n, r = {}) {
724
1276
  if (!e || e.game !== "battleship" || t?.game !== "battleship" || t.game_id !== e.gameId || n !== e.hostId && n !== e.guestId) return e;
725
1277
  let i = t.data;
726
1278
  if (t.type === "game_end") return i.reason !== "closed" || [
@@ -733,8 +1285,8 @@ function Vt(e, t, n, r = {}) {
733
1285
  closedBy: n,
734
1286
  error: ""
735
1287
  };
736
- if (t.type === "bs_reveal") return Bt(e, i, n);
737
- if (Qe.includes(e.status) || e.status === "conflict") return e;
1288
+ if (t.type === "bs_reveal") return Wn(e, i, n);
1289
+ if (en.includes(e.status) || e.status === "conflict") return e;
738
1290
  switch (t.type) {
739
1291
  case "game_accept":
740
1292
  case "game_decline": return n !== e.guestId || e.status !== "invited" || i.invite_event_id !== e.inviteEventId ? e : t.type === "game_accept" ? {
@@ -747,32 +1299,32 @@ function Vt(e, t, n, r = {}) {
747
1299
  status: "declined",
748
1300
  lastEventId: t.event_id
749
1301
  };
750
- case "bs_commit": return e.status === "invited" ? j(e, $e) : e.status === "placement" ? Ft(e, n, i.commitment, r.stored) ?? e : e;
751
- case "bs_fire": return Rt(e, t, n);
752
- case "bs_result": return zt(e, t, n);
1302
+ case "bs_commit": return e.status === "invited" ? L(e, tn) : e.status === "placement" ? zn(e, n, i.commitment, r.stored) ?? e : e;
1303
+ case "bs_fire": return Hn(e, t, n);
1304
+ case "bs_result": return Un(e, t, n);
753
1305
  default: return e;
754
1306
  }
755
1307
  }
756
- function Ht(e, t) {
757
- let n = Je({
1308
+ function Kn(e, t) {
1309
+ let n = Xt({
758
1310
  gameId: String(e.gameId),
759
1311
  players: [e.hostId, e.guestId],
760
1312
  firstPlayerId: e.hostId
761
1313
  });
762
1314
  for (let e of n.players) {
763
- for (let r of t[e]) n = Ye(n, {
1315
+ for (let r of t[e]) n = Zt(n, {
764
1316
  type: "place_ship",
765
1317
  playerId: e,
766
- ...gt(r)
1318
+ ...yn(r)
767
1319
  });
768
- n = Ye(n, {
1320
+ n = Zt(n, {
769
1321
  type: "ready",
770
1322
  playerId: e
771
1323
  });
772
1324
  }
773
1325
  if (n.phase !== "playing") return !1;
774
1326
  for (let t of e.shots) {
775
- let e = Ye(n, {
1327
+ let e = Zt(n, {
776
1328
  type: "fire",
777
1329
  playerId: t.by,
778
1330
  row: t.row,
@@ -783,30 +1335,30 @@ function Ht(e, t) {
783
1335
  if (r.result !== t.result || r.defeated !== t.defeated || r.sunk !== !!t.sunk) return !1;
784
1336
  if (t.sunk) {
785
1337
  let n = e.boards[e.players.indexOf(r.targetId)].ships.find((e) => e.id === r.shipId);
786
- if (t.sunk.id !== r.shipId || !dt(n.cells, t.sunk.cells)) return !1;
1338
+ if (t.sunk.id !== r.shipId || !mn(n.cells, t.sunk.cells)) return !1;
787
1339
  }
788
1340
  n = e;
789
1341
  }
790
1342
  return !e.winnerId || n.winnerId === e.winnerId;
791
1343
  }
792
- async function Ut(e, t = e?.opponentReveal) {
1344
+ async function qn(e, t = e?.opponentReveal) {
793
1345
  if (!e || !t) return "pending";
794
- let n = st(e, e.ownId), r = e[ct(e, n)], i = yt(t.fleet);
795
- if (!r || !i || typeof t.salt != "string" || !Ze.test(t.salt)) return "mismatch";
1346
+ let n = un(e, e.ownId), r = e[dn(e, n)], i = Cn(t.fleet);
1347
+ if (!r || !i || typeof t.salt != "string" || !$t.test(t.salt)) return "mismatch";
796
1348
  let a;
797
1349
  try {
798
- a = await At(t.fleet, t.salt);
1350
+ a = await Pn(t.fleet, t.salt);
799
1351
  } catch {
800
1352
  return "mismatch";
801
1353
  }
802
1354
  if (a !== r) return "mismatch";
803
- let o = yt(e.myFleet);
804
- return o ? Ht(e, {
1355
+ let o = Cn(e.myFleet);
1356
+ return o ? Kn(e, {
805
1357
  [e.ownId]: o,
806
1358
  [n]: i
807
1359
  }) ? "ok" : "mismatch" : "pending";
808
1360
  }
809
- var Wt = (e) => {
1361
+ var Jn = (e) => {
810
1362
  if (e.result === "miss") return [
811
1363
  e.row,
812
1364
  e.col,
@@ -828,13 +1380,13 @@ var Wt = (e) => {
828
1380
  +(e.sunk.orientation === "vertical")
829
1381
  ];
830
1382
  };
831
- function Gt(e) {
1383
+ function Yn(e) {
832
1384
  if (!e.acceptEventId) return {
833
1385
  commits: [null, null],
834
1386
  log: [],
835
1387
  head: e.inviteEventId
836
1388
  };
837
- let t = e.shots.map(Wt);
1389
+ let t = e.shots.map(Jn);
838
1390
  return e.pendingShot && t.push([e.pendingShot.row, e.pendingShot.col]), {
839
1391
  accept_event_id: e.acceptEventId,
840
1392
  commits: [e.hostCommitment ?? null, e.guestCommitment ?? null],
@@ -842,7 +1394,7 @@ function Gt(e) {
842
1394
  head: e.lastEventId
843
1395
  };
844
1396
  }
845
- function Kt(e, t) {
1397
+ function Xn(e, t) {
846
1398
  let n = e.accept_event_id ?? null, r = t.accept_event_id ?? null;
847
1399
  if (n && r && n !== r) return "diverged";
848
1400
  let i = /* @__PURE__ */ new Set();
@@ -862,7 +1414,7 @@ function Kt(e, t) {
862
1414
  }
863
1415
  return a.length !== o.length && i.add(a.length < o.length ? "behind" : "ahead"), i.size === 2 ? "mixed" : i.size === 1 ? [...i][0] : a.length && e.head !== t.head ? "diverged" : "equal";
864
1416
  }
865
- function qt(e, t) {
1417
+ function Zn(e, t) {
866
1418
  if ((e.log ?? []).length || (t.log ?? []).length) return null;
867
1419
  let n = e.accept_event_id ?? t.accept_event_id;
868
1420
  return n ? {
@@ -872,15 +1424,15 @@ function qt(e, t) {
872
1424
  head: n
873
1425
  } : null;
874
1426
  }
875
- function Jt(e, t, n = {}) {
1427
+ function Qn(e, t, n = {}) {
876
1428
  let r = {
877
1429
  ...e,
878
1430
  status: "invited",
879
1431
  turnId: null,
880
1432
  myReady: !1,
881
1433
  opponentReady: !1,
882
- incomingShots: nt(),
883
- targetShots: nt(),
1434
+ incomingShots: an(),
1435
+ targetShots: an(),
884
1436
  sunkEnemyShips: [],
885
1437
  pendingShot: null,
886
1438
  lastShot: null,
@@ -909,11 +1461,11 @@ function Jt(e, t, n = {}) {
909
1461
  acceptEventId: t.accept_event_id,
910
1462
  lastEventId: t.accept_event_id
911
1463
  };
912
- for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (s = Ft(s, r, a[t], n.stored), !s)) return null;
1464
+ for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (s = zn(s, r, a[t], n.stored), !s)) return null;
913
1465
  if (i.length && s.status !== "active") return null;
914
1466
  for (let e = 0; e < i.length; e += 1) {
915
1467
  let t = i[e], n = e + 1;
916
- if (s = It(s, ot(s, n), {
1468
+ if (s = Bn(s, ln(s, n), {
917
1469
  row: t[0],
918
1470
  col: t[1],
919
1471
  ply: n
@@ -922,7 +1474,7 @@ function Jt(e, t, n = {}) {
922
1474
  if (e !== i.length - 1) return null;
923
1475
  break;
924
1476
  }
925
- let r = st(s, s.pendingShot.by), a = null;
1477
+ let r = un(s, s.pendingShot.by), a = null;
926
1478
  if (t[2] === 2) {
927
1479
  let e = u[t[3]];
928
1480
  if (!e) return null;
@@ -932,14 +1484,14 @@ function Jt(e, t, n = {}) {
932
1484
  cells: Array.from({ length: e.size }, (e, r) => [t[4] + (n ? r : 0), t[5] + (n ? 0 : r)])
933
1485
  };
934
1486
  }
935
- let o = it(r === s.ownId ? s.incomingShots : s.targetShots) + (t[2] === 0 ? 0 : 1);
936
- if (s = Lt(s, r, {
1487
+ let o = sn(r === s.ownId ? s.incomingShots : s.targetShots) + (t[2] === 0 ? 0 : 1);
1488
+ if (s = Vn(s, r, {
937
1489
  ply: n,
938
1490
  row: t[0],
939
1491
  col: t[1],
940
1492
  result: t[2] === 0 ? "miss" : "hit",
941
1493
  sunk: a,
942
- defeated: o === Xe
1494
+ defeated: o === Qt
943
1495
  }, null), !s || s.status === "won" && e !== i.length - 1) return null;
944
1496
  }
945
1497
  return !i.length && t.head !== t.accept_event_id ? null : (s = {
@@ -952,7 +1504,7 @@ function Jt(e, t, n = {}) {
952
1504
  verification: e.verification
953
1505
  }), s);
954
1506
  }
955
- function Yt(e, t) {
1507
+ function $n(e, t) {
956
1508
  if (!e || !t) return !1;
957
1509
  let n = e.log?.[(t.data?.ply ?? 0) - 1];
958
1510
  switch (t.type) {
@@ -963,37 +1515,37 @@ function Yt(e, t) {
963
1515
  default: return !1;
964
1516
  }
965
1517
  }
966
- function Xt(e, t) {
1518
+ function er(e, t) {
967
1519
  let n = { ...e };
968
1520
  return t.acceptEventId && (n[t.acceptEventId] = !0), t.lastEventId && (n[t.lastEventId] = !0), n;
969
1521
  }
970
1522
  // src/games/battleship/net/fleetStorage.js
971
- var Zt = "lira:bs:", Qt = 12096e5, $t = (e, t) => `${Zt}${e}:${t}`, en = () => {
1523
+ var tr = "lira:bs:", nr = 12096e5, rr = (e, t) => `${tr}${e}:${t}`, ir = () => {
972
1524
  try {
973
1525
  return globalThis.localStorage ?? null;
974
1526
  } catch {
975
1527
  return null;
976
1528
  }
977
1529
  };
978
- function tn(e) {
1530
+ function ar(e) {
979
1531
  return typeof e == "object" && !!e && Array.isArray(e.fleet) && e.fleet.length === 5 && typeof e.salt == "string" && /^[0-9a-f]{32}$/.test(e.salt) && typeof e.commitment == "string" && /^[0-9a-f]{64}$/.test(e.commitment);
980
1532
  }
981
- function nn(e) {
1533
+ function or(e) {
982
1534
  let t = Date.now();
983
1535
  for (let n = e.length - 1; n >= 0; --n) {
984
1536
  let r = e.key(n);
985
- if (r?.startsWith(Zt)) try {
1537
+ if (r?.startsWith(tr)) try {
986
1538
  let n = JSON.parse(e.getItem(r));
987
- tn(n) && t - n.savedAt < Qt || e.removeItem(r);
1539
+ ar(n) && t - n.savedAt < nr || e.removeItem(r);
988
1540
  } catch {
989
1541
  e.removeItem(r);
990
1542
  }
991
1543
  }
992
1544
  }
993
- function rn(e, t, { fleet: n, salt: r, commitment: i }) {
1545
+ function sr(e, t, { fleet: n, salt: r, commitment: i }) {
994
1546
  try {
995
- let a = en();
996
- return a ? (nn(a), a.setItem($t(e, t), JSON.stringify({
1547
+ let a = ir();
1548
+ return a ? (or(a), a.setItem(rr(e, t), JSON.stringify({
997
1549
  fleet: n,
998
1550
  salt: r,
999
1551
  commitment: i,
@@ -1003,10 +1555,10 @@ function rn(e, t, { fleet: n, salt: r, commitment: i }) {
1003
1555
  return !1;
1004
1556
  }
1005
1557
  }
1006
- function an(e, t) {
1558
+ function cr(e, t) {
1007
1559
  try {
1008
- let n = JSON.parse(en()?.getItem($t(e, t)) ?? "null");
1009
- return tn(n) ? {
1560
+ let n = JSON.parse(ir()?.getItem(rr(e, t)) ?? "null");
1561
+ return ar(n) ? {
1010
1562
  fleet: n.fleet,
1011
1563
  salt: n.salt,
1012
1564
  commitment: n.commitment
@@ -1016,20 +1568,20 @@ function an(e, t) {
1016
1568
  }
1017
1569
  }
1018
1570
  // src/games/tanks/logic/constants.js
1019
- var N = 1e5, on = 160 * N, P = 2 * N, sn = 20 * N;
1020
- 2 * N;
1021
- var cn = 1 * N;
1022
- 4 * N, 4 * N;
1023
- var ln = 18e4, un = 25e4, dn = 5e4, F = 25e3, fn = 60 * N, pn = 4 * N, I = Object.freeze({
1571
+ var R = 1e5, lr = 160 * R, z = 2 * R, ur = 20 * R;
1572
+ 2 * R;
1573
+ var dr = 1 * R;
1574
+ 4 * R, 4 * R;
1575
+ var fr = 18e4, pr = 25e4, mr = 5e4, B = 25e3, hr = 60 * R, gr = 4 * R, V = Object.freeze({
1024
1576
  move: Object.freeze([-16, 16]),
1025
1577
  yaw: Object.freeze([0, 359]),
1026
1578
  pitch: Object.freeze([5, 80]),
1027
1579
  power: Object.freeze([0, 100])
1028
- }), L = Object.freeze({
1580
+ }), H = Object.freeze({
1029
1581
  standard: Object.freeze({
1030
1582
  id: "standard",
1031
1583
  cost: 0,
1032
- radius: 6 * N,
1584
+ radius: 6 * R,
1033
1585
  maxDmg: 40,
1034
1586
  depth: 15e4,
1035
1587
  speedPct: 100
@@ -1037,7 +1589,7 @@ var ln = 18e4, un = 25e4, dn = 5e4, F = 25e3, fn = 60 * N, pn = 4 * N, I = Objec
1037
1589
  heavy: Object.freeze({
1038
1590
  id: "heavy",
1039
1591
  cost: 1,
1040
- radius: 8 * N,
1592
+ radius: 8 * R,
1041
1593
  maxDmg: 55,
1042
1594
  depth: 25e4,
1043
1595
  speedPct: 85
@@ -1045,16 +1597,16 @@ var ln = 18e4, un = 25e4, dn = 5e4, F = 25e3, fn = 60 * N, pn = 4 * N, I = Objec
1045
1597
  cluster: Object.freeze({
1046
1598
  id: "cluster",
1047
1599
  cost: 1,
1048
- radius: 4 * N,
1600
+ radius: 4 * R,
1049
1601
  maxDmg: 15,
1050
1602
  depth: 8e4,
1051
1603
  speedPct: 100
1052
1604
  })
1053
- }), mn = Object.freeze({
1054
- radius: 4 * N,
1605
+ }), _r = Object.freeze({
1606
+ radius: 4 * R,
1055
1607
  maxDmg: 15,
1056
1608
  depth: 8e4
1057
- }), hn = Object.freeze([
1609
+ }), vr = Object.freeze([
1058
1610
  Object.freeze([
1059
1611
  0,
1060
1612
  0,
@@ -1080,10 +1632,10 @@ var ln = 18e4, un = 25e4, dn = 5e4, F = 25e3, fn = 60 * N, pn = 4 * N, I = Objec
1080
1632
  0,
1081
1633
  -6e3
1082
1634
  ])
1083
- ]), gn = Object.freeze({
1635
+ ]), yr = Object.freeze({
1084
1636
  heavy: 2,
1085
1637
  cluster: 2
1086
- }), _n = Object.freeze([
1638
+ }), br = Object.freeze([
1087
1639
  0,
1088
1640
  17452,
1089
1641
  34899,
@@ -1175,20 +1727,20 @@ var ln = 18e4, un = 25e4, dn = 5e4, F = 25e3, fn = 60 * N, pn = 4 * N, I = Objec
1175
1727
  999391,
1176
1728
  999848,
1177
1729
  1e6
1178
- ]), vn = 1e6;
1179
- function yn(e) {
1730
+ ]), xr = 1e6;
1731
+ function Sr(e) {
1180
1732
  let t = (e % 360 + 360) % 360;
1181
- return t <= 90 ? _n[t] : t <= 180 ? _n[180 - t] : t <= 270 ? -_n[t - 180] : -_n[360 - t];
1733
+ return t <= 90 ? br[t] : t <= 180 ? br[180 - t] : t <= 270 ? -br[t - 180] : -br[360 - t];
1182
1734
  }
1183
- function bn(e) {
1184
- return yn(e + 90);
1735
+ function Cr(e) {
1736
+ return Sr(e + 90);
1185
1737
  }
1186
- function R(e, t) {
1187
- return Math.trunc(e * t / vn);
1738
+ function U(e, t) {
1739
+ return Math.trunc(e * t / xr);
1188
1740
  }
1189
1741
  // src/games/tanks/logic/rng.js
1190
- var xn = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
1191
- function Sn(e) {
1742
+ var wr = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
1743
+ function Tr(e) {
1192
1744
  let t = e >>> 0;
1193
1745
  return function() {
1194
1746
  t = t + 1831565813 >>> 0;
@@ -1196,48 +1748,48 @@ function Sn(e) {
1196
1748
  return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), (e ^ e >>> 14) >>> 0;
1197
1749
  };
1198
1750
  }
1199
- function z(e, t, n) {
1751
+ function W(e, t, n) {
1200
1752
  return t + e() % (n - t + 1);
1201
1753
  }
1202
- function Cn(e, t) {
1203
- let n = Sn((e ^ Math.imul(t, 2654435761)) >>> 0);
1754
+ function Er(e, t) {
1755
+ let n = Tr((e ^ Math.imul(t, 2654435761)) >>> 0);
1204
1756
  return {
1205
- x: z(n, -40, 40),
1206
- z: z(n, -40, 40)
1757
+ x: W(n, -40, 40),
1758
+ z: W(n, -40, 40)
1207
1759
  };
1208
1760
  }
1209
1761
  // src/games/tanks/logic/terrain.js
1210
- var B = (e, t, n) => e < t ? t : e > n ? n : e, V = (e, t, n, r) => e + Math.trunc((t - e) * n / r);
1211
- function H(e, t, n) {
1212
- let r = B(t, 0, on), i = B(n, 0, on), a = Math.min(Math.trunc(r / P), 79), o = Math.min(Math.trunc(i / P), 79), s = r - a * P, c = i - o * P, l = o * 81;
1213
- return V(V(e[l + a], e[l + a + 1], s, P), V(e[l + 81 + a], e[l + 81 + a + 1], s, P), c, P);
1762
+ var G = (e, t, n) => e < t ? t : e > n ? n : e, K = (e, t, n, r) => e + Math.trunc((t - e) * n / r);
1763
+ function q(e, t, n) {
1764
+ let r = G(t, 0, lr), i = G(n, 0, lr), a = Math.min(Math.trunc(r / z), 79), o = Math.min(Math.trunc(i / z), 79), s = r - a * z, c = i - o * z, l = o * 81;
1765
+ return K(K(e[l + a], e[l + a + 1], s, z), K(e[l + 81 + a], e[l + 81 + a + 1], s, z), c, z);
1214
1766
  }
1215
- function wn(e, t, n, r) {
1767
+ function Dr(e, t, n, r) {
1216
1768
  let i = Math.trunc(80 / t) + 1, a = [];
1217
- for (let t = 0; t < i * i; t += 1) a.push(z(e, n, r) * 1e3);
1769
+ for (let t = 0; t < i * i; t += 1) a.push(W(e, n, r) * 1e3);
1218
1770
  return {
1219
1771
  n: i,
1220
1772
  step: t,
1221
1773
  values: a
1222
1774
  };
1223
1775
  }
1224
- function Tn({ n: e, step: t, values: n }, r, i) {
1776
+ function Or({ n: e, step: t, values: n }, r, i) {
1225
1777
  let a = Math.min(Math.trunc(r / t), e - 2), o = Math.min(Math.trunc(i / t), e - 2), s = r - a * t, c = i - o * t, l = (t, r) => n[r * e + t];
1226
- return V(V(l(a, o), l(a + 1, o), s, t), V(l(a, o + 1), l(a + 1, o + 1), s, t), c, t);
1778
+ return K(K(l(a, o), l(a + 1, o), s, t), K(l(a, o + 1), l(a + 1, o + 1), s, t), c, t);
1227
1779
  }
1228
- function En(e) {
1780
+ function kr(e) {
1229
1781
  let t = new Int32Array(e.length);
1230
1782
  for (let n = 0; n < 81; n += 1) for (let r = 0; r < 81; r += 1) {
1231
1783
  let i = 0;
1232
- for (let t = -1; t <= 1; t += 1) for (let a = -1; a <= 1; a += 1) i += e[B(n + t, 0, 80) * 81 + B(r + a, 0, 80)];
1784
+ for (let t = -1; t <= 1; t += 1) for (let a = -1; a <= 1; a += 1) i += e[G(n + t, 0, 80) * 81 + G(r + a, 0, 80)];
1233
1785
  t[n * 81 + r] = Math.trunc(i / 9);
1234
1786
  }
1235
1787
  return t;
1236
1788
  }
1237
- function Dn(e, t, n, r, i) {
1238
- let a = H(e, t, n), o = r * r, s = i * i;
1789
+ function Ar(e, t, n, r, i) {
1790
+ let a = q(e, t, n), o = r * r, s = i * i;
1239
1791
  for (let r = 0; r < 81; r += 1) for (let c = 0; c < 81; c += 1) {
1240
- let l = c * P - t, u = r * P - n;
1792
+ let l = c * z - t, u = r * z - n;
1241
1793
  if (l > i || l < -i || u > i || u < -i) continue;
1242
1794
  let d = l * l + u * u;
1243
1795
  if (d >= s) continue;
@@ -1249,44 +1801,44 @@ function Dn(e, t, n, r, i) {
1249
1801
  }
1250
1802
  }
1251
1803
  }
1252
- var U = (e, t, n) => z(e, t, n) * (N / 2), On = (e, t, n, r, i) => {
1804
+ var J = (e, t, n) => W(e, t, n) * (R / 2), jr = (e, t, n, r, i) => {
1253
1805
  let a = e - n, o = t - r;
1254
1806
  return a > i || a < -i || o > i || o < -i ? !1 : a * a + o * o < i * i;
1255
- }, kn = (e, t, n, r) => t >= e.x - e.w / 2 - r && t <= e.x + e.w / 2 + r && n >= e.z - e.d / 2 - r && n <= e.z + e.d / 2 + r;
1256
- function An(e) {
1257
- let t = Sn(e), n = wn(t, 20, 0, 1200), r = wn(t, 10, -250, 250), i = wn(t, 4, -60, 60), a = /* @__PURE__ */ new Int32Array(6561);
1807
+ }, Mr = (e, t, n, r) => t >= e.x - e.w / 2 - r && t <= e.x + e.w / 2 + r && n >= e.z - e.d / 2 - r && n <= e.z + e.d / 2 + r;
1808
+ function Nr(e) {
1809
+ let t = Tr(e), n = Dr(t, 20, 0, 1200), r = Dr(t, 10, -250, 250), i = Dr(t, 4, -60, 60), a = /* @__PURE__ */ new Int32Array(6561);
1258
1810
  for (let e = 0; e < 81; e += 1) for (let t = 0; t < 81; t += 1) {
1259
- let o = 3 * N + Tn(n, t, e) + Tn(r, t, e) + Tn(i, t, e);
1260
- a[e * 81 + t] = B(o, 0, sn);
1811
+ let o = 3 * R + Or(n, t, e) + Or(r, t, e) + Or(i, t, e);
1812
+ a[e * 81 + t] = G(o, 0, ur);
1261
1813
  }
1262
- a = En(En(a));
1814
+ a = kr(kr(a));
1263
1815
  let o = [{
1264
- x: 20 * N + U(t, -4, 4),
1265
- z: 80 * N + U(t, -40, 40)
1816
+ x: 20 * R + J(t, -4, 4),
1817
+ z: 80 * R + J(t, -40, 40)
1266
1818
  }, {
1267
- x: 140 * N + U(t, -4, 4),
1268
- z: 80 * N + U(t, -40, 40)
1819
+ x: 140 * R + J(t, -4, 4),
1820
+ z: 80 * R + J(t, -40, 40)
1269
1821
  }];
1270
- for (let e of o) Dn(a, e.x, e.z, pn, pn + 3 * N);
1271
- let s = [], c = z(t, 4, 6);
1822
+ for (let e of o) Ar(a, e.x, e.z, gr, gr + 3 * R);
1823
+ let s = [], c = W(t, 4, 6);
1272
1824
  for (let e = 0; e < 200 && s.length < c; e += 1) {
1273
- let e = t() % 2 == 0 ? "rock" : "wall", n = U(t, 4, 12), r = U(t, 4, 12);
1274
- e === "wall" && (n >= r ? r = 2 * N : n = 2 * N);
1275
- let i = U(t, 4, 10), c = U(t, 100, 220), l = U(t, 40, 280), u = 12 * N + (n > r ? n : r);
1276
- if (o.some((e) => On(e.x, e.z, c, l, u))) continue;
1825
+ let e = t() % 2 == 0 ? "rock" : "wall", n = J(t, 4, 12), r = J(t, 4, 12);
1826
+ e === "wall" && (n >= r ? r = 2 * R : n = 2 * R);
1827
+ let i = J(t, 4, 10), c = J(t, 100, 220), l = J(t, 40, 280), u = 12 * R + (n > r ? n : r);
1828
+ if (o.some((e) => jr(e.x, e.z, c, l, u))) continue;
1277
1829
  let d = {
1278
1830
  x: c,
1279
1831
  z: l,
1280
1832
  w: n,
1281
1833
  d: r
1282
1834
  };
1283
- if (s.some((e) => kn(e, c, l, (n > r ? n : r) + 4e5))) continue;
1835
+ if (s.some((e) => Mr(e, c, l, (n > r ? n : r) + 4e5))) continue;
1284
1836
  let f = [
1285
1837
  [-1, -1],
1286
1838
  [1, -1],
1287
1839
  [-1, 1],
1288
1840
  [1, 1]
1289
- ].map(([e, t]) => H(a, c + e * n / 2, l + t * r / 2)), p = Math.min(H(a, c, l), ...f);
1841
+ ].map(([e, t]) => q(a, c + e * n / 2, l + t * r / 2)), p = Math.min(q(a, c, l), ...f);
1290
1842
  s.push({
1291
1843
  id: s.length,
1292
1844
  kind: e,
@@ -1295,10 +1847,10 @@ function An(e) {
1295
1847
  y: p
1296
1848
  });
1297
1849
  }
1298
- let l = [], u = z(t, 30, 60);
1850
+ let l = [], u = W(t, 30, 60);
1299
1851
  for (let e = 0; e < u * 10 && l.length < u; e += 1) {
1300
- let e = U(t, 4, 316), n = U(t, 4, 316), r = t() % 3 == 0 ? "rock" : "tree", i = z(t, 80, 140);
1301
- o.some((t) => On(t.x, t.z, e, n, 1e6)) || s.some((t) => kn(t, e, n, 2e5)) || l.push({
1852
+ let e = J(t, 4, 316), n = J(t, 4, 316), r = t() % 3 == 0 ? "rock" : "tree", i = W(t, 80, 140);
1853
+ o.some((t) => jr(t.x, t.z, e, n, 1e6)) || s.some((t) => Mr(t, e, n, 2e5)) || l.push({
1302
1854
  id: l.length,
1303
1855
  kind: r,
1304
1856
  x: e,
@@ -1313,10 +1865,10 @@ function An(e) {
1313
1865
  decor: l
1314
1866
  };
1315
1867
  }
1316
- function jn(e, { x: t, z: n, radius: r, depth: i }) {
1317
- let a = r * r, o = (e) => B(Math.trunc(e / P) - 1, 0, 80);
1868
+ function Pr(e, { x: t, z: n, radius: r, depth: i }) {
1869
+ let a = r * r, o = (e) => G(Math.trunc(e / z) - 1, 0, 80);
1318
1870
  for (let s = o(n - r); s <= o(n + r) + 2 && s < 81; s += 1) for (let c = o(t - r); c <= o(t + r) + 2 && c < 81; c += 1) {
1319
- let o = c * P - t, l = s * P - n;
1871
+ let o = c * z - t, l = s * z - n;
1320
1872
  if (o > r || o < -r || l > r || l < -r) continue;
1321
1873
  let u = o * o + l * l;
1322
1874
  if (u >= a) continue;
@@ -1325,29 +1877,29 @@ function jn(e, { x: t, z: n, radius: r, depth: i }) {
1325
1877
  }
1326
1878
  return e;
1327
1879
  }
1328
- function Mn(e, t) {
1329
- return e.filter((e) => !t.some((t) => On(t.x, t.z, e.x, e.z, t.radius)));
1880
+ function Fr(e, t) {
1881
+ return e.filter((e) => !t.some((t) => jr(t.x, t.z, e.x, e.z, t.radius)));
1330
1882
  }
1331
1883
  // src/games/tanks/logic/ballistics.js
1332
- function Nn(e, t) {
1333
- return Math.trunc((2e4 + 600 * e) * L[t].speedPct / 100);
1884
+ function Ir(e, t) {
1885
+ return Math.trunc((2e4 + 600 * e) * H[t].speedPct / 100);
1334
1886
  }
1335
- function Pn(e, { yaw: t, pitch: n, power: r, ammo: i }) {
1336
- let a = bn(n), o = yn(n), s = bn(t), c = yn(t), l = R(un, a), u = Nn(r, i), d = R(u, a);
1887
+ function Lr(e, { yaw: t, pitch: n, power: r, ammo: i }) {
1888
+ let a = Cr(n), o = Sr(n), s = Cr(t), c = Sr(t), l = U(pr, a), u = Ir(r, i), d = U(u, a);
1337
1889
  return {
1338
- x: e.x + R(l, s),
1339
- y: e.y + ln + R(un, o),
1340
- z: e.z + R(l, c),
1341
- vx: R(d, s),
1342
- vy: R(u, o),
1343
- vz: R(d, c)
1890
+ x: e.x + U(l, s),
1891
+ y: e.y + fr + U(pr, o),
1892
+ z: e.z + U(l, c),
1893
+ vx: U(d, s),
1894
+ vy: U(u, o),
1895
+ vz: U(d, c)
1344
1896
  };
1345
1897
  }
1346
- function Fn(e, t, n, r, i, a, o) {
1898
+ function Rr(e, t, n, r, i, a, o) {
1347
1899
  let s = e - r, c = t - i, l = n - a;
1348
1900
  return s > o || s < -o || c > o || c < -o || l > o || l < -o ? !1 : s * s + c * c + l * l < o * o;
1349
1901
  }
1350
- function In(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600, split: o = !1 }) {
1902
+ function zr(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600, split: o = !1 }) {
1351
1903
  let { x: s, y: c, z: l, vx: u, vy: d, vz: f } = e, p = [
1352
1904
  s,
1353
1905
  c,
@@ -1357,7 +1909,7 @@ function In(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1357
1909
  let a = d;
1358
1910
  u += t.x, d -= 392, f += t.z, s += u, c += d, l += f;
1359
1911
  let m = null;
1360
- for (let e of r) if (Fn(s, c, l, e.x, e.y + 1e5, e.z, 2e5)) {
1912
+ for (let e of r) if (Rr(s, c, l, e.x, e.y + 1e5, e.z, 2e5)) {
1361
1913
  m = {
1362
1914
  x: s,
1363
1915
  y: c,
@@ -1368,7 +1920,7 @@ function In(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1368
1920
  break;
1369
1921
  }
1370
1922
  if (!m) {
1371
- let e = i.find((e) => c <= e.y + e.h && kn(e, s, l, 0));
1923
+ let e = i.find((e) => c <= e.y + e.h && Mr(e, s, l, 0));
1372
1924
  e && (m = {
1373
1925
  x: s,
1374
1926
  y: c,
@@ -1383,7 +1935,7 @@ function In(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1383
1935
  z: l,
1384
1936
  kind: "out"
1385
1937
  }), !m) {
1386
- let e = H(n, s, l);
1938
+ let e = q(n, s, l);
1387
1939
  c <= e && (m = {
1388
1940
  x: s,
1389
1941
  y: e,
@@ -1424,7 +1976,7 @@ function In(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1424
1976
  }
1425
1977
  };
1426
1978
  }
1427
- var Ln = (e, t, n, r) => ({
1979
+ var Br = (e, t, n, r) => ({
1428
1980
  role: e,
1429
1981
  startTick: t,
1430
1982
  samples: n.samples,
@@ -1434,17 +1986,17 @@ var Ln = (e, t, n, r) => ({
1434
1986
  maxDmg: n.impact.kind === "split" ? 0 : r.maxDmg,
1435
1987
  depth: n.impact.kind === "split" ? 0 : r.depth
1436
1988
  });
1437
- function Rn(e, t, n) {
1438
- let r = Pn(e, t);
1439
- if (t.ammo !== "cluster") return [Ln("main", 0, In(r, n), L[t.ammo])];
1440
- let i = In(r, {
1989
+ function Vr(e, t, n) {
1990
+ let r = Lr(e, t);
1991
+ if (t.ammo !== "cluster") return [Br("main", 0, zr(r, n), H[t.ammo])];
1992
+ let i = zr(r, {
1441
1993
  ...n,
1442
1994
  split: !0
1443
- }), a = [Ln("carrier", 0, i, mn)];
1995
+ }), a = [Br("carrier", 0, i, _r)];
1444
1996
  if (i.impact.kind !== "split") return a;
1445
1997
  let o = (n.maxTicks ?? 600) - i.ticks;
1446
- for (let [e, t, r] of hn) {
1447
- let { x: s, y: c, z: l } = i.impact, { vx: u, vy: d, vz: f } = i.velocity, p = In({
1998
+ for (let [e, t, r] of vr) {
1999
+ let { x: s, y: c, z: l } = i.impact, { vx: u, vy: d, vz: f } = i.velocity, p = zr({
1448
2000
  x: s,
1449
2001
  y: c,
1450
2002
  z: l,
@@ -1456,18 +2008,18 @@ function Rn(e, t, n) {
1456
2008
  maxTicks: o,
1457
2009
  split: !1
1458
2010
  });
1459
- a.push(Ln("bomblet", i.ticks, p, mn));
2011
+ a.push(Br("bomblet", i.ticks, p, _r));
1460
2012
  }
1461
2013
  return a;
1462
2014
  }
1463
- function zn(e, t) {
2015
+ function Hr(e, t) {
1464
2016
  let n = t.map(() => 0);
1465
2017
  for (let r of e) {
1466
2018
  let { impact: e, radius: i, maxDmg: a } = r;
1467
2019
  if (e.kind === "out" || e.kind === "split") continue;
1468
2020
  let o = i * i;
1469
2021
  t.forEach((t, r) => {
1470
- let s = t.y + cn;
2022
+ let s = t.y + dr;
1471
2023
  e.kind === "tank" && e.tankId === t.id && (n[r] += 25);
1472
2024
  let c = e.x - t.x, l = e.y - s, u = e.z - t.z;
1473
2025
  if (c >= i || c <= -i || l >= i || l <= -i || u >= i || u <= -i) return;
@@ -1477,7 +2029,7 @@ function zn(e, t) {
1477
2029
  }
1478
2030
  return n;
1479
2031
  }
1480
- function Bn(e) {
2032
+ function Ur(e) {
1481
2033
  return e.filter((e) => e.impact.kind !== "out" && e.impact.kind !== "split").map((e) => ({
1482
2034
  x: e.impact.x,
1483
2035
  z: e.impact.z,
@@ -1486,8 +2038,8 @@ function Bn(e) {
1486
2038
  }));
1487
2039
  }
1488
2040
  // src/games/tanks/logic/movement.js
1489
- function Vn(e, t, { heights: n, obstacles: r, others: i }) {
1490
- let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (dn / F), s = Math.min(o, Math.trunc(e.fuel / F)), c = a * R(F, bn(e.hullYaw)), l = a * R(F, yn(e.hullYaw)), { x: u, z: d } = e, f = H(n, u, d), p = [{
2041
+ function Wr(e, t, { heights: n, obstacles: r, others: i }) {
2042
+ let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (mr / B), s = Math.min(o, Math.trunc(e.fuel / B)), c = a * U(B, Cr(e.hullYaw)), l = a * U(B, Sr(e.hullYaw)), { x: u, z: d } = e, f = q(n, u, d), p = [{
1491
2043
  x: u,
1492
2044
  y: f,
1493
2045
  z: d
@@ -1498,7 +2050,7 @@ function Vn(e, t, { heights: n, obstacles: r, others: i }) {
1498
2050
  h = "border";
1499
2051
  break;
1500
2052
  }
1501
- if (r.some((n) => kn(n, e, t, 2e5))) {
2053
+ if (r.some((n) => Mr(n, e, t, 2e5))) {
1502
2054
  h = "obstacle";
1503
2055
  break;
1504
2056
  }
@@ -1509,7 +2061,7 @@ function Vn(e, t, { heights: n, obstacles: r, others: i }) {
1509
2061
  h = "tank";
1510
2062
  break;
1511
2063
  }
1512
- let a = H(n, e, t);
2064
+ let a = q(n, e, t);
1513
2065
  if ((a > f ? a - f : f - a) * 1e3 > 175e5) {
1514
2066
  h = "slope";
1515
2067
  break;
@@ -1529,29 +2081,29 @@ function Vn(e, t, { heights: n, obstacles: r, others: i }) {
1529
2081
  x: u,
1530
2082
  y: f,
1531
2083
  z: d,
1532
- used: m * F,
2084
+ used: m * B,
1533
2085
  stop: h
1534
2086
  };
1535
2087
  }
1536
2088
  // src/games/tanks/logic/game.js
1537
- var Hn = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, W = (e) => ({
2089
+ var Gr = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, Y = (e) => ({
1538
2090
  ok: !1,
1539
2091
  reason: e
1540
- }), Un = (e, [t, n]) => Number.isInteger(e) && e >= t && e <= n;
1541
- function Wn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {}) {
1542
- if (!Hn(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Hn) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
1543
- if (!xn(r)) throw TypeError("Supply an integer seed in 0..0xffffffff.");
1544
- let { heights: i, spawns: a, obstacles: o, decor: s } = An(r), c = t.map((e, t) => ({
2092
+ }), Kr = (e, [t, n]) => Number.isInteger(e) && e >= t && e <= n;
2093
+ function qr({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {}) {
2094
+ if (!Gr(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Gr) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
2095
+ if (!wr(r)) throw TypeError("Supply an integer seed in 0..0xffffffff.");
2096
+ let { heights: i, spawns: a, obstacles: o, decor: s } = Nr(r), c = t.map((e, t) => ({
1545
2097
  id: e,
1546
2098
  x: a[t].x,
1547
- y: H(i, a[t].x, a[t].z),
2099
+ y: q(i, a[t].x, a[t].z),
1548
2100
  z: a[t].z,
1549
2101
  hullYaw: t === 0 ? 0 : 180,
1550
2102
  yaw: t === 0 ? 0 : 180,
1551
2103
  pitch: 30,
1552
2104
  hp: 100,
1553
- fuel: fn,
1554
- ammo: { ...gn },
2105
+ fuel: hr,
2106
+ ammo: { ...yr },
1555
2107
  skips: 0
1556
2108
  }));
1557
2109
  return {
@@ -1577,24 +2129,24 @@ function Wn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {})
1577
2129
  revision: 0
1578
2130
  };
1579
2131
  }
1580
- function Gn(e, t) {
1581
- return !e || !t || typeof t != "object" ? W("invalid_action") : e.phase === "finished" ? W("game_finished") : t.gameId !== void 0 && t.gameId !== e.gameId ? W("wrong_game") : t.expectedRevision !== void 0 && t.expectedRevision !== e.revision ? W("stale_revision") : e.players.includes(t.playerId) ? { ok: !0 } : W("unknown_player");
2132
+ function Jr(e, t) {
2133
+ return !e || !t || typeof t != "object" ? Y("invalid_action") : e.phase === "finished" ? Y("game_finished") : t.gameId !== void 0 && t.gameId !== e.gameId ? Y("wrong_game") : t.expectedRevision !== void 0 && t.expectedRevision !== e.revision ? Y("stale_revision") : e.players.includes(t.playerId) ? { ok: !0 } : Y("unknown_player");
1582
2134
  }
1583
- function Kn(e, t) {
1584
- let n = Gn(e, t);
2135
+ function Yr(e, t) {
2136
+ let n = Jr(e, t);
1585
2137
  if (!n.ok) return n;
1586
2138
  let r = e.players.indexOf(t.playerId);
1587
- if (r !== e.turnIndex) return W("not_your_turn");
1588
- if (!Un(t.move, I.move)) return W("invalid_move");
1589
- if (!Un(t.yaw, I.yaw)) return W("invalid_yaw");
1590
- if (!Un(t.pitch, I.pitch)) return W("invalid_pitch");
1591
- if (!Un(t.power, I.power)) return W("invalid_power");
1592
- if (typeof t.ammo != "string" || !Object.hasOwn(L, t.ammo)) return W("unknown_ammo");
1593
- let i = L[t.ammo].cost;
1594
- return i > 0 && e.tanks[r].ammo[t.ammo] < i ? W("out_of_ammo") : { ok: !0 };
1595
- }
1596
- function qn(e, t, { maxTicks: n = 600 } = {}) {
1597
- let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o = Cn(e.seed, e.ply), s = Vn(i, t.move ?? 0, {
2139
+ if (r !== e.turnIndex) return Y("not_your_turn");
2140
+ if (!Kr(t.move, V.move)) return Y("invalid_move");
2141
+ if (!Kr(t.yaw, V.yaw)) return Y("invalid_yaw");
2142
+ if (!Kr(t.pitch, V.pitch)) return Y("invalid_pitch");
2143
+ if (!Kr(t.power, V.power)) return Y("invalid_power");
2144
+ if (typeof t.ammo != "string" || !Object.hasOwn(H, t.ammo)) return Y("unknown_ammo");
2145
+ let i = H[t.ammo].cost;
2146
+ return i > 0 && e.tanks[r].ammo[t.ammo] < i ? Y("out_of_ammo") : { ok: !0 };
2147
+ }
2148
+ function Xr(e, t, { maxTicks: n = 600 } = {}) {
2149
+ let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o = Er(e.seed, e.ply), s = Wr(i, t.move ?? 0, {
1598
2150
  heights: e.heights,
1599
2151
  obstacles: e.obstacles,
1600
2152
  others: [a]
@@ -1610,13 +2162,13 @@ function qn(e, t, { maxTicks: n = 600 } = {}) {
1610
2162
  x: e.x,
1611
2163
  y: e.y,
1612
2164
  z: e.z
1613
- }), u = Rn(c, t, {
2165
+ }), u = Vr(c, t, {
1614
2166
  wind: o,
1615
2167
  heights: e.heights,
1616
2168
  tanks: l,
1617
2169
  obstacles: e.obstacles,
1618
2170
  maxTicks: n
1619
- }), d = zn(u, l), f = {};
2171
+ }), d = Hr(u, l), f = {};
1620
2172
  return e.players.forEach((e, t) => {
1621
2173
  f[e] = d[t];
1622
2174
  }), {
@@ -1627,11 +2179,11 @@ function qn(e, t, { maxTicks: n = 600 } = {}) {
1627
2179
  tankAfter: c,
1628
2180
  shots: u,
1629
2181
  damage: f,
1630
- craters: Bn(u),
2182
+ craters: Ur(u),
1631
2183
  wind: o
1632
2184
  };
1633
2185
  }
1634
- function G(e, t, n, r) {
2186
+ function Zr(e, t, n, r) {
1635
2187
  return {
1636
2188
  ...e,
1637
2189
  ...r,
@@ -1642,7 +2194,7 @@ function G(e, t, n, r) {
1642
2194
  revision: e.revision + 1
1643
2195
  };
1644
2196
  }
1645
- function Jn(e, t) {
2197
+ function Qr(e, t) {
1646
2198
  let n = e.turnIndex, r = {
1647
2199
  playerId: t.playerId,
1648
2200
  move: t.move,
@@ -1650,23 +2202,23 @@ function Jn(e, t) {
1650
2202
  pitch: t.pitch,
1651
2203
  power: t.power,
1652
2204
  ammo: t.ammo
1653
- }, i = qn(e, r), a = e.heights;
2205
+ }, i = Xr(e, r), a = e.heights;
1654
2206
  if (i.craters.length) {
1655
2207
  a = Int32Array.from(e.heights);
1656
- for (let e of i.craters) jn(a, e);
2208
+ for (let e of i.craters) Pr(a, e);
1657
2209
  }
1658
- let o = i.craters.length ? Mn(e.decor, i.craters) : e.decor, s = e.tanks.map((e, t) => {
2210
+ let o = i.craters.length ? Fr(e.decor, i.craters) : e.decor, s = e.tanks.map((e, t) => {
1659
2211
  let o = t === n ? i.tankAfter : e, s = {
1660
2212
  ...e,
1661
2213
  ammo: { ...e.ammo },
1662
2214
  x: o.x,
1663
2215
  z: o.z,
1664
- y: H(a, o.x, o.z),
2216
+ y: q(a, o.x, o.z),
1665
2217
  hp: Math.max(0, e.hp - i.damage[e.id])
1666
2218
  };
1667
2219
  if (t === n) {
1668
2220
  s.fuel = e.fuel - i.fuelUsed, s.yaw = r.yaw, s.pitch = r.pitch, s.skips = 0;
1669
- let t = L[r.ammo].cost;
2221
+ let t = H[r.ammo].cost;
1670
2222
  t > 0 && (s.ammo[r.ammo] -= t);
1671
2223
  }
1672
2224
  return s;
@@ -1685,23 +2237,23 @@ function Jn(e, t) {
1685
2237
  ...i
1686
2238
  }
1687
2239
  }, l = s.map((e) => e.hp === 0);
1688
- if (l[0] && l[1]) return G(c, -1, "destroyed");
1689
- if (l[0] || l[1]) return G(c, +!!l[0], "destroyed");
2240
+ if (l[0] && l[1]) return Zr(c, -1, "destroyed");
2241
+ if (l[0] || l[1]) return Zr(c, +!!l[0], "destroyed");
1690
2242
  if (c.shots >= c.maxShots) {
1691
2243
  let [e, t] = s.map((e) => e.hp);
1692
- return G(c, e === t ? -1 : e > t ? 0 : 1, "max_shots");
2244
+ return Zr(c, e === t ? -1 : e > t ? 0 : 1, "max_shots");
1693
2245
  }
1694
2246
  return {
1695
2247
  ...c,
1696
2248
  revision: e.revision + 1
1697
2249
  };
1698
2250
  }
1699
- function Yn(e, t) {
2251
+ function $r(e, t) {
1700
2252
  if (!t || typeof t != "object") return e;
1701
- if (t.type === "turn") return Kn(e, t).ok ? Jn(e, t) : e;
1702
- if (!Gn(e, t).ok) return e;
2253
+ if (t.type === "turn") return Yr(e, t).ok ? Qr(e, t) : e;
2254
+ if (!Jr(e, t).ok) return e;
1703
2255
  let n = e.players.indexOf(t.playerId);
1704
- if (t.type === "resign") return G(e, 1 - n, "resign");
2256
+ if (t.type === "resign") return Zr(e, 1 - n, "resign");
1705
2257
  if (t.type === "skip") {
1706
2258
  if (n !== e.turnIndex || t.reason !== void 0 && t.reason !== "timeout") return e;
1707
2259
  let r = e.tanks[n].skips + 1, i = e.tanks.map((e, t) => t === n ? {
@@ -1718,22 +2270,22 @@ function Yn(e, t) {
1718
2270
  playerId: t.playerId
1719
2271
  }
1720
2272
  };
1721
- return r >= 3 ? G(a, 1 - n, "timeout") : {
2273
+ return r >= 3 ? Zr(a, 1 - n, "timeout") : {
1722
2274
  ...a,
1723
2275
  revision: e.revision + 1
1724
2276
  };
1725
2277
  }
1726
2278
  return e;
1727
2279
  }
1728
- function Xn(e, t) {
2280
+ function ei(e, t) {
1729
2281
  let n = (e.lo ^ t) >>> 0, r = n * 435, i = r >>> 0, a = (r - i) / 4294967296;
1730
2282
  e.hi = Math.imul(e.hi, 435) + a + (n << 8) >>> 0, e.lo = i;
1731
2283
  }
1732
- function Zn(e, t) {
2284
+ function ti(e, t) {
1733
2285
  let n = t | 0;
1734
- Xn(e, n & 255), Xn(e, n >>> 8 & 255), Xn(e, n >>> 16 & 255), Xn(e, n >>> 24 & 255);
2286
+ ei(e, n & 255), ei(e, n >>> 8 & 255), ei(e, n >>> 16 & 255), ei(e, n >>> 24 & 255);
1735
2287
  }
1736
- function Qn(e) {
2288
+ function ni(e) {
1737
2289
  let t = {
1738
2290
  hi: 3421674724,
1739
2291
  lo: 2216829733
@@ -1750,11 +2302,11 @@ function Qn(e) {
1750
2302
  ];
1751
2303
  for (let t of e.tanks) i.push(t.x, t.y, t.z, t.hp, t.fuel, t.ammo.heavy, t.ammo.cluster, t.skips, t.yaw, t.pitch);
1752
2304
  i.push(n, e.decor.length);
1753
- for (let e of i) Zn(t, e);
2305
+ for (let e of i) ti(t, e);
1754
2306
  return t.hi.toString(16).padStart(8, "0") + t.lo.toString(16).padStart(8, "0");
1755
2307
  }
1756
2308
  // src/games/tanks/net/sha256.js
1757
- var $n = new Uint32Array([
2309
+ var ri = new Uint32Array([
1758
2310
  1116352408,
1759
2311
  1899447441,
1760
2312
  3049323471,
@@ -1819,8 +2371,8 @@ var $n = new Uint32Array([
1819
2371
  2756734187,
1820
2372
  3204031479,
1821
2373
  3329325298
1822
- ]), K = (e, t) => e >>> t | e << 32 - t;
1823
- function er(e) {
2374
+ ]), X = (e, t) => e >>> t | e << 32 - t;
2375
+ function ii(e) {
1824
2376
  let t = new TextEncoder().encode(String(e)), n = t.length, r = new Uint8Array((n + 9 >> 6) + 1 << 6);
1825
2377
  r.set(t), r[n] = 128;
1826
2378
  let i = new DataView(r.buffer);
@@ -1838,12 +2390,12 @@ function er(e) {
1838
2390
  for (let e = 0; e < r.length; e += 64) {
1839
2391
  for (let t = 0; t < 16; t += 1) o[t] = i.getUint32(e + t * 4);
1840
2392
  for (let e = 16; e < 64; e += 1) {
1841
- let t = K(o[e - 15], 7) ^ K(o[e - 15], 18) ^ o[e - 15] >>> 3, n = K(o[e - 2], 17) ^ K(o[e - 2], 19) ^ o[e - 2] >>> 10;
2393
+ let t = X(o[e - 15], 7) ^ X(o[e - 15], 18) ^ o[e - 15] >>> 3, n = X(o[e - 2], 17) ^ X(o[e - 2], 19) ^ o[e - 2] >>> 10;
1842
2394
  o[e] = o[e - 16] + t + o[e - 7] + n >>> 0;
1843
2395
  }
1844
2396
  let [t, n, r, s, c, l, u, d] = a;
1845
2397
  for (let e = 0; e < 64; e += 1) {
1846
- let i = d + (K(c, 6) ^ K(c, 11) ^ K(c, 25)) + (c & l ^ ~c & u) + $n[e] + o[e] >>> 0, a = (K(t, 2) ^ K(t, 13) ^ K(t, 22)) + (t & n ^ t & r ^ n & r) >>> 0;
2398
+ let i = d + (X(c, 6) ^ X(c, 11) ^ X(c, 25)) + (c & l ^ ~c & u) + ri[e] + o[e] >>> 0, a = (X(t, 2) ^ X(t, 13) ^ X(t, 22)) + (t & n ^ t & r ^ n & r) >>> 0;
1847
2399
  d = u, u = l, l = c, c = s + i >>> 0, s = r, r = n, n = t, t = i + a >>> 0;
1848
2400
  }
1849
2401
  a[0] += t, a[1] += n, a[2] += r, a[3] += s, a[4] += c, a[5] += l, a[6] += u, a[7] += d;
@@ -1851,22 +2403,22 @@ function er(e) {
1851
2403
  return Array.from(a, (e) => e.toString(16).padStart(8, "0")).join("");
1852
2404
  }
1853
2405
  // src/games/tanks/net/session.js
1854
- var tr = "La partida perdió sincronización. Se intentará resincronizar.", nr = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", rr = "El rival reveló una semilla que no coincide con su invitación.", ir = "Los resultados del disparo no coinciden entre dispositivos.", ar = [
2406
+ var ai = "La partida perdió sincronización. Se intentará resincronizar.", oi = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", si = "El rival reveló una semilla que no coincide con su invitación.", ci = "Los resultados del disparo no coinciden entre dispositivos.", li = [
1855
2407
  "won",
1856
2408
  "draw",
1857
2409
  "closed",
1858
2410
  "declined"
1859
- ], q = (e, t) => ({
2411
+ ], ui = (e, t) => ({
1860
2412
  ...e,
1861
2413
  status: "conflict",
1862
2414
  error: t
1863
- }), or = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
1864
- function sr() {
2415
+ }), di = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
2416
+ function fi() {
1865
2417
  let e = /* @__PURE__ */ new Uint8Array(16);
1866
- return globalThis.crypto.getRandomValues(e), or(e);
2418
+ return globalThis.crypto.getRandomValues(e), di(e);
1867
2419
  }
1868
- var cr = (e) => er(`lira-tanks-seed:${e}`), lr = (e, t) => parseInt(er(`lira-tanks-map:${e}:${t}`).slice(0, 8), 16) >>> 0;
1869
- function ur(e, t) {
2420
+ var pi = (e) => ii(`lira-tanks-seed:${e}`), mi = (e, t) => parseInt(ii(`lira-tanks-map:${e}:${t}`).slice(0, 8), 16) >>> 0;
2421
+ function hi(e, t) {
1870
2422
  let n = t.first_player_id === e.guestId ? e.guestId : e.hostId;
1871
2423
  return {
1872
2424
  ...e,
@@ -1893,21 +2445,21 @@ function ur(e, t) {
1893
2445
  sync: e.sync ?? null
1894
2446
  };
1895
2447
  }
1896
- var J = (e) => [e.hostId, e.guestId], dr = (e) => e.logic && e.logic.phase === "playing" ? J(e)[e.logic.turnIndex] : null, fr = (e) => e?.status === "active" && !e.pendingEvent && dr(e) === e.ownId, pr = (e, t, n) => e === "tk_turn" ? [
2448
+ var Z = (e) => [e.hostId, e.guestId], gi = (e) => e.logic && e.logic.phase === "playing" ? Z(e)[e.logic.turnIndex] : null, _i = (e) => e?.status === "active" && !e.pendingEvent && gi(e) === e.ownId, vi = (e, t, n) => e === "tk_turn" ? [
1897
2449
  1,
1898
2450
  t.move,
1899
2451
  t.yaw,
1900
2452
  t.pitch,
1901
2453
  t.power,
1902
2454
  t.ammo
1903
- ] : e === "tk_skip" ? [2] : [3, n], mr = (e, t) => e.length === t.length && e.every((e, n) => e === t[n]);
1904
- function hr(e, t) {
1905
- let n = J(e);
2455
+ ] : e === "tk_skip" ? [2] : [3, n], yi = (e, t) => e.length === t.length && e.every((e, n) => e === t[n]);
2456
+ function bi(e, t) {
2457
+ let n = Z(e);
1906
2458
  if (t[0] === 3) return {
1907
2459
  type: "resign",
1908
2460
  playerId: n[t[1]]
1909
2461
  };
1910
- let r = dr(e);
2462
+ let r = gi(e);
1911
2463
  return t[0] === 2 ? {
1912
2464
  type: "skip",
1913
2465
  playerId: r,
@@ -1919,11 +2471,11 @@ function hr(e, t) {
1919
2471
  yaw: t[2],
1920
2472
  pitch: t[3],
1921
2473
  power: t[4],
1922
- ammo: he[t[5]]
2474
+ ammo: gt[t[5]]
1923
2475
  };
1924
2476
  }
1925
- function gr(e, t, n, r) {
1926
- let i = Yn(e.logic, hr(e, t));
2477
+ function xi(e, t, n, r) {
2478
+ let i = $r(e.logic, bi(e, t));
1927
2479
  if (i === e.logic) return null;
1928
2480
  let a = i.phase === "finished";
1929
2481
  return {
@@ -1938,19 +2490,19 @@ function gr(e, t, n, r) {
1938
2490
  author: r,
1939
2491
  turn: i.lastTurn ?? null
1940
2492
  },
1941
- turnId: a ? null : J(e)[i.turnIndex],
2493
+ turnId: a ? null : Z(e)[i.turnIndex],
1942
2494
  status: a ? i.result === "draw" ? "draw" : "won" : "active",
1943
2495
  winnerId: i.winnerId ?? null,
1944
2496
  result: i.result ?? null
1945
2497
  };
1946
2498
  }
1947
- function _r(e, t, n) {
1948
- if (cr(t) !== e.seedCommit) return null;
1949
- let r = Wn({
2499
+ function Si(e, t, n) {
2500
+ if (pi(t) !== e.seedCommit) return null;
2501
+ let r = qr({
1950
2502
  gameId: e.gameId,
1951
- players: J(e),
2503
+ players: Z(e),
1952
2504
  firstPlayerId: e.firstPlayerId,
1953
- seed: lr(t, e.seedB)
2505
+ seed: mi(t, e.seedB)
1954
2506
  });
1955
2507
  return {
1956
2508
  ...e,
@@ -1962,11 +2514,11 @@ function _r(e, t, n) {
1962
2514
  lastEventId: n,
1963
2515
  lastAction: null,
1964
2516
  status: "active",
1965
- turnId: J(e)[r.turnIndex],
2517
+ turnId: Z(e)[r.turnIndex],
1966
2518
  error: ""
1967
2519
  };
1968
2520
  }
1969
- function vr(e, t, n) {
2521
+ function Ci(e, t, n) {
1970
2522
  if (![e.hostId, e.guestId].includes(n)) return e;
1971
2523
  let r = t.data;
1972
2524
  if (t.type === "game_end") return ["closed", "declined"].includes(e.status) ? e : {
@@ -1975,7 +2527,7 @@ function vr(e, t, n) {
1975
2527
  closedBy: n,
1976
2528
  error: ""
1977
2529
  };
1978
- if (ar.includes(e.status) || e.status === "conflict") return e;
2530
+ if (li.includes(e.status) || e.status === "conflict") return e;
1979
2531
  if (t.type === "game_accept" || t.type === "game_decline") return n !== e.guestId || e.status !== "invited" || r.invite_event_id !== e.inviteEventId ? e : t.type === "game_decline" ? {
1980
2532
  ...e,
1981
2533
  status: "declined",
@@ -1987,22 +2539,22 @@ function vr(e, t, n) {
1987
2539
  acceptEventId: t.event_id,
1988
2540
  lastEventId: t.event_id
1989
2541
  };
1990
- if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e : _r(e, r.seed_a, t.event_id) ?? q(e, rr);
2542
+ if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e : Si(e, r.seed_a, t.event_id) ?? ui(e, si);
1991
2543
  if (![
1992
2544
  "tk_turn",
1993
2545
  "tk_skip",
1994
2546
  "tk_resign"
1995
2547
  ].includes(t.type)) return e;
1996
- if (e.status !== "active") return q(e, nr);
1997
- let i = J(e).indexOf(n), a = pr(t.type, r, i);
1998
- if (r.ply <= e.ply) return mr(e.log[r.ply - 1] ?? [], a) ? e : q(e, tr);
1999
- if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return q(e, tr);
2000
- if (t.type !== "tk_resign" && n !== dr(e)) return e;
2001
- let o = gr(e, a, t.event_id, n);
2002
- return o ? t.type === "tk_turn" && Qn(o.logic) !== r.hash ? q(e, ir) : o : e;
2003
- }
2004
- function yr(e, t) {
2005
- if (!fr(e)) return null;
2548
+ if (e.status !== "active") return ui(e, oi);
2549
+ let i = Z(e).indexOf(n), a = vi(t.type, r, i);
2550
+ if (r.ply <= e.ply) return yi(e.log[r.ply - 1] ?? [], a) ? e : ui(e, ai);
2551
+ if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return ui(e, ai);
2552
+ if (t.type !== "tk_resign" && n !== gi(e)) return e;
2553
+ let o = xi(e, a, t.event_id, n);
2554
+ return o ? t.type === "tk_turn" && ni(o.logic) !== r.hash ? ui(e, ci) : o : e;
2555
+ }
2556
+ function wi(e, t) {
2557
+ if (!_i(e)) return null;
2006
2558
  let n = {
2007
2559
  ply: e.ply + 1,
2008
2560
  prev_event_id: e.lastEventId,
@@ -2010,16 +2562,16 @@ function yr(e, t) {
2010
2562
  yaw: t.yaw,
2011
2563
  pitch: t.pitch,
2012
2564
  power: t.power,
2013
- ammo: he.indexOf(t.ammo)
2565
+ ammo: gt.indexOf(t.ammo)
2014
2566
  };
2015
2567
  if (n.ammo < 0) return null;
2016
- let r = gr(e, pr("tk_turn", n), "local", e.ownId);
2568
+ let r = xi(e, vi("tk_turn", n), "local", e.ownId);
2017
2569
  return r ? {
2018
2570
  ...n,
2019
- hash: Qn(r.logic)
2571
+ hash: ni(r.logic)
2020
2572
  } : null;
2021
2573
  }
2022
- function br(e) {
2574
+ function Ti(e) {
2023
2575
  let t = {
2024
2576
  log: e.log ?? [],
2025
2577
  head: e.lastEventId
@@ -2032,14 +2584,14 @@ function br(e) {
2032
2584
  seed_event_id: e.seedEventId
2033
2585
  }), t;
2034
2586
  }
2035
- function xr(e, t) {
2587
+ function Ei(e, t) {
2036
2588
  if (e.accept_event_id && t.accept_event_id && e.accept_event_id !== t.accept_event_id || e.seed_a && t.seed_a && e.seed_a !== t.seed_a) return "diverged";
2037
2589
  let n = Math.min(e.log.length, t.log.length);
2038
- for (let r = 0; r < n; r += 1) if (!mr(e.log[r], t.log[r])) return "diverged";
2590
+ for (let r = 0; r < n; r += 1) if (!yi(e.log[r], t.log[r])) return "diverged";
2039
2591
  let r = (e) => (e.seed_a ? 2 : +!!e.accept_event_id) * 1e3 + e.log.length;
2040
2592
  return r(e) === r(t) ? e.log.length === t.log.length && e.head !== t.head && e.log.length > 0 ? "diverged" : "equal" : r(e) < r(t) ? "behind" : "ahead";
2041
2593
  }
2042
- function Sr(e, t) {
2594
+ function Di(e, t) {
2043
2595
  let n = {
2044
2596
  ...e,
2045
2597
  status: "invited",
@@ -2069,16 +2621,16 @@ function Sr(e, t) {
2069
2621
  seedB: t.seed_b,
2070
2622
  lastEventId: t.accept_event_id
2071
2623
  }, !t.seed_a) return n;
2072
- if (n = _r(n, t.seed_a, t.seed_event_id), !n) return null;
2624
+ if (n = Si(n, t.seed_a, t.seed_event_id), !n) return null;
2073
2625
  for (let e = 0; e < t.log.length; e += 1) {
2074
2626
  let r = t.log[e];
2075
- if (!ve(r)) return null;
2076
- let i = e === t.log.length - 1, a = r[0] === 3 ? J(n)[r[1]] : dr(n);
2077
- if (n = gr(n, r, i ? t.head : `${t.seed_event_id}:${e + 1}`, a), !n) return null;
2627
+ if (!yt(r)) return null;
2628
+ let i = e === t.log.length - 1, a = r[0] === 3 ? Z(n)[r[1]] : gi(n);
2629
+ if (n = xi(n, r, i ? t.head : `${t.seed_event_id}:${e + 1}`, a), !n) return null;
2078
2630
  }
2079
2631
  return n;
2080
2632
  }
2081
- function Cr(e, t) {
2633
+ function Oi(e, t) {
2082
2634
  if (!t) return !1;
2083
2635
  if (t.type === "tk_seed") return e.seed_a === t.data.seed_a;
2084
2636
  if (t.type === "game_accept") return e.accept_event_id === t.event_id;
@@ -2088,9 +2640,9 @@ function Cr(e, t) {
2088
2640
  "tk_resign"
2089
2641
  ].includes(t.type)) return !1;
2090
2642
  let n = e.log[t.data.ply - 1];
2091
- return !!n && n[0] === pr(t.type, t.data, 0)[0];
2643
+ return !!n && n[0] === vi(t.type, t.data, 0)[0];
2092
2644
  }
2093
- function wr(e, t) {
2645
+ function ki(e, t) {
2094
2646
  let n = { ...e };
2095
2647
  return [
2096
2648
  t.acceptEventId,
@@ -2100,7 +2652,7 @@ function wr(e, t) {
2100
2652
  e && (n[e] = !0);
2101
2653
  }), n;
2102
2654
  }
2103
- function Tr(e) {
2655
+ function Ai(e) {
2104
2656
  return {
2105
2657
  gameId: e.gameId,
2106
2658
  roomId: e.roomId,
@@ -2113,22 +2665,22 @@ function Tr(e) {
2113
2665
  inviteEventId: e.inviteEventId,
2114
2666
  createdAt: e.createdAt,
2115
2667
  status: e.status,
2116
- ...br(e)
2668
+ ...Ti(e)
2117
2669
  };
2118
2670
  }
2119
2671
  // src/games/tanks/net/tankStorage.js
2120
- var Er = "lira:tk:", Dr = 6048e5, Or = 20, kr = (e, t) => `${Er}${e}:${t}`, Ar = () => {
2672
+ var ji = "lira:tk:", Mi = 6048e5, Ni = 20, Pi = (e, t) => `${ji}${e}:${t}`, Fi = () => {
2121
2673
  try {
2122
2674
  return globalThis.localStorage ?? null;
2123
2675
  } catch {
2124
2676
  return null;
2125
2677
  }
2126
2678
  };
2127
- function jr(e) {
2679
+ function Ii(e) {
2128
2680
  let t = [];
2129
2681
  for (let n = 0; n < e.length; n += 1) {
2130
2682
  let r = e.key(n);
2131
- if (r?.startsWith(Er)) try {
2683
+ if (r?.startsWith(ji)) try {
2132
2684
  let n = JSON.parse(e.getItem(r));
2133
2685
  t.push({
2134
2686
  key: r,
@@ -2143,61 +2695,61 @@ function jr(e) {
2143
2695
  }
2144
2696
  return t;
2145
2697
  }
2146
- function Mr(e) {
2147
- let t = Date.now(), n = jr(e);
2148
- n.filter(({ value: e }) => !e || !(t - e.savedAt < Dr)).forEach(({ key: t }) => e.removeItem(t));
2149
- let r = n.filter(({ value: e }) => e && t - e.savedAt < Dr).sort((e, t) => e.value.savedAt - t.value.savedAt);
2150
- r.slice(0, Math.max(0, r.length - Or)).forEach(({ key: t }) => e.removeItem(t));
2698
+ function Li(e) {
2699
+ let t = Date.now(), n = Ii(e);
2700
+ n.filter(({ value: e }) => !e || !(t - e.savedAt < Mi)).forEach(({ key: t }) => e.removeItem(t));
2701
+ let r = n.filter(({ value: e }) => e && t - e.savedAt < Mi).sort((e, t) => e.value.savedAt - t.value.savedAt);
2702
+ r.slice(0, Math.max(0, r.length - Ni)).forEach(({ key: t }) => e.removeItem(t));
2151
2703
  }
2152
- function Nr(e, t, n) {
2704
+ function Ri(e, t, n) {
2153
2705
  try {
2154
- let r = Ar();
2706
+ let r = Fi();
2155
2707
  if (!r) return !1;
2156
- let i = Pr(e, t) ?? {};
2157
- return r.setItem(kr(e, t), JSON.stringify({
2708
+ let i = zi(e, t) ?? {};
2709
+ return r.setItem(Pi(e, t), JSON.stringify({
2158
2710
  ...i,
2159
2711
  ...n,
2160
2712
  savedAt: Date.now()
2161
- })), Mr(r), !0;
2713
+ })), Li(r), !0;
2162
2714
  } catch {
2163
2715
  return !1;
2164
2716
  }
2165
2717
  }
2166
- function Pr(e, t) {
2718
+ function zi(e, t) {
2167
2719
  try {
2168
- let n = JSON.parse(Ar()?.getItem(kr(e, t)) ?? "null");
2169
- return !n || typeof n != "object" || !(Date.now() - n.savedAt < Dr) || n.seedA !== void 0 && !/^[0-9a-f]{32}$/.test(n.seedA) ? null : n;
2720
+ let n = JSON.parse(Fi()?.getItem(Pi(e, t)) ?? "null");
2721
+ return !n || typeof n != "object" || !(Date.now() - n.savedAt < Mi) || n.seedA !== void 0 && !/^[0-9a-f]{32}$/.test(n.seedA) ? null : n;
2170
2722
  } catch {
2171
2723
  return null;
2172
2724
  }
2173
2725
  }
2174
- function Fr(e) {
2726
+ function Bi(e) {
2175
2727
  try {
2176
- let t = Ar();
2177
- return t ? jr(t).filter(({ key: t, value: n }) => t.startsWith(`${Er}${e}:`) && n?.snapshot && Date.now() - n.savedAt < Dr).map(({ value: e }) => e).sort((e, t) => t.savedAt - e.savedAt) : [];
2728
+ let t = Fi();
2729
+ return t ? Ii(t).filter(({ key: t, value: n }) => t.startsWith(`${ji}${e}:`) && n?.snapshot && Date.now() - n.savedAt < Mi).map(({ value: e }) => e).sort((e, t) => t.savedAt - e.savedAt) : [];
2178
2730
  } catch {
2179
2731
  return [];
2180
2732
  }
2181
2733
  }
2182
2734
  // src/games/shared/useChatGames.js
2183
- var Ir = Le, Y = (e) => e?.game ?? "connect4", Lr = (e) => Y(e) === "battleship", X = (e) => Y(e) === "tanks", Rr = (e) => ["tanks_live", "racing_live"].includes(Y(e)), zr = 250, Z = (e) => [
2735
+ var Vi = zt, Q = (e) => e?.game ?? "connect4", Hi = (e) => Q(e) === "battleship", Ui = (e) => Q(e) === "tanks", Wi = (e) => ["tanks_live", "racing_live"].includes(Q(e)), Gi = 250, $ = (e) => [
2184
2736
  "won",
2185
2737
  "draw",
2186
2738
  "closed",
2187
2739
  "declined"
2188
- ].includes(e.status), Br = (e, t, n) => JSON.stringify([
2740
+ ].includes(e.status), Ki = (e, t, n) => JSON.stringify([
2189
2741
  e,
2190
2742
  String(t),
2191
2743
  n
2192
- ]), Vr = (e) => {
2193
- let t = Object.keys(e).filter((t) => Z(e[t]));
2744
+ ]), qi = (e) => {
2745
+ let t = Object.keys(e).filter((t) => $(e[t]));
2194
2746
  if (t.length <= 80) return e;
2195
2747
  let n = { ...e };
2196
2748
  return t.slice(0, t.length - 80).forEach((e) => {
2197
2749
  delete n[e];
2198
2750
  }), n;
2199
2751
  };
2200
- function Hr(e, t, n) {
2752
+ function Ji(e, t, n) {
2201
2753
  if (![e.hostId, e.guestId].includes(n)) return e;
2202
2754
  if (t.type === "game_end" && t.data.reason === "closed") return ["closed", "declined"].includes(e.status) ? e : {
2203
2755
  ...e,
@@ -2205,7 +2757,7 @@ function Hr(e, t, n) {
2205
2757
  closedBy: n,
2206
2758
  error: ""
2207
2759
  };
2208
- if (Z(e) || e.status === "conflict") return e;
2760
+ if ($(e) || e.status === "conflict") return e;
2209
2761
  if (t.type === "game_accept" || t.type === "game_decline") return n !== e.guestId || e.status !== "invited" || t.data.invite_event_id !== e.inviteEventId ? e : {
2210
2762
  ...e,
2211
2763
  status: t.type === "game_accept" ? "active" : "declined",
@@ -2226,7 +2778,7 @@ function Hr(e, t, n) {
2226
2778
  error: "La partida perdió sincronización. Ciérrala y envía una nueva invitación."
2227
2779
  };
2228
2780
  if (n !== e.turnId) return e;
2229
- let o = Ke(e.board, a, n);
2781
+ let o = Jt(e.board, a, n);
2230
2782
  return o ? {
2231
2783
  ...e,
2232
2784
  board: o.board,
@@ -2244,7 +2796,7 @@ function Hr(e, t, n) {
2244
2796
  turnId: n === e.hostId ? e.guestId : e.hostId
2245
2797
  } : e;
2246
2798
  }
2247
- var Ur = 8e3, Q = {
2799
+ var Yi = 8e3, Xi = {
2248
2800
  status: "idle",
2249
2801
  requestId: null,
2250
2802
  requestedAt: 0,
@@ -2253,14 +2805,14 @@ var Ur = 8e3, Q = {
2253
2805
  replies: [],
2254
2806
  offer: null,
2255
2807
  message: ""
2256
- }, Wr = (e) => [
2808
+ }, Zi = (e) => [
2257
2809
  "game_resync_request",
2258
2810
  "game_resync_state",
2259
2811
  "bs_sync_request",
2260
2812
  "bs_sync_state",
2261
2813
  "tk_sync_request",
2262
2814
  "tk_sync_state"
2263
- ].includes(e), Gr = (e) => e.acceptEventId ? {
2815
+ ].includes(e), Qi = (e) => e.acceptEventId ? {
2264
2816
  accept_event_id: e.acceptEventId,
2265
2817
  moves: e.moves ?? [],
2266
2818
  rev: (e.moves ?? []).length
@@ -2268,10 +2820,10 @@ var Ur = 8e3, Q = {
2268
2820
  moves: [],
2269
2821
  rev: 0
2270
2822
  };
2271
- function Kr(e, t, n) {
2823
+ function $i(e, t, n) {
2272
2824
  let r = {
2273
2825
  ...e,
2274
- board: Ve(),
2826
+ board: Ut(),
2275
2827
  ply: 0,
2276
2828
  turnId: e.hostId,
2277
2829
  winnerId: null,
@@ -2297,7 +2849,7 @@ function Kr(e, t, n) {
2297
2849
  let [r, o] = n[t];
2298
2850
  if (a.has(o)) return null;
2299
2851
  a.add(o);
2300
- let s = t % 2 == 0 ? e.hostId : e.guestId, c = Hr(i, {
2852
+ let s = t % 2 == 0 ? e.hostId : e.guestId, c = Ji(i, {
2301
2853
  type: "game_move",
2302
2854
  event_id: o,
2303
2855
  data: {
@@ -2311,18 +2863,18 @@ function Kr(e, t, n) {
2311
2863
  }
2312
2864
  return i;
2313
2865
  }
2314
- function qr(e, t) {
2866
+ function ea(e, t) {
2315
2867
  if (e.acceptEventId && t.acceptEventId && e.acceptEventId !== t.acceptEventId) return "diverged";
2316
2868
  let n = Math.min(e.moves.length, t.moves.length);
2317
2869
  for (let r = 0; r < n; r += 1) if (e.moves[r][0] !== t.moves[r][0] || e.moves[r][1] !== t.moves[r][1]) return "diverged";
2318
2870
  return e.moves.length === t.moves.length ? e.acceptEventId && !t.acceptEventId ? "ahead" : !e.acceptEventId && t.acceptEventId ? "behind" : "equal" : e.moves.length < t.moves.length ? "behind" : "ahead";
2319
2871
  }
2320
- var Jr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEvent.event_id : null, Yr = {
2872
+ var ta = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEvent.event_id : null, na = {
2321
2873
  requestType: "game_resync_request",
2322
2874
  stateType: "game_resync_state",
2323
- historyOf: Gr,
2324
- rebuild: (e, t) => Kr(e, t.accept_event_id ?? null, t.moves),
2325
- compare: (e, t) => qr({
2875
+ historyOf: Qi,
2876
+ rebuild: (e, t) => $i(e, t.accept_event_id ?? null, t.moves),
2877
+ compare: (e, t) => ea({
2326
2878
  acceptEventId: e.acceptEventId ?? null,
2327
2879
  moves: e.moves ?? []
2328
2880
  }, {
@@ -2334,7 +2886,7 @@ var Jr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
2334
2886
  moves: e.moves
2335
2887
  }),
2336
2888
  covers: (e, t) => {
2337
- let n = Jr(e);
2889
+ let n = ta(e);
2338
2890
  return !!(n && t.moves?.some((e) => e[1] === n));
2339
2891
  },
2340
2892
  markSeen: (e, t) => {
@@ -2344,40 +2896,40 @@ var Jr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
2344
2896
  }), n;
2345
2897
  },
2346
2898
  merge: () => null
2347
- }, Xr = (e) => ({
2899
+ }, ra = (e) => ({
2348
2900
  requestType: "bs_sync_request",
2349
2901
  stateType: "bs_sync_state",
2350
- historyOf: Gt,
2351
- rebuild: (t, n) => Jt(t, n, { stored: e(t.scope, t.gameId) }),
2352
- compare: (e, t) => Kt(Gt(e), t),
2902
+ historyOf: Yn,
2903
+ rebuild: (t, n) => Qn(t, n, { stored: e(t.scope, t.gameId) }),
2904
+ compare: (e, t) => Xn(Yn(e), t),
2353
2905
  offerOf: (e) => ({
2354
2906
  accept_event_id: e.accept_event_id,
2355
2907
  commits: e.commits,
2356
2908
  log: e.log,
2357
2909
  head: e.head
2358
2910
  }),
2359
- covers: (e, t) => !!(e.pendingEvent && !e.pending && Yt(t, e.pendingEvent)),
2360
- markSeen: Xt,
2361
- merge: (e, t) => qt(Gt(e), t)
2362
- }), Zr = {
2911
+ covers: (e, t) => !!(e.pendingEvent && !e.pending && $n(t, e.pendingEvent)),
2912
+ markSeen: er,
2913
+ merge: (e, t) => Zn(Yn(e), t)
2914
+ }), ia = {
2363
2915
  requestType: "tk_sync_request",
2364
2916
  stateType: "tk_sync_state",
2365
- historyOf: br,
2366
- rebuild: Sr,
2367
- compare: (e, t) => xr(br(e), t),
2917
+ historyOf: Ti,
2918
+ rebuild: Di,
2919
+ compare: (e, t) => Ei(Ti(e), t),
2368
2920
  offerOf: (e) => ({
2369
2921
  ...e,
2370
2922
  request_event_id: void 0
2371
2923
  }),
2372
- covers: (e, t) => !!(e.pendingEvent && !e.pending && Cr(t, e.pendingEvent)),
2373
- markSeen: wr,
2924
+ covers: (e, t) => !!(e.pendingEvent && !e.pending && Oi(t, e.pendingEvent)),
2925
+ markSeen: ki,
2374
2926
  merge: () => null
2375
- }, Qr = (e) => ({
2927
+ }, aa = (e) => ({
2376
2928
  ...e,
2377
2929
  game: "connect4",
2378
2930
  turnId: e.hostId,
2379
2931
  status: "invited",
2380
- board: Ve(),
2932
+ board: Ut(),
2381
2933
  ply: 0,
2382
2934
  winnerId: null,
2383
2935
  lastMove: null,
@@ -2386,39 +2938,39 @@ var Jr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
2386
2938
  pendingEvent: null,
2387
2939
  acceptEventId: null,
2388
2940
  moves: []
2389
- }), $r = (e, t, n) => k(t, {
2941
+ }), oa = (e, t, n) => F(t, {
2390
2942
  game_id: e.gameId,
2391
2943
  data: n,
2392
- game: Y(e)
2944
+ game: Q(e)
2393
2945
  });
2394
- function ei() {
2395
- let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ?? an(e, n), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = Xr(n), c = /* @__PURE__ */ new Map(), l = (e, t) => c.get(`${e}:${t}`) ?? Pr(e, t)?.seedA ?? null, u = {
2946
+ function sa() {
2947
+ let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ?? cr(e, n), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = ra(n), c = /* @__PURE__ */ new Map(), l = (e, t) => c.get(`${e}:${t}`) ?? zi(e, t)?.seedA ?? null, u = {
2396
2948
  connect4: {
2397
- create: (e) => Qr(e),
2398
- apply: (e, t, n) => Hr(e, t, n),
2399
- sync: Yr
2949
+ create: (e) => aa(e),
2950
+ apply: (e, t, n) => Ji(e, t, n),
2951
+ sync: na
2400
2952
  },
2401
2953
  battleship: {
2402
- create: (e) => ft(e),
2403
- apply: (e, t, r, i) => Vt(e, t, r, { stored: t.type === "bs_commit" && r === i ? n(e.scope, e.gameId) : null }),
2954
+ create: (e) => hn(e),
2955
+ apply: (e, t, r, i) => Gn(e, t, r, { stored: t.type === "bs_commit" && r === i ? n(e.scope, e.gameId) : null }),
2404
2956
  sync: s,
2405
2957
  after: (e, t) => t().bsScheduleEffects(e)
2406
2958
  },
2407
2959
  racing_live: {
2408
- create: (e, t) => ie(e, t.data),
2409
- apply: ae
2960
+ create: (e, t) => at(e, t.data),
2961
+ apply: ot
2410
2962
  },
2411
2963
  tanks_live: {
2412
- create: (e, t) => _(e, t.data),
2413
- apply: v
2964
+ create: (e, t) => Ye(e, t.data),
2965
+ apply: Xe
2414
2966
  },
2415
2967
  tanks: {
2416
- create: (e, t) => ur(e, t.data),
2417
- apply: (e, t, n) => vr(e, t, n),
2418
- sync: Zr,
2968
+ create: (e, t) => hi(e, t.data),
2969
+ apply: (e, t, n) => Ci(e, t, n),
2970
+ sync: ia,
2419
2971
  after: (e, t) => t().tkScheduleEffects(e)
2420
2972
  }
2421
- }, f = (e) => u[Y(e)] ?? null, m = (e) => f(e)?.sync ?? Yr;
2973
+ }, f = (e) => u[Q(e)] ?? null, m = (e) => f(e)?.sync ?? na;
2422
2974
  return d((s, d) => ({
2423
2975
  games: {},
2424
2976
  configureTransport: (t) => {
@@ -2427,12 +2979,12 @@ function ei() {
2427
2979
  clear: () => {
2428
2980
  r.forEach((e) => clearTimeout(e)), r.clear(), o.forEach((e) => clearTimeout(e)), o.clear(), t.clear(), c.clear(), i.clear(), a.clear(), s({ games: {} });
2429
2981
  },
2430
- markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && !Rr(n) && !Z(n) ? {
2982
+ markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && !Wi(n) && !$(n) ? {
2431
2983
  ...n,
2432
2984
  status: "conflict",
2433
2985
  error: "Conexión interrumpida. Se intentará resincronizar al reconectar.",
2434
2986
  sync: {
2435
- ...Q,
2987
+ ...Xi,
2436
2988
  ...n.sync,
2437
2989
  status: "idle",
2438
2990
  auto: !1
@@ -2447,13 +2999,13 @@ function ei() {
2447
2999
  ...t
2448
3000
  } : t, p = f.message ?? f.text;
2449
3001
  if (typeof p != "string" || !p.startsWith("LIRA_GAME_V1:")) return !1;
2450
- let m = ze(p), h = String(f.room_id ?? ""), g = String(f.user_id ?? "");
3002
+ let m = Vt(p), h = String(f.room_id ?? ""), g = String(f.user_id ?? "");
2451
3003
  if (!m || !o || !c || !g || !h.startsWith("private_")) return !0;
2452
3004
  let _ = h.slice(8).split("_");
2453
3005
  if (_.length !== 2 || !_.includes(c) || !_.includes(g)) return !0;
2454
- let v = Br(o, h, m.game_id), y = d().games[v];
2455
- if (y && Y(y) !== m.game) return !0;
2456
- if (Wr(m.type)) return y && !y.seen[m.event_id] && d().handleResync(v, m, g, c), !0;
3006
+ let v = Ki(o, h, m.game_id), y = d().games[v];
3007
+ if (y && Q(y) !== m.game) return !0;
3008
+ if (Zi(m.type)) return y && !y.seen[m.event_id] && d().handleResync(v, m, g, c), !0;
2457
3009
  if (!y && m.type !== "game_invite" && m.game === "tanks" && d().restoreTanks(o, m.game_id)) return d().ingest(t, n, r);
2458
3010
  if (!y && m.type !== "game_invite") {
2459
3011
  let e = Date.now();
@@ -2487,7 +3039,7 @@ function ei() {
2487
3039
  inviteEventId: m.event_id,
2488
3040
  lastEventId: m.event_id,
2489
3041
  seen: {},
2490
- sync: { ...Q }
3042
+ sync: { ...Xi }
2491
3043
  }, m);
2492
3044
  } else y && (b = x.apply(y, m, g, c));
2493
3045
  if (!b || b === y) return !0;
@@ -2503,7 +3055,7 @@ function ei() {
2503
3055
  [v]: b
2504
3056
  };
2505
3057
  if (m.type === "game_invite") {
2506
- let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !Z(e)), n = e.sort((e, t) => e.gameId < t.gameId ? -1 : +(e.gameId > t.gameId))[0];
3058
+ let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !$(e)), n = e.sort((e, t) => e.gameId < t.gameId ? -1 : +(e.gameId > t.gameId))[0];
2507
3059
  e.forEach((e) => {
2508
3060
  e.key !== n?.key && (t[e.key] = {
2509
3061
  ...e,
@@ -2512,7 +3064,7 @@ function ei() {
2512
3064
  });
2513
3065
  });
2514
3066
  }
2515
- return { games: Vr(t) };
3067
+ return { games: qi(t) };
2516
3068
  }), b.status === "conflict" && y?.status !== "conflict" && queueMicrotask(() => {
2517
3069
  d().requestResync(v, { auto: !0 });
2518
3070
  }), d().afterGameChange(v), m.type === "game_invite") {
@@ -2521,32 +3073,37 @@ function ei() {
2521
3073
  }
2522
3074
  return !0;
2523
3075
  },
2524
- invite: async ({ roomId: t, opponentId: n, gameType: r = "connect4", firstPlayerId: i, rematchOf: a, speedClass: o }) => {
3076
+ invite: async ({ roomId: t, opponentId: n, gameType: r = "connect4", firstPlayerId: i, rematchOf: a, speedClass: o, mapId: s, lives: l, seed: u }) => {
2525
3077
  if (!e) throw Error("Chat no disponible");
2526
- if (!Ir.includes(r)) throw Error("Juego no disponible");
2527
- let s = e.getScope();
3078
+ if (!Vi.includes(r)) throw Error("Juego no disponible");
3079
+ let f = e.getScope();
2528
3080
  if (!String(e.getUserId() ?? "") || !String(t).startsWith("private_")) throw Error("Abre un chat privado para jugar.");
2529
- if (Object.values(d().games).some((e) => e.scope === s && e.roomId === String(t) && (!Z(e) || e.pendingEvent))) throw Error("Cierra la partida actual antes de invitar.");
2530
- let l = p(), u = r === "racing_live" ? re({
3081
+ if (Object.values(d().games).some((e) => e.scope === f && e.roomId === String(t) && (!$(e) || e.pendingEvent))) throw Error("Cierra la partida actual antes de invitar.");
3082
+ let m = p(), h = r === "racing_live" ? it({
2531
3083
  opponentId: String(n),
2532
- seed: parseInt(l.slice(0, 8), 16),
3084
+ seed: parseInt(m.slice(0, 8), 16),
2533
3085
  rematchOf: a,
2534
3086
  ...o === void 0 ? {} : { speedClass: o }
3087
+ }) : r === "tanks_live" ? Je({
3088
+ opponentId: String(n),
3089
+ rematchOf: a,
3090
+ ...s === void 0 ? {} : { mapId: s },
3091
+ ...l === void 0 ? {} : { lives: l },
3092
+ ...u === void 0 ? {} : { seed: u }
2535
3093
  }) : {
2536
3094
  opponent_id: String(n),
2537
3095
  rules_version: 1
2538
3096
  };
2539
3097
  if (r === "tanks") {
2540
- let e = sr();
2541
- c.set(`${s}:${l}`, e), Nr(s, l, { seedA: e }), u.seed_commit = cr(e), i != null && (u.first_player_id = String(i)), a && (u.rematch_of = a);
3098
+ let e = fi();
3099
+ c.set(`${f}:${m}`, e), Ri(f, m, { seedA: e }), h.seed_commit = pi(e), i != null && (h.first_player_id = String(i)), a && (h.rematch_of = a);
2542
3100
  }
2543
- r === "tanks_live" && a && (u.rematch_of = a);
2544
- let f = k("game_invite", {
2545
- game_id: l,
2546
- data: u,
3101
+ let g = F("game_invite", {
3102
+ game_id: m,
3103
+ data: h,
2547
3104
  game: r
2548
3105
  });
2549
- return d().sendEvent(t, f);
3106
+ return d().sendEvent(t, g);
2550
3107
  },
2551
3108
  act: async (t, n, r = {}) => {
2552
3109
  let i = d().games[t], a = String(e?.getUserId?.() ?? "");
@@ -2555,9 +3112,9 @@ function ei() {
2555
3112
  let o = r;
2556
3113
  if (n === "game_accept" || n === "game_decline") {
2557
3114
  if (i.status !== "invited" || a !== i.guestId) return;
2558
- o = { invite_event_id: i.inviteEventId }, n === "game_accept" && X(i) && (o.seed_b = sr()), n === "game_accept" && i.game === "racing_live" && (o.track_hash = i.raceConfig.trackHash);
3115
+ o = { invite_event_id: i.inviteEventId }, n === "game_accept" && Ui(i) && (o.seed_b = fi()), n === "game_accept" && i.game === "racing_live" && (o.track_hash = i.raceConfig.trackHash), n === "game_accept" && i.game === "tanks_live" && i.liveConfig && (o.map_hash = i.liveConfig.mapHash);
2559
3116
  } else if (n === "game_move") {
2560
- if (Y(i) !== "connect4" || i.status !== "active" || a !== i.turnId || !Ke(i.board, r.column, a)) return;
3117
+ if (Q(i) !== "connect4" || i.status !== "active" || a !== i.turnId || !Jt(i.board, r.column, a)) return;
2561
3118
  o = {
2562
3119
  column: r.column,
2563
3120
  ply: i.ply + 1,
@@ -2565,41 +3122,41 @@ function ei() {
2565
3122
  };
2566
3123
  } else if (n === "game_end") o = { reason: "closed" };
2567
3124
  else return;
2568
- return d().sendEvent(i.roomId, k(n, {
3125
+ return d().sendEvent(i.roomId, F(n, {
2569
3126
  game_id: i.gameId,
2570
3127
  data: o,
2571
- game: Y(i)
3128
+ game: Q(i)
2572
3129
  }));
2573
3130
  },
2574
3131
  bsUpdateLocal: (e, t) => {
2575
3132
  let n = d().games[e];
2576
- if (!Lr(n)) return !1;
3133
+ if (!Hi(n)) return !1;
2577
3134
  let r = t(n);
2578
3135
  return r !== n && (s((t) => t.games[e] === n ? { games: {
2579
3136
  ...t.games,
2580
3137
  [e]: r
2581
3138
  } } : t), d().games[e] === r);
2582
3139
  },
2583
- bsPlaceShip: (e, t) => d().bsUpdateLocal(e, (e) => St(e, t)),
2584
- bsRemoveShip: (e, t) => d().bsUpdateLocal(e, (e) => Ct(e, t)),
2585
- bsRandomFleet: (e) => d().bsUpdateLocal(e, (e) => Et(e)),
3140
+ bsPlaceShip: (e, t) => d().bsUpdateLocal(e, (e) => En(e, t)),
3141
+ bsRemoveShip: (e, t) => d().bsUpdateLocal(e, (e) => Dn(e, t)),
3142
+ bsRandomFleet: (e) => d().bsUpdateLocal(e, (e) => An(e)),
2586
3143
  bsReady: async (n) => {
2587
3144
  let r = d().games[n];
2588
- if (!Lr(r) || r.status !== "placement" || r.myReady) return;
3145
+ if (!Hi(r) || r.status !== "placement" || r.myReady) return;
2589
3146
  if (r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2590
3147
  if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
2591
- let i = M(r.myFleet);
2592
- if (!bt(i)) throw Error("Coloca los cinco barcos antes de continuar.");
2593
- let a = Ot(), o = await At(i, a), s = d().games[n];
2594
- if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(M(s.myFleet)) !== JSON.stringify(i))) return t.set(`${r.scope}:${r.gameId}`, {
3148
+ let i = Sn(r.myFleet);
3149
+ if (!wn(i)) throw Error("Coloca los cinco barcos antes de continuar.");
3150
+ let a = Mn(), o = await Pn(i, a), s = d().games[n];
3151
+ if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(Sn(s.myFleet)) !== JSON.stringify(i))) return t.set(`${r.scope}:${r.gameId}`, {
2595
3152
  fleet: i,
2596
3153
  salt: a,
2597
3154
  commitment: o
2598
- }), rn(r.scope, r.gameId, {
3155
+ }), sr(r.scope, r.gameId, {
2599
3156
  fleet: i,
2600
3157
  salt: a,
2601
3158
  commitment: o
2602
- }), d().sendEvent(r.roomId, k("bs_commit", {
3159
+ }), d().sendEvent(r.roomId, F("bs_commit", {
2603
3160
  game_id: r.gameId,
2604
3161
  data: { commitment: o },
2605
3162
  game: "battleship"
@@ -2607,9 +3164,9 @@ function ei() {
2607
3164
  },
2608
3165
  bsFire: async (t, { row: n, col: r } = {}) => {
2609
3166
  let i = d().games[t];
2610
- if (!Lr(i) || i.scope !== e?.getScope?.()) throw Error("Partida no disponible");
3167
+ if (!Hi(i) || i.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2611
3168
  if (i.pending || i.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
2612
- if (mt(i) && i.targetShots[n]?.[r] === null) return d().sendEvent(i.roomId, k("bs_fire", {
3169
+ if (_n(i) && i.targetShots[n]?.[r] === null) return d().sendEvent(i.roomId, F("bs_fire", {
2613
3170
  game_id: i.gameId,
2614
3171
  data: {
2615
3172
  ply: i.ply + 1,
@@ -2623,14 +3180,14 @@ function ei() {
2623
3180
  bsScheduleEffects: (e) => {
2624
3181
  r.has(e) || r.set(e, setTimeout(() => {
2625
3182
  r.delete(e), d().bsRunEffects(e);
2626
- }, zr));
3183
+ }, Gi));
2627
3184
  },
2628
3185
  bsRunEffects: (t) => {
2629
3186
  let r = d().games[t];
2630
- if (!Lr(r) || !e || r.scope !== e.getScope?.()) return;
3187
+ if (!Hi(r) || !e || r.scope !== e.getScope?.()) return;
2631
3188
  if (r.opponentReveal && r.verification === "pending" && !i.has(t)) {
2632
3189
  let e = r.opponentReveal;
2633
- i.add(t), Ut(r, e).then((n) => s((r) => {
3190
+ i.add(t), qn(r, e).then((n) => s((r) => {
2634
3191
  let i = r.games[t];
2635
3192
  return !i || i.opponentReveal !== e || i.verification === n ? r : { games: {
2636
3193
  ...r.games,
@@ -2645,14 +3202,14 @@ function ei() {
2645
3202
  }
2646
3203
  if (r.pending || r.pendingEvent) return;
2647
3204
  let a = (e, t) => {
2648
- d().sendEvent(r.roomId, k(e, {
3205
+ d().sendEvent(r.roomId, F(e, {
2649
3206
  game_id: r.gameId,
2650
3207
  data: t,
2651
3208
  game: "battleship"
2652
3209
  })).catch(() => {});
2653
3210
  };
2654
3211
  if (r.status === "active" && r.pendingShot && r.pendingShot.by !== r.ownId) {
2655
- let e = jt(xt(r), r.pendingShot);
3212
+ let e = Fn(Tn(r), r.pendingShot);
2656
3213
  e ? a("bs_result", e) : r.error || s((e) => ({ games: {
2657
3214
  ...e.games,
2658
3215
  [t]: {
@@ -2664,8 +3221,8 @@ function ei() {
2664
3221
  }
2665
3222
  let o = String(r.winnerId) !== String(r.ownId) || !!r.opponentReveal;
2666
3223
  if (r.winnerId && ["won", "closed"].includes(r.status) && !r.myRevealSent && o) {
2667
- let e = M(r.myFleet), t = r.mySalt ?? n(r.scope, r.gameId)?.salt;
2668
- bt(e) && t && a("bs_reveal", {
3224
+ let e = Sn(r.myFleet), t = r.mySalt ?? n(r.scope, r.gameId)?.salt;
3225
+ wn(e) && t && a("bs_reveal", {
2669
3226
  fleet: e,
2670
3227
  salt: t
2671
3228
  });
@@ -2677,10 +3234,10 @@ function ei() {
2677
3234
  },
2678
3235
  tkTurn: async (t, n) => {
2679
3236
  let r = d().games[t];
2680
- if (!X(r) || r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
3237
+ if (!Ui(r) || r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2681
3238
  if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
2682
- let i = yr(r, n);
2683
- if (i) return d().sendEvent(r.roomId, k("tk_turn", {
3239
+ let i = wi(r, n);
3240
+ if (i) return d().sendEvent(r.roomId, F("tk_turn", {
2684
3241
  game_id: r.gameId,
2685
3242
  data: i,
2686
3243
  game: "tanks"
@@ -2688,7 +3245,7 @@ function ei() {
2688
3245
  },
2689
3246
  tkSkip: async (t) => {
2690
3247
  let n = d().games[t];
2691
- if (X(n) && fr(n) && n.scope === e?.getScope?.()) return d().sendEvent(n.roomId, k("tk_skip", {
3248
+ if (Ui(n) && _i(n) && n.scope === e?.getScope?.()) return d().sendEvent(n.roomId, F("tk_skip", {
2692
3249
  game_id: n.gameId,
2693
3250
  data: {
2694
3251
  ply: n.ply + 1,
@@ -2699,7 +3256,7 @@ function ei() {
2699
3256
  },
2700
3257
  tkResign: async (t) => {
2701
3258
  let n = d().games[t];
2702
- if (!(!X(n) || n.status !== "active" || n.pending || n.pendingEvent || n.scope !== e?.getScope?.())) return d().sendEvent(n.roomId, k("tk_resign", {
3259
+ if (!(!Ui(n) || n.status !== "active" || n.pending || n.pendingEvent || n.scope !== e?.getScope?.())) return d().sendEvent(n.roomId, F("tk_resign", {
2703
3260
  game_id: n.gameId,
2704
3261
  data: {
2705
3262
  ply: n.ply + 1,
@@ -2711,13 +3268,13 @@ function ei() {
2711
3268
  tkScheduleEffects: (e) => {
2712
3269
  r.has(e) || r.set(e, setTimeout(() => {
2713
3270
  r.delete(e), d().tkRunEffects(e);
2714
- }, zr));
3271
+ }, Gi));
2715
3272
  },
2716
3273
  tkRunEffects: (t) => {
2717
3274
  let n = d().games[t];
2718
- if (!X(n) || (Nr(n.scope, n.gameId, { snapshot: Tr(n) }), !e || n.scope !== e.getScope?.() || n.pending || n.pendingEvent) || n.status !== "seeding" || n.ownId !== n.hostId) return;
3275
+ if (!Ui(n) || (Ri(n.scope, n.gameId, { snapshot: Ai(n) }), !e || n.scope !== e.getScope?.() || n.pending || n.pendingEvent) || n.status !== "seeding" || n.ownId !== n.hostId) return;
2719
3276
  let r = l(n.scope, n.gameId);
2720
- r ? d().sendEvent(n.roomId, k("tk_seed", {
3277
+ r ? d().sendEvent(n.roomId, F("tk_seed", {
2721
3278
  game_id: n.gameId,
2722
3279
  data: { seed_a: r },
2723
3280
  game: "tanks"
@@ -2731,16 +3288,16 @@ function ei() {
2731
3288
  },
2732
3289
  restoreTanks: (e, t) => {
2733
3290
  let n = !1;
2734
- return Fr(e).forEach(({ snapshot: r }) => {
3291
+ return Bi(e).forEach(({ snapshot: r }) => {
2735
3292
  if (!r || t && r.gameId !== t || [
2736
3293
  "closed",
2737
3294
  "declined",
2738
3295
  "won",
2739
3296
  "draw"
2740
3297
  ].includes(r.status)) return;
2741
- let i = Br(e, r.roomId, r.gameId);
3298
+ let i = Ki(e, r.roomId, r.gameId);
2742
3299
  if (d().games[i]) return;
2743
- let a = Sr(ur({
3300
+ let a = Di(hi({
2744
3301
  key: i,
2745
3302
  gameId: r.gameId,
2746
3303
  game_id: r.gameId,
@@ -2753,7 +3310,7 @@ function ei() {
2753
3310
  inviteEventId: r.inviteEventId,
2754
3311
  lastEventId: r.inviteEventId,
2755
3312
  seen: {},
2756
- sync: { ...Q }
3313
+ sync: { ...Xi }
2757
3314
  }, {
2758
3315
  seed_commit: r.seedCommit,
2759
3316
  first_player_id: r.firstPlayerId,
@@ -2763,11 +3320,11 @@ function ei() {
2763
3320
  n = !0;
2764
3321
  let o = {
2765
3322
  ...a,
2766
- seen: wr({ [r.inviteEventId]: !0 }, a),
3323
+ seen: ki({ [r.inviteEventId]: !0 }, a),
2767
3324
  status: "conflict",
2768
3325
  error: "Partida recuperada en este dispositivo. Sincronizando con el rival…"
2769
3326
  };
2770
- s((e) => ({ games: Vr({
3327
+ s((e) => ({ games: qi({
2771
3328
  ...e.games,
2772
3329
  [i]: o
2773
3330
  }) })), queueMicrotask(() => {
@@ -2779,7 +3336,7 @@ function ei() {
2779
3336
  let n = d().games[t];
2780
3337
  if (!["tanks_live", "racing_live"].includes(n?.game) || n.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2781
3338
  let r = e;
2782
- return ce({
3339
+ return lt({
2783
3340
  roomId: n.roomId,
2784
3341
  send: (n, i) => {
2785
3342
  if (e !== r || d().games[t]?.scope !== r.getScope()) throw Error("La sesión cambió");
@@ -2798,18 +3355,34 @@ function ei() {
2798
3355
  }
2799
3356
  } }));
2800
3357
  },
2801
- liveRematch: (t) => {
2802
- let n = d().games[t];
2803
- if (n?.game === "tanks_live" && n.scope === e?.getScope?.() && Z(n)) return d().invite({
2804
- roomId: n.roomId,
2805
- opponentId: n.ownId === n.hostId ? n.guestId : n.hostId,
3358
+ liveRematch: (t, { newMap: n = !1, mapId: r, lives: i } = {}) => {
3359
+ let a = d().games[t];
3360
+ if (a?.game !== "tanks_live" || a.scope !== e?.getScope?.() || !$(a)) return;
3361
+ let o = a.liveConfig, s = n ? {
3362
+ mapId: r ?? "random",
3363
+ lives: i ?? o?.lives
3364
+ } : r === void 0 ? o ? {
3365
+ mapId: o.mapId,
3366
+ seed: o.seed,
3367
+ lives: i ?? o.lives
3368
+ } : i === void 0 ? { mapId: null } : {
3369
+ mapId: "random",
3370
+ lives: i
3371
+ } : {
3372
+ mapId: r,
3373
+ lives: i ?? o?.lives
3374
+ };
3375
+ return s.lives === void 0 && delete s.lives, d().invite({
3376
+ roomId: a.roomId,
3377
+ opponentId: a.ownId === a.hostId ? a.guestId : a.hostId,
2806
3378
  gameType: "tanks_live",
2807
- rematchOf: n.gameId
3379
+ rematchOf: a.gameId,
3380
+ ...s
2808
3381
  });
2809
3382
  },
2810
3383
  sendEvent: async (t, n) => {
2811
3384
  if (!e) throw Error("Chat no disponible");
2812
- let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o = Br(i, t, n.game_id), c = Be(n);
3385
+ let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o = Ki(i, t, n.game_id), c = Ht(n);
2813
3386
  if (d().ingest({
2814
3387
  room_id: t,
2815
3388
  user_id: a,
@@ -2861,7 +3434,7 @@ function ei() {
2861
3434
  return;
2862
3435
  }
2863
3436
  let l = {
2864
- ...Q,
3437
+ ...Xi,
2865
3438
  ...i.sync
2866
3439
  };
2867
3440
  if (![a.requestType, a.stateType].includes(t.type)) {
@@ -2949,7 +3522,7 @@ function ei() {
2949
3522
  };
2950
3523
  let b = Date.now(), x = g.sync.replies.filter((e) => b - e < 3e4), S = null;
2951
3524
  if (_ && x.length < 6) try {
2952
- S = $r(i, a.stateType, {
3525
+ S = oa(i, a.stateType, {
2953
3526
  ...a.historyOf(g),
2954
3527
  request_event_id: t.event_id
2955
3528
  });
@@ -2984,19 +3557,19 @@ function ei() {
2984
3557
  sendResync: async (t, n) => {
2985
3558
  let r = d().games[t];
2986
3559
  if (!e || !r || r.scope !== e.getScope?.()) throw Error("Chat no disponible");
2987
- await e.send(r.roomId, Be(n));
3560
+ await e.send(r.roomId, Ht(n));
2988
3561
  },
2989
3562
  requestResync: async (t, { auto: n = !1 } = {}) => {
2990
3563
  let r = d().games[t];
2991
- if (!r || Rr(r) || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
3564
+ if (!r || Wi(r) || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
2992
3565
  let i = {
2993
- ...Q,
3566
+ ...Xi,
2994
3567
  ...r.sync
2995
3568
  };
2996
- if (i.status === "requesting" && Date.now() - i.requestedAt < Ur || n && i.auto) return;
3569
+ if (i.status === "requesting" && Date.now() - i.requestedAt < Yi || n && i.auto) return;
2997
3570
  let a;
2998
3571
  try {
2999
- a = $r(r, m(r).requestType, m(r).historyOf(r));
3572
+ a = oa(r, m(r).requestType, m(r).historyOf(r));
3000
3573
  } catch {
3001
3574
  return;
3002
3575
  }
@@ -3038,7 +3611,7 @@ function ei() {
3038
3611
  });
3039
3612
  let l = setTimeout(() => {
3040
3613
  o.delete(l), c("El rival no respondió a la sincronización. Reintenta cuando esté conectado.");
3041
- }, Ur);
3614
+ }, Yi);
3042
3615
  o.add(l);
3043
3616
  try {
3044
3617
  await d().sendResync(t, a);
@@ -3086,23 +3659,23 @@ function ei() {
3086
3659
  }
3087
3660
  }));
3088
3661
  }
3089
- var $ = ei(), ti = (e) => f($, e);
3090
- Object.assign(ti, {
3091
- getState: $.getState,
3092
- setState: $.setState,
3093
- subscribe: $.subscribe
3662
+ var ca = sa(), la = (e) => f(ca, e);
3663
+ Object.assign(la, {
3664
+ getState: ca.getState,
3665
+ setState: ca.setState,
3666
+ subscribe: ca.subscribe
3094
3667
  });
3095
3668
  // src/assets/chatAssets.js
3096
- var ni = "/sounds", ri = ni, ii = (e) => String(e).replace(/\/+$/, "");
3097
- function ai(e) {
3098
- ri = e == null ? ni : ii(e);
3669
+ var ua = "/sounds", da = ua, fa = (e) => String(e).replace(/\/+$/, "");
3670
+ function pa(e) {
3671
+ da = e == null ? ua : fa(e);
3099
3672
  }
3100
- function oi() {
3101
- return ri;
3673
+ function ma() {
3674
+ return da;
3102
3675
  }
3103
- function si(e) {
3104
- return `${ri}/${String(e).replace(/^\/+/, "")}`;
3676
+ function ha(e) {
3677
+ return `${da}/${String(e).replace(/^\/+/, "")}`;
3105
3678
  }
3106
- export { se as _, ti as a, In as c, I as d, on as f, ce as g, Pe as h, $ as i, Cn as l, xe as m, oi as n, fr as o, N as p, ai as r, Pn as s, si as t, L as u, p as v };
3679
+ export { oe as C, te as D, b as E, ee as O, v as S, le as T, ct as _, la as a, ae as b, zr as c, V as d, lr as f, lt as g, It as h, ca as i, p as k, Er as l, St as m, ma as n, _i as o, R as p, pa as r, Lr as s, ha as t, H as u, Fe as v, ce as w, _ as x, m as y };
3107
3680
 
3108
- //# sourceMappingURL=games-BvYTWgaR.js.map
3681
+ //# sourceMappingURL=games-Bl_8raG6.js.map