@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.
- package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js → BattleshipGameCard-8H-sBCsv.js} +3 -3
- package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js.map → BattleshipGameCard-8H-sBCsv.js.map} +1 -1
- package/dist/chunks/{ChatContext-DQtKsR6Z.js → ChatContext-CVW58bzC.js} +2 -2
- package/dist/chunks/{ChatContext-DQtKsR6Z.js.map → ChatContext-CVW58bzC.js.map} +1 -1
- package/dist/chunks/{RacingLiveGameCard-c1G7uoDI.js → RacingLiveGameCard-8j9QLnxW.js} +4 -4
- package/dist/chunks/{RacingLiveGameCard-c1G7uoDI.js.map → RacingLiveGameCard-8j9QLnxW.js.map} +1 -1
- package/dist/chunks/{TanksGameCard-CvTaF7tu.js → TanksGameCard-DnCufSH6.js} +12 -12
- package/dist/chunks/{TanksGameCard-CvTaF7tu.js.map → TanksGameCard-DnCufSH6.js.map} +1 -1
- package/dist/chunks/TanksLiveGameCard-D_27Jomp.js +1274 -0
- package/dist/chunks/TanksLiveGameCard-D_27Jomp.js.map +1 -0
- package/dist/chunks/{avalancheScene3d-Z5QyZIid.js → avalancheScene3d-CIE2WKQn.js} +51 -50
- package/dist/chunks/{avalancheScene3d-Z5QyZIid.js.map → avalancheScene3d-CIE2WKQn.js.map} +1 -1
- package/dist/chunks/cars-D1PM7mVD.js +340 -0
- package/dist/chunks/cars-D1PM7mVD.js.map +1 -0
- package/dist/chunks/{connect4Sounds-DmD-E9kX.js → connect4Sounds-BqEHULjv.js} +2 -2
- package/dist/chunks/{connect4Sounds-DmD-E9kX.js.map → connect4Sounds-BqEHULjv.js.map} +1 -1
- package/dist/chunks/createLiveScene-MTGRv8rx.js +758 -0
- package/dist/chunks/createLiveScene-MTGRv8rx.js.map +1 -0
- package/dist/chunks/{createRaceScene-C7Rw89kj.js → createRaceScene-BiEtQsVs.js} +4 -3
- package/dist/chunks/{createRaceScene-C7Rw89kj.js.map → createRaceScene-BiEtQsVs.js.map} +1 -1
- package/dist/chunks/fx-DhXerGyt.js +248 -0
- package/dist/chunks/fx-DhXerGyt.js.map +1 -0
- package/dist/chunks/{games-BvYTWgaR.js → games-Bl_8raG6.js} +1147 -574
- package/dist/chunks/games-Bl_8raG6.js.map +1 -0
- package/dist/chunks/{tanksSounds-DwjfSp3W.js → tanksSounds-DTnidbiq.js} +5 -5
- package/dist/chunks/{tanksSounds-DwjfSp3W.js.map → tanksSounds-DTnidbiq.js.map} +1 -1
- package/dist/index.js +28 -28
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/chunks/TanksLiveGameCard-COr9Oay5.js +0 -1011
- package/dist/chunks/TanksLiveGameCard-COr9Oay5.js.map +0 -1
- package/dist/chunks/createLiveScene-CWBunxPi.js +0 -367
- package/dist/chunks/createLiveScene-CWBunxPi.js.map +0 -1
- package/dist/chunks/fx-UZwhOmdl.js +0 -584
- package/dist/chunks/fx-UZwhOmdl.js.map +0 -1
- 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
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
60
|
-
function
|
|
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 (
|
|
614
|
+
if (!$e(i)) return !1;
|
|
63
615
|
switch (n.type) {
|
|
64
|
-
case "game_invite": return
|
|
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
|
-
]) &&
|
|
75
|
-
case "game_accept": return
|
|
76
|
-
case "game_decline": return
|
|
77
|
-
case "game_end": return
|
|
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
|
|
633
|
+
function it({ opponentId: i, seed: a = 0, rematchOf: o, speedClass: s = n } = {}) {
|
|
82
634
|
let c = t(s);
|
|
83
|
-
if (!
|
|
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
|
|
97
|
-
if (!
|
|
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
|
|
124
|
-
return !e || t?.game !== "racing_live" || t.game_id !== e.gameId || ![e.hostId, e.guestId].includes(n) || !
|
|
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
|
|
694
|
+
var st = /* @__PURE__ */ new Set(), ct = {
|
|
143
695
|
emit(e) {
|
|
144
|
-
|
|
696
|
+
st.forEach((t) => {
|
|
145
697
|
try {
|
|
146
698
|
t(e);
|
|
147
699
|
} catch {}
|
|
148
700
|
});
|
|
149
701
|
},
|
|
150
702
|
subscribe(e) {
|
|
151
|
-
return
|
|
703
|
+
return st.add(e), () => st.delete(e);
|
|
152
704
|
}
|
|
153
|
-
},
|
|
705
|
+
}, lt = ({ send: e, roomId: t }) => ({
|
|
154
706
|
send: (n) => e(t, n),
|
|
155
|
-
subscribe: (e) =>
|
|
707
|
+
subscribe: (e) => ct.subscribe((n) => {
|
|
156
708
|
String(n.roomId) === String(t) && e(n);
|
|
157
709
|
})
|
|
158
|
-
}),
|
|
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
|
-
]),
|
|
163
|
-
function
|
|
164
|
-
return Array.isArray(e) ? e[0] === 1 ? e.length === 6 &&
|
|
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
|
|
173
|
-
function
|
|
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
|
|
177
|
-
case "game_accept": return
|
|
178
|
-
case "game_decline": return
|
|
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" &&
|
|
181
|
-
case "tk_turn": return
|
|
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
|
|
184
|
-
case "tk_sync_request": return
|
|
185
|
-
case "tk_sync_state": return
|
|
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
|
|
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
|
-
],
|
|
197
|
-
function
|
|
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
|
|
752
|
+
case "game_invite": return M(t.opponent_id) && t.rules_version === 1;
|
|
201
753
|
case "game_accept":
|
|
202
|
-
case "game_decline": return
|
|
203
|
-
case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 ||
|
|
204
|
-
case "bs_commit": return
|
|
205
|
-
case "bs_fire": return
|
|
206
|
-
case "bs_result": return
|
|
207
|
-
case "bs_reveal": return
|
|
208
|
-
case "bs_sync_request": return
|
|
209
|
-
case "bs_sync_state": return
|
|
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
|
|
765
|
+
function It(e) {
|
|
214
766
|
return typeof e == "string" && e.startsWith("LIRA_GAME_V1:");
|
|
215
767
|
}
|
|
216
|
-
function
|
|
768
|
+
function Lt(e) {
|
|
217
769
|
let t = e.data;
|
|
218
770
|
switch (e.type) {
|
|
219
|
-
case "game_invite": return
|
|
771
|
+
case "game_invite": return M(t.opponent_id) && t.rules_version === 1;
|
|
220
772
|
case "game_accept":
|
|
221
|
-
case "game_decline": return
|
|
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 &&
|
|
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 ||
|
|
228
|
-
case "game_resync_request": return
|
|
229
|
-
case "game_resync_state": return
|
|
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
|
|
234
|
-
connect4:
|
|
235
|
-
battleship:
|
|
236
|
-
tanks:
|
|
237
|
-
tanks_live:
|
|
238
|
-
racing_live:
|
|
239
|
-
},
|
|
240
|
-
function
|
|
241
|
-
return !
|
|
242
|
-
}
|
|
243
|
-
function
|
|
244
|
-
if (!
|
|
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
|
|
799
|
+
return Bt(t) ? t : null;
|
|
248
800
|
} catch {
|
|
249
801
|
return null;
|
|
250
802
|
}
|
|
251
803
|
}
|
|
252
|
-
function
|
|
253
|
-
if (!
|
|
254
|
-
let t =
|
|
255
|
-
if (t.length >
|
|
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
|
|
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 (!
|
|
819
|
+
if (!Bt(a)) throw Error("Evento de juego inválido");
|
|
268
820
|
return a;
|
|
269
821
|
}
|
|
270
|
-
function
|
|
822
|
+
function Ut() {
|
|
271
823
|
return Array.from({ length: 6 }, () => Array(7).fill(null));
|
|
272
824
|
}
|
|
273
|
-
var
|
|
825
|
+
var Wt = [
|
|
274
826
|
[0, 1],
|
|
275
827
|
[1, 0],
|
|
276
828
|
[1, 1],
|
|
277
829
|
[1, -1]
|
|
278
830
|
];
|
|
279
|
-
function
|
|
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
|
|
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
|
|
295
|
-
let t =
|
|
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
|
|
850
|
+
function qt(e) {
|
|
299
851
|
return e[0].every((e) => e !== null);
|
|
300
852
|
}
|
|
301
|
-
function
|
|
302
|
-
if (!Number.isInteger(t) || t < 0 || t >= 7 || n == 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 =
|
|
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 &&
|
|
866
|
+
draw: o === null && qt(i),
|
|
315
867
|
winningCells: a
|
|
316
868
|
};
|
|
317
869
|
}
|
|
318
870
|
// src/games/battleship/logic/game.js
|
|
319
|
-
var
|
|
320
|
-
function
|
|
321
|
-
if (!
|
|
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
|
|
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
|
|
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
|
-
],
|
|
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
|
-
}),
|
|
403
|
-
function
|
|
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:
|
|
413
|
-
targetShots:
|
|
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
|
|
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
|
-
}),
|
|
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
|
|
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 ?
|
|
1007
|
+
} : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ? yn(e) : null;
|
|
456
1008
|
}
|
|
457
|
-
function
|
|
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 =
|
|
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
|
|
1019
|
+
function Sn(e) {
|
|
468
1020
|
if (!Array.isArray(e)) return null;
|
|
469
|
-
let t = e.map(
|
|
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
|
|
478
|
-
let t =
|
|
479
|
-
return t && i(t) ? t.ships.map(
|
|
1029
|
+
function Cn(e) {
|
|
1030
|
+
let t = xn(e);
|
|
1031
|
+
return t && i(t) ? t.ships.map(vn) : null;
|
|
480
1032
|
}
|
|
481
|
-
var
|
|
482
|
-
function
|
|
483
|
-
let t =
|
|
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
|
|
490
|
-
if (!
|
|
491
|
-
let 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(
|
|
1051
|
+
myFleet: o.board.ships.map(vn)
|
|
500
1052
|
} : e;
|
|
501
1053
|
}
|
|
502
|
-
function
|
|
503
|
-
return !
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
1086
|
+
var An = (e, t) => gn(e) ? {
|
|
535
1087
|
...e,
|
|
536
|
-
myFleet:
|
|
537
|
-
} : e,
|
|
538
|
-
function
|
|
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),
|
|
1092
|
+
return globalThis.crypto.getRandomValues(e), jn(e);
|
|
541
1093
|
}
|
|
542
|
-
function
|
|
543
|
-
let n =
|
|
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
|
|
551
|
-
let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(
|
|
552
|
-
return
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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 =
|
|
1147
|
+
let s = on(e.targetShots, n, r, i), c = sn(s), l = null;
|
|
596
1148
|
if (a) {
|
|
597
|
-
if (l = i === "hit" ?
|
|
598
|
-
let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(
|
|
599
|
-
if (!l.cells.some((e) => e.row === n && e.col === r) || l.cells.some((e) => s[e.row][e.col] !== "hit" || t.has(
|
|
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 >
|
|
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
|
|
608
|
-
let n =
|
|
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 ?
|
|
611
|
-
return r && (t.sunk.ship_id !== r.id || !
|
|
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:
|
|
1167
|
+
shots: on(e.incomingShots, t.row, t.col, t.result),
|
|
616
1168
|
ship: r
|
|
617
1169
|
};
|
|
618
1170
|
}
|
|
619
|
-
function
|
|
620
|
-
let i =
|
|
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 ?
|
|
628
|
-
t &&
|
|
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:
|
|
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
|
|
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
|
|
666
|
-
let i = e.pendingShot, a = t === e.ownId, o = a ?
|
|
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
|
|
1248
|
+
function Hn(e, t, n) {
|
|
697
1249
|
let { ply: r, row: i, col: a, prev_event_id: o } = t.data;
|
|
698
|
-
return 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 :
|
|
1254
|
+
}, t.event_id) ?? e : L(e, I) : e : L(e, e.status === "invited" ? tn : I) : e;
|
|
703
1255
|
}
|
|
704
|
-
function
|
|
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" ?
|
|
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 :
|
|
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
|
|
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
|
|
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
|
|
737
|
-
if (
|
|
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" ?
|
|
751
|
-
case "bs_fire": return
|
|
752
|
-
case "bs_result": return
|
|
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
|
|
757
|
-
let n =
|
|
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 =
|
|
1315
|
+
for (let r of t[e]) n = Zt(n, {
|
|
764
1316
|
type: "place_ship",
|
|
765
1317
|
playerId: e,
|
|
766
|
-
...
|
|
1318
|
+
...yn(r)
|
|
767
1319
|
});
|
|
768
|
-
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 =
|
|
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 || !
|
|
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
|
|
1344
|
+
async function qn(e, t = e?.opponentReveal) {
|
|
793
1345
|
if (!e || !t) return "pending";
|
|
794
|
-
let n =
|
|
795
|
-
if (!r || !i || typeof t.salt != "string" ||
|
|
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
|
|
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 =
|
|
804
|
-
return o ?
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
883
|
-
targetShots:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
936
|
-
if (s =
|
|
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 ===
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
1537
|
+
if (r?.startsWith(tr)) try {
|
|
986
1538
|
let n = JSON.parse(e.getItem(r));
|
|
987
|
-
|
|
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
|
|
1545
|
+
function sr(e, t, { fleet: n, salt: r, commitment: i }) {
|
|
994
1546
|
try {
|
|
995
|
-
let a =
|
|
996
|
-
return a ? (
|
|
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
|
|
1558
|
+
function cr(e, t) {
|
|
1007
1559
|
try {
|
|
1008
|
-
let n = JSON.parse(
|
|
1009
|
-
return
|
|
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
|
|
1020
|
-
2 *
|
|
1021
|
-
var
|
|
1022
|
-
4 *
|
|
1023
|
-
var
|
|
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
|
-
}),
|
|
1580
|
+
}), H = Object.freeze({
|
|
1029
1581
|
standard: Object.freeze({
|
|
1030
1582
|
id: "standard",
|
|
1031
1583
|
cost: 0,
|
|
1032
|
-
radius: 6 *
|
|
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 *
|
|
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 *
|
|
1600
|
+
radius: 4 * R,
|
|
1049
1601
|
maxDmg: 15,
|
|
1050
1602
|
depth: 8e4,
|
|
1051
1603
|
speedPct: 100
|
|
1052
1604
|
})
|
|
1053
|
-
}),
|
|
1054
|
-
radius: 4 *
|
|
1605
|
+
}), _r = Object.freeze({
|
|
1606
|
+
radius: 4 * R,
|
|
1055
1607
|
maxDmg: 15,
|
|
1056
1608
|
depth: 8e4
|
|
1057
|
-
}),
|
|
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
|
-
]),
|
|
1635
|
+
]), yr = Object.freeze({
|
|
1084
1636
|
heavy: 2,
|
|
1085
1637
|
cluster: 2
|
|
1086
|
-
}),
|
|
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
|
-
]),
|
|
1179
|
-
function
|
|
1730
|
+
]), xr = 1e6;
|
|
1731
|
+
function Sr(e) {
|
|
1180
1732
|
let t = (e % 360 + 360) % 360;
|
|
1181
|
-
return t <= 90 ?
|
|
1733
|
+
return t <= 90 ? br[t] : t <= 180 ? br[180 - t] : t <= 270 ? -br[t - 180] : -br[360 - t];
|
|
1182
1734
|
}
|
|
1183
|
-
function
|
|
1184
|
-
return
|
|
1735
|
+
function Cr(e) {
|
|
1736
|
+
return Sr(e + 90);
|
|
1185
1737
|
}
|
|
1186
|
-
function
|
|
1187
|
-
return Math.trunc(e * t /
|
|
1738
|
+
function U(e, t) {
|
|
1739
|
+
return Math.trunc(e * t / xr);
|
|
1188
1740
|
}
|
|
1189
1741
|
// src/games/tanks/logic/rng.js
|
|
1190
|
-
var
|
|
1191
|
-
function
|
|
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
|
|
1751
|
+
function W(e, t, n) {
|
|
1200
1752
|
return t + e() % (n - t + 1);
|
|
1201
1753
|
}
|
|
1202
|
-
function
|
|
1203
|
-
let n =
|
|
1754
|
+
function Er(e, t) {
|
|
1755
|
+
let n = Tr((e ^ Math.imul(t, 2654435761)) >>> 0);
|
|
1204
1756
|
return {
|
|
1205
|
-
x:
|
|
1206
|
-
z:
|
|
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
|
|
1211
|
-
function
|
|
1212
|
-
let r =
|
|
1213
|
-
return
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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[
|
|
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
|
|
1238
|
-
let a =
|
|
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 *
|
|
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
|
|
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
|
-
},
|
|
1256
|
-
function
|
|
1257
|
-
let t =
|
|
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 *
|
|
1260
|
-
a[e * 81 + t] =
|
|
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 =
|
|
1814
|
+
a = kr(kr(a));
|
|
1263
1815
|
let o = [{
|
|
1264
|
-
x: 20 *
|
|
1265
|
-
z: 80 *
|
|
1816
|
+
x: 20 * R + J(t, -4, 4),
|
|
1817
|
+
z: 80 * R + J(t, -40, 40)
|
|
1266
1818
|
}, {
|
|
1267
|
-
x: 140 *
|
|
1268
|
-
z: 80 *
|
|
1819
|
+
x: 140 * R + J(t, -4, 4),
|
|
1820
|
+
z: 80 * R + J(t, -40, 40)
|
|
1269
1821
|
}];
|
|
1270
|
-
for (let e of o)
|
|
1271
|
-
let s = [], c =
|
|
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 =
|
|
1274
|
-
e === "wall" && (n >= r ? r = 2 *
|
|
1275
|
-
let i =
|
|
1276
|
-
if (o.some((e) =>
|
|
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) =>
|
|
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]) =>
|
|
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 =
|
|
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 =
|
|
1301
|
-
o.some((t) =>
|
|
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
|
|
1317
|
-
let a = r * r, o = (e) =>
|
|
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 *
|
|
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
|
|
1329
|
-
return e.filter((e) => !t.some((t) =>
|
|
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
|
|
1333
|
-
return Math.trunc((2e4 + 600 * e) *
|
|
1884
|
+
function Ir(e, t) {
|
|
1885
|
+
return Math.trunc((2e4 + 600 * e) * H[t].speedPct / 100);
|
|
1334
1886
|
}
|
|
1335
|
-
function
|
|
1336
|
-
let 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 +
|
|
1339
|
-
y: e.y +
|
|
1340
|
-
z: e.z +
|
|
1341
|
-
vx:
|
|
1342
|
-
vy:
|
|
1343
|
-
vz:
|
|
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
|
|
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
|
|
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 (
|
|
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 &&
|
|
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 =
|
|
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
|
|
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
|
|
1438
|
-
let r =
|
|
1439
|
-
if (t.ammo !== "cluster") return [
|
|
1440
|
-
let i =
|
|
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 = [
|
|
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
|
|
1447
|
-
let { x: s, y: c, z: l } = i.impact, { vx: u, vy: d, vz: f } = i.velocity, p =
|
|
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(
|
|
2011
|
+
a.push(Br("bomblet", i.ticks, p, _r));
|
|
1460
2012
|
}
|
|
1461
2013
|
return a;
|
|
1462
2014
|
}
|
|
1463
|
-
function
|
|
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 +
|
|
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
|
|
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
|
|
1490
|
-
let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (
|
|
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) =>
|
|
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 =
|
|
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 *
|
|
2084
|
+
used: m * B,
|
|
1533
2085
|
stop: h
|
|
1534
2086
|
};
|
|
1535
2087
|
}
|
|
1536
2088
|
// src/games/tanks/logic/game.js
|
|
1537
|
-
var
|
|
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
|
-
}),
|
|
1541
|
-
function
|
|
1542
|
-
if (!
|
|
1543
|
-
if (!
|
|
1544
|
-
let { heights: i, spawns: a, obstacles: o, decor: s } =
|
|
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:
|
|
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:
|
|
1554
|
-
ammo: { ...
|
|
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
|
|
1581
|
-
return !e || !t || typeof t != "object" ?
|
|
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
|
|
1584
|
-
let n =
|
|
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
|
|
1588
|
-
if (!
|
|
1589
|
-
if (!
|
|
1590
|
-
if (!
|
|
1591
|
-
if (!
|
|
1592
|
-
if (typeof t.ammo != "string" || !Object.hasOwn(
|
|
1593
|
-
let i =
|
|
1594
|
-
return i > 0 && e.tanks[r].ammo[t.ammo] < i ?
|
|
1595
|
-
}
|
|
1596
|
-
function
|
|
1597
|
-
let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o =
|
|
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 =
|
|
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 =
|
|
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:
|
|
2182
|
+
craters: Ur(u),
|
|
1631
2183
|
wind: o
|
|
1632
2184
|
};
|
|
1633
2185
|
}
|
|
1634
|
-
function
|
|
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
|
|
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 =
|
|
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)
|
|
2208
|
+
for (let e of i.craters) Pr(a, e);
|
|
1657
2209
|
}
|
|
1658
|
-
let o = i.craters.length ?
|
|
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:
|
|
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 =
|
|
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
|
|
1689
|
-
if (l[0] || l[1]) return
|
|
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
|
|
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
|
|
2251
|
+
function $r(e, t) {
|
|
1700
2252
|
if (!t || typeof t != "object") return e;
|
|
1701
|
-
if (t.type === "turn") return
|
|
1702
|
-
if (!
|
|
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
|
|
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 ?
|
|
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
|
|
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
|
|
2284
|
+
function ti(e, t) {
|
|
1733
2285
|
let n = t | 0;
|
|
1734
|
-
|
|
2286
|
+
ei(e, n & 255), ei(e, n >>> 8 & 255), ei(e, n >>> 16 & 255), ei(e, n >>> 24 & 255);
|
|
1735
2287
|
}
|
|
1736
|
-
function
|
|
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)
|
|
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
|
|
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
|
-
]),
|
|
1823
|
-
function
|
|
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 =
|
|
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 + (
|
|
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
|
|
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
|
-
],
|
|
2411
|
+
], ui = (e, t) => ({
|
|
1860
2412
|
...e,
|
|
1861
2413
|
status: "conflict",
|
|
1862
2414
|
error: t
|
|
1863
|
-
}),
|
|
1864
|
-
function
|
|
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),
|
|
2418
|
+
return globalThis.crypto.getRandomValues(e), di(e);
|
|
1867
2419
|
}
|
|
1868
|
-
var
|
|
1869
|
-
function
|
|
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
|
|
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],
|
|
1904
|
-
function
|
|
1905
|
-
let n =
|
|
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 =
|
|
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:
|
|
2474
|
+
ammo: gt[t[5]]
|
|
1923
2475
|
};
|
|
1924
2476
|
}
|
|
1925
|
-
function
|
|
1926
|
-
let i =
|
|
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 :
|
|
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
|
|
1948
|
-
if (
|
|
1949
|
-
let r =
|
|
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:
|
|
2503
|
+
players: Z(e),
|
|
1952
2504
|
firstPlayerId: e.firstPlayerId,
|
|
1953
|
-
seed:
|
|
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:
|
|
2517
|
+
turnId: Z(e)[r.turnIndex],
|
|
1966
2518
|
error: ""
|
|
1967
2519
|
};
|
|
1968
2520
|
}
|
|
1969
|
-
function
|
|
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 (
|
|
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 :
|
|
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
|
|
1997
|
-
let i =
|
|
1998
|
-
if (r.ply <= e.ply) return
|
|
1999
|
-
if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return
|
|
2000
|
-
if (t.type !== "tk_resign" && n !==
|
|
2001
|
-
let o =
|
|
2002
|
-
return o ? t.type === "tk_turn" &&
|
|
2003
|
-
}
|
|
2004
|
-
function
|
|
2005
|
-
if (!
|
|
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:
|
|
2565
|
+
ammo: gt.indexOf(t.ammo)
|
|
2014
2566
|
};
|
|
2015
2567
|
if (n.ammo < 0) return null;
|
|
2016
|
-
let r =
|
|
2568
|
+
let r = xi(e, vi("tk_turn", n), "local", e.ownId);
|
|
2017
2569
|
return r ? {
|
|
2018
2570
|
...n,
|
|
2019
|
-
hash:
|
|
2571
|
+
hash: ni(r.logic)
|
|
2020
2572
|
} : null;
|
|
2021
2573
|
}
|
|
2022
|
-
function
|
|
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
|
|
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 (!
|
|
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
|
|
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 =
|
|
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 (!
|
|
2076
|
-
let i = e === t.log.length - 1, a = r[0] === 3 ?
|
|
2077
|
-
if (n =
|
|
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
|
|
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] ===
|
|
2643
|
+
return !!n && n[0] === vi(t.type, t.data, 0)[0];
|
|
2092
2644
|
}
|
|
2093
|
-
function
|
|
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
|
|
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
|
-
...
|
|
2668
|
+
...Ti(e)
|
|
2117
2669
|
};
|
|
2118
2670
|
}
|
|
2119
2671
|
// src/games/tanks/net/tankStorage.js
|
|
2120
|
-
var
|
|
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
|
|
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(
|
|
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
|
|
2147
|
-
let t = Date.now(), n =
|
|
2148
|
-
n.filter(({ value: e }) => !e || !(t - e.savedAt <
|
|
2149
|
-
let r = n.filter(({ value: e }) => e && t - e.savedAt <
|
|
2150
|
-
r.slice(0, Math.max(0, r.length -
|
|
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
|
|
2704
|
+
function Ri(e, t, n) {
|
|
2153
2705
|
try {
|
|
2154
|
-
let r =
|
|
2706
|
+
let r = Fi();
|
|
2155
2707
|
if (!r) return !1;
|
|
2156
|
-
let i =
|
|
2157
|
-
return r.setItem(
|
|
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
|
-
})),
|
|
2713
|
+
})), Li(r), !0;
|
|
2162
2714
|
} catch {
|
|
2163
2715
|
return !1;
|
|
2164
2716
|
}
|
|
2165
2717
|
}
|
|
2166
|
-
function
|
|
2718
|
+
function zi(e, t) {
|
|
2167
2719
|
try {
|
|
2168
|
-
let n = JSON.parse(
|
|
2169
|
-
return !n || typeof n != "object" || !(Date.now() - n.savedAt <
|
|
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
|
|
2726
|
+
function Bi(e) {
|
|
2175
2727
|
try {
|
|
2176
|
-
let t =
|
|
2177
|
-
return t ?
|
|
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
|
|
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),
|
|
2740
|
+
].includes(e.status), Ki = (e, t, n) => JSON.stringify([
|
|
2189
2741
|
e,
|
|
2190
2742
|
String(t),
|
|
2191
2743
|
n
|
|
2192
|
-
]),
|
|
2193
|
-
let t = Object.keys(e).filter((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
|
|
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 (
|
|
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 =
|
|
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
|
|
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
|
-
},
|
|
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),
|
|
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
|
|
2823
|
+
function $i(e, t, n) {
|
|
2272
2824
|
let r = {
|
|
2273
2825
|
...e,
|
|
2274
|
-
board:
|
|
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 =
|
|
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
|
|
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
|
|
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:
|
|
2324
|
-
rebuild: (e, t) =>
|
|
2325
|
-
compare: (e, t) =>
|
|
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 =
|
|
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
|
-
},
|
|
2899
|
+
}, ra = (e) => ({
|
|
2348
2900
|
requestType: "bs_sync_request",
|
|
2349
2901
|
stateType: "bs_sync_state",
|
|
2350
|
-
historyOf:
|
|
2351
|
-
rebuild: (t, n) =>
|
|
2352
|
-
compare: (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 &&
|
|
2360
|
-
markSeen:
|
|
2361
|
-
merge: (e, t) =>
|
|
2362
|
-
}),
|
|
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:
|
|
2366
|
-
rebuild:
|
|
2367
|
-
compare: (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 &&
|
|
2373
|
-
markSeen:
|
|
2924
|
+
covers: (e, t) => !!(e.pendingEvent && !e.pending && Oi(t, e.pendingEvent)),
|
|
2925
|
+
markSeen: ki,
|
|
2374
2926
|
merge: () => null
|
|
2375
|
-
},
|
|
2927
|
+
}, aa = (e) => ({
|
|
2376
2928
|
...e,
|
|
2377
2929
|
game: "connect4",
|
|
2378
2930
|
turnId: e.hostId,
|
|
2379
2931
|
status: "invited",
|
|
2380
|
-
board:
|
|
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
|
-
}),
|
|
2941
|
+
}), oa = (e, t, n) => F(t, {
|
|
2390
2942
|
game_id: e.gameId,
|
|
2391
2943
|
data: n,
|
|
2392
|
-
game:
|
|
2944
|
+
game: Q(e)
|
|
2393
2945
|
});
|
|
2394
|
-
function
|
|
2395
|
-
let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ??
|
|
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) =>
|
|
2398
|
-
apply: (e, t, n) =>
|
|
2399
|
-
sync:
|
|
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) =>
|
|
2403
|
-
apply: (e, t, r, i) =>
|
|
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) =>
|
|
2409
|
-
apply:
|
|
2960
|
+
create: (e, t) => at(e, t.data),
|
|
2961
|
+
apply: ot
|
|
2410
2962
|
},
|
|
2411
2963
|
tanks_live: {
|
|
2412
|
-
create: (e, t) =>
|
|
2413
|
-
apply:
|
|
2964
|
+
create: (e, t) => Ye(e, t.data),
|
|
2965
|
+
apply: Xe
|
|
2414
2966
|
},
|
|
2415
2967
|
tanks: {
|
|
2416
|
-
create: (e, t) =>
|
|
2417
|
-
apply: (e, t, n) =>
|
|
2418
|
-
sync:
|
|
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[
|
|
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 && !
|
|
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
|
-
...
|
|
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 =
|
|
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 =
|
|
2455
|
-
if (y &&
|
|
2456
|
-
if (
|
|
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: { ...
|
|
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 &&
|
|
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:
|
|
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 (!
|
|
2527
|
-
let
|
|
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 ===
|
|
2530
|
-
let
|
|
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(
|
|
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 =
|
|
2541
|
-
c.set(`${
|
|
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
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
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,
|
|
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" &&
|
|
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 (
|
|
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,
|
|
3125
|
+
return d().sendEvent(i.roomId, F(n, {
|
|
2569
3126
|
game_id: i.gameId,
|
|
2570
3127
|
data: o,
|
|
2571
|
-
game:
|
|
3128
|
+
game: Q(i)
|
|
2572
3129
|
}));
|
|
2573
3130
|
},
|
|
2574
3131
|
bsUpdateLocal: (e, t) => {
|
|
2575
3132
|
let n = d().games[e];
|
|
2576
|
-
if (!
|
|
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) =>
|
|
2584
|
-
bsRemoveShip: (e, t) => d().bsUpdateLocal(e, (e) =>
|
|
2585
|
-
bsRandomFleet: (e) => d().bsUpdateLocal(e, (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 (!
|
|
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 =
|
|
2592
|
-
if (!
|
|
2593
|
-
let a =
|
|
2594
|
-
if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(
|
|
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
|
-
}),
|
|
3155
|
+
}), sr(r.scope, r.gameId, {
|
|
2599
3156
|
fleet: i,
|
|
2600
3157
|
salt: a,
|
|
2601
3158
|
commitment: o
|
|
2602
|
-
}), d().sendEvent(r.roomId,
|
|
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 (!
|
|
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 (
|
|
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
|
-
},
|
|
3183
|
+
}, Gi));
|
|
2627
3184
|
},
|
|
2628
3185
|
bsRunEffects: (t) => {
|
|
2629
3186
|
let r = d().games[t];
|
|
2630
|
-
if (!
|
|
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),
|
|
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,
|
|
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 =
|
|
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 =
|
|
2668
|
-
|
|
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 (!
|
|
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 =
|
|
2683
|
-
if (i) return d().sendEvent(r.roomId,
|
|
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 (
|
|
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 (!(!
|
|
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
|
-
},
|
|
3271
|
+
}, Gi));
|
|
2715
3272
|
},
|
|
2716
3273
|
tkRunEffects: (t) => {
|
|
2717
3274
|
let n = d().games[t];
|
|
2718
|
-
if (!
|
|
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,
|
|
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
|
|
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 =
|
|
3298
|
+
let i = Ki(e, r.roomId, r.gameId);
|
|
2742
3299
|
if (d().games[i]) return;
|
|
2743
|
-
let a =
|
|
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: { ...
|
|
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:
|
|
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:
|
|
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
|
|
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
|
|
2803
|
-
if (
|
|
2804
|
-
|
|
2805
|
-
|
|
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:
|
|
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 =
|
|
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
|
-
...
|
|
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 =
|
|
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,
|
|
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 ||
|
|
3564
|
+
if (!r || Wi(r) || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
|
|
2992
3565
|
let i = {
|
|
2993
|
-
...
|
|
3566
|
+
...Xi,
|
|
2994
3567
|
...r.sync
|
|
2995
3568
|
};
|
|
2996
|
-
if (i.status === "requesting" && Date.now() - i.requestedAt <
|
|
3569
|
+
if (i.status === "requesting" && Date.now() - i.requestedAt < Yi || n && i.auto) return;
|
|
2997
3570
|
let a;
|
|
2998
3571
|
try {
|
|
2999
|
-
a =
|
|
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
|
-
},
|
|
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
|
|
3090
|
-
Object.assign(
|
|
3091
|
-
getState:
|
|
3092
|
-
setState:
|
|
3093
|
-
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
|
|
3097
|
-
function
|
|
3098
|
-
|
|
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
|
|
3101
|
-
return
|
|
3673
|
+
function ma() {
|
|
3674
|
+
return da;
|
|
3102
3675
|
}
|
|
3103
|
-
function
|
|
3104
|
-
return `${
|
|
3676
|
+
function ha(e) {
|
|
3677
|
+
return `${da}/${String(e).replace(/^\/+/, "")}`;
|
|
3105
3678
|
}
|
|
3106
|
-
export {
|
|
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-
|
|
3681
|
+
//# sourceMappingURL=games-Bl_8raG6.js.map
|