@minicode-dev/chat 0.1.7 → 0.1.9
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/README.md +25 -0
- package/dist/chunks/{BattleshipGameCard-CAWHxqJE.js → BattleshipGameCard-BFqA0cjT.js} +247 -246
- package/dist/chunks/{BattleshipGameCard-CAWHxqJE.js.map → BattleshipGameCard-BFqA0cjT.js.map} +1 -1
- package/dist/chunks/{ChatContext-CUiEAMKK.js → ChatContext-dty_KPDX.js} +2 -2
- package/dist/chunks/{ChatContext-CUiEAMKK.js.map → ChatContext-dty_KPDX.js.map} +1 -1
- package/dist/chunks/TanksGameCard-D0n-lzTs.js +1535 -0
- package/dist/chunks/TanksGameCard-D0n-lzTs.js.map +1 -0
- package/dist/chunks/TanksLiveGameCard-BmNRXP66.js +849 -0
- package/dist/chunks/TanksLiveGameCard-BmNRXP66.js.map +1 -0
- package/dist/chunks/WebRtcLab-B7xBlJy1.js +510 -0
- package/dist/chunks/WebRtcLab-B7xBlJy1.js.map +1 -0
- package/dist/chunks/{connect4Sounds-BDXQAvU1.js → connect4Sounds-BN7d_TM2.js} +654 -618
- package/dist/chunks/connect4Sounds-BN7d_TM2.js.map +1 -0
- package/dist/chunks/createLiveScene-CtYPcOPo.js +364 -0
- package/dist/chunks/createLiveScene-CtYPcOPo.js.map +1 -0
- package/dist/chunks/createPeerLink-qei05vpV.js +478 -0
- package/dist/chunks/createPeerLink-qei05vpV.js.map +1 -0
- package/dist/chunks/createTankScene-CV7Brxmt.js +685 -0
- package/dist/chunks/createTankScene-CV7Brxmt.js.map +1 -0
- package/dist/chunks/fx-BHsl4S_J.js +1470 -0
- package/dist/chunks/fx-BHsl4S_J.js.map +1 -0
- package/dist/chunks/gameStatus-Cu1Z8un9.js +69 -0
- package/dist/chunks/gameStatus-Cu1Z8un9.js.map +1 -0
- package/dist/chunks/signalFaults-Dv2YjjKy.js +36 -0
- package/dist/chunks/signalFaults-Dv2YjjKy.js.map +1 -0
- package/dist/chunks/tanksSounds-C99OD2xD.js +177 -0
- package/dist/chunks/tanksSounds-C99OD2xD.js.map +1 -0
- package/dist/index.js +1956 -1857
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/index.d.ts +61 -0
- package/package.json +1 -1
- package/dist/chunks/TanksGameCard-BEnXTz_J.js +0 -1705
- package/dist/chunks/TanksGameCard-BEnXTz_J.js.map +0 -1
- package/dist/chunks/connect4Sounds-BDXQAvU1.js.map +0 -1
- package/dist/chunks/createTankScene-BuliAxwR.js +0 -2150
- package/dist/chunks/createTankScene-BuliAxwR.js.map +0 -1
|
@@ -4,14 +4,73 @@ import { createStore as c } from "zustand/vanilla";
|
|
|
4
4
|
import { useStore as l } from "zustand";
|
|
5
5
|
import { Volume2 as u, VolumeX as d } from "lucide-react";
|
|
6
6
|
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
7
|
-
// src/games/tanks/
|
|
8
|
-
var m = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
7
|
+
// src/games/tanks-live/session.js
|
|
8
|
+
var m = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), h = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
|
|
9
|
+
function g(e) {
|
|
10
|
+
let t = e.data;
|
|
11
|
+
switch (e.type) {
|
|
12
|
+
case "game_invite": return h(t.opponent_id) && t.rules_version === 1 && (t.rematch_of === void 0 || m(t.rematch_of));
|
|
13
|
+
case "game_accept":
|
|
14
|
+
case "game_decline": return m(t.invite_event_id);
|
|
15
|
+
case "game_end": return t.reason === "closed";
|
|
16
|
+
default: return !1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _(e, t) {
|
|
20
|
+
return {
|
|
21
|
+
...e,
|
|
22
|
+
game: "tanks_live",
|
|
23
|
+
status: "invited",
|
|
24
|
+
turnId: null,
|
|
25
|
+
winnerId: null,
|
|
26
|
+
rematchOf: t.rematch_of ?? null,
|
|
27
|
+
pending: !1,
|
|
28
|
+
pendingEvent: null,
|
|
29
|
+
error: "",
|
|
30
|
+
acceptEventId: null
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function v(e, t, n) {
|
|
34
|
+
return [e.hostId, e.guestId].includes(n) ? t.type === "game_end" ? ["closed", "declined"].includes(e.status) ? e : {
|
|
35
|
+
...e,
|
|
36
|
+
status: "closed",
|
|
37
|
+
closedBy: n,
|
|
38
|
+
error: ""
|
|
39
|
+
} : e.status !== "invited" || n !== e.guestId || t.data.invite_event_id !== e.inviteEventId ? e : t.type === "game_decline" ? {
|
|
40
|
+
...e,
|
|
41
|
+
status: "declined",
|
|
42
|
+
lastEventId: t.event_id
|
|
43
|
+
} : t.type === "game_accept" ? {
|
|
44
|
+
...e,
|
|
45
|
+
status: "active",
|
|
46
|
+
acceptEventId: t.event_id,
|
|
47
|
+
lastEventId: t.event_id
|
|
48
|
+
} : e : e;
|
|
49
|
+
}
|
|
50
|
+
// src/net/webrtc/rtcSignals.js
|
|
51
|
+
var y = /* @__PURE__ */ new Set(), b = {
|
|
52
|
+
emit(e) {
|
|
53
|
+
y.forEach((t) => {
|
|
54
|
+
try {
|
|
55
|
+
t(e);
|
|
56
|
+
} catch {}
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
subscribe(e) {
|
|
60
|
+
return y.add(e), () => y.delete(e);
|
|
61
|
+
}
|
|
62
|
+
}, x = ({ send: e, roomId: t }) => ({
|
|
63
|
+
send: (n) => e(t, n),
|
|
64
|
+
subscribe: (e) => b.subscribe((n) => {
|
|
65
|
+
String(n.roomId) === String(t) && e(n);
|
|
66
|
+
})
|
|
67
|
+
}), S = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, ee = /^[0-9a-f]{16}$/, C = /^[0-9a-f]{32}$/, w = /^[0-9a-f]{64}$/, T = (e) => typeof e == "object" && !!e && !Array.isArray(e), te = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, E = (e) => typeof e == "string" && S.test(e), D = (e, t, n) => Number.isInteger(e) && e >= t && e <= n, O = Object.freeze([
|
|
9
68
|
"standard",
|
|
10
69
|
"heavy",
|
|
11
70
|
"cluster"
|
|
12
|
-
]),
|
|
13
|
-
function
|
|
14
|
-
return Array.isArray(e) ? e[0] === 1 ? e.length === 6 &&
|
|
71
|
+
]), ne = (e) => D(e, 1, 120), re = (e) => D(e.move, -16, 16) && D(e.yaw, 0, 359) && D(e.pitch, 5, 80) && D(e.power, 0, 100) && D(e.ammo, 0, O.length - 1);
|
|
72
|
+
function ie(e) {
|
|
73
|
+
return Array.isArray(e) ? e[0] === 1 ? e.length === 6 && re({
|
|
15
74
|
move: e[1],
|
|
16
75
|
yaw: e[2],
|
|
17
76
|
pitch: e[3],
|
|
@@ -19,91 +78,92 @@ function C(e) {
|
|
|
19
78
|
ammo: e[5]
|
|
20
79
|
}) : e[0] === 2 ? e.length === 1 : e[0] === 3 && e.length === 2 && (e[1] === 0 || e[1] === 1) : !1;
|
|
21
80
|
}
|
|
22
|
-
var
|
|
23
|
-
function
|
|
81
|
+
var ae = (e) => Array.isArray(e.log) && e.log.length <= 120 && e.log.every(ie) && E(e.head) && (e.accept_event_id === void 0 ? e.log.length === 0 && e.seed_b === void 0 && e.seed_a === void 0 : E(e.accept_event_id) && typeof e.seed_b == "string" && C.test(e.seed_b)) && (e.seed_a === void 0 ? e.log.length === 0 : C.test(e.seed_a) && E(e.seed_event_id));
|
|
82
|
+
function oe(e) {
|
|
24
83
|
let t = e.data;
|
|
25
84
|
switch (e.type) {
|
|
26
|
-
case "game_invite": return
|
|
27
|
-
case "game_accept": return
|
|
28
|
-
case "game_decline": return
|
|
85
|
+
case "game_invite": return te(t.opponent_id) && t.rules_version === 1 && typeof t.seed_commit == "string" && w.test(t.seed_commit) && (t.first_player_id === void 0 || te(t.first_player_id)) && (t.rematch_of === void 0 || E(t.rematch_of));
|
|
86
|
+
case "game_accept": return E(t.invite_event_id) && typeof t.seed_b == "string" && C.test(t.seed_b);
|
|
87
|
+
case "game_decline": return E(t.invite_event_id);
|
|
29
88
|
case "game_end": return t.reason === "closed";
|
|
30
|
-
case "tk_seed": return typeof t.seed_a == "string" &&
|
|
31
|
-
case "tk_turn": return
|
|
89
|
+
case "tk_seed": return typeof t.seed_a == "string" && C.test(t.seed_a);
|
|
90
|
+
case "tk_turn": return ne(t.ply) && E(t.prev_event_id) && re(t) && typeof t.hash == "string" && ee.test(t.hash);
|
|
32
91
|
case "tk_skip":
|
|
33
|
-
case "tk_resign": return
|
|
34
|
-
case "tk_sync_request": return
|
|
35
|
-
case "tk_sync_state": return
|
|
92
|
+
case "tk_resign": return ne(t.ply) && E(t.prev_event_id);
|
|
93
|
+
case "tk_sync_request": return T(t) && ae(t);
|
|
94
|
+
case "tk_sync_state": return T(t) && ae(t) && E(t.request_event_id);
|
|
36
95
|
default: return !1;
|
|
37
96
|
}
|
|
38
97
|
}
|
|
39
98
|
// src/games/shared/protocol.js
|
|
40
|
-
var
|
|
99
|
+
var k = "LIRA_GAME_V1:", se = 4096, ce = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, le = (e) => typeof e == "object" && !!e && !Array.isArray(e), ue = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, A = (e) => typeof e == "string" && ce.test(e), de = (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 && A(e[1])) && new Set(e.map((e) => e[1])).size === e.length, fe = (e) => de(e.moves) && e.rev === e.moves.length && (e.accept_event_id === void 0 ? e.moves.length === 0 : A(e.accept_event_id)), pe = [
|
|
41
100
|
"carrier",
|
|
42
101
|
"battleship",
|
|
43
102
|
"cruiser",
|
|
44
103
|
"submarine",
|
|
45
104
|
"destroyer"
|
|
46
|
-
],
|
|
47
|
-
function
|
|
105
|
+
], j = (e) => Number.isInteger(e) && e >= 0 && e < 10, me = (e) => typeof e == "string" && /^[0-9a-f]{64}$/.test(e), he = (e) => Number.isInteger(e) && e >= 1 && e <= 200, ge = (e) => e === null || le(e) && pe.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 && j(e[0]) && j(e[1])), _e = (e) => Array.isArray(e) && e.length === pe.length && e.every((e) => le(e) && pe.includes(e.ship_id) && j(e.row) && j(e.col) && (e.orientation === "horizontal" || e.orientation === "vertical")) && new Set(e.map((e) => e.ship_id)).size === e.length, ve = (e, t) => Array.isArray(e) && j(e[0]) && j(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] < pe.length && j(e[4]) && j(e[5]) && (e[6] === 0 || e[6] === 1)), ye = (e) => Array.isArray(e.commits) && e.commits.length === 2 && e.commits.every((e) => e === null || me(e)) && Array.isArray(e.log) && e.log.length <= 200 && e.log.every((t, n) => ve(t, n === e.log.length - 1)) && A(e.head) && (e.accept_event_id === void 0 ? e.commits.every((e) => e === null) && e.log.length === 0 : A(e.accept_event_id)) && (e.log.length === 0 || e.commits.every(Boolean));
|
|
106
|
+
function be(e) {
|
|
48
107
|
let t = e.data;
|
|
49
108
|
switch (e.type) {
|
|
50
|
-
case "game_invite": return
|
|
109
|
+
case "game_invite": return ue(t.opponent_id) && t.rules_version === 1;
|
|
51
110
|
case "game_accept":
|
|
52
|
-
case "game_decline": return
|
|
53
|
-
case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 ||
|
|
54
|
-
case "bs_commit": return
|
|
55
|
-
case "bs_fire": return
|
|
56
|
-
case "bs_result": return
|
|
57
|
-
case "bs_reveal": return
|
|
58
|
-
case "bs_sync_request": return
|
|
59
|
-
case "bs_sync_state": return
|
|
111
|
+
case "game_decline": return A(t.invite_event_id);
|
|
112
|
+
case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 || ue(t.winner_id));
|
|
113
|
+
case "bs_commit": return me(t.commitment);
|
|
114
|
+
case "bs_fire": return he(t.ply) && j(t.row) && j(t.col) && A(t.prev_event_id);
|
|
115
|
+
case "bs_result": return he(t.ply) && j(t.row) && j(t.col) && ["hit", "miss"].includes(t.result) && ge(t.sunk) && typeof t.defeated == "boolean" && (t.result === "hit" || t.sunk === null && !t.defeated);
|
|
116
|
+
case "bs_reveal": return _e(t.fleet) && typeof t.salt == "string" && /^[0-9a-f]{32}$/.test(t.salt);
|
|
117
|
+
case "bs_sync_request": return ye(t);
|
|
118
|
+
case "bs_sync_state": return ye(t) && A(t.request_event_id);
|
|
60
119
|
default: return !1;
|
|
61
120
|
}
|
|
62
121
|
}
|
|
63
|
-
function
|
|
122
|
+
function xe(e) {
|
|
64
123
|
return typeof e == "string" && e.startsWith("LIRA_GAME_V1:");
|
|
65
124
|
}
|
|
66
|
-
function
|
|
125
|
+
function Se(e) {
|
|
67
126
|
let t = e.data;
|
|
68
127
|
switch (e.type) {
|
|
69
|
-
case "game_invite": return
|
|
128
|
+
case "game_invite": return ue(t.opponent_id) && t.rules_version === 1;
|
|
70
129
|
case "game_accept":
|
|
71
|
-
case "game_decline": return
|
|
72
|
-
case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 &&
|
|
130
|
+
case "game_decline": return A(t.invite_event_id);
|
|
131
|
+
case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 && A(t.prev_event_id);
|
|
73
132
|
case "game_end": return [
|
|
74
133
|
"closed",
|
|
75
134
|
"win",
|
|
76
135
|
"draw"
|
|
77
|
-
].includes(t.reason) && (t.winner_id === void 0 ||
|
|
78
|
-
case "game_resync_request": return
|
|
79
|
-
case "game_resync_state": return
|
|
136
|
+
].includes(t.reason) && (t.winner_id === void 0 || ue(t.winner_id)) && (t.final_move_event_id === void 0 || A(t.final_move_event_id)) && (t.reason !== "win" || ue(t.winner_id) && A(t.final_move_event_id)) && (t.reason !== "draw" || A(t.final_move_event_id));
|
|
137
|
+
case "game_resync_request": return fe(t);
|
|
138
|
+
case "game_resync_state": return fe(t) && A(t.request_event_id);
|
|
80
139
|
default: return !1;
|
|
81
140
|
}
|
|
82
141
|
}
|
|
83
|
-
var
|
|
84
|
-
connect4:
|
|
85
|
-
battleship:
|
|
86
|
-
tanks:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
142
|
+
var Ce = {
|
|
143
|
+
connect4: Se,
|
|
144
|
+
battleship: be,
|
|
145
|
+
tanks: oe,
|
|
146
|
+
tanks_live: g
|
|
147
|
+
}, we = Object.freeze(Object.keys(Ce));
|
|
148
|
+
function Te(e) {
|
|
149
|
+
return !le(e) || e.version !== 1 || !Object.hasOwn(Ce, e.game) || !A(e.game_id) || !A(e.event_id) || !le(e.data) ? !1 : Ce[e.game](e);
|
|
90
150
|
}
|
|
91
|
-
function
|
|
92
|
-
if (!
|
|
151
|
+
function Ee(e) {
|
|
152
|
+
if (!xe(e) || e.length > se) return null;
|
|
93
153
|
try {
|
|
94
154
|
let t = JSON.parse(e.slice(13));
|
|
95
|
-
return
|
|
155
|
+
return Te(t) ? t : null;
|
|
96
156
|
} catch {
|
|
97
157
|
return null;
|
|
98
158
|
}
|
|
99
159
|
}
|
|
100
|
-
function
|
|
101
|
-
if (!
|
|
102
|
-
let t =
|
|
103
|
-
if (t.length >
|
|
160
|
+
function De(e) {
|
|
161
|
+
if (!Te(e)) throw Error("Evento de juego inválido");
|
|
162
|
+
let t = k + JSON.stringify(e);
|
|
163
|
+
if (t.length > se) throw Error("Evento de juego demasiado grande");
|
|
104
164
|
return t;
|
|
105
165
|
}
|
|
106
|
-
function
|
|
166
|
+
function M(e, { game_id: t, data: n, event_id: r = crypto.randomUUID(), game: i = "connect4" }) {
|
|
107
167
|
let a = {
|
|
108
168
|
version: 1,
|
|
109
169
|
game: i,
|
|
@@ -112,22 +172,22 @@ function j(e, { game_id: t, data: n, event_id: r = crypto.randomUUID(), game: i
|
|
|
112
172
|
type: e,
|
|
113
173
|
data: n
|
|
114
174
|
};
|
|
115
|
-
if (!
|
|
175
|
+
if (!Te(a)) throw Error("Evento de juego inválido");
|
|
116
176
|
return a;
|
|
117
177
|
}
|
|
118
|
-
function
|
|
178
|
+
function Oe() {
|
|
119
179
|
return Array.from({ length: 6 }, () => Array(7).fill(null));
|
|
120
180
|
}
|
|
121
|
-
var
|
|
181
|
+
var ke = [
|
|
122
182
|
[0, 1],
|
|
123
183
|
[1, 0],
|
|
124
184
|
[1, 1],
|
|
125
185
|
[1, -1]
|
|
126
186
|
];
|
|
127
|
-
function
|
|
187
|
+
function Ae(e) {
|
|
128
188
|
for (let t = 0; t < 6; t += 1) for (let n = 0; n < 7; n += 1) {
|
|
129
189
|
let r = e[t][n];
|
|
130
|
-
if (r != null) for (let [i, a] of
|
|
190
|
+
if (r != null) for (let [i, a] of ke) {
|
|
131
191
|
let o = [];
|
|
132
192
|
for (let s = 0; s < 4; s += 1) {
|
|
133
193
|
let c = t + i * s, l = n + a * s;
|
|
@@ -139,34 +199,34 @@ function Ce(e) {
|
|
|
139
199
|
}
|
|
140
200
|
return [];
|
|
141
201
|
}
|
|
142
|
-
function
|
|
143
|
-
let t =
|
|
202
|
+
function je(e) {
|
|
203
|
+
let t = Ae(e);
|
|
144
204
|
return t.length ? e[t[0][0]][t[0][1]] : null;
|
|
145
205
|
}
|
|
146
|
-
function
|
|
206
|
+
function Me(e) {
|
|
147
207
|
return e[0].every((e) => e !== null);
|
|
148
208
|
}
|
|
149
|
-
function
|
|
150
|
-
if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null ||
|
|
209
|
+
function Ne(e, t, n) {
|
|
210
|
+
if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null || je(e) !== null) return null;
|
|
151
211
|
let r = 5;
|
|
152
212
|
for (; r >= 0 && e[r][t] !== null;) --r;
|
|
153
213
|
if (r < 0) return null;
|
|
154
214
|
let i = e.map((e) => e.slice());
|
|
155
215
|
i[r][t] = n;
|
|
156
|
-
let a =
|
|
216
|
+
let a = Ae(i), o = a.length ? i[a[0][0]][a[0][1]] : null;
|
|
157
217
|
return {
|
|
158
218
|
board: i,
|
|
159
219
|
row: r,
|
|
160
220
|
column: t,
|
|
161
221
|
winner: o,
|
|
162
|
-
draw: o === null &&
|
|
222
|
+
draw: o === null && Me(i),
|
|
163
223
|
winningCells: a
|
|
164
224
|
};
|
|
165
225
|
}
|
|
166
226
|
// src/games/battleship/logic/game.js
|
|
167
|
-
var
|
|
168
|
-
function
|
|
169
|
-
if (!
|
|
227
|
+
var Pe = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
|
|
228
|
+
function Fe({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
|
|
229
|
+
if (!Pe(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Pe) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
|
|
170
230
|
return {
|
|
171
231
|
game: "battleship",
|
|
172
232
|
rulesVersion: 1,
|
|
@@ -183,7 +243,7 @@ function Oe({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
|
|
|
183
243
|
revision: 0
|
|
184
244
|
};
|
|
185
245
|
}
|
|
186
|
-
function
|
|
246
|
+
function Ie(n, r) {
|
|
187
247
|
if (!n || !r || typeof r != "object" || n.phase === "finished" || r.gameId !== void 0 && r.gameId !== n.gameId || r.expectedRevision !== void 0 && r.expectedRevision !== n.revision) return n;
|
|
188
248
|
let o = n.players.indexOf(r.playerId);
|
|
189
249
|
if (o < 0) return n;
|
|
@@ -239,16 +299,16 @@ function ke(n, r) {
|
|
|
239
299
|
};
|
|
240
300
|
}
|
|
241
301
|
// src/games/battleship/net/session.js
|
|
242
|
-
var
|
|
302
|
+
var Le = o.reduce((e, t) => e + t.size, 0), Re = /^[0-9a-f]{32}$/, ze = [
|
|
243
303
|
"won",
|
|
244
304
|
"closed",
|
|
245
305
|
"declined"
|
|
246
|
-
],
|
|
306
|
+
], N = "La partida perdió sincronización. Se intentará resincronizar.", Be = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", Ve = "El rival envió un resultado imposible para ese disparo.", He = "Tu flota no está disponible en este dispositivo; no se pueden responder disparos.", Ue = () => Array.from({ length: 10 }, () => Array(10).fill(null)), We = (e, t, n, r) => e.map((e, i) => i === t ? e.map((e, t) => t === n ? r : e) : e), Ge = (e) => e.reduce((e, t) => e + t.filter((e) => e === "hit").length, 0), Ke = (e) => e.reduce((e, t) => e + t.filter((e) => e !== null).length, 0), qe = (e, t) => t % 2 == 1 ? e.hostId : e.guestId, Je = (e, t) => t === e.hostId ? e.guestId : e.hostId, Ye = (e, t) => t === e.hostId ? "hostCommitment" : "guestCommitment", P = (e, t) => ({
|
|
247
307
|
...e,
|
|
248
308
|
status: "conflict",
|
|
249
309
|
error: t
|
|
250
|
-
}),
|
|
251
|
-
function
|
|
310
|
+
}), Xe = (e) => `${e.row},${e.col}`, Ze = (e, t) => e.row - t.row || e.col - t.col, Qe = (e, t) => e.length === t.length && e.map(Xe).sort().join("|") === t.map(Xe).sort().join("|");
|
|
311
|
+
function $e(e) {
|
|
252
312
|
return {
|
|
253
313
|
...e,
|
|
254
314
|
game: "battleship",
|
|
@@ -257,8 +317,8 @@ function Ke(e) {
|
|
|
257
317
|
myFleet: [],
|
|
258
318
|
myReady: !1,
|
|
259
319
|
opponentReady: !1,
|
|
260
|
-
incomingShots:
|
|
261
|
-
targetShots:
|
|
320
|
+
incomingShots: Ue(),
|
|
321
|
+
targetShots: Ue(),
|
|
262
322
|
sunkEnemyShips: [],
|
|
263
323
|
pendingShot: null,
|
|
264
324
|
lastShot: null,
|
|
@@ -280,7 +340,7 @@ function Ke(e) {
|
|
|
280
340
|
sync: e.sync ?? null
|
|
281
341
|
};
|
|
282
342
|
}
|
|
283
|
-
var
|
|
343
|
+
var et = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.status) && !e.myReady, tt = (e) => e?.status === "active" && e.turnId === e.ownId && !e.pendingShot, nt = (e) => ({
|
|
284
344
|
id: e.id,
|
|
285
345
|
size: e.size,
|
|
286
346
|
orientation: e.orientation,
|
|
@@ -288,33 +348,33 @@ var qe = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.
|
|
|
288
348
|
row: e.row,
|
|
289
349
|
col: e.col
|
|
290
350
|
}))
|
|
291
|
-
}),
|
|
351
|
+
}), rt = (e) => ({
|
|
292
352
|
shipId: e.id,
|
|
293
353
|
row: e.cells[0].row,
|
|
294
354
|
col: e.cells[0].col,
|
|
295
355
|
orientation: e.orientation
|
|
296
356
|
});
|
|
297
|
-
function
|
|
357
|
+
function it(e) {
|
|
298
358
|
return !e || typeof e != "object" ? null : typeof e.ship_id == "string" ? {
|
|
299
359
|
shipId: e.ship_id,
|
|
300
360
|
row: e.row,
|
|
301
361
|
col: e.col,
|
|
302
362
|
orientation: e.orientation
|
|
303
|
-
} : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ?
|
|
363
|
+
} : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ? rt(e) : null;
|
|
304
364
|
}
|
|
305
|
-
function
|
|
365
|
+
function at(e) {
|
|
306
366
|
if (!Array.isArray(e)) return null;
|
|
307
367
|
let t = r();
|
|
308
368
|
for (let n of e) {
|
|
309
|
-
let e =
|
|
369
|
+
let e = it(n), r = e && a(t, e);
|
|
310
370
|
if (!r?.ok) return null;
|
|
311
371
|
t = r.board;
|
|
312
372
|
}
|
|
313
373
|
return t;
|
|
314
374
|
}
|
|
315
|
-
function
|
|
375
|
+
function ot(e) {
|
|
316
376
|
if (!Array.isArray(e)) return null;
|
|
317
|
-
let t = e.map(
|
|
377
|
+
let t = e.map(it);
|
|
318
378
|
return t.some((e) => !e) ? null : t.map(({ shipId: e, row: t, col: n, orientation: r }) => ({
|
|
319
379
|
ship_id: e,
|
|
320
380
|
row: t,
|
|
@@ -322,21 +382,21 @@ function $e(e) {
|
|
|
322
382
|
orientation: r
|
|
323
383
|
})).sort((e, t) => e.ship_id < t.ship_id ? -1 : +(e.ship_id > t.ship_id));
|
|
324
384
|
}
|
|
325
|
-
function
|
|
326
|
-
let n =
|
|
327
|
-
return n && e(n) ? n.ships.map(
|
|
385
|
+
function st(t) {
|
|
386
|
+
let n = at(t);
|
|
387
|
+
return n && e(n) ? n.ships.map(nt) : null;
|
|
328
388
|
}
|
|
329
|
-
var
|
|
330
|
-
function
|
|
331
|
-
let n =
|
|
389
|
+
var ct = (e) => !!st(e);
|
|
390
|
+
function lt(t) {
|
|
391
|
+
let n = at(t?.myFleet);
|
|
332
392
|
return n && e(n) ? {
|
|
333
393
|
...n,
|
|
334
394
|
shots: t.incomingShots.map((e) => e.slice())
|
|
335
395
|
} : null;
|
|
336
396
|
}
|
|
337
|
-
function
|
|
338
|
-
if (!
|
|
339
|
-
let o =
|
|
397
|
+
function ut(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
|
|
398
|
+
if (!et(e)) return e;
|
|
399
|
+
let o = at(e.myFleet.filter((e) => e.id !== t)), s = o && a(o, {
|
|
340
400
|
shipId: t,
|
|
341
401
|
row: n,
|
|
342
402
|
col: r,
|
|
@@ -344,23 +404,23 @@ function rt(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
|
|
|
344
404
|
});
|
|
345
405
|
return s?.ok ? {
|
|
346
406
|
...e,
|
|
347
|
-
myFleet: s.board.ships.map(
|
|
407
|
+
myFleet: s.board.ships.map(nt)
|
|
348
408
|
} : e;
|
|
349
409
|
}
|
|
350
|
-
function
|
|
351
|
-
return !
|
|
410
|
+
function dt(e, t) {
|
|
411
|
+
return !et(e) || !e.myFleet.some((e) => e.id === t) ? e : {
|
|
352
412
|
...e,
|
|
353
413
|
myFleet: e.myFleet.filter((e) => e.id !== t)
|
|
354
414
|
};
|
|
355
415
|
}
|
|
356
|
-
function
|
|
416
|
+
function ft(e) {
|
|
357
417
|
let t = Math.floor(4294967296 / e) * e, n = /* @__PURE__ */ new Uint32Array(1);
|
|
358
418
|
do
|
|
359
419
|
globalThis.crypto.getRandomValues(n);
|
|
360
420
|
while (n[0] >= t);
|
|
361
421
|
return n[0] % e;
|
|
362
422
|
}
|
|
363
|
-
function
|
|
423
|
+
function pt(t = ft) {
|
|
364
424
|
for (let n = 0; n < 50; n += 1) {
|
|
365
425
|
let n = r();
|
|
366
426
|
for (let e of o) for (let r = 0; r < 300; r += 1) {
|
|
@@ -375,31 +435,31 @@ function ot(t = at) {
|
|
|
375
435
|
break;
|
|
376
436
|
}
|
|
377
437
|
}
|
|
378
|
-
if (e(n)) return n.ships.map(
|
|
438
|
+
if (e(n)) return n.ships.map(nt);
|
|
379
439
|
}
|
|
380
440
|
throw Error("No se pudo generar una flota aleatoria.");
|
|
381
441
|
}
|
|
382
|
-
var
|
|
442
|
+
var mt = (e, t) => et(e) ? {
|
|
383
443
|
...e,
|
|
384
|
-
myFleet:
|
|
385
|
-
} : e,
|
|
386
|
-
function
|
|
444
|
+
myFleet: pt(t)
|
|
445
|
+
} : e, ht = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
446
|
+
function gt() {
|
|
387
447
|
let e = /* @__PURE__ */ new Uint8Array(16);
|
|
388
|
-
return globalThis.crypto.getRandomValues(e),
|
|
448
|
+
return globalThis.crypto.getRandomValues(e), ht(e);
|
|
389
449
|
}
|
|
390
|
-
function
|
|
391
|
-
let n =
|
|
450
|
+
function _t(e, t) {
|
|
451
|
+
let n = ot(e);
|
|
392
452
|
if (!n || typeof t != "string") throw TypeError("Flota inválida");
|
|
393
453
|
return JSON.stringify({
|
|
394
454
|
fleet: n,
|
|
395
455
|
salt: t
|
|
396
456
|
});
|
|
397
457
|
}
|
|
398
|
-
async function
|
|
399
|
-
let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(
|
|
400
|
-
return
|
|
458
|
+
async function vt(e, t) {
|
|
459
|
+
let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(_t(e, t)));
|
|
460
|
+
return ht(new Uint8Array(n));
|
|
401
461
|
}
|
|
402
|
-
function
|
|
462
|
+
function yt(e, t) {
|
|
403
463
|
if (!e || !t) return null;
|
|
404
464
|
let n = i(e, {
|
|
405
465
|
row: t.row,
|
|
@@ -419,7 +479,7 @@ function ft(e, t) {
|
|
|
419
479
|
defeated: n.defeated
|
|
420
480
|
};
|
|
421
481
|
}
|
|
422
|
-
function
|
|
482
|
+
function bt(e) {
|
|
423
483
|
let t = o.find((t) => t.id === e?.ship_id);
|
|
424
484
|
if (!t || !Array.isArray(e.cells) || e.cells.length !== t.size) return null;
|
|
425
485
|
let r = e.cells.map((e) => Array.isArray(e) ? {
|
|
@@ -427,7 +487,7 @@ function pt(e) {
|
|
|
427
487
|
col: e[1]
|
|
428
488
|
} : null);
|
|
429
489
|
if (r.some((e) => !n(e))) return null;
|
|
430
|
-
r.sort(
|
|
490
|
+
r.sort(Ze);
|
|
431
491
|
let i = r.every((e, t) => e.row === r[0].row && e.col === r[0].col + t), a = r.every((e, t) => e.col === r[0].col && e.row === r[0].row + t);
|
|
432
492
|
return !i && !a ? null : {
|
|
433
493
|
id: t.id,
|
|
@@ -437,43 +497,43 @@ function pt(e) {
|
|
|
437
497
|
sunk: !0
|
|
438
498
|
};
|
|
439
499
|
}
|
|
440
|
-
function
|
|
500
|
+
function xt(e, t) {
|
|
441
501
|
let { row: n, col: r, result: i, sunk: a } = t, s = !!t.defeated;
|
|
442
502
|
if (i !== "hit" && i !== "miss" || e.targetShots[n][r] !== null) return null;
|
|
443
|
-
let c =
|
|
503
|
+
let c = We(e.targetShots, n, r, i), l = Ge(c), u = null;
|
|
444
504
|
if (a) {
|
|
445
|
-
if (u = i === "hit" ?
|
|
446
|
-
let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(
|
|
447
|
-
if (!u.cells.some((e) => e.row === n && e.col === r) || u.cells.some((e) => c[e.row][e.col] !== "hit" || t.has(
|
|
505
|
+
if (u = i === "hit" ? bt(a) : null, !u || e.sunkEnemyShips.some((e) => e.id === u.id)) return null;
|
|
506
|
+
let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(Xe)));
|
|
507
|
+
if (!u.cells.some((e) => e.row === n && e.col === r) || u.cells.some((e) => c[e.row][e.col] !== "hit" || t.has(Xe(e)))) return null;
|
|
448
508
|
}
|
|
449
509
|
let d = e.sunkEnemyShips.length + +!!u;
|
|
450
|
-
return l >
|
|
510
|
+
return l > Le || s !== (l === Le) || s !== (d === o.length) || !s && Le - l > 100 - Ke(c) ? null : {
|
|
451
511
|
shots: c,
|
|
452
512
|
ship: u
|
|
453
513
|
};
|
|
454
514
|
}
|
|
455
|
-
function
|
|
456
|
-
let n =
|
|
515
|
+
function St(e, t) {
|
|
516
|
+
let n = yt(lt(e), t);
|
|
457
517
|
if (!n || n.result !== t.result || n.defeated !== !!t.defeated || !!n.sunk != !!t.sunk) return null;
|
|
458
|
-
let r = n.sunk ?
|
|
459
|
-
return r && (t.sunk.ship_id !== r.id || !
|
|
518
|
+
let r = n.sunk ? bt(n.sunk) : null;
|
|
519
|
+
return r && (t.sunk.ship_id !== r.id || !Qe(r.cells, t.sunk.cells.map(([e, t]) => ({
|
|
460
520
|
row: e,
|
|
461
521
|
col: t
|
|
462
522
|
})))) ? null : {
|
|
463
|
-
shots:
|
|
523
|
+
shots: We(e.incomingShots, t.row, t.col, t.result),
|
|
464
524
|
ship: r
|
|
465
525
|
};
|
|
466
526
|
}
|
|
467
|
-
function
|
|
468
|
-
let i =
|
|
527
|
+
function Ct(e, t, n, r) {
|
|
528
|
+
let i = Ye(e, t);
|
|
469
529
|
if (e[i]) return e[i] === n ? e : null;
|
|
470
530
|
let a = {
|
|
471
531
|
...e,
|
|
472
532
|
[i]: n
|
|
473
533
|
};
|
|
474
534
|
if (t === e.ownId) {
|
|
475
|
-
let t = r?.commitment === n ?
|
|
476
|
-
t &&
|
|
535
|
+
let t = r?.commitment === n ? st(r.fleet) : null;
|
|
536
|
+
t && Re.test(r.salt ?? "") ? a = {
|
|
477
537
|
...a,
|
|
478
538
|
myFleet: t,
|
|
479
539
|
mySalt: r.salt,
|
|
@@ -483,7 +543,7 @@ function gt(e, t, n, r) {
|
|
|
483
543
|
myFleet: [],
|
|
484
544
|
mySalt: null,
|
|
485
545
|
myCommitment: n,
|
|
486
|
-
error:
|
|
546
|
+
error: He
|
|
487
547
|
}), a.myReady = !0;
|
|
488
548
|
} else a.opponentReady = !0;
|
|
489
549
|
return a.hostCommitment && a.guestCommitment && (a = {
|
|
@@ -494,7 +554,7 @@ function gt(e, t, n, r) {
|
|
|
494
554
|
pendingShot: null
|
|
495
555
|
}), a;
|
|
496
556
|
}
|
|
497
|
-
function
|
|
557
|
+
function wt(e, t, { row: r, col: i, ply: a }, o) {
|
|
498
558
|
let s = t === e.ownId ? e.targetShots : e.incomingShots;
|
|
499
559
|
return !n({
|
|
500
560
|
row: r,
|
|
@@ -510,8 +570,8 @@ function _t(e, t, { row: r, col: i, ply: a }, o) {
|
|
|
510
570
|
lastEventId: o ?? e.lastEventId
|
|
511
571
|
};
|
|
512
572
|
}
|
|
513
|
-
function
|
|
514
|
-
let i = e.pendingShot, a = t === e.ownId, o = a ?
|
|
573
|
+
function Tt(e, t, n, r) {
|
|
574
|
+
let i = e.pendingShot, a = t === e.ownId, o = a ? St(e, n) : xt(e, n);
|
|
515
575
|
if (!o) return null;
|
|
516
576
|
let s = !!n.defeated, c = {
|
|
517
577
|
ply: i.ply,
|
|
@@ -541,21 +601,21 @@ function vt(e, t, n, r) {
|
|
|
541
601
|
verification: s ? "pending" : e.verification
|
|
542
602
|
};
|
|
543
603
|
}
|
|
544
|
-
function
|
|
604
|
+
function Et(e, t, n) {
|
|
545
605
|
let { ply: r, row: i, col: a, prev_event_id: o } = t.data;
|
|
546
|
-
return n ===
|
|
606
|
+
return n === qe(e, r) ? e.status === "active" ? r <= e.ply ? e : e.pendingShot ? r === e.pendingShot.ply ? e : P(e, N) : r > e.ply + 1 ? P(e, N) : n === e.turnId ? o === e.lastEventId ? wt(e, n, {
|
|
547
607
|
row: i,
|
|
548
608
|
col: a,
|
|
549
609
|
ply: r
|
|
550
|
-
}, t.event_id) ?? e :
|
|
610
|
+
}, t.event_id) ?? e : P(e, N) : e : P(e, e.status === "invited" ? Be : N) : e;
|
|
551
611
|
}
|
|
552
|
-
function
|
|
612
|
+
function Dt(e, t, n) {
|
|
553
613
|
let { ply: r, row: i, col: a } = t.data;
|
|
554
|
-
if (e.status !== "active") return e.status === "placement" ?
|
|
614
|
+
if (e.status !== "active") return e.status === "placement" ? P(e, N) : e;
|
|
555
615
|
let o = e.pendingShot;
|
|
556
|
-
return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e :
|
|
616
|
+
return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e : P(e, "El rival respondió a un disparo distinto.") : Tt(e, n, t.data, t.event_id) || (n === e.ownId ? e : P(e, Ve)) : r < o.ply ? e : P(e, N) : r <= e.ply ? e : P(e, N);
|
|
557
617
|
}
|
|
558
|
-
function
|
|
618
|
+
function Ot(e, t, n) {
|
|
559
619
|
return !e.winnerId || !["won", "closed"].includes(e.status) ? e : n === e.ownId ? e.myRevealSent ? e : {
|
|
560
620
|
...e,
|
|
561
621
|
myRevealSent: !0
|
|
@@ -568,7 +628,7 @@ function xt(e, t, n) {
|
|
|
568
628
|
verification: "pending"
|
|
569
629
|
};
|
|
570
630
|
}
|
|
571
|
-
function
|
|
631
|
+
function kt(e, t, n, r = {}) {
|
|
572
632
|
if (!e || e.game !== "battleship" || t?.game !== "battleship" || t.game_id !== e.gameId || n !== e.hostId && n !== e.guestId) return e;
|
|
573
633
|
let i = t.data;
|
|
574
634
|
if (t.type === "game_end") return i.reason !== "closed" || [
|
|
@@ -581,8 +641,8 @@ function St(e, t, n, r = {}) {
|
|
|
581
641
|
closedBy: n,
|
|
582
642
|
error: ""
|
|
583
643
|
};
|
|
584
|
-
if (t.type === "bs_reveal") return
|
|
585
|
-
if (
|
|
644
|
+
if (t.type === "bs_reveal") return Ot(e, i, n);
|
|
645
|
+
if (ze.includes(e.status) || e.status === "conflict") return e;
|
|
586
646
|
switch (t.type) {
|
|
587
647
|
case "game_accept":
|
|
588
648
|
case "game_decline": return n !== e.guestId || e.status !== "invited" || i.invite_event_id !== e.inviteEventId ? e : t.type === "game_accept" ? {
|
|
@@ -595,32 +655,32 @@ function St(e, t, n, r = {}) {
|
|
|
595
655
|
status: "declined",
|
|
596
656
|
lastEventId: t.event_id
|
|
597
657
|
};
|
|
598
|
-
case "bs_commit": return e.status === "invited" ?
|
|
599
|
-
case "bs_fire": return
|
|
600
|
-
case "bs_result": return
|
|
658
|
+
case "bs_commit": return e.status === "invited" ? P(e, Be) : e.status === "placement" ? Ct(e, n, i.commitment, r.stored) ?? e : e;
|
|
659
|
+
case "bs_fire": return Et(e, t, n);
|
|
660
|
+
case "bs_result": return Dt(e, t, n);
|
|
601
661
|
default: return e;
|
|
602
662
|
}
|
|
603
663
|
}
|
|
604
|
-
function
|
|
605
|
-
let n =
|
|
664
|
+
function At(e, t) {
|
|
665
|
+
let n = Fe({
|
|
606
666
|
gameId: String(e.gameId),
|
|
607
667
|
players: [e.hostId, e.guestId],
|
|
608
668
|
firstPlayerId: e.hostId
|
|
609
669
|
});
|
|
610
670
|
for (let e of n.players) {
|
|
611
|
-
for (let r of t[e]) n =
|
|
671
|
+
for (let r of t[e]) n = Ie(n, {
|
|
612
672
|
type: "place_ship",
|
|
613
673
|
playerId: e,
|
|
614
|
-
...
|
|
674
|
+
...rt(r)
|
|
615
675
|
});
|
|
616
|
-
n =
|
|
676
|
+
n = Ie(n, {
|
|
617
677
|
type: "ready",
|
|
618
678
|
playerId: e
|
|
619
679
|
});
|
|
620
680
|
}
|
|
621
681
|
if (n.phase !== "playing") return !1;
|
|
622
682
|
for (let t of e.shots) {
|
|
623
|
-
let e =
|
|
683
|
+
let e = Ie(n, {
|
|
624
684
|
type: "fire",
|
|
625
685
|
playerId: t.by,
|
|
626
686
|
row: t.row,
|
|
@@ -631,30 +691,30 @@ function Ct(e, t) {
|
|
|
631
691
|
if (r.result !== t.result || r.defeated !== t.defeated || r.sunk !== !!t.sunk) return !1;
|
|
632
692
|
if (t.sunk) {
|
|
633
693
|
let n = e.boards[e.players.indexOf(r.targetId)].ships.find((e) => e.id === r.shipId);
|
|
634
|
-
if (t.sunk.id !== r.shipId || !
|
|
694
|
+
if (t.sunk.id !== r.shipId || !Qe(n.cells, t.sunk.cells)) return !1;
|
|
635
695
|
}
|
|
636
696
|
n = e;
|
|
637
697
|
}
|
|
638
698
|
return !e.winnerId || n.winnerId === e.winnerId;
|
|
639
699
|
}
|
|
640
|
-
async function
|
|
700
|
+
async function jt(e, t = e?.opponentReveal) {
|
|
641
701
|
if (!e || !t) return "pending";
|
|
642
|
-
let n =
|
|
643
|
-
if (!r || !i || typeof t.salt != "string" || !
|
|
702
|
+
let n = Je(e, e.ownId), r = e[Ye(e, n)], i = st(t.fleet);
|
|
703
|
+
if (!r || !i || typeof t.salt != "string" || !Re.test(t.salt)) return "mismatch";
|
|
644
704
|
let a;
|
|
645
705
|
try {
|
|
646
|
-
a = await
|
|
706
|
+
a = await vt(t.fleet, t.salt);
|
|
647
707
|
} catch {
|
|
648
708
|
return "mismatch";
|
|
649
709
|
}
|
|
650
710
|
if (a !== r) return "mismatch";
|
|
651
|
-
let o =
|
|
652
|
-
return o ?
|
|
711
|
+
let o = st(e.myFleet);
|
|
712
|
+
return o ? At(e, {
|
|
653
713
|
[e.ownId]: o,
|
|
654
714
|
[n]: i
|
|
655
715
|
}) ? "ok" : "mismatch" : "pending";
|
|
656
716
|
}
|
|
657
|
-
var
|
|
717
|
+
var Mt = (e) => {
|
|
658
718
|
if (e.result === "miss") return [
|
|
659
719
|
e.row,
|
|
660
720
|
e.col,
|
|
@@ -676,13 +736,13 @@ var Tt = (e) => {
|
|
|
676
736
|
+(e.sunk.orientation === "vertical")
|
|
677
737
|
];
|
|
678
738
|
};
|
|
679
|
-
function
|
|
739
|
+
function Nt(e) {
|
|
680
740
|
if (!e.acceptEventId) return {
|
|
681
741
|
commits: [null, null],
|
|
682
742
|
log: [],
|
|
683
743
|
head: e.inviteEventId
|
|
684
744
|
};
|
|
685
|
-
let t = e.shots.map(
|
|
745
|
+
let t = e.shots.map(Mt);
|
|
686
746
|
return e.pendingShot && t.push([e.pendingShot.row, e.pendingShot.col]), {
|
|
687
747
|
accept_event_id: e.acceptEventId,
|
|
688
748
|
commits: [e.hostCommitment ?? null, e.guestCommitment ?? null],
|
|
@@ -690,7 +750,7 @@ function Et(e) {
|
|
|
690
750
|
head: e.lastEventId
|
|
691
751
|
};
|
|
692
752
|
}
|
|
693
|
-
function
|
|
753
|
+
function Pt(e, t) {
|
|
694
754
|
let n = e.accept_event_id ?? null, r = t.accept_event_id ?? null;
|
|
695
755
|
if (n && r && n !== r) return "diverged";
|
|
696
756
|
let i = /* @__PURE__ */ new Set();
|
|
@@ -710,7 +770,7 @@ function Dt(e, t) {
|
|
|
710
770
|
}
|
|
711
771
|
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";
|
|
712
772
|
}
|
|
713
|
-
function
|
|
773
|
+
function Ft(e, t) {
|
|
714
774
|
if ((e.log ?? []).length || (t.log ?? []).length) return null;
|
|
715
775
|
let n = e.accept_event_id ?? t.accept_event_id;
|
|
716
776
|
return n ? {
|
|
@@ -720,15 +780,15 @@ function Ot(e, t) {
|
|
|
720
780
|
head: n
|
|
721
781
|
} : null;
|
|
722
782
|
}
|
|
723
|
-
function
|
|
783
|
+
function It(e, t, n = {}) {
|
|
724
784
|
let r = {
|
|
725
785
|
...e,
|
|
726
786
|
status: "invited",
|
|
727
787
|
turnId: null,
|
|
728
788
|
myReady: !1,
|
|
729
789
|
opponentReady: !1,
|
|
730
|
-
incomingShots:
|
|
731
|
-
targetShots:
|
|
790
|
+
incomingShots: Ue(),
|
|
791
|
+
targetShots: Ue(),
|
|
732
792
|
sunkEnemyShips: [],
|
|
733
793
|
pendingShot: null,
|
|
734
794
|
lastShot: null,
|
|
@@ -757,11 +817,11 @@ function kt(e, t, n = {}) {
|
|
|
757
817
|
acceptEventId: t.accept_event_id,
|
|
758
818
|
lastEventId: t.accept_event_id
|
|
759
819
|
};
|
|
760
|
-
for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (c =
|
|
820
|
+
for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (c = Ct(c, r, a[t], n.stored), !c)) return null;
|
|
761
821
|
if (i.length && c.status !== "active") return null;
|
|
762
822
|
for (let e = 0; e < i.length; e += 1) {
|
|
763
823
|
let t = i[e], n = e + 1;
|
|
764
|
-
if (c =
|
|
824
|
+
if (c = wt(c, qe(c, n), {
|
|
765
825
|
row: t[0],
|
|
766
826
|
col: t[1],
|
|
767
827
|
ply: n
|
|
@@ -770,7 +830,7 @@ function kt(e, t, n = {}) {
|
|
|
770
830
|
if (e !== i.length - 1) return null;
|
|
771
831
|
break;
|
|
772
832
|
}
|
|
773
|
-
let r =
|
|
833
|
+
let r = Je(c, c.pendingShot.by), a = null;
|
|
774
834
|
if (t[2] === 2) {
|
|
775
835
|
let e = o[t[3]];
|
|
776
836
|
if (!e) return null;
|
|
@@ -780,14 +840,14 @@ function kt(e, t, n = {}) {
|
|
|
780
840
|
cells: Array.from({ length: e.size }, (e, r) => [t[4] + (n ? r : 0), t[5] + (n ? 0 : r)])
|
|
781
841
|
};
|
|
782
842
|
}
|
|
783
|
-
let s =
|
|
784
|
-
if (c =
|
|
843
|
+
let s = Ge(r === c.ownId ? c.incomingShots : c.targetShots) + (t[2] === 0 ? 0 : 1);
|
|
844
|
+
if (c = Tt(c, r, {
|
|
785
845
|
ply: n,
|
|
786
846
|
row: t[0],
|
|
787
847
|
col: t[1],
|
|
788
848
|
result: t[2] === 0 ? "miss" : "hit",
|
|
789
849
|
sunk: a,
|
|
790
|
-
defeated: s ===
|
|
850
|
+
defeated: s === Le
|
|
791
851
|
}, null), !c || c.status === "won" && e !== i.length - 1) return null;
|
|
792
852
|
}
|
|
793
853
|
return !i.length && t.head !== t.accept_event_id ? null : (c = {
|
|
@@ -800,7 +860,7 @@ function kt(e, t, n = {}) {
|
|
|
800
860
|
verification: e.verification
|
|
801
861
|
}), c);
|
|
802
862
|
}
|
|
803
|
-
function
|
|
863
|
+
function Lt(e, t) {
|
|
804
864
|
if (!e || !t) return !1;
|
|
805
865
|
let n = e.log?.[(t.data?.ply ?? 0) - 1];
|
|
806
866
|
switch (t.type) {
|
|
@@ -811,37 +871,37 @@ function At(e, t) {
|
|
|
811
871
|
default: return !1;
|
|
812
872
|
}
|
|
813
873
|
}
|
|
814
|
-
function
|
|
874
|
+
function Rt(e, t) {
|
|
815
875
|
let n = { ...e };
|
|
816
876
|
return t.acceptEventId && (n[t.acceptEventId] = !0), t.lastEventId && (n[t.lastEventId] = !0), n;
|
|
817
877
|
}
|
|
818
878
|
// src/games/battleship/net/fleetStorage.js
|
|
819
|
-
var
|
|
879
|
+
var zt = "lira:bs:", Bt = 12096e5, Vt = (e, t) => `${zt}${e}:${t}`, Ht = () => {
|
|
820
880
|
try {
|
|
821
881
|
return globalThis.localStorage ?? null;
|
|
822
882
|
} catch {
|
|
823
883
|
return null;
|
|
824
884
|
}
|
|
825
885
|
};
|
|
826
|
-
function
|
|
886
|
+
function Ut(e) {
|
|
827
887
|
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);
|
|
828
888
|
}
|
|
829
|
-
function
|
|
889
|
+
function Wt(e) {
|
|
830
890
|
let t = Date.now();
|
|
831
891
|
for (let n = e.length - 1; n >= 0; --n) {
|
|
832
892
|
let r = e.key(n);
|
|
833
|
-
if (r?.startsWith(
|
|
893
|
+
if (r?.startsWith(zt)) try {
|
|
834
894
|
let n = JSON.parse(e.getItem(r));
|
|
835
|
-
|
|
895
|
+
Ut(n) && t - n.savedAt < Bt || e.removeItem(r);
|
|
836
896
|
} catch {
|
|
837
897
|
e.removeItem(r);
|
|
838
898
|
}
|
|
839
899
|
}
|
|
840
900
|
}
|
|
841
|
-
function
|
|
901
|
+
function Gt(e, t, { fleet: n, salt: r, commitment: i }) {
|
|
842
902
|
try {
|
|
843
|
-
let a =
|
|
844
|
-
return a ? (
|
|
903
|
+
let a = Ht();
|
|
904
|
+
return a ? (Wt(a), a.setItem(Vt(e, t), JSON.stringify({
|
|
845
905
|
fleet: n,
|
|
846
906
|
salt: r,
|
|
847
907
|
commitment: i,
|
|
@@ -851,10 +911,10 @@ function Rt(e, t, { fleet: n, salt: r, commitment: i }) {
|
|
|
851
911
|
return !1;
|
|
852
912
|
}
|
|
853
913
|
}
|
|
854
|
-
function
|
|
914
|
+
function Kt(e, t) {
|
|
855
915
|
try {
|
|
856
|
-
let n = JSON.parse(
|
|
857
|
-
return
|
|
916
|
+
let n = JSON.parse(Ht()?.getItem(Vt(e, t)) ?? "null");
|
|
917
|
+
return Ut(n) ? {
|
|
858
918
|
fleet: n.fleet,
|
|
859
919
|
salt: n.salt,
|
|
860
920
|
commitment: n.commitment
|
|
@@ -864,11 +924,11 @@ function zt(e, t) {
|
|
|
864
924
|
}
|
|
865
925
|
}
|
|
866
926
|
// src/games/tanks/logic/constants.js
|
|
867
|
-
var
|
|
868
|
-
2 *
|
|
869
|
-
var
|
|
870
|
-
4 *
|
|
871
|
-
var
|
|
927
|
+
var F = 1e5, qt = 160 * F, I = 2 * F, Jt = 20 * F;
|
|
928
|
+
2 * F;
|
|
929
|
+
var Yt = 1 * F;
|
|
930
|
+
4 * F, 4 * F;
|
|
931
|
+
var Xt = 18e4, Zt = 25e4, Qt = 5e4, $t = 25e3, en = 60 * F, tn = 4 * F, nn = Object.freeze({
|
|
872
932
|
move: Object.freeze([-16, 16]),
|
|
873
933
|
yaw: Object.freeze([0, 359]),
|
|
874
934
|
pitch: Object.freeze([5, 80]),
|
|
@@ -877,7 +937,7 @@ var Ut = 18e4, Wt = 25e4, Gt = 5e4, I = 25e3, Kt = 60 * P, qt = 4 * P, Jt = Obje
|
|
|
877
937
|
standard: Object.freeze({
|
|
878
938
|
id: "standard",
|
|
879
939
|
cost: 0,
|
|
880
|
-
radius: 6 *
|
|
940
|
+
radius: 6 * F,
|
|
881
941
|
maxDmg: 40,
|
|
882
942
|
depth: 15e4,
|
|
883
943
|
speedPct: 100
|
|
@@ -885,7 +945,7 @@ var Ut = 18e4, Wt = 25e4, Gt = 5e4, I = 25e3, Kt = 60 * P, qt = 4 * P, Jt = Obje
|
|
|
885
945
|
heavy: Object.freeze({
|
|
886
946
|
id: "heavy",
|
|
887
947
|
cost: 1,
|
|
888
|
-
radius: 8 *
|
|
948
|
+
radius: 8 * F,
|
|
889
949
|
maxDmg: 55,
|
|
890
950
|
depth: 25e4,
|
|
891
951
|
speedPct: 85
|
|
@@ -893,16 +953,16 @@ var Ut = 18e4, Wt = 25e4, Gt = 5e4, I = 25e3, Kt = 60 * P, qt = 4 * P, Jt = Obje
|
|
|
893
953
|
cluster: Object.freeze({
|
|
894
954
|
id: "cluster",
|
|
895
955
|
cost: 1,
|
|
896
|
-
radius: 4 *
|
|
956
|
+
radius: 4 * F,
|
|
897
957
|
maxDmg: 15,
|
|
898
958
|
depth: 8e4,
|
|
899
959
|
speedPct: 100
|
|
900
960
|
})
|
|
901
|
-
}),
|
|
902
|
-
radius: 4 *
|
|
961
|
+
}), rn = Object.freeze({
|
|
962
|
+
radius: 4 * F,
|
|
903
963
|
maxDmg: 15,
|
|
904
964
|
depth: 8e4
|
|
905
|
-
}),
|
|
965
|
+
}), an = Object.freeze([
|
|
906
966
|
Object.freeze([
|
|
907
967
|
0,
|
|
908
968
|
0,
|
|
@@ -928,10 +988,10 @@ var Ut = 18e4, Wt = 25e4, Gt = 5e4, I = 25e3, Kt = 60 * P, qt = 4 * P, Jt = Obje
|
|
|
928
988
|
0,
|
|
929
989
|
-6e3
|
|
930
990
|
])
|
|
931
|
-
]),
|
|
991
|
+
]), on = Object.freeze({
|
|
932
992
|
heavy: 2,
|
|
933
993
|
cluster: 2
|
|
934
|
-
}),
|
|
994
|
+
}), sn = Object.freeze([
|
|
935
995
|
0,
|
|
936
996
|
17452,
|
|
937
997
|
34899,
|
|
@@ -1023,20 +1083,20 @@ var Ut = 18e4, Wt = 25e4, Gt = 5e4, I = 25e3, Kt = 60 * P, qt = 4 * P, Jt = Obje
|
|
|
1023
1083
|
999391,
|
|
1024
1084
|
999848,
|
|
1025
1085
|
1e6
|
|
1026
|
-
]),
|
|
1027
|
-
function
|
|
1086
|
+
]), cn = 1e6;
|
|
1087
|
+
function ln(e) {
|
|
1028
1088
|
let t = (e % 360 + 360) % 360;
|
|
1029
|
-
return t <= 90 ?
|
|
1089
|
+
return t <= 90 ? sn[t] : t <= 180 ? sn[180 - t] : t <= 270 ? -sn[t - 180] : -sn[360 - t];
|
|
1030
1090
|
}
|
|
1031
|
-
function
|
|
1032
|
-
return
|
|
1091
|
+
function un(e) {
|
|
1092
|
+
return ln(e + 90);
|
|
1033
1093
|
}
|
|
1034
1094
|
function R(e, t) {
|
|
1035
|
-
return Math.trunc(e * t /
|
|
1095
|
+
return Math.trunc(e * t / cn);
|
|
1036
1096
|
}
|
|
1037
1097
|
// src/games/tanks/logic/rng.js
|
|
1038
|
-
var
|
|
1039
|
-
function
|
|
1098
|
+
var dn = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
|
|
1099
|
+
function fn(e) {
|
|
1040
1100
|
let t = e >>> 0;
|
|
1041
1101
|
return function() {
|
|
1042
1102
|
t = t + 1831565813 >>> 0;
|
|
@@ -1047,8 +1107,8 @@ function rn(e) {
|
|
|
1047
1107
|
function z(e, t, n) {
|
|
1048
1108
|
return t + e() % (n - t + 1);
|
|
1049
1109
|
}
|
|
1050
|
-
function
|
|
1051
|
-
let n =
|
|
1110
|
+
function pn(e, t) {
|
|
1111
|
+
let n = fn((e ^ Math.imul(t, 2654435761)) >>> 0);
|
|
1052
1112
|
return {
|
|
1053
1113
|
x: z(n, -40, 40),
|
|
1054
1114
|
z: z(n, -40, 40)
|
|
@@ -1057,10 +1117,10 @@ function an(e, t) {
|
|
|
1057
1117
|
// src/games/tanks/logic/terrain.js
|
|
1058
1118
|
var B = (e, t, n) => e < t ? t : e > n ? n : e, V = (e, t, n, r) => e + Math.trunc((t - e) * n / r);
|
|
1059
1119
|
function H(e, t, n) {
|
|
1060
|
-
let r = B(t, 0,
|
|
1061
|
-
return V(V(e[l + a], e[l + a + 1], s,
|
|
1120
|
+
let r = B(t, 0, qt), i = B(n, 0, qt), a = Math.min(Math.trunc(r / I), 79), o = Math.min(Math.trunc(i / I), 79), s = r - a * I, c = i - o * I, l = o * 81;
|
|
1121
|
+
return V(V(e[l + a], e[l + a + 1], s, I), V(e[l + 81 + a], e[l + 81 + a + 1], s, I), c, I);
|
|
1062
1122
|
}
|
|
1063
|
-
function
|
|
1123
|
+
function mn(e, t, n, r) {
|
|
1064
1124
|
let i = Math.trunc(80 / t) + 1, a = [];
|
|
1065
1125
|
for (let t = 0; t < i * i; t += 1) a.push(z(e, n, r) * 1e3);
|
|
1066
1126
|
return {
|
|
@@ -1069,11 +1129,11 @@ function on(e, t, n, r) {
|
|
|
1069
1129
|
values: a
|
|
1070
1130
|
};
|
|
1071
1131
|
}
|
|
1072
|
-
function
|
|
1132
|
+
function hn({ n: e, step: t, values: n }, r, i) {
|
|
1073
1133
|
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];
|
|
1074
1134
|
return V(V(l(a, o), l(a + 1, o), s, t), V(l(a, o + 1), l(a + 1, o + 1), s, t), c, t);
|
|
1075
1135
|
}
|
|
1076
|
-
function
|
|
1136
|
+
function gn(e) {
|
|
1077
1137
|
let t = new Int32Array(e.length);
|
|
1078
1138
|
for (let n = 0; n < 81; n += 1) for (let r = 0; r < 81; r += 1) {
|
|
1079
1139
|
let i = 0;
|
|
@@ -1082,10 +1142,10 @@ function cn(e) {
|
|
|
1082
1142
|
}
|
|
1083
1143
|
return t;
|
|
1084
1144
|
}
|
|
1085
|
-
function
|
|
1145
|
+
function _n(e, t, n, r, i) {
|
|
1086
1146
|
let a = H(e, t, n), o = r * r, s = i * i;
|
|
1087
1147
|
for (let r = 0; r < 81; r += 1) for (let c = 0; c < 81; c += 1) {
|
|
1088
|
-
let l = c *
|
|
1148
|
+
let l = c * I - t, u = r * I - n;
|
|
1089
1149
|
if (l > i || l < -i || u > i || u < -i) continue;
|
|
1090
1150
|
let d = l * l + u * u;
|
|
1091
1151
|
if (d >= s) continue;
|
|
@@ -1097,38 +1157,38 @@ function ln(e, t, n, r, i) {
|
|
|
1097
1157
|
}
|
|
1098
1158
|
}
|
|
1099
1159
|
}
|
|
1100
|
-
var U = (e, t, n) => z(e, t, n) * (
|
|
1160
|
+
var U = (e, t, n) => z(e, t, n) * (F / 2), vn = (e, t, n, r, i) => {
|
|
1101
1161
|
let a = e - n, o = t - r;
|
|
1102
1162
|
return a > i || a < -i || o > i || o < -i ? !1 : a * a + o * o < i * i;
|
|
1103
|
-
},
|
|
1104
|
-
function
|
|
1105
|
-
let t =
|
|
1163
|
+
}, yn = (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;
|
|
1164
|
+
function bn(e) {
|
|
1165
|
+
let t = fn(e), n = mn(t, 20, 0, 1200), r = mn(t, 10, -250, 250), i = mn(t, 4, -60, 60), a = /* @__PURE__ */ new Int32Array(6561);
|
|
1106
1166
|
for (let e = 0; e < 81; e += 1) for (let t = 0; t < 81; t += 1) {
|
|
1107
|
-
let o = 3 *
|
|
1108
|
-
a[e * 81 + t] = B(o, 0,
|
|
1167
|
+
let o = 3 * F + hn(n, t, e) + hn(r, t, e) + hn(i, t, e);
|
|
1168
|
+
a[e * 81 + t] = B(o, 0, Jt);
|
|
1109
1169
|
}
|
|
1110
|
-
a =
|
|
1170
|
+
a = gn(gn(a));
|
|
1111
1171
|
let o = [{
|
|
1112
|
-
x: 20 *
|
|
1113
|
-
z: 80 *
|
|
1172
|
+
x: 20 * F + U(t, -4, 4),
|
|
1173
|
+
z: 80 * F + U(t, -40, 40)
|
|
1114
1174
|
}, {
|
|
1115
|
-
x: 140 *
|
|
1116
|
-
z: 80 *
|
|
1175
|
+
x: 140 * F + U(t, -4, 4),
|
|
1176
|
+
z: 80 * F + U(t, -40, 40)
|
|
1117
1177
|
}];
|
|
1118
|
-
for (let e of o)
|
|
1178
|
+
for (let e of o) _n(a, e.x, e.z, tn, tn + 3 * F);
|
|
1119
1179
|
let s = [], c = z(t, 4, 6);
|
|
1120
1180
|
for (let e = 0; e < 200 && s.length < c; e += 1) {
|
|
1121
1181
|
let e = t() % 2 == 0 ? "rock" : "wall", n = U(t, 4, 12), r = U(t, 4, 12);
|
|
1122
|
-
e === "wall" && (n >= r ? r = 2 *
|
|
1123
|
-
let i = U(t, 4, 10), c = U(t, 100, 220), l = U(t, 40, 280), u = 12 *
|
|
1124
|
-
if (o.some((e) =>
|
|
1182
|
+
e === "wall" && (n >= r ? r = 2 * F : n = 2 * F);
|
|
1183
|
+
let i = U(t, 4, 10), c = U(t, 100, 220), l = U(t, 40, 280), u = 12 * F + (n > r ? n : r);
|
|
1184
|
+
if (o.some((e) => vn(e.x, e.z, c, l, u))) continue;
|
|
1125
1185
|
let d = {
|
|
1126
1186
|
x: c,
|
|
1127
1187
|
z: l,
|
|
1128
1188
|
w: n,
|
|
1129
1189
|
d: r
|
|
1130
1190
|
};
|
|
1131
|
-
if (s.some((e) =>
|
|
1191
|
+
if (s.some((e) => yn(e, c, l, (n > r ? n : r) + 4e5))) continue;
|
|
1132
1192
|
let f = [
|
|
1133
1193
|
[-1, -1],
|
|
1134
1194
|
[1, -1],
|
|
@@ -1146,7 +1206,7 @@ function fn(e) {
|
|
|
1146
1206
|
let l = [], u = z(t, 30, 60);
|
|
1147
1207
|
for (let e = 0; e < u * 10 && l.length < u; e += 1) {
|
|
1148
1208
|
let e = U(t, 4, 316), n = U(t, 4, 316), r = t() % 3 == 0 ? "rock" : "tree", i = z(t, 80, 140);
|
|
1149
|
-
o.some((t) =>
|
|
1209
|
+
o.some((t) => vn(t.x, t.z, e, n, 1e6)) || s.some((t) => yn(t, e, n, 2e5)) || l.push({
|
|
1150
1210
|
id: l.length,
|
|
1151
1211
|
kind: r,
|
|
1152
1212
|
x: e,
|
|
@@ -1161,10 +1221,10 @@ function fn(e) {
|
|
|
1161
1221
|
decor: l
|
|
1162
1222
|
};
|
|
1163
1223
|
}
|
|
1164
|
-
function
|
|
1165
|
-
let a = r * r, o = (e) => B(Math.trunc(e /
|
|
1224
|
+
function xn(e, { x: t, z: n, radius: r, depth: i }) {
|
|
1225
|
+
let a = r * r, o = (e) => B(Math.trunc(e / I) - 1, 0, 80);
|
|
1166
1226
|
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) {
|
|
1167
|
-
let o = c *
|
|
1227
|
+
let o = c * I - t, l = s * I - n;
|
|
1168
1228
|
if (o > r || o < -r || l > r || l < -r) continue;
|
|
1169
1229
|
let u = o * o + l * l;
|
|
1170
1230
|
if (u >= a) continue;
|
|
@@ -1173,29 +1233,29 @@ function pn(e, { x: t, z: n, radius: r, depth: i }) {
|
|
|
1173
1233
|
}
|
|
1174
1234
|
return e;
|
|
1175
1235
|
}
|
|
1176
|
-
function
|
|
1177
|
-
return e.filter((e) => !t.some((t) =>
|
|
1236
|
+
function Sn(e, t) {
|
|
1237
|
+
return e.filter((e) => !t.some((t) => vn(t.x, t.z, e.x, e.z, t.radius)));
|
|
1178
1238
|
}
|
|
1179
1239
|
// src/games/tanks/logic/ballistics.js
|
|
1180
|
-
function
|
|
1240
|
+
function Cn(e, t) {
|
|
1181
1241
|
return Math.trunc((2e4 + 600 * e) * L[t].speedPct / 100);
|
|
1182
1242
|
}
|
|
1183
|
-
function
|
|
1184
|
-
let a =
|
|
1243
|
+
function wn(e, { yaw: t, pitch: n, power: r, ammo: i }) {
|
|
1244
|
+
let a = un(n), o = ln(n), s = un(t), c = ln(t), l = R(Zt, a), u = Cn(r, i), d = R(u, a);
|
|
1185
1245
|
return {
|
|
1186
1246
|
x: e.x + R(l, s),
|
|
1187
|
-
y: e.y +
|
|
1247
|
+
y: e.y + Xt + R(Zt, o),
|
|
1188
1248
|
z: e.z + R(l, c),
|
|
1189
1249
|
vx: R(d, s),
|
|
1190
1250
|
vy: R(u, o),
|
|
1191
1251
|
vz: R(d, c)
|
|
1192
1252
|
};
|
|
1193
1253
|
}
|
|
1194
|
-
function
|
|
1254
|
+
function Tn(e, t, n, r, i, a, o) {
|
|
1195
1255
|
let s = e - r, c = t - i, l = n - a;
|
|
1196
1256
|
return s > o || s < -o || c > o || c < -o || l > o || l < -o ? !1 : s * s + c * c + l * l < o * o;
|
|
1197
1257
|
}
|
|
1198
|
-
function
|
|
1258
|
+
function En(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600, split: o = !1 }) {
|
|
1199
1259
|
let { x: s, y: c, z: l, vx: u, vy: d, vz: f } = e, p = [
|
|
1200
1260
|
s,
|
|
1201
1261
|
c,
|
|
@@ -1205,7 +1265,7 @@ function vn(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
|
|
|
1205
1265
|
let a = d;
|
|
1206
1266
|
u += t.x, d -= 392, f += t.z, s += u, c += d, l += f;
|
|
1207
1267
|
let m = null;
|
|
1208
|
-
for (let e of r) if (
|
|
1268
|
+
for (let e of r) if (Tn(s, c, l, e.x, e.y + 1e5, e.z, 2e5)) {
|
|
1209
1269
|
m = {
|
|
1210
1270
|
x: s,
|
|
1211
1271
|
y: c,
|
|
@@ -1216,7 +1276,7 @@ function vn(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
|
|
|
1216
1276
|
break;
|
|
1217
1277
|
}
|
|
1218
1278
|
if (!m) {
|
|
1219
|
-
let e = i.find((e) => c <= e.y + e.h &&
|
|
1279
|
+
let e = i.find((e) => c <= e.y + e.h && yn(e, s, l, 0));
|
|
1220
1280
|
e && (m = {
|
|
1221
1281
|
x: s,
|
|
1222
1282
|
y: c,
|
|
@@ -1272,7 +1332,7 @@ function vn(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
|
|
|
1272
1332
|
}
|
|
1273
1333
|
};
|
|
1274
1334
|
}
|
|
1275
|
-
var
|
|
1335
|
+
var Dn = (e, t, n, r) => ({
|
|
1276
1336
|
role: e,
|
|
1277
1337
|
startTick: t,
|
|
1278
1338
|
samples: n.samples,
|
|
@@ -1282,17 +1342,17 @@ var yn = (e, t, n, r) => ({
|
|
|
1282
1342
|
maxDmg: n.impact.kind === "split" ? 0 : r.maxDmg,
|
|
1283
1343
|
depth: n.impact.kind === "split" ? 0 : r.depth
|
|
1284
1344
|
});
|
|
1285
|
-
function
|
|
1286
|
-
let r =
|
|
1287
|
-
if (t.ammo !== "cluster") return [
|
|
1288
|
-
let i =
|
|
1345
|
+
function On(e, t, n) {
|
|
1346
|
+
let r = wn(e, t);
|
|
1347
|
+
if (t.ammo !== "cluster") return [Dn("main", 0, En(r, n), L[t.ammo])];
|
|
1348
|
+
let i = En(r, {
|
|
1289
1349
|
...n,
|
|
1290
1350
|
split: !0
|
|
1291
|
-
}), a = [
|
|
1351
|
+
}), a = [Dn("carrier", 0, i, rn)];
|
|
1292
1352
|
if (i.impact.kind !== "split") return a;
|
|
1293
1353
|
let o = (n.maxTicks ?? 600) - i.ticks;
|
|
1294
|
-
for (let [e, t, r] of
|
|
1295
|
-
let { x: s, y: c, z: l } = i.impact, { vx: u, vy: d, vz: f } = i.velocity, p =
|
|
1354
|
+
for (let [e, t, r] of an) {
|
|
1355
|
+
let { x: s, y: c, z: l } = i.impact, { vx: u, vy: d, vz: f } = i.velocity, p = En({
|
|
1296
1356
|
x: s,
|
|
1297
1357
|
y: c,
|
|
1298
1358
|
z: l,
|
|
@@ -1304,18 +1364,18 @@ function bn(e, t, n) {
|
|
|
1304
1364
|
maxTicks: o,
|
|
1305
1365
|
split: !1
|
|
1306
1366
|
});
|
|
1307
|
-
a.push(
|
|
1367
|
+
a.push(Dn("bomblet", i.ticks, p, rn));
|
|
1308
1368
|
}
|
|
1309
1369
|
return a;
|
|
1310
1370
|
}
|
|
1311
|
-
function
|
|
1371
|
+
function kn(e, t) {
|
|
1312
1372
|
let n = t.map(() => 0);
|
|
1313
1373
|
for (let r of e) {
|
|
1314
1374
|
let { impact: e, radius: i, maxDmg: a } = r;
|
|
1315
1375
|
if (e.kind === "out" || e.kind === "split") continue;
|
|
1316
1376
|
let o = i * i;
|
|
1317
1377
|
t.forEach((t, r) => {
|
|
1318
|
-
let s = t.y +
|
|
1378
|
+
let s = t.y + Yt;
|
|
1319
1379
|
e.kind === "tank" && e.tankId === t.id && (n[r] += 25);
|
|
1320
1380
|
let c = e.x - t.x, l = e.y - s, u = e.z - t.z;
|
|
1321
1381
|
if (c >= i || c <= -i || l >= i || l <= -i || u >= i || u <= -i) return;
|
|
@@ -1325,7 +1385,7 @@ function xn(e, t) {
|
|
|
1325
1385
|
}
|
|
1326
1386
|
return n;
|
|
1327
1387
|
}
|
|
1328
|
-
function
|
|
1388
|
+
function An(e) {
|
|
1329
1389
|
return e.filter((e) => e.impact.kind !== "out" && e.impact.kind !== "split").map((e) => ({
|
|
1330
1390
|
x: e.impact.x,
|
|
1331
1391
|
z: e.impact.z,
|
|
@@ -1334,8 +1394,8 @@ function Sn(e) {
|
|
|
1334
1394
|
}));
|
|
1335
1395
|
}
|
|
1336
1396
|
// src/games/tanks/logic/movement.js
|
|
1337
|
-
function
|
|
1338
|
-
let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (
|
|
1397
|
+
function jn(e, t, { heights: n, obstacles: r, others: i }) {
|
|
1398
|
+
let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (Qt / $t), s = Math.min(o, Math.trunc(e.fuel / $t)), c = a * R($t, un(e.hullYaw)), l = a * R($t, ln(e.hullYaw)), { x: u, z: d } = e, f = H(n, u, d), p = [{
|
|
1339
1399
|
x: u,
|
|
1340
1400
|
y: f,
|
|
1341
1401
|
z: d
|
|
@@ -1346,7 +1406,7 @@ function Cn(e, t, { heights: n, obstacles: r, others: i }) {
|
|
|
1346
1406
|
h = "border";
|
|
1347
1407
|
break;
|
|
1348
1408
|
}
|
|
1349
|
-
if (r.some((n) =>
|
|
1409
|
+
if (r.some((n) => yn(n, e, t, 2e5))) {
|
|
1350
1410
|
h = "obstacle";
|
|
1351
1411
|
break;
|
|
1352
1412
|
}
|
|
@@ -1377,19 +1437,19 @@ function Cn(e, t, { heights: n, obstacles: r, others: i }) {
|
|
|
1377
1437
|
x: u,
|
|
1378
1438
|
y: f,
|
|
1379
1439
|
z: d,
|
|
1380
|
-
used: m *
|
|
1440
|
+
used: m * $t,
|
|
1381
1441
|
stop: h
|
|
1382
1442
|
};
|
|
1383
1443
|
}
|
|
1384
1444
|
// src/games/tanks/logic/game.js
|
|
1385
|
-
var
|
|
1445
|
+
var Mn = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, W = (e) => ({
|
|
1386
1446
|
ok: !1,
|
|
1387
1447
|
reason: e
|
|
1388
|
-
}),
|
|
1389
|
-
function
|
|
1390
|
-
if (!
|
|
1391
|
-
if (!
|
|
1392
|
-
let { heights: i, spawns: a, obstacles: o, decor: s } =
|
|
1448
|
+
}), Nn = (e, [t, n]) => Number.isInteger(e) && e >= t && e <= n;
|
|
1449
|
+
function Pn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {}) {
|
|
1450
|
+
if (!Mn(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Mn) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
|
|
1451
|
+
if (!dn(r)) throw TypeError("Supply an integer seed in 0..0xffffffff.");
|
|
1452
|
+
let { heights: i, spawns: a, obstacles: o, decor: s } = bn(r), c = t.map((e, t) => ({
|
|
1393
1453
|
id: e,
|
|
1394
1454
|
x: a[t].x,
|
|
1395
1455
|
y: H(i, a[t].x, a[t].z),
|
|
@@ -1398,8 +1458,8 @@ function En({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {})
|
|
|
1398
1458
|
yaw: t === 0 ? 0 : 180,
|
|
1399
1459
|
pitch: 30,
|
|
1400
1460
|
hp: 100,
|
|
1401
|
-
fuel:
|
|
1402
|
-
ammo: { ...
|
|
1461
|
+
fuel: en,
|
|
1462
|
+
ammo: { ...on },
|
|
1403
1463
|
skips: 0
|
|
1404
1464
|
}));
|
|
1405
1465
|
return {
|
|
@@ -1425,24 +1485,24 @@ function En({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {})
|
|
|
1425
1485
|
revision: 0
|
|
1426
1486
|
};
|
|
1427
1487
|
}
|
|
1428
|
-
function
|
|
1488
|
+
function Fn(e, t) {
|
|
1429
1489
|
return !e || !t || typeof t != "object" ? W("invalid_action") : e.phase === "finished" ? W("game_finished") : t.gameId !== void 0 && t.gameId !== e.gameId ? W("wrong_game") : t.expectedRevision !== void 0 && t.expectedRevision !== e.revision ? W("stale_revision") : e.players.includes(t.playerId) ? { ok: !0 } : W("unknown_player");
|
|
1430
1490
|
}
|
|
1431
|
-
function
|
|
1432
|
-
let n =
|
|
1491
|
+
function In(e, t) {
|
|
1492
|
+
let n = Fn(e, t);
|
|
1433
1493
|
if (!n.ok) return n;
|
|
1434
1494
|
let r = e.players.indexOf(t.playerId);
|
|
1435
1495
|
if (r !== e.turnIndex) return W("not_your_turn");
|
|
1436
|
-
if (!
|
|
1437
|
-
if (!
|
|
1438
|
-
if (!
|
|
1439
|
-
if (!
|
|
1496
|
+
if (!Nn(t.move, nn.move)) return W("invalid_move");
|
|
1497
|
+
if (!Nn(t.yaw, nn.yaw)) return W("invalid_yaw");
|
|
1498
|
+
if (!Nn(t.pitch, nn.pitch)) return W("invalid_pitch");
|
|
1499
|
+
if (!Nn(t.power, nn.power)) return W("invalid_power");
|
|
1440
1500
|
if (typeof t.ammo != "string" || !Object.hasOwn(L, t.ammo)) return W("unknown_ammo");
|
|
1441
1501
|
let i = L[t.ammo].cost;
|
|
1442
1502
|
return i > 0 && e.tanks[r].ammo[t.ammo] < i ? W("out_of_ammo") : { ok: !0 };
|
|
1443
1503
|
}
|
|
1444
|
-
function
|
|
1445
|
-
let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o =
|
|
1504
|
+
function Ln(e, t, { maxTicks: n = 600 } = {}) {
|
|
1505
|
+
let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o = pn(e.seed, e.ply), s = jn(i, t.move ?? 0, {
|
|
1446
1506
|
heights: e.heights,
|
|
1447
1507
|
obstacles: e.obstacles,
|
|
1448
1508
|
others: [a]
|
|
@@ -1458,13 +1518,13 @@ function kn(e, t, { maxTicks: n = 600 } = {}) {
|
|
|
1458
1518
|
x: e.x,
|
|
1459
1519
|
y: e.y,
|
|
1460
1520
|
z: e.z
|
|
1461
|
-
}), u =
|
|
1521
|
+
}), u = On(c, t, {
|
|
1462
1522
|
wind: o,
|
|
1463
1523
|
heights: e.heights,
|
|
1464
1524
|
tanks: l,
|
|
1465
1525
|
obstacles: e.obstacles,
|
|
1466
1526
|
maxTicks: n
|
|
1467
|
-
}), d =
|
|
1527
|
+
}), d = kn(u, l), f = {};
|
|
1468
1528
|
return e.players.forEach((e, t) => {
|
|
1469
1529
|
f[e] = d[t];
|
|
1470
1530
|
}), {
|
|
@@ -1475,11 +1535,11 @@ function kn(e, t, { maxTicks: n = 600 } = {}) {
|
|
|
1475
1535
|
tankAfter: c,
|
|
1476
1536
|
shots: u,
|
|
1477
1537
|
damage: f,
|
|
1478
|
-
craters:
|
|
1538
|
+
craters: An(u),
|
|
1479
1539
|
wind: o
|
|
1480
1540
|
};
|
|
1481
1541
|
}
|
|
1482
|
-
function
|
|
1542
|
+
function Rn(e, t, n, r) {
|
|
1483
1543
|
return {
|
|
1484
1544
|
...e,
|
|
1485
1545
|
...r,
|
|
@@ -1490,7 +1550,7 @@ function G(e, t, n, r) {
|
|
|
1490
1550
|
revision: e.revision + 1
|
|
1491
1551
|
};
|
|
1492
1552
|
}
|
|
1493
|
-
function
|
|
1553
|
+
function zn(e, t) {
|
|
1494
1554
|
let n = e.turnIndex, r = {
|
|
1495
1555
|
playerId: t.playerId,
|
|
1496
1556
|
move: t.move,
|
|
@@ -1498,12 +1558,12 @@ function An(e, t) {
|
|
|
1498
1558
|
pitch: t.pitch,
|
|
1499
1559
|
power: t.power,
|
|
1500
1560
|
ammo: t.ammo
|
|
1501
|
-
}, i =
|
|
1561
|
+
}, i = Ln(e, r), a = e.heights;
|
|
1502
1562
|
if (i.craters.length) {
|
|
1503
1563
|
a = Int32Array.from(e.heights);
|
|
1504
|
-
for (let e of i.craters)
|
|
1564
|
+
for (let e of i.craters) xn(a, e);
|
|
1505
1565
|
}
|
|
1506
|
-
let o = i.craters.length ?
|
|
1566
|
+
let o = i.craters.length ? Sn(e.decor, i.craters) : e.decor, s = e.tanks.map((e, t) => {
|
|
1507
1567
|
let o = t === n ? i.tankAfter : e, s = {
|
|
1508
1568
|
...e,
|
|
1509
1569
|
ammo: { ...e.ammo },
|
|
@@ -1533,23 +1593,23 @@ function An(e, t) {
|
|
|
1533
1593
|
...i
|
|
1534
1594
|
}
|
|
1535
1595
|
}, l = s.map((e) => e.hp === 0);
|
|
1536
|
-
if (l[0] && l[1]) return
|
|
1537
|
-
if (l[0] || l[1]) return
|
|
1596
|
+
if (l[0] && l[1]) return Rn(c, -1, "destroyed");
|
|
1597
|
+
if (l[0] || l[1]) return Rn(c, +!!l[0], "destroyed");
|
|
1538
1598
|
if (c.shots >= c.maxShots) {
|
|
1539
1599
|
let [e, t] = s.map((e) => e.hp);
|
|
1540
|
-
return
|
|
1600
|
+
return Rn(c, e === t ? -1 : e > t ? 0 : 1, "max_shots");
|
|
1541
1601
|
}
|
|
1542
1602
|
return {
|
|
1543
1603
|
...c,
|
|
1544
1604
|
revision: e.revision + 1
|
|
1545
1605
|
};
|
|
1546
1606
|
}
|
|
1547
|
-
function
|
|
1607
|
+
function Bn(e, t) {
|
|
1548
1608
|
if (!t || typeof t != "object") return e;
|
|
1549
|
-
if (t.type === "turn") return
|
|
1550
|
-
if (!
|
|
1609
|
+
if (t.type === "turn") return In(e, t).ok ? zn(e, t) : e;
|
|
1610
|
+
if (!Fn(e, t).ok) return e;
|
|
1551
1611
|
let n = e.players.indexOf(t.playerId);
|
|
1552
|
-
if (t.type === "resign") return
|
|
1612
|
+
if (t.type === "resign") return Rn(e, 1 - n, "resign");
|
|
1553
1613
|
if (t.type === "skip") {
|
|
1554
1614
|
if (n !== e.turnIndex || t.reason !== void 0 && t.reason !== "timeout") return e;
|
|
1555
1615
|
let r = e.tanks[n].skips + 1, i = e.tanks.map((e, t) => t === n ? {
|
|
@@ -1566,22 +1626,22 @@ function jn(e, t) {
|
|
|
1566
1626
|
playerId: t.playerId
|
|
1567
1627
|
}
|
|
1568
1628
|
};
|
|
1569
|
-
return r >= 3 ?
|
|
1629
|
+
return r >= 3 ? Rn(a, 1 - n, "timeout") : {
|
|
1570
1630
|
...a,
|
|
1571
1631
|
revision: e.revision + 1
|
|
1572
1632
|
};
|
|
1573
1633
|
}
|
|
1574
1634
|
return e;
|
|
1575
1635
|
}
|
|
1576
|
-
function
|
|
1636
|
+
function Vn(e, t) {
|
|
1577
1637
|
let n = (e.lo ^ t) >>> 0, r = n * 435, i = r >>> 0, a = (r - i) / 4294967296;
|
|
1578
1638
|
e.hi = Math.imul(e.hi, 435) + a + (n << 8) >>> 0, e.lo = i;
|
|
1579
1639
|
}
|
|
1580
|
-
function
|
|
1640
|
+
function Hn(e, t) {
|
|
1581
1641
|
let n = t | 0;
|
|
1582
|
-
|
|
1642
|
+
Vn(e, n & 255), Vn(e, n >>> 8 & 255), Vn(e, n >>> 16 & 255), Vn(e, n >>> 24 & 255);
|
|
1583
1643
|
}
|
|
1584
|
-
function
|
|
1644
|
+
function Un(e) {
|
|
1585
1645
|
let t = {
|
|
1586
1646
|
hi: 3421674724,
|
|
1587
1647
|
lo: 2216829733
|
|
@@ -1598,11 +1658,11 @@ function Pn(e) {
|
|
|
1598
1658
|
];
|
|
1599
1659
|
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);
|
|
1600
1660
|
i.push(n, e.decor.length);
|
|
1601
|
-
for (let e of i)
|
|
1661
|
+
for (let e of i) Hn(t, e);
|
|
1602
1662
|
return t.hi.toString(16).padStart(8, "0") + t.lo.toString(16).padStart(8, "0");
|
|
1603
1663
|
}
|
|
1604
1664
|
// src/games/tanks/net/sha256.js
|
|
1605
|
-
var
|
|
1665
|
+
var Wn = new Uint32Array([
|
|
1606
1666
|
1116352408,
|
|
1607
1667
|
1899447441,
|
|
1608
1668
|
3049323471,
|
|
@@ -1667,8 +1727,8 @@ var Fn = new Uint32Array([
|
|
|
1667
1727
|
2756734187,
|
|
1668
1728
|
3204031479,
|
|
1669
1729
|
3329325298
|
|
1670
|
-
]),
|
|
1671
|
-
function
|
|
1730
|
+
]), G = (e, t) => e >>> t | e << 32 - t;
|
|
1731
|
+
function Gn(e) {
|
|
1672
1732
|
let t = new TextEncoder().encode(String(e)), n = t.length, r = new Uint8Array((n + 9 >> 6) + 1 << 6);
|
|
1673
1733
|
r.set(t), r[n] = 128;
|
|
1674
1734
|
let i = new DataView(r.buffer);
|
|
@@ -1686,12 +1746,12 @@ function In(e) {
|
|
|
1686
1746
|
for (let e = 0; e < r.length; e += 64) {
|
|
1687
1747
|
for (let t = 0; t < 16; t += 1) o[t] = i.getUint32(e + t * 4);
|
|
1688
1748
|
for (let e = 16; e < 64; e += 1) {
|
|
1689
|
-
let t =
|
|
1749
|
+
let t = G(o[e - 15], 7) ^ G(o[e - 15], 18) ^ o[e - 15] >>> 3, n = G(o[e - 2], 17) ^ G(o[e - 2], 19) ^ o[e - 2] >>> 10;
|
|
1690
1750
|
o[e] = o[e - 16] + t + o[e - 7] + n >>> 0;
|
|
1691
1751
|
}
|
|
1692
1752
|
let [t, n, r, s, c, l, u, d] = a;
|
|
1693
1753
|
for (let e = 0; e < 64; e += 1) {
|
|
1694
|
-
let i = d + (
|
|
1754
|
+
let i = d + (G(c, 6) ^ G(c, 11) ^ G(c, 25)) + (c & l ^ ~c & u) + Wn[e] + o[e] >>> 0, a = (G(t, 2) ^ G(t, 13) ^ G(t, 22)) + (t & n ^ t & r ^ n & r) >>> 0;
|
|
1695
1755
|
d = u, u = l, l = c, c = s + i >>> 0, s = r, r = n, n = t, t = i + a >>> 0;
|
|
1696
1756
|
}
|
|
1697
1757
|
a[0] += t, a[1] += n, a[2] += r, a[3] += s, a[4] += c, a[5] += l, a[6] += u, a[7] += d;
|
|
@@ -1699,22 +1759,22 @@ function In(e) {
|
|
|
1699
1759
|
return Array.from(a, (e) => e.toString(16).padStart(8, "0")).join("");
|
|
1700
1760
|
}
|
|
1701
1761
|
// src/games/tanks/net/session.js
|
|
1702
|
-
var
|
|
1762
|
+
var Kn = "La partida perdió sincronización. Se intentará resincronizar.", qn = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", Jn = "El rival reveló una semilla que no coincide con su invitación.", Yn = "Los resultados del disparo no coinciden entre dispositivos.", Xn = [
|
|
1703
1763
|
"won",
|
|
1704
1764
|
"draw",
|
|
1705
1765
|
"closed",
|
|
1706
1766
|
"declined"
|
|
1707
|
-
],
|
|
1767
|
+
], K = (e, t) => ({
|
|
1708
1768
|
...e,
|
|
1709
1769
|
status: "conflict",
|
|
1710
1770
|
error: t
|
|
1711
|
-
}),
|
|
1712
|
-
function
|
|
1771
|
+
}), Zn = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
1772
|
+
function Qn() {
|
|
1713
1773
|
let e = /* @__PURE__ */ new Uint8Array(16);
|
|
1714
|
-
return globalThis.crypto.getRandomValues(e),
|
|
1774
|
+
return globalThis.crypto.getRandomValues(e), Zn(e);
|
|
1715
1775
|
}
|
|
1716
|
-
var
|
|
1717
|
-
function
|
|
1776
|
+
var $n = (e) => Gn(`lira-tanks-seed:${e}`), er = (e, t) => parseInt(Gn(`lira-tanks-map:${e}:${t}`).slice(0, 8), 16) >>> 0;
|
|
1777
|
+
function tr(e, t) {
|
|
1718
1778
|
let n = t.first_player_id === e.guestId ? e.guestId : e.hostId;
|
|
1719
1779
|
return {
|
|
1720
1780
|
...e,
|
|
@@ -1741,21 +1801,21 @@ function Kn(e, t) {
|
|
|
1741
1801
|
sync: e.sync ?? null
|
|
1742
1802
|
};
|
|
1743
1803
|
}
|
|
1744
|
-
var
|
|
1804
|
+
var q = (e) => [e.hostId, e.guestId], nr = (e) => e.logic && e.logic.phase === "playing" ? q(e)[e.logic.turnIndex] : null, rr = (e) => e?.status === "active" && !e.pendingEvent && nr(e) === e.ownId, ir = (e, t, n) => e === "tk_turn" ? [
|
|
1745
1805
|
1,
|
|
1746
1806
|
t.move,
|
|
1747
1807
|
t.yaw,
|
|
1748
1808
|
t.pitch,
|
|
1749
1809
|
t.power,
|
|
1750
1810
|
t.ammo
|
|
1751
|
-
] : e === "tk_skip" ? [2] : [3, n],
|
|
1752
|
-
function
|
|
1753
|
-
let n =
|
|
1811
|
+
] : e === "tk_skip" ? [2] : [3, n], ar = (e, t) => e.length === t.length && e.every((e, n) => e === t[n]);
|
|
1812
|
+
function or(e, t) {
|
|
1813
|
+
let n = q(e);
|
|
1754
1814
|
if (t[0] === 3) return {
|
|
1755
1815
|
type: "resign",
|
|
1756
1816
|
playerId: n[t[1]]
|
|
1757
1817
|
};
|
|
1758
|
-
let r =
|
|
1818
|
+
let r = nr(e);
|
|
1759
1819
|
return t[0] === 2 ? {
|
|
1760
1820
|
type: "skip",
|
|
1761
1821
|
playerId: r,
|
|
@@ -1767,11 +1827,11 @@ function Zn(e, t) {
|
|
|
1767
1827
|
yaw: t[2],
|
|
1768
1828
|
pitch: t[3],
|
|
1769
1829
|
power: t[4],
|
|
1770
|
-
ammo:
|
|
1830
|
+
ammo: O[t[5]]
|
|
1771
1831
|
};
|
|
1772
1832
|
}
|
|
1773
|
-
function
|
|
1774
|
-
let i =
|
|
1833
|
+
function sr(e, t, n, r) {
|
|
1834
|
+
let i = Bn(e.logic, or(e, t));
|
|
1775
1835
|
if (i === e.logic) return null;
|
|
1776
1836
|
let a = i.phase === "finished";
|
|
1777
1837
|
return {
|
|
@@ -1786,19 +1846,19 @@ function Qn(e, t, n, r) {
|
|
|
1786
1846
|
author: r,
|
|
1787
1847
|
turn: i.lastTurn ?? null
|
|
1788
1848
|
},
|
|
1789
|
-
turnId: a ? null :
|
|
1849
|
+
turnId: a ? null : q(e)[i.turnIndex],
|
|
1790
1850
|
status: a ? i.result === "draw" ? "draw" : "won" : "active",
|
|
1791
1851
|
winnerId: i.winnerId ?? null,
|
|
1792
1852
|
result: i.result ?? null
|
|
1793
1853
|
};
|
|
1794
1854
|
}
|
|
1795
|
-
function
|
|
1796
|
-
if (
|
|
1797
|
-
let r =
|
|
1855
|
+
function cr(e, t, n) {
|
|
1856
|
+
if ($n(t) !== e.seedCommit) return null;
|
|
1857
|
+
let r = Pn({
|
|
1798
1858
|
gameId: e.gameId,
|
|
1799
|
-
players:
|
|
1859
|
+
players: q(e),
|
|
1800
1860
|
firstPlayerId: e.firstPlayerId,
|
|
1801
|
-
seed:
|
|
1861
|
+
seed: er(t, e.seedB)
|
|
1802
1862
|
});
|
|
1803
1863
|
return {
|
|
1804
1864
|
...e,
|
|
@@ -1810,11 +1870,11 @@ function $n(e, t, n) {
|
|
|
1810
1870
|
lastEventId: n,
|
|
1811
1871
|
lastAction: null,
|
|
1812
1872
|
status: "active",
|
|
1813
|
-
turnId:
|
|
1873
|
+
turnId: q(e)[r.turnIndex],
|
|
1814
1874
|
error: ""
|
|
1815
1875
|
};
|
|
1816
1876
|
}
|
|
1817
|
-
function
|
|
1877
|
+
function lr(e, t, n) {
|
|
1818
1878
|
if (![e.hostId, e.guestId].includes(n)) return e;
|
|
1819
1879
|
let r = t.data;
|
|
1820
1880
|
if (t.type === "game_end") return ["closed", "declined"].includes(e.status) ? e : {
|
|
@@ -1823,7 +1883,7 @@ function er(e, t, n) {
|
|
|
1823
1883
|
closedBy: n,
|
|
1824
1884
|
error: ""
|
|
1825
1885
|
};
|
|
1826
|
-
if (
|
|
1886
|
+
if (Xn.includes(e.status) || e.status === "conflict") return e;
|
|
1827
1887
|
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" ? {
|
|
1828
1888
|
...e,
|
|
1829
1889
|
status: "declined",
|
|
@@ -1835,22 +1895,22 @@ function er(e, t, n) {
|
|
|
1835
1895
|
acceptEventId: t.event_id,
|
|
1836
1896
|
lastEventId: t.event_id
|
|
1837
1897
|
};
|
|
1838
|
-
if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e :
|
|
1898
|
+
if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e : cr(e, r.seed_a, t.event_id) ?? K(e, Jn);
|
|
1839
1899
|
if (![
|
|
1840
1900
|
"tk_turn",
|
|
1841
1901
|
"tk_skip",
|
|
1842
1902
|
"tk_resign"
|
|
1843
1903
|
].includes(t.type)) return e;
|
|
1844
|
-
if (e.status !== "active") return
|
|
1845
|
-
let i =
|
|
1846
|
-
if (r.ply <= e.ply) return
|
|
1847
|
-
if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return
|
|
1848
|
-
if (t.type !== "tk_resign" && n !==
|
|
1849
|
-
let o =
|
|
1850
|
-
return o ? t.type === "tk_turn" &&
|
|
1851
|
-
}
|
|
1852
|
-
function
|
|
1853
|
-
if (!
|
|
1904
|
+
if (e.status !== "active") return K(e, qn);
|
|
1905
|
+
let i = q(e).indexOf(n), a = ir(t.type, r, i);
|
|
1906
|
+
if (r.ply <= e.ply) return ar(e.log[r.ply - 1] ?? [], a) ? e : K(e, Kn);
|
|
1907
|
+
if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return K(e, Kn);
|
|
1908
|
+
if (t.type !== "tk_resign" && n !== nr(e)) return e;
|
|
1909
|
+
let o = sr(e, a, t.event_id, n);
|
|
1910
|
+
return o ? t.type === "tk_turn" && Un(o.logic) !== r.hash ? K(e, Yn) : o : e;
|
|
1911
|
+
}
|
|
1912
|
+
function ur(e, t) {
|
|
1913
|
+
if (!rr(e)) return null;
|
|
1854
1914
|
let n = {
|
|
1855
1915
|
ply: e.ply + 1,
|
|
1856
1916
|
prev_event_id: e.lastEventId,
|
|
@@ -1858,16 +1918,16 @@ function tr(e, t) {
|
|
|
1858
1918
|
yaw: t.yaw,
|
|
1859
1919
|
pitch: t.pitch,
|
|
1860
1920
|
power: t.power,
|
|
1861
|
-
ammo:
|
|
1921
|
+
ammo: O.indexOf(t.ammo)
|
|
1862
1922
|
};
|
|
1863
1923
|
if (n.ammo < 0) return null;
|
|
1864
|
-
let r =
|
|
1924
|
+
let r = sr(e, ir("tk_turn", n), "local", e.ownId);
|
|
1865
1925
|
return r ? {
|
|
1866
1926
|
...n,
|
|
1867
|
-
hash:
|
|
1927
|
+
hash: Un(r.logic)
|
|
1868
1928
|
} : null;
|
|
1869
1929
|
}
|
|
1870
|
-
function
|
|
1930
|
+
function dr(e) {
|
|
1871
1931
|
let t = {
|
|
1872
1932
|
log: e.log ?? [],
|
|
1873
1933
|
head: e.lastEventId
|
|
@@ -1880,14 +1940,14 @@ function nr(e) {
|
|
|
1880
1940
|
seed_event_id: e.seedEventId
|
|
1881
1941
|
}), t;
|
|
1882
1942
|
}
|
|
1883
|
-
function
|
|
1943
|
+
function fr(e, t) {
|
|
1884
1944
|
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";
|
|
1885
1945
|
let n = Math.min(e.log.length, t.log.length);
|
|
1886
|
-
for (let r = 0; r < n; r += 1) if (!
|
|
1946
|
+
for (let r = 0; r < n; r += 1) if (!ar(e.log[r], t.log[r])) return "diverged";
|
|
1887
1947
|
let r = (e) => (e.seed_a ? 2 : +!!e.accept_event_id) * 1e3 + e.log.length;
|
|
1888
1948
|
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";
|
|
1889
1949
|
}
|
|
1890
|
-
function
|
|
1950
|
+
function pr(e, t) {
|
|
1891
1951
|
let n = {
|
|
1892
1952
|
...e,
|
|
1893
1953
|
status: "invited",
|
|
@@ -1917,16 +1977,16 @@ function ir(e, t) {
|
|
|
1917
1977
|
seedB: t.seed_b,
|
|
1918
1978
|
lastEventId: t.accept_event_id
|
|
1919
1979
|
}, !t.seed_a) return n;
|
|
1920
|
-
if (n =
|
|
1980
|
+
if (n = cr(n, t.seed_a, t.seed_event_id), !n) return null;
|
|
1921
1981
|
for (let e = 0; e < t.log.length; e += 1) {
|
|
1922
1982
|
let r = t.log[e];
|
|
1923
|
-
if (!
|
|
1924
|
-
let i = e === t.log.length - 1, a = r[0] === 3 ?
|
|
1925
|
-
if (n =
|
|
1983
|
+
if (!ie(r)) return null;
|
|
1984
|
+
let i = e === t.log.length - 1, a = r[0] === 3 ? q(n)[r[1]] : nr(n);
|
|
1985
|
+
if (n = sr(n, r, i ? t.head : `${t.seed_event_id}:${e + 1}`, a), !n) return null;
|
|
1926
1986
|
}
|
|
1927
1987
|
return n;
|
|
1928
1988
|
}
|
|
1929
|
-
function
|
|
1989
|
+
function mr(e, t) {
|
|
1930
1990
|
if (!t) return !1;
|
|
1931
1991
|
if (t.type === "tk_seed") return e.seed_a === t.data.seed_a;
|
|
1932
1992
|
if (t.type === "game_accept") return e.accept_event_id === t.event_id;
|
|
@@ -1936,9 +1996,9 @@ function ar(e, t) {
|
|
|
1936
1996
|
"tk_resign"
|
|
1937
1997
|
].includes(t.type)) return !1;
|
|
1938
1998
|
let n = e.log[t.data.ply - 1];
|
|
1939
|
-
return !!n && n[0] ===
|
|
1999
|
+
return !!n && n[0] === ir(t.type, t.data, 0)[0];
|
|
1940
2000
|
}
|
|
1941
|
-
function
|
|
2001
|
+
function hr(e, t) {
|
|
1942
2002
|
let n = { ...e };
|
|
1943
2003
|
return [
|
|
1944
2004
|
t.acceptEventId,
|
|
@@ -1948,7 +2008,7 @@ function or(e, t) {
|
|
|
1948
2008
|
e && (n[e] = !0);
|
|
1949
2009
|
}), n;
|
|
1950
2010
|
}
|
|
1951
|
-
function
|
|
2011
|
+
function gr(e) {
|
|
1952
2012
|
return {
|
|
1953
2013
|
gameId: e.gameId,
|
|
1954
2014
|
roomId: e.roomId,
|
|
@@ -1961,22 +2021,22 @@ function sr(e) {
|
|
|
1961
2021
|
inviteEventId: e.inviteEventId,
|
|
1962
2022
|
createdAt: e.createdAt,
|
|
1963
2023
|
status: e.status,
|
|
1964
|
-
...
|
|
2024
|
+
...dr(e)
|
|
1965
2025
|
};
|
|
1966
2026
|
}
|
|
1967
2027
|
// src/games/tanks/net/tankStorage.js
|
|
1968
|
-
var
|
|
2028
|
+
var _r = "lira:tk:", vr = 6048e5, yr = 20, br = (e, t) => `${_r}${e}:${t}`, xr = () => {
|
|
1969
2029
|
try {
|
|
1970
2030
|
return globalThis.localStorage ?? null;
|
|
1971
2031
|
} catch {
|
|
1972
2032
|
return null;
|
|
1973
2033
|
}
|
|
1974
2034
|
};
|
|
1975
|
-
function
|
|
2035
|
+
function Sr(e) {
|
|
1976
2036
|
let t = [];
|
|
1977
2037
|
for (let n = 0; n < e.length; n += 1) {
|
|
1978
2038
|
let r = e.key(n);
|
|
1979
|
-
if (r?.startsWith(
|
|
2039
|
+
if (r?.startsWith(_r)) try {
|
|
1980
2040
|
let n = JSON.parse(e.getItem(r));
|
|
1981
2041
|
t.push({
|
|
1982
2042
|
key: r,
|
|
@@ -1991,61 +2051,61 @@ function pr(e) {
|
|
|
1991
2051
|
}
|
|
1992
2052
|
return t;
|
|
1993
2053
|
}
|
|
1994
|
-
function
|
|
1995
|
-
let t = Date.now(), n =
|
|
1996
|
-
n.filter(({ value: e }) => !e || !(t - e.savedAt <
|
|
1997
|
-
let r = n.filter(({ value: e }) => e && t - e.savedAt <
|
|
1998
|
-
r.slice(0, Math.max(0, r.length -
|
|
2054
|
+
function Cr(e) {
|
|
2055
|
+
let t = Date.now(), n = Sr(e);
|
|
2056
|
+
n.filter(({ value: e }) => !e || !(t - e.savedAt < vr)).forEach(({ key: t }) => e.removeItem(t));
|
|
2057
|
+
let r = n.filter(({ value: e }) => e && t - e.savedAt < vr).sort((e, t) => e.value.savedAt - t.value.savedAt);
|
|
2058
|
+
r.slice(0, Math.max(0, r.length - yr)).forEach(({ key: t }) => e.removeItem(t));
|
|
1999
2059
|
}
|
|
2000
|
-
function
|
|
2060
|
+
function wr(e, t, n) {
|
|
2001
2061
|
try {
|
|
2002
|
-
let r =
|
|
2062
|
+
let r = xr();
|
|
2003
2063
|
if (!r) return !1;
|
|
2004
|
-
let i =
|
|
2005
|
-
return r.setItem(
|
|
2064
|
+
let i = Tr(e, t) ?? {};
|
|
2065
|
+
return r.setItem(br(e, t), JSON.stringify({
|
|
2006
2066
|
...i,
|
|
2007
2067
|
...n,
|
|
2008
2068
|
savedAt: Date.now()
|
|
2009
|
-
})),
|
|
2069
|
+
})), Cr(r), !0;
|
|
2010
2070
|
} catch {
|
|
2011
2071
|
return !1;
|
|
2012
2072
|
}
|
|
2013
2073
|
}
|
|
2014
|
-
function
|
|
2074
|
+
function Tr(e, t) {
|
|
2015
2075
|
try {
|
|
2016
|
-
let n = JSON.parse(
|
|
2017
|
-
return !n || typeof n != "object" || !(Date.now() - n.savedAt <
|
|
2076
|
+
let n = JSON.parse(xr()?.getItem(br(e, t)) ?? "null");
|
|
2077
|
+
return !n || typeof n != "object" || !(Date.now() - n.savedAt < vr) || n.seedA !== void 0 && !/^[0-9a-f]{32}$/.test(n.seedA) ? null : n;
|
|
2018
2078
|
} catch {
|
|
2019
2079
|
return null;
|
|
2020
2080
|
}
|
|
2021
2081
|
}
|
|
2022
|
-
function
|
|
2082
|
+
function Er(e) {
|
|
2023
2083
|
try {
|
|
2024
|
-
let t =
|
|
2025
|
-
return t ?
|
|
2084
|
+
let t = xr();
|
|
2085
|
+
return t ? Sr(t).filter(({ key: t, value: n }) => t.startsWith(`${_r}${e}:`) && n?.snapshot && Date.now() - n.savedAt < vr).map(({ value: e }) => e).sort((e, t) => t.savedAt - e.savedAt) : [];
|
|
2026
2086
|
} catch {
|
|
2027
2087
|
return [];
|
|
2028
2088
|
}
|
|
2029
2089
|
}
|
|
2030
2090
|
// src/games/shared/useChatGames.js
|
|
2031
|
-
var
|
|
2091
|
+
var Dr = we, J = (e) => e?.game ?? "connect4", Or = (e) => J(e) === "battleship", Y = (e) => J(e) === "tanks", kr = 250, X = (e) => [
|
|
2032
2092
|
"won",
|
|
2033
2093
|
"draw",
|
|
2034
2094
|
"closed",
|
|
2035
2095
|
"declined"
|
|
2036
|
-
].includes(e.status),
|
|
2096
|
+
].includes(e.status), Ar = (e, t, n) => JSON.stringify([
|
|
2037
2097
|
e,
|
|
2038
2098
|
String(t),
|
|
2039
2099
|
n
|
|
2040
|
-
]),
|
|
2041
|
-
let t = Object.keys(e).filter((t) =>
|
|
2100
|
+
]), jr = (e) => {
|
|
2101
|
+
let t = Object.keys(e).filter((t) => X(e[t]));
|
|
2042
2102
|
if (t.length <= 80) return e;
|
|
2043
2103
|
let n = { ...e };
|
|
2044
2104
|
return t.slice(0, t.length - 80).forEach((e) => {
|
|
2045
2105
|
delete n[e];
|
|
2046
2106
|
}), n;
|
|
2047
2107
|
};
|
|
2048
|
-
function
|
|
2108
|
+
function Mr(e, t, n) {
|
|
2049
2109
|
if (![e.hostId, e.guestId].includes(n)) return e;
|
|
2050
2110
|
if (t.type === "game_end" && t.data.reason === "closed") return ["closed", "declined"].includes(e.status) ? e : {
|
|
2051
2111
|
...e,
|
|
@@ -2053,7 +2113,7 @@ function Tr(e, t, n) {
|
|
|
2053
2113
|
closedBy: n,
|
|
2054
2114
|
error: ""
|
|
2055
2115
|
};
|
|
2056
|
-
if (
|
|
2116
|
+
if (X(e) || e.status === "conflict") return e;
|
|
2057
2117
|
if (t.type === "game_accept" || t.type === "game_decline") return n !== e.guestId || e.status !== "invited" || t.data.invite_event_id !== e.inviteEventId ? e : {
|
|
2058
2118
|
...e,
|
|
2059
2119
|
status: t.type === "game_accept" ? "active" : "declined",
|
|
@@ -2074,7 +2134,7 @@ function Tr(e, t, n) {
|
|
|
2074
2134
|
error: "La partida perdió sincronización. Ciérrala y envía una nueva invitación."
|
|
2075
2135
|
};
|
|
2076
2136
|
if (n !== e.turnId) return e;
|
|
2077
|
-
let o =
|
|
2137
|
+
let o = Ne(e.board, a, n);
|
|
2078
2138
|
return o ? {
|
|
2079
2139
|
...e,
|
|
2080
2140
|
board: o.board,
|
|
@@ -2092,7 +2152,7 @@ function Tr(e, t, n) {
|
|
|
2092
2152
|
turnId: n === e.hostId ? e.guestId : e.hostId
|
|
2093
2153
|
} : e;
|
|
2094
2154
|
}
|
|
2095
|
-
var
|
|
2155
|
+
var Nr = 8e3, Pr = {
|
|
2096
2156
|
status: "idle",
|
|
2097
2157
|
requestId: null,
|
|
2098
2158
|
requestedAt: 0,
|
|
@@ -2101,14 +2161,14 @@ var Er = 8e3, Dr = {
|
|
|
2101
2161
|
replies: [],
|
|
2102
2162
|
offer: null,
|
|
2103
2163
|
message: ""
|
|
2104
|
-
},
|
|
2164
|
+
}, Fr = (e) => [
|
|
2105
2165
|
"game_resync_request",
|
|
2106
2166
|
"game_resync_state",
|
|
2107
2167
|
"bs_sync_request",
|
|
2108
2168
|
"bs_sync_state",
|
|
2109
2169
|
"tk_sync_request",
|
|
2110
2170
|
"tk_sync_state"
|
|
2111
|
-
].includes(e),
|
|
2171
|
+
].includes(e), Ir = (e) => e.acceptEventId ? {
|
|
2112
2172
|
accept_event_id: e.acceptEventId,
|
|
2113
2173
|
moves: e.moves ?? [],
|
|
2114
2174
|
rev: (e.moves ?? []).length
|
|
@@ -2116,10 +2176,10 @@ var Er = 8e3, Dr = {
|
|
|
2116
2176
|
moves: [],
|
|
2117
2177
|
rev: 0
|
|
2118
2178
|
};
|
|
2119
|
-
function
|
|
2179
|
+
function Lr(e, t, n) {
|
|
2120
2180
|
let r = {
|
|
2121
2181
|
...e,
|
|
2122
|
-
board:
|
|
2182
|
+
board: Oe(),
|
|
2123
2183
|
ply: 0,
|
|
2124
2184
|
turnId: e.hostId,
|
|
2125
2185
|
winnerId: null,
|
|
@@ -2145,7 +2205,7 @@ function Ar(e, t, n) {
|
|
|
2145
2205
|
let [r, o] = n[t];
|
|
2146
2206
|
if (a.has(o)) return null;
|
|
2147
2207
|
a.add(o);
|
|
2148
|
-
let s = t % 2 == 0 ? e.hostId : e.guestId, c =
|
|
2208
|
+
let s = t % 2 == 0 ? e.hostId : e.guestId, c = Mr(i, {
|
|
2149
2209
|
type: "game_move",
|
|
2150
2210
|
event_id: o,
|
|
2151
2211
|
data: {
|
|
@@ -2159,18 +2219,18 @@ function Ar(e, t, n) {
|
|
|
2159
2219
|
}
|
|
2160
2220
|
return i;
|
|
2161
2221
|
}
|
|
2162
|
-
function
|
|
2222
|
+
function Rr(e, t) {
|
|
2163
2223
|
if (e.acceptEventId && t.acceptEventId && e.acceptEventId !== t.acceptEventId) return "diverged";
|
|
2164
2224
|
let n = Math.min(e.moves.length, t.moves.length);
|
|
2165
2225
|
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";
|
|
2166
2226
|
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";
|
|
2167
2227
|
}
|
|
2168
|
-
var
|
|
2228
|
+
var zr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEvent.event_id : null, Br = {
|
|
2169
2229
|
requestType: "game_resync_request",
|
|
2170
2230
|
stateType: "game_resync_state",
|
|
2171
|
-
historyOf:
|
|
2172
|
-
rebuild: (e, t) =>
|
|
2173
|
-
compare: (e, t) =>
|
|
2231
|
+
historyOf: Ir,
|
|
2232
|
+
rebuild: (e, t) => Lr(e, t.accept_event_id ?? null, t.moves),
|
|
2233
|
+
compare: (e, t) => Rr({
|
|
2174
2234
|
acceptEventId: e.acceptEventId ?? null,
|
|
2175
2235
|
moves: e.moves ?? []
|
|
2176
2236
|
}, {
|
|
@@ -2182,7 +2242,7 @@ var Mr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
|
|
|
2182
2242
|
moves: e.moves
|
|
2183
2243
|
}),
|
|
2184
2244
|
covers: (e, t) => {
|
|
2185
|
-
let n =
|
|
2245
|
+
let n = zr(e);
|
|
2186
2246
|
return !!(n && t.moves?.some((e) => e[1] === n));
|
|
2187
2247
|
},
|
|
2188
2248
|
markSeen: (e, t) => {
|
|
@@ -2192,40 +2252,40 @@ var Mr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
|
|
|
2192
2252
|
}), n;
|
|
2193
2253
|
},
|
|
2194
2254
|
merge: () => null
|
|
2195
|
-
},
|
|
2255
|
+
}, Vr = (e) => ({
|
|
2196
2256
|
requestType: "bs_sync_request",
|
|
2197
2257
|
stateType: "bs_sync_state",
|
|
2198
|
-
historyOf:
|
|
2199
|
-
rebuild: (t, n) =>
|
|
2200
|
-
compare: (e, t) =>
|
|
2258
|
+
historyOf: Nt,
|
|
2259
|
+
rebuild: (t, n) => It(t, n, { stored: e(t.scope, t.gameId) }),
|
|
2260
|
+
compare: (e, t) => Pt(Nt(e), t),
|
|
2201
2261
|
offerOf: (e) => ({
|
|
2202
2262
|
accept_event_id: e.accept_event_id,
|
|
2203
2263
|
commits: e.commits,
|
|
2204
2264
|
log: e.log,
|
|
2205
2265
|
head: e.head
|
|
2206
2266
|
}),
|
|
2207
|
-
covers: (e, t) => !!(e.pendingEvent && !e.pending &&
|
|
2208
|
-
markSeen:
|
|
2209
|
-
merge: (e, t) =>
|
|
2210
|
-
}),
|
|
2267
|
+
covers: (e, t) => !!(e.pendingEvent && !e.pending && Lt(t, e.pendingEvent)),
|
|
2268
|
+
markSeen: Rt,
|
|
2269
|
+
merge: (e, t) => Ft(Nt(e), t)
|
|
2270
|
+
}), Hr = {
|
|
2211
2271
|
requestType: "tk_sync_request",
|
|
2212
2272
|
stateType: "tk_sync_state",
|
|
2213
|
-
historyOf:
|
|
2214
|
-
rebuild:
|
|
2215
|
-
compare: (e, t) =>
|
|
2273
|
+
historyOf: dr,
|
|
2274
|
+
rebuild: pr,
|
|
2275
|
+
compare: (e, t) => fr(dr(e), t),
|
|
2216
2276
|
offerOf: (e) => ({
|
|
2217
2277
|
...e,
|
|
2218
2278
|
request_event_id: void 0
|
|
2219
2279
|
}),
|
|
2220
|
-
covers: (e, t) => !!(e.pendingEvent && !e.pending &&
|
|
2221
|
-
markSeen:
|
|
2280
|
+
covers: (e, t) => !!(e.pendingEvent && !e.pending && mr(t, e.pendingEvent)),
|
|
2281
|
+
markSeen: hr,
|
|
2222
2282
|
merge: () => null
|
|
2223
|
-
},
|
|
2283
|
+
}, Ur = (e) => ({
|
|
2224
2284
|
...e,
|
|
2225
2285
|
game: "connect4",
|
|
2226
2286
|
turnId: e.hostId,
|
|
2227
2287
|
status: "invited",
|
|
2228
|
-
board:
|
|
2288
|
+
board: Oe(),
|
|
2229
2289
|
ply: 0,
|
|
2230
2290
|
winnerId: null,
|
|
2231
2291
|
lastMove: null,
|
|
@@ -2234,31 +2294,35 @@ var Mr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
|
|
|
2234
2294
|
pendingEvent: null,
|
|
2235
2295
|
acceptEventId: null,
|
|
2236
2296
|
moves: []
|
|
2237
|
-
}),
|
|
2297
|
+
}), Wr = (e, t, n) => M(t, {
|
|
2238
2298
|
game_id: e.gameId,
|
|
2239
2299
|
data: n,
|
|
2240
|
-
game:
|
|
2300
|
+
game: J(e)
|
|
2241
2301
|
});
|
|
2242
|
-
function
|
|
2243
|
-
let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ??
|
|
2302
|
+
function Gr() {
|
|
2303
|
+
let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ?? Kt(e, n), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = Vr(n), l = /* @__PURE__ */ new Map(), u = (e, t) => l.get(`${e}:${t}`) ?? Tr(e, t)?.seedA ?? null, d = {
|
|
2244
2304
|
connect4: {
|
|
2245
|
-
create: (e) =>
|
|
2246
|
-
apply: (e, t, n) =>
|
|
2247
|
-
sync:
|
|
2305
|
+
create: (e) => Ur(e),
|
|
2306
|
+
apply: (e, t, n) => Mr(e, t, n),
|
|
2307
|
+
sync: Br
|
|
2248
2308
|
},
|
|
2249
2309
|
battleship: {
|
|
2250
|
-
create: (e) =>
|
|
2251
|
-
apply: (e, t, r, i) =>
|
|
2310
|
+
create: (e) => $e(e),
|
|
2311
|
+
apply: (e, t, r, i) => kt(e, t, r, { stored: t.type === "bs_commit" && r === i ? n(e.scope, e.gameId) : null }),
|
|
2252
2312
|
sync: s,
|
|
2253
2313
|
after: (e, t) => t().bsScheduleEffects(e)
|
|
2254
2314
|
},
|
|
2315
|
+
tanks_live: {
|
|
2316
|
+
create: (e, t) => _(e, t.data),
|
|
2317
|
+
apply: v
|
|
2318
|
+
},
|
|
2255
2319
|
tanks: {
|
|
2256
|
-
create: (e, t) =>
|
|
2257
|
-
apply: (e, t, n) =>
|
|
2258
|
-
sync:
|
|
2320
|
+
create: (e, t) => tr(e, t.data),
|
|
2321
|
+
apply: (e, t, n) => lr(e, t, n),
|
|
2322
|
+
sync: Hr,
|
|
2259
2323
|
after: (e, t) => t().tkScheduleEffects(e)
|
|
2260
2324
|
}
|
|
2261
|
-
}, f = (e) => d[
|
|
2325
|
+
}, f = (e) => d[J(e)] ?? null, p = (e) => f(e)?.sync ?? Br;
|
|
2262
2326
|
return c((s, c) => ({
|
|
2263
2327
|
games: {},
|
|
2264
2328
|
configureTransport: (t) => {
|
|
@@ -2267,12 +2331,12 @@ function Rr() {
|
|
|
2267
2331
|
clear: () => {
|
|
2268
2332
|
r.forEach((e) => clearTimeout(e)), r.clear(), o.forEach((e) => clearTimeout(e)), o.clear(), t.clear(), l.clear(), i.clear(), a.clear(), s({ games: {} });
|
|
2269
2333
|
},
|
|
2270
|
-
markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && !
|
|
2334
|
+
markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && n.game !== "tanks_live" && !X(n) ? {
|
|
2271
2335
|
...n,
|
|
2272
2336
|
status: "conflict",
|
|
2273
2337
|
error: "Conexión interrumpida. Se intentará resincronizar al reconectar.",
|
|
2274
2338
|
sync: {
|
|
2275
|
-
...
|
|
2339
|
+
...Pr,
|
|
2276
2340
|
...n.sync,
|
|
2277
2341
|
status: "idle",
|
|
2278
2342
|
auto: !1
|
|
@@ -2287,13 +2351,13 @@ function Rr() {
|
|
|
2287
2351
|
...t
|
|
2288
2352
|
} : t, p = f.message ?? f.text;
|
|
2289
2353
|
if (typeof p != "string" || !p.startsWith("LIRA_GAME_V1:")) return !1;
|
|
2290
|
-
let m =
|
|
2354
|
+
let m = Ee(p), h = String(f.room_id ?? ""), g = String(f.user_id ?? "");
|
|
2291
2355
|
if (!m || !o || !l || !g || !h.startsWith("private_")) return !0;
|
|
2292
2356
|
let _ = h.slice(8).split("_");
|
|
2293
2357
|
if (_.length !== 2 || !_.includes(l) || !_.includes(g)) return !0;
|
|
2294
|
-
let v =
|
|
2295
|
-
if (y &&
|
|
2296
|
-
if (
|
|
2358
|
+
let v = Ar(o, h, m.game_id), y = c().games[v];
|
|
2359
|
+
if (y && J(y) !== m.game) return !0;
|
|
2360
|
+
if (Fr(m.type)) return y && !y.seen[m.event_id] && c().handleResync(v, m, g, l), !0;
|
|
2297
2361
|
if (!y && m.type !== "game_invite" && m.game === "tanks" && c().restoreTanks(o, m.game_id)) return c().ingest(t, n, r);
|
|
2298
2362
|
if (!y && m.type !== "game_invite") {
|
|
2299
2363
|
let e = Date.now();
|
|
@@ -2327,7 +2391,7 @@ function Rr() {
|
|
|
2327
2391
|
inviteEventId: m.event_id,
|
|
2328
2392
|
lastEventId: m.event_id,
|
|
2329
2393
|
seen: {},
|
|
2330
|
-
sync: { ...
|
|
2394
|
+
sync: { ...Pr }
|
|
2331
2395
|
}, m);
|
|
2332
2396
|
} else y && (b = x.apply(y, m, g, l));
|
|
2333
2397
|
if (!b || b === y) return !0;
|
|
@@ -2343,7 +2407,7 @@ function Rr() {
|
|
|
2343
2407
|
[v]: b
|
|
2344
2408
|
};
|
|
2345
2409
|
if (m.type === "game_invite") {
|
|
2346
|
-
let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !
|
|
2410
|
+
let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !X(e)), n = e.sort((e, t) => e.gameId < t.gameId ? -1 : +(e.gameId > t.gameId))[0];
|
|
2347
2411
|
e.forEach((e) => {
|
|
2348
2412
|
e.key !== n?.key && (t[e.key] = {
|
|
2349
2413
|
...e,
|
|
@@ -2352,7 +2416,7 @@ function Rr() {
|
|
|
2352
2416
|
});
|
|
2353
2417
|
});
|
|
2354
2418
|
}
|
|
2355
|
-
return { games:
|
|
2419
|
+
return { games: jr(t) };
|
|
2356
2420
|
}), b.status === "conflict" && y?.status !== "conflict" && queueMicrotask(() => {
|
|
2357
2421
|
c().requestResync(v, { auto: !0 });
|
|
2358
2422
|
}), c().afterGameChange(v), m.type === "game_invite") {
|
|
@@ -2363,19 +2427,20 @@ function Rr() {
|
|
|
2363
2427
|
},
|
|
2364
2428
|
invite: async ({ roomId: t, opponentId: n, gameType: r = "connect4", firstPlayerId: i, rematchOf: a }) => {
|
|
2365
2429
|
if (!e) throw Error("Chat no disponible");
|
|
2366
|
-
if (!
|
|
2430
|
+
if (!Dr.includes(r)) throw Error("Juego no disponible");
|
|
2367
2431
|
let o = e.getScope();
|
|
2368
2432
|
if (!String(e.getUserId() ?? "") || !String(t).startsWith("private_")) throw Error("Abre un chat privado para jugar.");
|
|
2369
|
-
if (Object.values(c().games).some((e) => e.scope === o && e.roomId === String(t) && (!
|
|
2433
|
+
if (Object.values(c().games).some((e) => e.scope === o && e.roomId === String(t) && (!X(e) || e.pendingEvent))) throw Error("Cierra la partida actual antes de invitar.");
|
|
2370
2434
|
let s = crypto.randomUUID(), u = {
|
|
2371
2435
|
opponent_id: String(n),
|
|
2372
2436
|
rules_version: 1
|
|
2373
2437
|
};
|
|
2374
2438
|
if (r === "tanks") {
|
|
2375
|
-
let e =
|
|
2376
|
-
l.set(`${o}:${s}`, e),
|
|
2439
|
+
let e = Qn();
|
|
2440
|
+
l.set(`${o}:${s}`, e), wr(o, s, { seedA: e }), u.seed_commit = $n(e), i != null && (u.first_player_id = String(i)), a && (u.rematch_of = a);
|
|
2377
2441
|
}
|
|
2378
|
-
|
|
2442
|
+
r === "tanks_live" && a && (u.rematch_of = a);
|
|
2443
|
+
let d = M("game_invite", {
|
|
2379
2444
|
game_id: s,
|
|
2380
2445
|
data: u,
|
|
2381
2446
|
game: r
|
|
@@ -2389,9 +2454,9 @@ function Rr() {
|
|
|
2389
2454
|
let o = r;
|
|
2390
2455
|
if (n === "game_accept" || n === "game_decline") {
|
|
2391
2456
|
if (i.status !== "invited" || a !== i.guestId) return;
|
|
2392
|
-
o = { invite_event_id: i.inviteEventId }, n === "game_accept" &&
|
|
2457
|
+
o = { invite_event_id: i.inviteEventId }, n === "game_accept" && Y(i) && (o.seed_b = Qn());
|
|
2393
2458
|
} else if (n === "game_move") {
|
|
2394
|
-
if (
|
|
2459
|
+
if (J(i) !== "connect4" || i.status !== "active" || a !== i.turnId || !Ne(i.board, r.column, a)) return;
|
|
2395
2460
|
o = {
|
|
2396
2461
|
column: r.column,
|
|
2397
2462
|
ply: i.ply + 1,
|
|
@@ -2399,41 +2464,41 @@ function Rr() {
|
|
|
2399
2464
|
};
|
|
2400
2465
|
} else if (n === "game_end") o = { reason: "closed" };
|
|
2401
2466
|
else return;
|
|
2402
|
-
return c().sendEvent(i.roomId,
|
|
2467
|
+
return c().sendEvent(i.roomId, M(n, {
|
|
2403
2468
|
game_id: i.gameId,
|
|
2404
2469
|
data: o,
|
|
2405
|
-
game:
|
|
2470
|
+
game: J(i)
|
|
2406
2471
|
}));
|
|
2407
2472
|
},
|
|
2408
2473
|
bsUpdateLocal: (e, t) => {
|
|
2409
2474
|
let n = c().games[e];
|
|
2410
|
-
if (!
|
|
2475
|
+
if (!Or(n)) return !1;
|
|
2411
2476
|
let r = t(n);
|
|
2412
2477
|
return r !== n && (s((t) => t.games[e] === n ? { games: {
|
|
2413
2478
|
...t.games,
|
|
2414
2479
|
[e]: r
|
|
2415
2480
|
} } : t), c().games[e] === r);
|
|
2416
2481
|
},
|
|
2417
|
-
bsPlaceShip: (e, t) => c().bsUpdateLocal(e, (e) =>
|
|
2418
|
-
bsRemoveShip: (e, t) => c().bsUpdateLocal(e, (e) =>
|
|
2419
|
-
bsRandomFleet: (e) => c().bsUpdateLocal(e, (e) =>
|
|
2482
|
+
bsPlaceShip: (e, t) => c().bsUpdateLocal(e, (e) => ut(e, t)),
|
|
2483
|
+
bsRemoveShip: (e, t) => c().bsUpdateLocal(e, (e) => dt(e, t)),
|
|
2484
|
+
bsRandomFleet: (e) => c().bsUpdateLocal(e, (e) => mt(e)),
|
|
2420
2485
|
bsReady: async (n) => {
|
|
2421
2486
|
let r = c().games[n];
|
|
2422
|
-
if (!
|
|
2487
|
+
if (!Or(r) || r.status !== "placement" || r.myReady) return;
|
|
2423
2488
|
if (r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2424
2489
|
if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
|
|
2425
|
-
let i =
|
|
2426
|
-
if (!
|
|
2427
|
-
let a =
|
|
2428
|
-
if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(
|
|
2490
|
+
let i = ot(r.myFleet);
|
|
2491
|
+
if (!ct(i)) throw Error("Coloca los cinco barcos antes de continuar.");
|
|
2492
|
+
let a = gt(), o = await vt(i, a), s = c().games[n];
|
|
2493
|
+
if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(ot(s.myFleet)) !== JSON.stringify(i))) return t.set(`${r.scope}:${r.gameId}`, {
|
|
2429
2494
|
fleet: i,
|
|
2430
2495
|
salt: a,
|
|
2431
2496
|
commitment: o
|
|
2432
|
-
}),
|
|
2497
|
+
}), Gt(r.scope, r.gameId, {
|
|
2433
2498
|
fleet: i,
|
|
2434
2499
|
salt: a,
|
|
2435
2500
|
commitment: o
|
|
2436
|
-
}), c().sendEvent(r.roomId,
|
|
2501
|
+
}), c().sendEvent(r.roomId, M("bs_commit", {
|
|
2437
2502
|
game_id: r.gameId,
|
|
2438
2503
|
data: { commitment: o },
|
|
2439
2504
|
game: "battleship"
|
|
@@ -2441,9 +2506,9 @@ function Rr() {
|
|
|
2441
2506
|
},
|
|
2442
2507
|
bsFire: async (t, { row: n, col: r } = {}) => {
|
|
2443
2508
|
let i = c().games[t];
|
|
2444
|
-
if (!
|
|
2509
|
+
if (!Or(i) || i.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2445
2510
|
if (i.pending || i.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
|
|
2446
|
-
if (
|
|
2511
|
+
if (tt(i) && i.targetShots[n]?.[r] === null) return c().sendEvent(i.roomId, M("bs_fire", {
|
|
2447
2512
|
game_id: i.gameId,
|
|
2448
2513
|
data: {
|
|
2449
2514
|
ply: i.ply + 1,
|
|
@@ -2457,14 +2522,14 @@ function Rr() {
|
|
|
2457
2522
|
bsScheduleEffects: (e) => {
|
|
2458
2523
|
r.has(e) || r.set(e, setTimeout(() => {
|
|
2459
2524
|
r.delete(e), c().bsRunEffects(e);
|
|
2460
|
-
},
|
|
2525
|
+
}, kr));
|
|
2461
2526
|
},
|
|
2462
2527
|
bsRunEffects: (t) => {
|
|
2463
2528
|
let r = c().games[t];
|
|
2464
|
-
if (!
|
|
2529
|
+
if (!Or(r) || !e || r.scope !== e.getScope?.()) return;
|
|
2465
2530
|
if (r.opponentReveal && r.verification === "pending" && !i.has(t)) {
|
|
2466
2531
|
let e = r.opponentReveal;
|
|
2467
|
-
i.add(t),
|
|
2532
|
+
i.add(t), jt(r, e).then((n) => s((r) => {
|
|
2468
2533
|
let i = r.games[t];
|
|
2469
2534
|
return !i || i.opponentReveal !== e || i.verification === n ? r : { games: {
|
|
2470
2535
|
...r.games,
|
|
@@ -2479,14 +2544,14 @@ function Rr() {
|
|
|
2479
2544
|
}
|
|
2480
2545
|
if (r.pending || r.pendingEvent) return;
|
|
2481
2546
|
let a = (e, t) => {
|
|
2482
|
-
c().sendEvent(r.roomId,
|
|
2547
|
+
c().sendEvent(r.roomId, M(e, {
|
|
2483
2548
|
game_id: r.gameId,
|
|
2484
2549
|
data: t,
|
|
2485
2550
|
game: "battleship"
|
|
2486
2551
|
})).catch(() => {});
|
|
2487
2552
|
};
|
|
2488
2553
|
if (r.status === "active" && r.pendingShot && r.pendingShot.by !== r.ownId) {
|
|
2489
|
-
let e =
|
|
2554
|
+
let e = yt(lt(r), r.pendingShot);
|
|
2490
2555
|
e ? a("bs_result", e) : r.error || s((e) => ({ games: {
|
|
2491
2556
|
...e.games,
|
|
2492
2557
|
[t]: {
|
|
@@ -2498,8 +2563,8 @@ function Rr() {
|
|
|
2498
2563
|
}
|
|
2499
2564
|
let o = String(r.winnerId) !== String(r.ownId) || !!r.opponentReveal;
|
|
2500
2565
|
if (r.winnerId && ["won", "closed"].includes(r.status) && !r.myRevealSent && o) {
|
|
2501
|
-
let e =
|
|
2502
|
-
|
|
2566
|
+
let e = ot(r.myFleet), t = r.mySalt ?? n(r.scope, r.gameId)?.salt;
|
|
2567
|
+
ct(e) && t && a("bs_reveal", {
|
|
2503
2568
|
fleet: e,
|
|
2504
2569
|
salt: t
|
|
2505
2570
|
});
|
|
@@ -2511,10 +2576,10 @@ function Rr() {
|
|
|
2511
2576
|
},
|
|
2512
2577
|
tkTurn: async (t, n) => {
|
|
2513
2578
|
let r = c().games[t];
|
|
2514
|
-
if (!
|
|
2579
|
+
if (!Y(r) || r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2515
2580
|
if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
|
|
2516
|
-
let i =
|
|
2517
|
-
if (i) return c().sendEvent(r.roomId,
|
|
2581
|
+
let i = ur(r, n);
|
|
2582
|
+
if (i) return c().sendEvent(r.roomId, M("tk_turn", {
|
|
2518
2583
|
game_id: r.gameId,
|
|
2519
2584
|
data: i,
|
|
2520
2585
|
game: "tanks"
|
|
@@ -2522,7 +2587,7 @@ function Rr() {
|
|
|
2522
2587
|
},
|
|
2523
2588
|
tkSkip: async (t) => {
|
|
2524
2589
|
let n = c().games[t];
|
|
2525
|
-
if (
|
|
2590
|
+
if (Y(n) && rr(n) && n.scope === e?.getScope?.()) return c().sendEvent(n.roomId, M("tk_skip", {
|
|
2526
2591
|
game_id: n.gameId,
|
|
2527
2592
|
data: {
|
|
2528
2593
|
ply: n.ply + 1,
|
|
@@ -2533,7 +2598,7 @@ function Rr() {
|
|
|
2533
2598
|
},
|
|
2534
2599
|
tkResign: async (t) => {
|
|
2535
2600
|
let n = c().games[t];
|
|
2536
|
-
if (!(!
|
|
2601
|
+
if (!(!Y(n) || n.status !== "active" || n.pending || n.pendingEvent || n.scope !== e?.getScope?.())) return c().sendEvent(n.roomId, M("tk_resign", {
|
|
2537
2602
|
game_id: n.gameId,
|
|
2538
2603
|
data: {
|
|
2539
2604
|
ply: n.ply + 1,
|
|
@@ -2545,13 +2610,13 @@ function Rr() {
|
|
|
2545
2610
|
tkScheduleEffects: (e) => {
|
|
2546
2611
|
r.has(e) || r.set(e, setTimeout(() => {
|
|
2547
2612
|
r.delete(e), c().tkRunEffects(e);
|
|
2548
|
-
},
|
|
2613
|
+
}, kr));
|
|
2549
2614
|
},
|
|
2550
2615
|
tkRunEffects: (t) => {
|
|
2551
2616
|
let n = c().games[t];
|
|
2552
|
-
if (!
|
|
2617
|
+
if (!Y(n) || (wr(n.scope, n.gameId, { snapshot: gr(n) }), !e || n.scope !== e.getScope?.() || n.pending || n.pendingEvent) || n.status !== "seeding" || n.ownId !== n.hostId) return;
|
|
2553
2618
|
let r = u(n.scope, n.gameId);
|
|
2554
|
-
r ? c().sendEvent(n.roomId,
|
|
2619
|
+
r ? c().sendEvent(n.roomId, M("tk_seed", {
|
|
2555
2620
|
game_id: n.gameId,
|
|
2556
2621
|
data: { seed_a: r },
|
|
2557
2622
|
game: "tanks"
|
|
@@ -2565,16 +2630,16 @@ function Rr() {
|
|
|
2565
2630
|
},
|
|
2566
2631
|
restoreTanks: (e, t) => {
|
|
2567
2632
|
let n = !1;
|
|
2568
|
-
return
|
|
2633
|
+
return Er(e).forEach(({ snapshot: r }) => {
|
|
2569
2634
|
if (!r || t && r.gameId !== t || [
|
|
2570
2635
|
"closed",
|
|
2571
2636
|
"declined",
|
|
2572
2637
|
"won",
|
|
2573
2638
|
"draw"
|
|
2574
2639
|
].includes(r.status)) return;
|
|
2575
|
-
let i =
|
|
2640
|
+
let i = Ar(e, r.roomId, r.gameId);
|
|
2576
2641
|
if (c().games[i]) return;
|
|
2577
|
-
let a =
|
|
2642
|
+
let a = pr(tr({
|
|
2578
2643
|
key: i,
|
|
2579
2644
|
gameId: r.gameId,
|
|
2580
2645
|
game_id: r.gameId,
|
|
@@ -2587,7 +2652,7 @@ function Rr() {
|
|
|
2587
2652
|
inviteEventId: r.inviteEventId,
|
|
2588
2653
|
lastEventId: r.inviteEventId,
|
|
2589
2654
|
seen: {},
|
|
2590
|
-
sync: { ...
|
|
2655
|
+
sync: { ...Pr }
|
|
2591
2656
|
}, {
|
|
2592
2657
|
seed_commit: r.seedCommit,
|
|
2593
2658
|
first_player_id: r.firstPlayerId,
|
|
@@ -2597,11 +2662,11 @@ function Rr() {
|
|
|
2597
2662
|
n = !0;
|
|
2598
2663
|
let o = {
|
|
2599
2664
|
...a,
|
|
2600
|
-
seen:
|
|
2665
|
+
seen: hr({ [r.inviteEventId]: !0 }, a),
|
|
2601
2666
|
status: "conflict",
|
|
2602
2667
|
error: "Partida recuperada en este dispositivo. Sincronizando con el rival…"
|
|
2603
2668
|
};
|
|
2604
|
-
s((e) => ({ games:
|
|
2669
|
+
s((e) => ({ games: jr({
|
|
2605
2670
|
...e.games,
|
|
2606
2671
|
[i]: o
|
|
2607
2672
|
}) })), queueMicrotask(() => {
|
|
@@ -2609,9 +2674,41 @@ function Rr() {
|
|
|
2609
2674
|
});
|
|
2610
2675
|
}), n;
|
|
2611
2676
|
},
|
|
2677
|
+
createLiveSignaling: (t) => {
|
|
2678
|
+
let n = c().games[t];
|
|
2679
|
+
if (n?.game !== "tanks_live" || n.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2680
|
+
let r = e;
|
|
2681
|
+
return x({
|
|
2682
|
+
roomId: n.roomId,
|
|
2683
|
+
send: (n, i) => {
|
|
2684
|
+
if (e !== r || c().games[t]?.scope !== r.getScope()) throw Error("La sesión cambió");
|
|
2685
|
+
return r.send(n, i);
|
|
2686
|
+
}
|
|
2687
|
+
});
|
|
2688
|
+
},
|
|
2689
|
+
liveFinish: (t, n) => {
|
|
2690
|
+
let r = c().games[t];
|
|
2691
|
+
r?.game === "tanks_live" && r.scope === e?.getScope?.() && r.status === "active" && [r.hostId, r.guestId].includes(String(n)) && s((e) => ({ games: {
|
|
2692
|
+
...e.games,
|
|
2693
|
+
[t]: {
|
|
2694
|
+
...r,
|
|
2695
|
+
status: "won",
|
|
2696
|
+
winnerId: String(n)
|
|
2697
|
+
}
|
|
2698
|
+
} }));
|
|
2699
|
+
},
|
|
2700
|
+
liveRematch: (t) => {
|
|
2701
|
+
let n = c().games[t];
|
|
2702
|
+
if (n?.game === "tanks_live" && n.scope === e?.getScope?.() && X(n)) return c().invite({
|
|
2703
|
+
roomId: n.roomId,
|
|
2704
|
+
opponentId: n.ownId === n.hostId ? n.guestId : n.hostId,
|
|
2705
|
+
gameType: "tanks_live",
|
|
2706
|
+
rematchOf: n.gameId
|
|
2707
|
+
});
|
|
2708
|
+
},
|
|
2612
2709
|
sendEvent: async (t, n) => {
|
|
2613
2710
|
if (!e) throw Error("Chat no disponible");
|
|
2614
|
-
let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o =
|
|
2711
|
+
let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o = Ar(i, t, n.game_id), l = De(n);
|
|
2615
2712
|
if (c().ingest({
|
|
2616
2713
|
room_id: t,
|
|
2617
2714
|
user_id: a,
|
|
@@ -2663,7 +2760,7 @@ function Rr() {
|
|
|
2663
2760
|
return;
|
|
2664
2761
|
}
|
|
2665
2762
|
let u = {
|
|
2666
|
-
...
|
|
2763
|
+
...Pr,
|
|
2667
2764
|
...i.sync
|
|
2668
2765
|
};
|
|
2669
2766
|
if (![a.requestType, a.stateType].includes(t.type)) {
|
|
@@ -2751,7 +2848,7 @@ function Rr() {
|
|
|
2751
2848
|
};
|
|
2752
2849
|
let b = Date.now(), x = g.sync.replies.filter((e) => b - e < 3e4), S = null;
|
|
2753
2850
|
if (_ && x.length < 6) try {
|
|
2754
|
-
S =
|
|
2851
|
+
S = Wr(i, a.stateType, {
|
|
2755
2852
|
...a.historyOf(g),
|
|
2756
2853
|
request_event_id: t.event_id
|
|
2757
2854
|
});
|
|
@@ -2786,19 +2883,19 @@ function Rr() {
|
|
|
2786
2883
|
sendResync: async (t, n) => {
|
|
2787
2884
|
let r = c().games[t];
|
|
2788
2885
|
if (!e || !r || r.scope !== e.getScope?.()) throw Error("Chat no disponible");
|
|
2789
|
-
await e.send(r.roomId,
|
|
2886
|
+
await e.send(r.roomId, De(n));
|
|
2790
2887
|
},
|
|
2791
2888
|
requestResync: async (t, { auto: n = !1 } = {}) => {
|
|
2792
2889
|
let r = c().games[t];
|
|
2793
|
-
if (!r || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
|
|
2890
|
+
if (!r || r.game === "tanks_live" || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
|
|
2794
2891
|
let i = {
|
|
2795
|
-
...
|
|
2892
|
+
...Pr,
|
|
2796
2893
|
...r.sync
|
|
2797
2894
|
};
|
|
2798
|
-
if (i.status === "requesting" && Date.now() - i.requestedAt <
|
|
2895
|
+
if (i.status === "requesting" && Date.now() - i.requestedAt < Nr || n && i.auto) return;
|
|
2799
2896
|
let a;
|
|
2800
2897
|
try {
|
|
2801
|
-
a =
|
|
2898
|
+
a = Wr(r, p(r).requestType, p(r).historyOf(r));
|
|
2802
2899
|
} catch {
|
|
2803
2900
|
return;
|
|
2804
2901
|
}
|
|
@@ -2840,7 +2937,7 @@ function Rr() {
|
|
|
2840
2937
|
});
|
|
2841
2938
|
let u = setTimeout(() => {
|
|
2842
2939
|
o.delete(u), l("El rival no respondió a la sincronización. Reintenta cuando esté conectado.");
|
|
2843
|
-
},
|
|
2940
|
+
}, Nr);
|
|
2844
2941
|
o.add(u);
|
|
2845
2942
|
try {
|
|
2846
2943
|
await c().sendResync(t, a);
|
|
@@ -2888,91 +2985,30 @@ function Rr() {
|
|
|
2888
2985
|
}
|
|
2889
2986
|
}));
|
|
2890
2987
|
}
|
|
2891
|
-
var
|
|
2892
|
-
Object.assign(
|
|
2893
|
-
getState:
|
|
2894
|
-
setState:
|
|
2895
|
-
subscribe:
|
|
2988
|
+
var Kr = Gr(), qr = (e) => l(Kr, e);
|
|
2989
|
+
Object.assign(qr, {
|
|
2990
|
+
getState: Kr.getState,
|
|
2991
|
+
setState: Kr.setState,
|
|
2992
|
+
subscribe: Kr.subscribe
|
|
2896
2993
|
});
|
|
2897
2994
|
// src/assets/chatAssets.js
|
|
2898
|
-
var
|
|
2899
|
-
function
|
|
2900
|
-
|
|
2901
|
-
}
|
|
2902
|
-
function Gr() {
|
|
2903
|
-
return Hr;
|
|
2904
|
-
}
|
|
2905
|
-
function Kr(e) {
|
|
2906
|
-
return `${Hr}/${String(e).replace(/^\/+/, "")}`;
|
|
2907
|
-
}
|
|
2908
|
-
// src/core/connection/connectionStore.js
|
|
2909
|
-
var qr = c(() => ({ status: "idle" }));
|
|
2910
|
-
function Jr(e) {
|
|
2911
|
-
qr.setState({ status: e });
|
|
2912
|
-
}
|
|
2913
|
-
function Yr() {
|
|
2914
|
-
return l(qr, (e) => e.status);
|
|
2915
|
-
}
|
|
2916
|
-
// src/games/shared/gameStatus.js
|
|
2917
|
-
var X = (e, t) => e != null && t != null && String(e) === String(t), Xr = (e) => [
|
|
2918
|
-
"won",
|
|
2919
|
-
"draw",
|
|
2920
|
-
"declined",
|
|
2921
|
-
"closed"
|
|
2922
|
-
].includes(e?.status), Zr = (e) => !!e && ([
|
|
2923
|
-
"invited",
|
|
2924
|
-
"placement",
|
|
2925
|
-
"seeding",
|
|
2926
|
-
"active",
|
|
2927
|
-
"conflict"
|
|
2928
|
-
].includes(e.status) || !!e.pendingEvent), Qr = (e) => e?.game === "battleship", $r = (e) => e?.game === "tanks", ei = {
|
|
2929
|
-
connect4: "Conecta 4",
|
|
2930
|
-
battleship: "Batalla Naval",
|
|
2931
|
-
tanks: "Tanques de guerra"
|
|
2932
|
-
}, ti = (e) => ei[e?.game] ?? "Conecta 4", ni = {
|
|
2933
|
-
ok: "Partida verificada",
|
|
2934
|
-
mismatch: "Resultados inconsistentes del rival",
|
|
2935
|
-
pending: "Verificando…"
|
|
2936
|
-
}, ri = (e) => ni[e?.verification] || "";
|
|
2937
|
-
function ii(e, t) {
|
|
2938
|
-
let n = X(t, e.turnId);
|
|
2939
|
-
return e.status === "placement" ? e.myReady ? e.opponentReady ? "Iniciando batalla…" : "Esperando a que el rival coloque su flota" : "Coloca tu flota" : e.status === "active" ? e.pendingShot ? "Esperando resultado…" : n ? "Tu turno · elige una casilla" : "Turno del rival" : e.status === "won" ? X(t, e.winnerId) ? "¡Ganaste!" : "Tu rival ganó" : null;
|
|
2940
|
-
}
|
|
2941
|
-
function ai(e, t) {
|
|
2942
|
-
if (e.status === "seeding") return "Preparando el campo de batalla…";
|
|
2943
|
-
if (e.status === "active") return X(t, e.turnId) ? "Tu turno · apunta y dispara" : "Turno del rival";
|
|
2944
|
-
if (e.status === "won") {
|
|
2945
|
-
let n = X(t, e.winnerId), r = e.logic?.reason;
|
|
2946
|
-
return r === "resign" ? n ? "¡Victoria! Tu rival se rindió" : "Te rendiste" : r === "timeout" ? n ? "¡Victoria! Tu rival dejó pasar sus turnos" : "Perdiste por inactividad" : r === "max_shots" ? n ? "¡Victoria por vida restante!" : "Tu rival terminó con más vida" : n ? "¡Victoria! Destruiste al rival" : "Tu tanque fue destruido";
|
|
2947
|
-
}
|
|
2948
|
-
return e.status === "draw" ? e.logic?.reason === "max_shots" ? "Empate · misma vida al agotar los disparos" : "Empate · ambos tanques destruidos" : null;
|
|
2995
|
+
var Jr = "/sounds", Yr = Jr, Xr = (e) => String(e).replace(/\/+$/, "");
|
|
2996
|
+
function Zr(e) {
|
|
2997
|
+
Yr = e == null ? Jr : Xr(e);
|
|
2949
2998
|
}
|
|
2950
|
-
function
|
|
2951
|
-
|
|
2952
|
-
let n = ii(e, t);
|
|
2953
|
-
if (n) return n;
|
|
2954
|
-
}
|
|
2955
|
-
if ($r(e)) {
|
|
2956
|
-
let n = ai(e, t);
|
|
2957
|
-
if (n) return n;
|
|
2958
|
-
}
|
|
2959
|
-
let n = e.status === "active" && X(t, e.turnId);
|
|
2960
|
-
return e.status === "invited" ? X(t, e.guestId) ? "Te han invitado a jugar" : "Esperando respuesta a la invitación" : e.status === "active" ? n ? "Tu turno · elige una columna" : "Turno de tu rival" : e.status === "won" ? X(t, e.winnerId) ? "¡Ganaste la partida!" : "Tu rival ganó la partida" : e.status === "draw" ? "Empate · tablero completo" : e.status === "declined" ? "Invitación rechazada" : e.status === "closed" ? "Partida finalizada" : e.status === "conflict" ? "Partida pausada por un conflicto de sincronización" : "Esperando respuesta a la invitación";
|
|
2999
|
+
function Qr() {
|
|
3000
|
+
return Yr;
|
|
2961
3001
|
}
|
|
2962
|
-
function
|
|
2963
|
-
|
|
2964
|
-
if (e.status === "placement") return e.myReady ? "Esperando al rival" : "Coloca tu flota";
|
|
2965
|
-
if (e.status === "active" && e.pendingShot) return "Esperando resultado…";
|
|
2966
|
-
}
|
|
2967
|
-
return $r(e) && e.status === "seeding" ? "Preparando…" : e.status === "active" ? X(t, e.turnId) ? "Tu turno" : "Turno del rival" : e.status === "invited" ? X(t, e.guestId) ? "Invitación recibida" : "Invitación enviada" : e.status === "conflict" ? e.sync?.status === "requesting" ? "Sincronizando…" : "Sin sincronizar" : oi(e, t);
|
|
3002
|
+
function $r(e) {
|
|
3003
|
+
return `${Yr}/${String(e).replace(/^\/+/, "")}`;
|
|
2968
3004
|
}
|
|
2969
3005
|
// src/audio/useSoundSettings.js
|
|
2970
|
-
function
|
|
3006
|
+
function ei(e) {
|
|
2971
3007
|
return s(e.subscribe, e.getSettings, e.getSettings);
|
|
2972
3008
|
}
|
|
2973
3009
|
// src/games/shared/GameSoundControls.jsx
|
|
2974
|
-
function
|
|
2975
|
-
let { volume: t, muted: n } =
|
|
3010
|
+
function ti({ manager: e }) {
|
|
3011
|
+
let { volume: t, muted: n } = ei(e), r = n || t === 0;
|
|
2976
3012
|
return /* @__PURE__ */ p("div", {
|
|
2977
3013
|
className: "chat-game-sound",
|
|
2978
3014
|
children: [/* @__PURE__ */ f("button", {
|
|
@@ -2995,27 +3031,27 @@ function li({ manager: e }) {
|
|
|
2995
3031
|
});
|
|
2996
3032
|
}
|
|
2997
3033
|
// src/audio/createSoundManager.js
|
|
2998
|
-
var
|
|
3034
|
+
var ni = [
|
|
2999
3035
|
"pointerdown",
|
|
3000
3036
|
"keydown",
|
|
3001
3037
|
"touchend"
|
|
3002
|
-
],
|
|
3003
|
-
function
|
|
3038
|
+
], ri = 300, ii = 800, ai = (e) => Math.min(1, Math.max(0, Number(e) || 0));
|
|
3039
|
+
function oi(e, t) {
|
|
3004
3040
|
try {
|
|
3005
3041
|
let n = JSON.parse(localStorage.getItem(e) ?? "null");
|
|
3006
3042
|
if (n && typeof n == "object") return {
|
|
3007
|
-
volume:
|
|
3043
|
+
volume: ai(n.volume ?? t.volume),
|
|
3008
3044
|
muted: !!n.muted
|
|
3009
3045
|
};
|
|
3010
3046
|
} catch {}
|
|
3011
3047
|
return {
|
|
3012
|
-
volume:
|
|
3048
|
+
volume: ai(t.volume),
|
|
3013
3049
|
muted: !1
|
|
3014
3050
|
};
|
|
3015
3051
|
}
|
|
3016
|
-
var
|
|
3017
|
-
function
|
|
3018
|
-
let o = `lira.sound.${e}`, s = typeof window < "u" ? window.AudioContext || window.webkitAudioContext : null, c = a ? a.getSettings() :
|
|
3052
|
+
var si = 1.5, ci = .6;
|
|
3053
|
+
function li({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .6, settingsFrom: a = null }) {
|
|
3054
|
+
let o = `lira.sound.${e}`, s = typeof window < "u" ? window.AudioContext || window.webkitAudioContext : null, c = a ? a.getSettings() : oi(o, { volume: i }), l = null, u = null, d = !1, f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), _ = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), b = !1, x = !1, S = null, ee = (e) => `${String(typeof t == "function" ? t() : t).replace(/\/$/, "")}/${n[e]}`, C = (e) => (f.has(e) || f.set(e, fetch(ee(e)).then((e) => e.ok ? e.arrayBuffer() : null).catch(() => null)), f.get(e)), w = () => {
|
|
3019
3055
|
if (!s) return null;
|
|
3020
3056
|
if (!l) try {
|
|
3021
3057
|
l = new s(), u = l.createGain(), u.gain.value = c.muted ? 0 : c.volume, u.connect(l.destination);
|
|
@@ -3023,27 +3059,27 @@ function _i({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3023
3059
|
return l = null, null;
|
|
3024
3060
|
}
|
|
3025
3061
|
return l.state === "suspended" && l.resume().catch(() => {}), l;
|
|
3026
|
-
},
|
|
3062
|
+
}, T = (e) => {
|
|
3027
3063
|
if (m.has(e) || !n[e]) return Promise.resolve(null);
|
|
3028
3064
|
if (!p.has(e)) {
|
|
3029
|
-
let t =
|
|
3065
|
+
let t = w();
|
|
3030
3066
|
if (!t) return Promise.resolve(null);
|
|
3031
|
-
p.set(e,
|
|
3067
|
+
p.set(e, C(e).then((e) => e ? new Promise((n) => {
|
|
3032
3068
|
t.decodeAudioData(e.slice(0), n, () => n(null))?.catch?.(() => n(null));
|
|
3033
3069
|
}) : null).then((t) => (t || m.add(e), t)).catch(() => (m.add(e), null)));
|
|
3034
3070
|
}
|
|
3035
3071
|
return p.get(e);
|
|
3036
|
-
},
|
|
3072
|
+
}, te = (e) => ai(r[e] ?? 1), E = (e) => {
|
|
3037
3073
|
if (!_.has(e) || v.has(e) || !d) return;
|
|
3038
|
-
let t =
|
|
3074
|
+
let t = w();
|
|
3039
3075
|
if (!t) return;
|
|
3040
3076
|
let n = {};
|
|
3041
|
-
v.set(e, n),
|
|
3077
|
+
v.set(e, n), T(e).then((r) => {
|
|
3042
3078
|
if (v.get(e) === n) {
|
|
3043
3079
|
if (!r || t.state === "closed") v.delete(e);
|
|
3044
3080
|
else try {
|
|
3045
|
-
let { fadeIn: n =
|
|
3046
|
-
a.gain.setValueAtTime(0, t.currentTime), a.gain.linearRampToValueAtTime(
|
|
3081
|
+
let { fadeIn: n = si, trim: i = 0 } = y.get(e) ?? {}, a = t.createGain();
|
|
3082
|
+
a.gain.setValueAtTime(0, t.currentTime), a.gain.linearRampToValueAtTime(te(e), t.currentTime + n), a.connect(u);
|
|
3047
3083
|
let o = t.createBufferSource();
|
|
3048
3084
|
o.buffer = r, o.loop = !0, i > 0 && r.duration > i * 4 && (o.loopStart = i, o.loopEnd = r.duration - i), o.connect(a), o.start(0, i > 0 && r.duration > i * 4 ? i : 0), v.set(e, {
|
|
3049
3085
|
source: o,
|
|
@@ -3054,33 +3090,33 @@ function _i({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3054
3090
|
}
|
|
3055
3091
|
}
|
|
3056
3092
|
});
|
|
3057
|
-
},
|
|
3093
|
+
}, D = (e) => {
|
|
3058
3094
|
let t = v.get(e);
|
|
3059
3095
|
if (v.delete(e), t?.source && l) try {
|
|
3060
|
-
let n = y.get(e)?.fadeOut ??
|
|
3096
|
+
let n = y.get(e)?.fadeOut ?? ci, r = l.currentTime;
|
|
3061
3097
|
t.level.gain.cancelScheduledValues(r), t.level.gain.setValueAtTime(t.level.gain.value, r), t.level.gain.linearRampToValueAtTime(0, r + n), t.source.stop(r + n + .05);
|
|
3062
3098
|
} catch {}
|
|
3063
|
-
},
|
|
3064
|
-
d || (d = !0,
|
|
3065
|
-
f.has(e) &&
|
|
3066
|
-
}), _.forEach(
|
|
3099
|
+
}, O = () => {
|
|
3100
|
+
d || (d = !0, ne(), w() && Object.keys(n).forEach((e) => {
|
|
3101
|
+
f.has(e) && T(e);
|
|
3102
|
+
}), _.forEach(E));
|
|
3067
3103
|
};
|
|
3068
|
-
function
|
|
3069
|
-
x && (x = !1,
|
|
3104
|
+
function ne() {
|
|
3105
|
+
x && (x = !1, ni.forEach((e) => window.removeEventListener(e, O, !0)));
|
|
3070
3106
|
}
|
|
3071
|
-
let
|
|
3072
|
-
c = e, u && (u.gain.value = c.muted ? 0 : c.volume),
|
|
3073
|
-
},
|
|
3107
|
+
let re = (e) => !h.has(e) && (h.add(e), h.size > ri && h.delete(h.values().next().value), !0), ie = () => g.forEach((e) => e()), ae = (e) => {
|
|
3108
|
+
c = e, u && (u.gain.value = c.muted ? 0 : c.volume), ie();
|
|
3109
|
+
}, oe = (e) => {
|
|
3074
3110
|
let t = {
|
|
3075
|
-
volume:
|
|
3111
|
+
volume: ai(e.volume ?? c.volume),
|
|
3076
3112
|
muted: e.muted ?? c.muted
|
|
3077
3113
|
};
|
|
3078
3114
|
try {
|
|
3079
3115
|
localStorage.setItem(o, JSON.stringify(t));
|
|
3080
3116
|
} catch {}
|
|
3081
|
-
|
|
3117
|
+
ae(t);
|
|
3082
3118
|
}, k = () => {
|
|
3083
|
-
b || (b = !0, a && (c = a.getSettings(), S = a.subscribe(() =>
|
|
3119
|
+
b || (b = !0, a && (c = a.getSettings(), S = a.subscribe(() => ae(a.getSettings()))), !(typeof window > "u" || d) && (typeof navigator < "u" && navigator.userActivation?.hasBeenActive ? d = !0 : (x = !0, ni.forEach((e) => window.addEventListener(e, O, {
|
|
3084
3120
|
capture: !0,
|
|
3085
3121
|
passive: !0
|
|
3086
3122
|
})))));
|
|
@@ -3088,7 +3124,7 @@ function _i({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3088
3124
|
return {
|
|
3089
3125
|
start: k,
|
|
3090
3126
|
dispose: () => {
|
|
3091
|
-
|
|
3127
|
+
ne(), S && (S(), S = null), b = !1, _.clear(), v.forEach((e) => {
|
|
3092
3128
|
try {
|
|
3093
3129
|
e?.source?.stop();
|
|
3094
3130
|
} catch {}
|
|
@@ -3098,19 +3134,19 @@ function _i({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3098
3134
|
},
|
|
3099
3135
|
preload(e = Object.keys(n)) {
|
|
3100
3136
|
k(), e.forEach((e) => {
|
|
3101
|
-
n[e] && !m.has(e) && (
|
|
3137
|
+
n[e] && !m.has(e) && (C(e), l && T(e));
|
|
3102
3138
|
});
|
|
3103
3139
|
},
|
|
3104
3140
|
play(e, { key: t } = {}) {
|
|
3105
|
-
if (k(), t != null && !
|
|
3106
|
-
let r =
|
|
3141
|
+
if (k(), t != null && !re(`${e}:${t}`) || !n[e] || m.has(e) || !d || c.muted || c.volume === 0) return !1;
|
|
3142
|
+
let r = w();
|
|
3107
3143
|
if (!r) return !1;
|
|
3108
3144
|
let i = Date.now();
|
|
3109
|
-
return
|
|
3110
|
-
if (!(!t || r.state === "closed" || Date.now() - i >
|
|
3145
|
+
return T(e).then((t) => {
|
|
3146
|
+
if (!(!t || r.state === "closed" || Date.now() - i > ii)) try {
|
|
3111
3147
|
let n = r.createBufferSource();
|
|
3112
3148
|
n.buffer = t;
|
|
3113
|
-
let i =
|
|
3149
|
+
let i = te(e);
|
|
3114
3150
|
if (i === 1) n.connect(u);
|
|
3115
3151
|
else {
|
|
3116
3152
|
let e = r.createGain();
|
|
@@ -3121,30 +3157,30 @@ function _i({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3121
3157
|
}), !0;
|
|
3122
3158
|
},
|
|
3123
3159
|
markPlayed(e, t) {
|
|
3124
|
-
|
|
3160
|
+
re(`${e}:${t}`);
|
|
3125
3161
|
},
|
|
3126
3162
|
startLoop(e, t) {
|
|
3127
|
-
k(), n[e] && !m.has(e) && (t && y.set(e, t), _.add(e),
|
|
3163
|
+
k(), n[e] && !m.has(e) && (t && y.set(e, t), _.add(e), E(e));
|
|
3128
3164
|
},
|
|
3129
3165
|
stopLoop(e) {
|
|
3130
|
-
_.delete(e),
|
|
3166
|
+
_.delete(e), D(e);
|
|
3131
3167
|
},
|
|
3132
3168
|
getSettings: () => a && !b ? a.getSettings() : c,
|
|
3133
|
-
setVolume: a ? a.setVolume : (e) =>
|
|
3169
|
+
setVolume: a ? a.setVolume : (e) => oe({
|
|
3134
3170
|
volume: e,
|
|
3135
|
-
muted:
|
|
3171
|
+
muted: ai(e) === 0 && c.muted
|
|
3136
3172
|
}),
|
|
3137
|
-
setMuted: a ? a.setMuted : (e) =>
|
|
3138
|
-
toggleMuted: a ? a.toggleMuted : () =>
|
|
3173
|
+
setMuted: a ? a.setMuted : (e) => oe({ muted: !!e }),
|
|
3174
|
+
toggleMuted: a ? a.toggleMuted : () => oe({ muted: !c.muted }),
|
|
3139
3175
|
subscribe(e) {
|
|
3140
3176
|
return k(), g.add(e), () => g.delete(e);
|
|
3141
3177
|
}
|
|
3142
3178
|
};
|
|
3143
3179
|
}
|
|
3144
3180
|
// src/games/connect4/connect4Sounds.js
|
|
3145
|
-
var Z =
|
|
3181
|
+
var Z = li({
|
|
3146
3182
|
id: "connect4",
|
|
3147
|
-
baseUrl: () =>
|
|
3183
|
+
baseUrl: () => $r("connect4"),
|
|
3148
3184
|
sounds: {
|
|
3149
3185
|
invite: "invite.ogg",
|
|
3150
3186
|
start: "start.ogg",
|
|
@@ -3155,45 +3191,45 @@ var Z = _i({
|
|
|
3155
3191
|
draw: "draw.ogg",
|
|
3156
3192
|
close: "close.ogg"
|
|
3157
3193
|
}
|
|
3158
|
-
}),
|
|
3159
|
-
function
|
|
3160
|
-
e.status === "won" ? Z.play(
|
|
3194
|
+
}), ui = 140, Q = /* @__PURE__ */ new Map(), di = /* @__PURE__ */ new Set(), $ = null, fi = (e, t) => e != null && t != null && String(e) === String(t), pi = () => typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
3195
|
+
function mi(e, t) {
|
|
3196
|
+
e.status === "won" ? Z.play(fi(e.winnerId, e.ownId) ? "win" : "lose", { key: t }) : e.status === "draw" ? Z.play("draw", { key: t }) : e.status === "active" && fi(e.turnId, e.ownId) && Z.play("turn", { key: t });
|
|
3161
3197
|
}
|
|
3162
|
-
function
|
|
3198
|
+
function hi(e) {
|
|
3163
3199
|
let t = Q.get(e);
|
|
3164
3200
|
if (!t) return;
|
|
3165
3201
|
clearTimeout(t.timer), Q.delete(e), Z.play("drop", { key: e });
|
|
3166
3202
|
let n = setTimeout(() => {
|
|
3167
|
-
|
|
3168
|
-
},
|
|
3169
|
-
|
|
3203
|
+
di.delete(n), mi(t.game, e);
|
|
3204
|
+
}, ui);
|
|
3205
|
+
di.add(n);
|
|
3170
3206
|
}
|
|
3171
|
-
function
|
|
3207
|
+
function gi(e) {
|
|
3172
3208
|
let t = e.lastMove?.eventId;
|
|
3173
3209
|
if (!t || Q.has(t)) return;
|
|
3174
|
-
let n =
|
|
3210
|
+
let n = pi() ? 0 : 440;
|
|
3175
3211
|
Q.set(t, {
|
|
3176
3212
|
game: e,
|
|
3177
|
-
timer: setTimeout(() =>
|
|
3213
|
+
timer: setTimeout(() => hi(t), n)
|
|
3178
3214
|
});
|
|
3179
3215
|
}
|
|
3180
|
-
function
|
|
3181
|
-
t ? t.status === "invited" && e.status === "active" ? Z.play("start", { key: e.lastEventId }) : e.ply > t.ply ?
|
|
3216
|
+
function _i(e, t) {
|
|
3217
|
+
t ? t.status === "invited" && e.status === "active" ? Z.play("start", { key: e.lastEventId }) : e.ply > t.ply ? gi(e) : (e.status === "closed" && e.closedBy != null || e.status === "declined") && t.status !== e.status && Z.play("close", { key: e.gameId }) : e.status === "invited" && fi(e.guestId, e.ownId) && Z.play("invite", { key: e.inviteEventId });
|
|
3182
3218
|
}
|
|
3183
|
-
var
|
|
3184
|
-
function
|
|
3219
|
+
var vi = () => $ != null;
|
|
3220
|
+
function yi() {
|
|
3185
3221
|
if ($) return $;
|
|
3186
3222
|
Z.start();
|
|
3187
|
-
let e =
|
|
3223
|
+
let e = qr.subscribe((e, t) => {
|
|
3188
3224
|
e.games !== t.games && Object.entries(e.games).forEach(([e, n]) => {
|
|
3189
3225
|
let r = t.games[e];
|
|
3190
|
-
n.game && n.game !== "connect4" || n !== r && n.ownId != null &&
|
|
3226
|
+
n.game && n.game !== "connect4" || n !== r && n.ownId != null && _i(n, r);
|
|
3191
3227
|
});
|
|
3192
3228
|
}), t = () => {
|
|
3193
|
-
$ === t && ($ = null, e(), Q.forEach(({ timer: e }) => clearTimeout(e)), Q.clear(),
|
|
3229
|
+
$ === t && ($ = null, e(), Q.forEach(({ timer: e }) => clearTimeout(e)), Q.clear(), di.forEach(clearTimeout), di.clear());
|
|
3194
3230
|
};
|
|
3195
3231
|
return $ = t, t;
|
|
3196
3232
|
}
|
|
3197
|
-
export {
|
|
3233
|
+
export { b as C, x as S, nn as _, li as a, k as b, Qr as c, qr as d, rr as f, L as g, pn as h, yi as i, Zr as l, En as m, vi as n, ti as o, wn as p, hi as r, $r as s, Z as t, Kr as u, qt as v, xe as x, F as y };
|
|
3198
3234
|
|
|
3199
|
-
//# sourceMappingURL=connect4Sounds-
|
|
3235
|
+
//# sourceMappingURL=connect4Sounds-BN7d_TM2.js.map
|