yolkbot 1.4.5 → 1.4.7
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/LICENSE.md +114 -0
- package/browser/build/global.js +1 -1
- package/browser/build/module.js +1 -1
- package/dist/api.js +200 -1
- package/dist/bot/GamePlayer.js +74 -1
- package/dist/bot.js +1679 -1
- package/dist/comm/CommIn.js +79 -1
- package/dist/comm/CommOut.js +60 -1
- package/dist/comm/index.js +11 -1
- package/dist/constants/CloseCode.js +27 -1
- package/dist/constants/CommCode.js +53 -1
- package/dist/constants/challenges.js +1821 -1
- package/dist/constants/findItemById.js +2 -3
- package/dist/constants/guns.js +277 -1
- package/dist/constants/index.js +139 -1
- package/dist/constants/items.js +45042 -1
- package/dist/constants/maps.js +1263 -1
- package/dist/constants/regions.js +30 -1
- package/dist/dispatches/BanPlayerDispatch.js +32 -1
- package/dist/dispatches/BootPlayerDispatch.js +21 -1
- package/dist/dispatches/ChatDispatch.js +32 -1
- package/dist/dispatches/FireDispatch.js +15 -1
- package/dist/dispatches/GameOptionsDispatch.js +66 -1
- package/dist/dispatches/GoToAmmoDispatch.js +38 -1
- package/dist/dispatches/GoToCoopDispatch.js +38 -1
- package/dist/dispatches/GoToGrenadeDispatch.js +38 -1
- package/dist/dispatches/GoToPlayerDispatch.js +39 -1
- package/dist/dispatches/GoToSpatulaDispatch.js +26 -1
- package/dist/dispatches/LookAtDispatch.js +35 -1
- package/dist/dispatches/LookAtPosDispatch.js +29 -1
- package/dist/dispatches/MeleeDispatch.js +26 -1
- package/dist/dispatches/MovementDispatch.js +26 -1
- package/dist/dispatches/PauseDispatch.js +18 -1
- package/dist/dispatches/ReloadDispatch.js +28 -1
- package/dist/dispatches/ReportPlayerDispatch.js +42 -1
- package/dist/dispatches/ResetGameDispatch.js +19 -1
- package/dist/dispatches/SaveLoadoutDispatch.js +105 -1
- package/dist/dispatches/SpawnDispatch.js +22 -1
- package/dist/dispatches/SwapWeaponDispatch.js +25 -1
- package/dist/dispatches/SwitchTeamDispatch.js +33 -1
- package/dist/dispatches/ThrowGrenadeDispatch.js +21 -1
- package/dist/dispatches/index.js +74 -1
- package/dist/env/fetch.js +97 -10
- package/dist/env/globals.js +15 -1
- package/dist/index.js +14 -2
- package/dist/matchmaker.js +141 -1
- package/dist/pathing/astar.js +55 -1
- package/dist/pathing/binaryheap.js +79 -1
- package/dist/pathing/mapnode.js +179 -1
- package/dist/socket.js +97 -1
- package/dist/util.js +68 -1
- package/dist/wasm/bytes.js +8 -1
- package/dist/wasm/direct.js +84 -1
- package/dist/wasm/legacy.js +170 -1
- package/dist/wasm/util.js +19 -1
- package/package.json +41 -40
- /package/dist/{types/api.d.ts → api.d.ts} +0 -0
- /package/dist/{types/bot → bot}/GamePlayer.d.ts +0 -0
- /package/dist/{types/bot.d.ts → bot.d.ts} +0 -0
- /package/dist/{types/comm → comm}/CommIn.d.ts +0 -0
- /package/dist/{types/comm → comm}/CommOut.d.ts +0 -0
- /package/dist/{types/comm → comm}/index.d.ts +0 -0
- /package/dist/{types/constants → constants}/CloseCode.d.ts +0 -0
- /package/dist/{types/constants → constants}/CommCode.d.ts +0 -0
- /package/dist/{types/constants → constants}/challenges.d.ts +0 -0
- /package/dist/{types/constants → constants}/changelog.d.ts +0 -0
- /package/dist/{types/constants → constants}/findItemById.d.ts +0 -0
- /package/dist/{types/constants → constants}/guns.d.ts +0 -0
- /package/dist/{types/constants → constants}/housePromo.d.ts +0 -0
- /package/dist/{types/constants → constants}/index.d.ts +0 -0
- /package/dist/{types/constants → constants}/items.d.ts +0 -0
- /package/dist/{types/constants → constants}/language.d.ts +0 -0
- /package/dist/{types/constants → constants}/maps.d.ts +0 -0
- /package/dist/{types/constants → constants}/notices.d.ts +0 -0
- /package/dist/{types/constants → constants}/regions.d.ts +0 -0
- /package/dist/{types/constants → constants}/shellNews.d.ts +0 -0
- /package/dist/{types/constants → constants}/shellYoutube.d.ts +0 -0
- /package/dist/{types/constants → constants}/shopItems.d.ts +0 -0
- /package/dist/{types/constants → constants}/sounds.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/BanPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/BootPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ChatDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/FireDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GameOptionsDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToAmmoDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToCoopDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToGrenadeDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToSpatulaDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/LookAtDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/LookAtPosDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/MeleeDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/MovementDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/PauseDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ReloadDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ReportPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ResetGameDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SaveLoadoutDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SpawnDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SwapWeaponDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SwitchTeamDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ThrowGrenadeDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/index.d.ts +0 -0
- /package/dist/{types/matchmaker.d.ts → matchmaker.d.ts} +0 -0
- /package/dist/{types/pathing → pathing}/astar.d.ts +0 -0
- /package/dist/{types/pathing → pathing}/binaryheap.d.ts +0 -0
- /package/dist/{types/pathing → pathing}/mapnode.d.ts +0 -0
- /package/dist/{types/socket.d.ts → socket.d.ts} +0 -0
- /package/dist/{types/util.d.ts → util.d.ts} +0 -0
- /package/dist/{types/wasm → wasm}/bytes.d.ts +0 -0
- /package/dist/{types/wasm → wasm}/direct.d.ts +0 -0
- /package/dist/{types/wasm → wasm}/legacy.d.ts +0 -0
- /package/dist/{types/wasm → wasm}/util.d.ts +0 -0
package/dist/pathing/astar.js
CHANGED
|
@@ -1 +1,55 @@
|
|
|
1
|
-
import{BinaryHeap
|
|
1
|
+
import { BinaryHeap } from "./binaryheap.js";
|
|
2
|
+
export default class AStar {
|
|
3
|
+
constructor(list) {
|
|
4
|
+
this.list = list;
|
|
5
|
+
}
|
|
6
|
+
heuristic(pos1, pos2) {
|
|
7
|
+
return Math.abs(pos1.x - pos2.x) + Math.abs(pos1.y - pos2.y) + Math.abs(pos1.z - pos2.z);
|
|
8
|
+
}
|
|
9
|
+
reversePath(node) {
|
|
10
|
+
const path = [];
|
|
11
|
+
while (node.parent) {
|
|
12
|
+
path.push(node);
|
|
13
|
+
node = node.parent;
|
|
14
|
+
}
|
|
15
|
+
path.reverse();
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
path(start, end) {
|
|
19
|
+
this.list.clean();
|
|
20
|
+
const heap = new BinaryHeap((node) => node.f);
|
|
21
|
+
const closedSet = [];
|
|
22
|
+
start.h = this.heuristic(start, end);
|
|
23
|
+
start.g = 0;
|
|
24
|
+
start.f = start.g + start.h;
|
|
25
|
+
heap.push(start);
|
|
26
|
+
while (heap.size() !== 0) {
|
|
27
|
+
const current = heap.pop();
|
|
28
|
+
if (current === end) {
|
|
29
|
+
const val = this.reversePath(current);
|
|
30
|
+
return val;
|
|
31
|
+
}
|
|
32
|
+
closedSet.push(current);
|
|
33
|
+
const neighbors = current.links;
|
|
34
|
+
for (let i = 0;i < neighbors.length; i++) {
|
|
35
|
+
const neighbor = neighbors[i];
|
|
36
|
+
if (closedSet.includes(neighbor))
|
|
37
|
+
continue;
|
|
38
|
+
const tentativeGScore = current.g + 1;
|
|
39
|
+
const visited = neighbor.visited;
|
|
40
|
+
if (!visited || tentativeGScore < neighbor.g) {
|
|
41
|
+
neighbor.visited = true;
|
|
42
|
+
neighbor.parent = current;
|
|
43
|
+
neighbor.g = tentativeGScore;
|
|
44
|
+
neighbor.h = this.heuristic(neighbor.position, end.position);
|
|
45
|
+
neighbor.f = neighbor.g + neighbor.h;
|
|
46
|
+
if (visited)
|
|
47
|
+
heap.rescoreElement(neighbor);
|
|
48
|
+
else
|
|
49
|
+
heap.push(neighbor);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1 +1,79 @@
|
|
|
1
|
-
class BinaryHeap
|
|
1
|
+
class BinaryHeap {
|
|
2
|
+
constructor(scoreFunction) {
|
|
3
|
+
this.content = [];
|
|
4
|
+
this.scoreFunction = scoreFunction;
|
|
5
|
+
}
|
|
6
|
+
push(element) {
|
|
7
|
+
this.content.push(element);
|
|
8
|
+
this.bubbleUp(this.content.length - 1);
|
|
9
|
+
}
|
|
10
|
+
rescoreElement(node) {
|
|
11
|
+
this.sinkDown(this.content.indexOf(node));
|
|
12
|
+
}
|
|
13
|
+
pop() {
|
|
14
|
+
const result = this.content[0];
|
|
15
|
+
const end = this.content.pop();
|
|
16
|
+
if (this.content.length > 0) {
|
|
17
|
+
this.content[0] = end;
|
|
18
|
+
this.sinkDown(0);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
remove(node) {
|
|
23
|
+
const length = this.content.length;
|
|
24
|
+
for (let i = 0;i < length; i++) {
|
|
25
|
+
if (this.content[i] !== node)
|
|
26
|
+
continue;
|
|
27
|
+
const end = this.content.pop();
|
|
28
|
+
if (i === length - 1)
|
|
29
|
+
break;
|
|
30
|
+
this.content[i] = end;
|
|
31
|
+
this.bubbleUp(i);
|
|
32
|
+
this.sinkDown(i);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
size() {
|
|
37
|
+
return this.content.length;
|
|
38
|
+
}
|
|
39
|
+
bubbleUp(n) {
|
|
40
|
+
const element = this.content[n], score = this.scoreFunction(element);
|
|
41
|
+
while (n > 0) {
|
|
42
|
+
const parentN = Math.floor((n + 1) / 2) - 1, parent = this.content[parentN];
|
|
43
|
+
if (score >= this.scoreFunction(parent))
|
|
44
|
+
break;
|
|
45
|
+
this.content[parentN] = element;
|
|
46
|
+
this.content[n] = parent;
|
|
47
|
+
n = parentN;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
includes(n) {
|
|
51
|
+
return this.content.includes(n);
|
|
52
|
+
}
|
|
53
|
+
sinkDown(n) {
|
|
54
|
+
const length = this.content.length, element = this.content[n], elemScore = this.scoreFunction(element);
|
|
55
|
+
while (true) {
|
|
56
|
+
const child2N = (n + 1) * 2, child1N = child2N - 1;
|
|
57
|
+
let swap = null;
|
|
58
|
+
let child1Score;
|
|
59
|
+
if (child1N < length) {
|
|
60
|
+
const child1 = this.content[child1N];
|
|
61
|
+
child1Score = this.scoreFunction(child1);
|
|
62
|
+
if (child1Score < elemScore)
|
|
63
|
+
swap = child1N;
|
|
64
|
+
}
|
|
65
|
+
if (child2N < length) {
|
|
66
|
+
const child2 = this.content[child2N], child2Score = this.scoreFunction(child2);
|
|
67
|
+
if (child2Score < (swap === null ? elemScore : child1Score))
|
|
68
|
+
swap = child2N;
|
|
69
|
+
}
|
|
70
|
+
if (swap === null)
|
|
71
|
+
break;
|
|
72
|
+
this.content[n] = this.content[swap];
|
|
73
|
+
this.content[swap] = element;
|
|
74
|
+
n = swap;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export default BinaryHeap;
|
|
79
|
+
export { BinaryHeap };
|
package/dist/pathing/mapnode.js
CHANGED
|
@@ -1 +1,179 @@
|
|
|
1
|
-
class MapNode
|
|
1
|
+
class MapNode {
|
|
2
|
+
constructor(meshType, data) {
|
|
3
|
+
this.x = data.x;
|
|
4
|
+
this.y = data.y;
|
|
5
|
+
this.z = data.z;
|
|
6
|
+
this.positionStr = `${this.x},${this.y},${this.z}`;
|
|
7
|
+
this.position = { x: this.x, y: this.y, z: this.z };
|
|
8
|
+
this.meshType = meshType.split(".").pop();
|
|
9
|
+
this.f = 0;
|
|
10
|
+
this.g = 0;
|
|
11
|
+
this.h = 0;
|
|
12
|
+
this.visited = null;
|
|
13
|
+
this.parent = null;
|
|
14
|
+
this.closed = null;
|
|
15
|
+
this.links = [];
|
|
16
|
+
if (this.isStair()) {
|
|
17
|
+
if (data.ry)
|
|
18
|
+
this.ry = data.ry;
|
|
19
|
+
else
|
|
20
|
+
this.ry = 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
isFull() {
|
|
24
|
+
return this.meshType === "full";
|
|
25
|
+
}
|
|
26
|
+
canWalkThrough() {
|
|
27
|
+
return this.meshType === "none" || this.meshType === "ladder";
|
|
28
|
+
}
|
|
29
|
+
canWalkOn() {
|
|
30
|
+
return this.meshType === "full";
|
|
31
|
+
}
|
|
32
|
+
isLadder() {
|
|
33
|
+
return this.meshType === "ladder";
|
|
34
|
+
}
|
|
35
|
+
isStair() {
|
|
36
|
+
return this.meshType === "wedge";
|
|
37
|
+
}
|
|
38
|
+
isAir() {
|
|
39
|
+
return this.meshType === "none";
|
|
40
|
+
}
|
|
41
|
+
canLink(node, list) {
|
|
42
|
+
const dx0 = this.x - node.x;
|
|
43
|
+
const dz0 = this.z - node.z;
|
|
44
|
+
const dy0 = this.y - node.y;
|
|
45
|
+
const dx = Math.abs(dx0);
|
|
46
|
+
const dy = Math.abs(dy0);
|
|
47
|
+
const dz = Math.abs(dz0);
|
|
48
|
+
if (dx + dy + dz === 0 || dx + dz > 1 || this.isFull() || node.isFull())
|
|
49
|
+
return false;
|
|
50
|
+
const belowMe = list.at(this.x, this.y - 1, this.z);
|
|
51
|
+
const belowOther = list.at(node.x, node.y - 1, node.z);
|
|
52
|
+
if (!belowMe || !belowOther)
|
|
53
|
+
return false;
|
|
54
|
+
const FORWARD_RY_WEDGE_MAPPING = {
|
|
55
|
+
0: { x: 0, z: -1 },
|
|
56
|
+
1: { x: -1, z: 0 },
|
|
57
|
+
2: { x: 0, z: 1 },
|
|
58
|
+
3: { x: 1, z: 0 }
|
|
59
|
+
};
|
|
60
|
+
switch (this.meshType) {
|
|
61
|
+
case "none":
|
|
62
|
+
if (dy0 === 1 && node.canWalkThrough())
|
|
63
|
+
return true;
|
|
64
|
+
if (belowMe.canWalkOn() || belowMe.isLadder()) {
|
|
65
|
+
if (node.meshType === "none" || node.meshType === "ladder" && dy === 0 || node.meshType === "wedge" && dy0 === 0 && dx0 === -FORWARD_RY_WEDGE_MAPPING[node.ry].x && dz0 === -FORWARD_RY_WEDGE_MAPPING[node.ry].z) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
case "ladder":
|
|
71
|
+
if (dy === 1 && node.canWalkThrough())
|
|
72
|
+
return true;
|
|
73
|
+
if (dy === 0 && belowMe.canWalkOn())
|
|
74
|
+
return true;
|
|
75
|
+
if (node.meshType === "ladder" && (dy === 1 || belowMe.canWalkOn() && belowOther.canWalkOn()))
|
|
76
|
+
return true;
|
|
77
|
+
return false;
|
|
78
|
+
case "wedge":
|
|
79
|
+
if (this.x + FORWARD_RY_WEDGE_MAPPING[this.ry].x === node.x && this.z + FORWARD_RY_WEDGE_MAPPING[this.ry].z === node.z && this.y + 1 === node.y)
|
|
80
|
+
return true;
|
|
81
|
+
if (this.x - FORWARD_RY_WEDGE_MAPPING[this.ry].x === node.x && this.z - FORWARD_RY_WEDGE_MAPPING[this.ry].z === node.z && (this.y === node.y || this.y - 1 === node.y))
|
|
82
|
+
return true;
|
|
83
|
+
return false;
|
|
84
|
+
default:
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
flatCenter() {
|
|
89
|
+
return {
|
|
90
|
+
x: this.x + 0.5,
|
|
91
|
+
y: this.y + 0,
|
|
92
|
+
z: this.z + 0.5
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
flatRadialDistance(position) {
|
|
96
|
+
const pos = this.flatCenter();
|
|
97
|
+
return Math.hypot(pos.x - position.x, pos.z - position.z);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class NodeList {
|
|
102
|
+
list = [];
|
|
103
|
+
constructor(raw) {
|
|
104
|
+
const addedPositions = {};
|
|
105
|
+
for (const meshName of Object.keys(raw.data))
|
|
106
|
+
for (const nodeData of raw.data[meshName]) {
|
|
107
|
+
addedPositions[nodeData.x << 16 | nodeData.y << 8 | nodeData.z] = true;
|
|
108
|
+
this.list.push(new MapNode(meshName, nodeData));
|
|
109
|
+
}
|
|
110
|
+
for (let x = 0;x < raw.width; x++)
|
|
111
|
+
for (let y = 0;y < raw.height; y++)
|
|
112
|
+
for (let z = 0;z < raw.depth; z++)
|
|
113
|
+
if (!addedPositions[x << 16 | y << 8 | z])
|
|
114
|
+
this.list.push(new MapNode("SPECIAL.air.none", { x, y, z }));
|
|
115
|
+
const nodeMap = new Map;
|
|
116
|
+
for (const node of this.list)
|
|
117
|
+
nodeMap.set(node.positionStr, node);
|
|
118
|
+
for (const node of this.list) {
|
|
119
|
+
const neighbors = [
|
|
120
|
+
{ x: node.x + 1, y: node.y, z: node.z },
|
|
121
|
+
{ x: node.x - 1, y: node.y, z: node.z },
|
|
122
|
+
{ x: node.x, y: node.y + 1, z: node.z },
|
|
123
|
+
{ x: node.x, y: node.y - 1, z: node.z },
|
|
124
|
+
{ x: node.x, y: node.y, z: node.z + 1 },
|
|
125
|
+
{ x: node.x, y: node.y, z: node.z - 1 }
|
|
126
|
+
];
|
|
127
|
+
for (const neighborPos of neighbors) {
|
|
128
|
+
const neighborKey = `${neighborPos.x},${neighborPos.y},${neighborPos.z}`;
|
|
129
|
+
const neighborNode = nodeMap.get(neighborKey);
|
|
130
|
+
if (neighborNode && node.canLink(neighborNode, this))
|
|
131
|
+
node.links.push(neighborNode);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
at(x, y, z) {
|
|
136
|
+
if (!this.nodeMap) {
|
|
137
|
+
this.nodeMap = new Map;
|
|
138
|
+
for (const node of this.list) {
|
|
139
|
+
const key = `${node.x},${node.y},${node.z}`;
|
|
140
|
+
this.nodeMap.set(key, node);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const key = `${x},${y},${z}`;
|
|
144
|
+
return this.nodeMap.get(key);
|
|
145
|
+
}
|
|
146
|
+
clean() {
|
|
147
|
+
for (const node of this.list) {
|
|
148
|
+
node.f = 0;
|
|
149
|
+
node.g = 0;
|
|
150
|
+
node.h = 0;
|
|
151
|
+
node.visited = null;
|
|
152
|
+
node.parent = null;
|
|
153
|
+
node.closed = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
hasLineOfSight(bot, target) {
|
|
157
|
+
const dx = target.x - bot.x;
|
|
158
|
+
const dy = target.y - bot.y;
|
|
159
|
+
const dz = target.z - bot.z;
|
|
160
|
+
const steps = Math.max(Math.abs(dx), Math.abs(dy), Math.abs(dz));
|
|
161
|
+
const xStep = dx / steps;
|
|
162
|
+
const yStep = dy / steps;
|
|
163
|
+
const zStep = dz / steps;
|
|
164
|
+
let x = bot.x;
|
|
165
|
+
let y = bot.y;
|
|
166
|
+
let z = bot.z;
|
|
167
|
+
for (let i = 0;i <= steps; i++) {
|
|
168
|
+
const node = this.at(Math.round(x), Math.round(y), Math.round(z));
|
|
169
|
+
if (node && node.isFull())
|
|
170
|
+
return false;
|
|
171
|
+
x += xStep;
|
|
172
|
+
y += yStep;
|
|
173
|
+
z += zStep;
|
|
174
|
+
}
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export default MapNode;
|
|
179
|
+
export { MapNode, NodeList };
|
package/dist/socket.js
CHANGED
|
@@ -1 +1,97 @@
|
|
|
1
|
-
import
|
|
1
|
+
import globals from "./env/globals.js";
|
|
2
|
+
import { UserAgent } from "./constants/index.js";
|
|
3
|
+
|
|
4
|
+
class yolkws {
|
|
5
|
+
url = "";
|
|
6
|
+
proxy = "";
|
|
7
|
+
binaryType = "";
|
|
8
|
+
maxRetries = 5;
|
|
9
|
+
connectionTimeout = 5000;
|
|
10
|
+
constructor(url, proxy) {
|
|
11
|
+
if (globals.isBrowser && proxy)
|
|
12
|
+
throw new Error("You cannot pass a proxy to a WebSocket in a browser.");
|
|
13
|
+
this.url = url;
|
|
14
|
+
this.proxy = proxy;
|
|
15
|
+
}
|
|
16
|
+
async tryConnect(tries = 1) {
|
|
17
|
+
const url = new URL(this.url);
|
|
18
|
+
const retryOrQuit = async () => {
|
|
19
|
+
if (tries === 5)
|
|
20
|
+
return false;
|
|
21
|
+
return await this.tryConnect(tries + 1);
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
this.socket = globals.isBrowser ? new globals.WebSocket(this.url) : new globals.WebSocket(this.url, {
|
|
25
|
+
proxy: this.proxy || null,
|
|
26
|
+
headers: {
|
|
27
|
+
"accept-encoding": "gzip, deflate, br, zstd",
|
|
28
|
+
"accept-language": "en-US,en;q=0.9",
|
|
29
|
+
"cache-control": "no-cache",
|
|
30
|
+
connection: "Upgrade",
|
|
31
|
+
origin: url.origin.replace("ws", "http"),
|
|
32
|
+
pragma: "no-cache",
|
|
33
|
+
"sec-websocket-extensions": "permessage-deflate; client_max_window_bits",
|
|
34
|
+
"user-agent": UserAgent
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (this.binaryType)
|
|
38
|
+
this.socket.binaryType = this.binaryType;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.error(`Failed to connect on try ${tries}, trying again...`, e);
|
|
41
|
+
return await retryOrQuit();
|
|
42
|
+
}
|
|
43
|
+
if (this.onBeforeConnect)
|
|
44
|
+
this.onBeforeConnect();
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const timeout = setTimeout(async () => {
|
|
47
|
+
this.socket.close();
|
|
48
|
+
resolve(await retryOrQuit());
|
|
49
|
+
}, this.connectionTimeout);
|
|
50
|
+
const errorListener = async (e) => {
|
|
51
|
+
clearTimeout(timeout);
|
|
52
|
+
console.error("WebSocket error", e);
|
|
53
|
+
resolve(await retryOrQuit());
|
|
54
|
+
};
|
|
55
|
+
this.socket.addEventListener("open", async () => {
|
|
56
|
+
clearTimeout(timeout);
|
|
57
|
+
this.socket.removeEventListener("error", errorListener);
|
|
58
|
+
resolve(true);
|
|
59
|
+
});
|
|
60
|
+
this.socket.addEventListener("error", errorListener);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
get onmessage() {
|
|
64
|
+
return this.socket?.onmessage;
|
|
65
|
+
}
|
|
66
|
+
set onmessage(handler) {
|
|
67
|
+
if (this.socket)
|
|
68
|
+
this.socket.onmessage = handler;
|
|
69
|
+
else
|
|
70
|
+
console.error("set onmessage before socket existed");
|
|
71
|
+
}
|
|
72
|
+
get onclose() {
|
|
73
|
+
return this.socket?.onclose;
|
|
74
|
+
}
|
|
75
|
+
set onclose(handler) {
|
|
76
|
+
if (this.socket)
|
|
77
|
+
this.socket.onclose = handler;
|
|
78
|
+
else
|
|
79
|
+
console.error("set onclose before socket existed");
|
|
80
|
+
}
|
|
81
|
+
get onerror() {
|
|
82
|
+
return this.socket?.onerror;
|
|
83
|
+
}
|
|
84
|
+
set onerror(handler) {
|
|
85
|
+
if (this.socket)
|
|
86
|
+
this.socket.onerror = handler;
|
|
87
|
+
else
|
|
88
|
+
console.error("set onclose before socket existed");
|
|
89
|
+
}
|
|
90
|
+
send(data) {
|
|
91
|
+
return this.socket?.send(data);
|
|
92
|
+
}
|
|
93
|
+
close(data) {
|
|
94
|
+
return this.socket?.close(data);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export default yolkws;
|
package/dist/util.js
CHANGED
|
@@ -1 +1,68 @@
|
|
|
1
|
-
import
|
|
1
|
+
import globals from "./env/globals.js";
|
|
2
|
+
export const fetchMap = async (name, hash) => {
|
|
3
|
+
if (!globals.isIsolated && typeof process !== "undefined") {
|
|
4
|
+
const { existsSync, mkdirSync, readFileSync, writeFileSync } = process.getBuiltinModule("node:fs");
|
|
5
|
+
const { join } = process.getBuiltinModule("node:path");
|
|
6
|
+
const { homedir } = process.getBuiltinModule("node:os");
|
|
7
|
+
const yolkbotCache = join(homedir(), ".yolkbot");
|
|
8
|
+
if (!existsSync(yolkbotCache))
|
|
9
|
+
mkdirSync(yolkbotCache);
|
|
10
|
+
const mapCache = join(yolkbotCache, "maps");
|
|
11
|
+
if (!existsSync(mapCache))
|
|
12
|
+
mkdirSync(mapCache);
|
|
13
|
+
const mapFile = join(mapCache, `${name}-${hash}.json`);
|
|
14
|
+
if (existsSync(mapFile))
|
|
15
|
+
return JSON.parse(readFileSync(mapFile, "utf-8"));
|
|
16
|
+
const data = await (await fetch(`https://x.yolkbot.xyz/data/maps/full/${name}.json?${hash}`)).json();
|
|
17
|
+
writeFileSync(mapFile, JSON.stringify(data, null, 4), { flag: "w+" });
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
const data = await (await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${name}.json?${hash}`)).json();
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
export const initKotcZones = (meshData) => {
|
|
24
|
+
let numCaptureZones = 0;
|
|
25
|
+
const mapData = {};
|
|
26
|
+
const zones = [];
|
|
27
|
+
for (const cell of meshData) {
|
|
28
|
+
if (!mapData[cell.x])
|
|
29
|
+
mapData[cell.x] = {};
|
|
30
|
+
if (!mapData[cell.x][cell.y])
|
|
31
|
+
mapData[cell.x][cell.y] = {};
|
|
32
|
+
mapData[cell.x][cell.y][cell.z] = { zone: null };
|
|
33
|
+
}
|
|
34
|
+
const offsets = [
|
|
35
|
+
{ x: -1, z: 0 },
|
|
36
|
+
{ x: 1, z: 0 },
|
|
37
|
+
{ x: 0, z: -1 },
|
|
38
|
+
{ x: 0, z: 1 }
|
|
39
|
+
];
|
|
40
|
+
const getMapCellAt = (x, y, z) => mapData[x] && mapData[x][y] && mapData[x][y][z] ? mapData[x][y][z] : null;
|
|
41
|
+
for (const cellA of meshData) {
|
|
42
|
+
if (!mapData[cellA.x][cellA.y][cellA.z].zone) {
|
|
43
|
+
cellA.zone = ++numCaptureZones;
|
|
44
|
+
mapData[cellA.x][cellA.y][cellA.z].zone = cellA.zone;
|
|
45
|
+
const currentZone = [cellA];
|
|
46
|
+
let hits;
|
|
47
|
+
do {
|
|
48
|
+
hits = 0;
|
|
49
|
+
for (const cellB of meshData) {
|
|
50
|
+
if (!mapData[cellB.x][cellB.y][cellB.z].zone) {
|
|
51
|
+
for (const o of offsets) {
|
|
52
|
+
const cell = getMapCellAt(cellB.x + o.x, cellB.y, cellB.z + o.z);
|
|
53
|
+
if (cell && cell.zone === cellA.zone) {
|
|
54
|
+
hits++;
|
|
55
|
+
cellB.zone = cellA.zone;
|
|
56
|
+
mapData[cellB.x][cellB.y][cellB.z].zone = cellA.zone;
|
|
57
|
+
currentZone.push(cellB);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} while (hits > 0);
|
|
64
|
+
zones.push(currentZone);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return zones;
|
|
68
|
+
};
|