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.
Files changed (113) hide show
  1. package/LICENSE.md +114 -0
  2. package/browser/build/global.js +1 -1
  3. package/browser/build/module.js +1 -1
  4. package/dist/api.js +200 -1
  5. package/dist/bot/GamePlayer.js +74 -1
  6. package/dist/bot.js +1679 -1
  7. package/dist/comm/CommIn.js +79 -1
  8. package/dist/comm/CommOut.js +60 -1
  9. package/dist/comm/index.js +11 -1
  10. package/dist/constants/CloseCode.js +27 -1
  11. package/dist/constants/CommCode.js +53 -1
  12. package/dist/constants/challenges.js +1821 -1
  13. package/dist/constants/findItemById.js +2 -3
  14. package/dist/constants/guns.js +277 -1
  15. package/dist/constants/index.js +139 -1
  16. package/dist/constants/items.js +45042 -1
  17. package/dist/constants/maps.js +1263 -1
  18. package/dist/constants/regions.js +30 -1
  19. package/dist/dispatches/BanPlayerDispatch.js +32 -1
  20. package/dist/dispatches/BootPlayerDispatch.js +21 -1
  21. package/dist/dispatches/ChatDispatch.js +32 -1
  22. package/dist/dispatches/FireDispatch.js +15 -1
  23. package/dist/dispatches/GameOptionsDispatch.js +66 -1
  24. package/dist/dispatches/GoToAmmoDispatch.js +38 -1
  25. package/dist/dispatches/GoToCoopDispatch.js +38 -1
  26. package/dist/dispatches/GoToGrenadeDispatch.js +38 -1
  27. package/dist/dispatches/GoToPlayerDispatch.js +39 -1
  28. package/dist/dispatches/GoToSpatulaDispatch.js +26 -1
  29. package/dist/dispatches/LookAtDispatch.js +35 -1
  30. package/dist/dispatches/LookAtPosDispatch.js +29 -1
  31. package/dist/dispatches/MeleeDispatch.js +26 -1
  32. package/dist/dispatches/MovementDispatch.js +26 -1
  33. package/dist/dispatches/PauseDispatch.js +18 -1
  34. package/dist/dispatches/ReloadDispatch.js +28 -1
  35. package/dist/dispatches/ReportPlayerDispatch.js +42 -1
  36. package/dist/dispatches/ResetGameDispatch.js +19 -1
  37. package/dist/dispatches/SaveLoadoutDispatch.js +105 -1
  38. package/dist/dispatches/SpawnDispatch.js +22 -1
  39. package/dist/dispatches/SwapWeaponDispatch.js +25 -1
  40. package/dist/dispatches/SwitchTeamDispatch.js +33 -1
  41. package/dist/dispatches/ThrowGrenadeDispatch.js +21 -1
  42. package/dist/dispatches/index.js +74 -1
  43. package/dist/env/fetch.js +97 -10
  44. package/dist/env/globals.js +15 -1
  45. package/dist/index.js +14 -2
  46. package/dist/matchmaker.js +141 -1
  47. package/dist/pathing/astar.js +55 -1
  48. package/dist/pathing/binaryheap.js +79 -1
  49. package/dist/pathing/mapnode.js +179 -1
  50. package/dist/socket.js +97 -1
  51. package/dist/util.js +68 -1
  52. package/dist/wasm/bytes.js +8 -1
  53. package/dist/wasm/direct.js +84 -1
  54. package/dist/wasm/legacy.js +170 -1
  55. package/dist/wasm/util.js +19 -1
  56. package/package.json +41 -40
  57. /package/dist/{types/api.d.ts → api.d.ts} +0 -0
  58. /package/dist/{types/bot → bot}/GamePlayer.d.ts +0 -0
  59. /package/dist/{types/bot.d.ts → bot.d.ts} +0 -0
  60. /package/dist/{types/comm → comm}/CommIn.d.ts +0 -0
  61. /package/dist/{types/comm → comm}/CommOut.d.ts +0 -0
  62. /package/dist/{types/comm → comm}/index.d.ts +0 -0
  63. /package/dist/{types/constants → constants}/CloseCode.d.ts +0 -0
  64. /package/dist/{types/constants → constants}/CommCode.d.ts +0 -0
  65. /package/dist/{types/constants → constants}/challenges.d.ts +0 -0
  66. /package/dist/{types/constants → constants}/changelog.d.ts +0 -0
  67. /package/dist/{types/constants → constants}/findItemById.d.ts +0 -0
  68. /package/dist/{types/constants → constants}/guns.d.ts +0 -0
  69. /package/dist/{types/constants → constants}/housePromo.d.ts +0 -0
  70. /package/dist/{types/constants → constants}/index.d.ts +0 -0
  71. /package/dist/{types/constants → constants}/items.d.ts +0 -0
  72. /package/dist/{types/constants → constants}/language.d.ts +0 -0
  73. /package/dist/{types/constants → constants}/maps.d.ts +0 -0
  74. /package/dist/{types/constants → constants}/notices.d.ts +0 -0
  75. /package/dist/{types/constants → constants}/regions.d.ts +0 -0
  76. /package/dist/{types/constants → constants}/shellNews.d.ts +0 -0
  77. /package/dist/{types/constants → constants}/shellYoutube.d.ts +0 -0
  78. /package/dist/{types/constants → constants}/shopItems.d.ts +0 -0
  79. /package/dist/{types/constants → constants}/sounds.d.ts +0 -0
  80. /package/dist/{types/dispatches → dispatches}/BanPlayerDispatch.d.ts +0 -0
  81. /package/dist/{types/dispatches → dispatches}/BootPlayerDispatch.d.ts +0 -0
  82. /package/dist/{types/dispatches → dispatches}/ChatDispatch.d.ts +0 -0
  83. /package/dist/{types/dispatches → dispatches}/FireDispatch.d.ts +0 -0
  84. /package/dist/{types/dispatches → dispatches}/GameOptionsDispatch.d.ts +0 -0
  85. /package/dist/{types/dispatches → dispatches}/GoToAmmoDispatch.d.ts +0 -0
  86. /package/dist/{types/dispatches → dispatches}/GoToCoopDispatch.d.ts +0 -0
  87. /package/dist/{types/dispatches → dispatches}/GoToGrenadeDispatch.d.ts +0 -0
  88. /package/dist/{types/dispatches → dispatches}/GoToPlayerDispatch.d.ts +0 -0
  89. /package/dist/{types/dispatches → dispatches}/GoToSpatulaDispatch.d.ts +0 -0
  90. /package/dist/{types/dispatches → dispatches}/LookAtDispatch.d.ts +0 -0
  91. /package/dist/{types/dispatches → dispatches}/LookAtPosDispatch.d.ts +0 -0
  92. /package/dist/{types/dispatches → dispatches}/MeleeDispatch.d.ts +0 -0
  93. /package/dist/{types/dispatches → dispatches}/MovementDispatch.d.ts +0 -0
  94. /package/dist/{types/dispatches → dispatches}/PauseDispatch.d.ts +0 -0
  95. /package/dist/{types/dispatches → dispatches}/ReloadDispatch.d.ts +0 -0
  96. /package/dist/{types/dispatches → dispatches}/ReportPlayerDispatch.d.ts +0 -0
  97. /package/dist/{types/dispatches → dispatches}/ResetGameDispatch.d.ts +0 -0
  98. /package/dist/{types/dispatches → dispatches}/SaveLoadoutDispatch.d.ts +0 -0
  99. /package/dist/{types/dispatches → dispatches}/SpawnDispatch.d.ts +0 -0
  100. /package/dist/{types/dispatches → dispatches}/SwapWeaponDispatch.d.ts +0 -0
  101. /package/dist/{types/dispatches → dispatches}/SwitchTeamDispatch.d.ts +0 -0
  102. /package/dist/{types/dispatches → dispatches}/ThrowGrenadeDispatch.d.ts +0 -0
  103. /package/dist/{types/dispatches → dispatches}/index.d.ts +0 -0
  104. /package/dist/{types/matchmaker.d.ts → matchmaker.d.ts} +0 -0
  105. /package/dist/{types/pathing → pathing}/astar.d.ts +0 -0
  106. /package/dist/{types/pathing → pathing}/binaryheap.d.ts +0 -0
  107. /package/dist/{types/pathing → pathing}/mapnode.d.ts +0 -0
  108. /package/dist/{types/socket.d.ts → socket.d.ts} +0 -0
  109. /package/dist/{types/util.d.ts → util.d.ts} +0 -0
  110. /package/dist/{types/wasm → wasm}/bytes.d.ts +0 -0
  111. /package/dist/{types/wasm → wasm}/direct.d.ts +0 -0
  112. /package/dist/{types/wasm → wasm}/legacy.d.ts +0 -0
  113. /package/dist/{types/wasm → wasm}/util.d.ts +0 -0
@@ -1 +1,55 @@
1
- import{BinaryHeap as l}from"./binaryheap.js";export default class AStar{constructor(e){this.list=e}heuristic(e,t){return Math.abs(e.x-t.x)+Math.abs(e.y-t.y)+Math.abs(e.z-t.z)}reversePath(e){const t=[];while(e.parent){t.push(e);e=e.parent}t.reverse();return t}path(e,t){this.list.clean();const n=new l((s)=>s.f),r=[];e.h=this.heuristic(e,t);e.g=0;e.f=e.g+e.h;n.push(e);while(n.size()!==0){const s=n.pop();if(s===t)return this.reversePath(s);r.push(s);const c=s.links;for(let h=0;h<c.length;h++){const i=c[h];if(r.includes(i))continue;const a=s.g+1,o=i.visited;if(!o||a<i.g){i.visited=!0;i.parent=s;i.g=a;i.h=this.heuristic(i.position,t.position);i.f=i.g+i.h;if(o)n.rescoreElement(i);else n.push(i)}}}return null}}
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{constructor(b){this.content=[];this.scoreFunction=b}push(b){this.content.push(b);this.bubbleUp(this.content.length-1)}rescoreElement(b){this.sinkDown(this.content.indexOf(b))}pop(){const b=this.content[0],j=this.content.pop();if(this.content.length>0){this.content[0]=j;this.sinkDown(0)}return b}remove(b){const j=this.content.length;for(let f=0;f<j;f++){if(this.content[f]!==b)continue;const k=this.content.pop();if(f===j-1)break;this.content[f]=k;this.bubbleUp(f);this.sinkDown(f);break}}size(){return this.content.length}bubbleUp(b){const j=this.content[b],f=this.scoreFunction(j);while(b>0){const k=Math.floor((b+1)/2)-1,q=this.content[k];if(f>=this.scoreFunction(q))break;this.content[k]=j;this.content[b]=q;b=k}}includes(b){return this.content.includes(b)}sinkDown(b){const j=this.content.length,f=this.content[b],k=this.scoreFunction(f);while(!0){const q=(b+1)*2,x=q-1;let v=null,z;if(x<j){const A=this.content[x];z=this.scoreFunction(A);if(z<k)v=x}if(q<j){const A=this.content[q];if(this.scoreFunction(A)<(v===null?k:z))v=q}if(v===null)break;this.content[b]=this.content[v];this.content[v]=f;b=v}}}export default BinaryHeap;export{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 };
@@ -1 +1,179 @@
1
- class MapNode{constructor(t,i){this.x=i.x;this.y=i.y;this.z=i.z;this.positionStr=`${this.x},${this.y},${this.z}`;this.position={x:this.x,y:this.y,z:this.z};this.meshType=t.split(".").pop();this.f=0;this.g=0;this.h=0;this.visited=null;this.parent=null;this.closed=null;this.links=[];if(this.isStair())if(i.ry)this.ry=i.ry;else this.ry=0}isFull(){return this.meshType==="full"}canWalkThrough(){return this.meshType==="none"||this.meshType==="ladder"}canWalkOn(){return this.meshType==="full"}isLadder(){return this.meshType==="ladder"}isStair(){return this.meshType==="wedge"}isAir(){return this.meshType==="none"}canLink(t,i){const r=this.x-t.x,s=this.z-t.z,e=this.y-t.y,h=Math.abs(r),n=Math.abs(e),a=Math.abs(s);if(h+n+a===0||h+a>1||this.isFull()||t.isFull())return!1;const y=i.at(this.x,this.y-1,this.z),o=i.at(t.x,t.y-1,t.z);if(!y||!o)return!1;const l={0:{x:0,z:-1},1:{x:-1,z:0},2:{x:0,z:1},3:{x:1,z:0}};switch(this.meshType){case"none":if(e===1&&t.canWalkThrough())return!0;if(y.canWalkOn()||y.isLadder()){if(t.meshType==="none"||t.meshType==="ladder"&&n===0||t.meshType==="wedge"&&e===0&&r===-l[t.ry].x&&s===-l[t.ry].z)return!0}return!1;case"ladder":if(n===1&&t.canWalkThrough())return!0;if(n===0&&y.canWalkOn())return!0;if(t.meshType==="ladder"&&(n===1||y.canWalkOn()&&o.canWalkOn()))return!0;return!1;case"wedge":if(this.x+l[this.ry].x===t.x&&this.z+l[this.ry].z===t.z&&this.y+1===t.y)return!0;if(this.x-l[this.ry].x===t.x&&this.z-l[this.ry].z===t.z&&(this.y===t.y||this.y-1===t.y))return!0;return!1;default:return!1}}flatCenter(){return{x:this.x+0.5,y:this.y+0,z:this.z+0.5}}flatRadialDistance(t){const i=this.flatCenter();return Math.hypot(i.x-t.x,i.z-t.z)}}class NodeList{list=[];constructor(t){const i={};for(const s of Object.keys(t.data))for(const e of t.data[s]){i[e.x<<16|e.y<<8|e.z]=!0;this.list.push(new MapNode(s,e))}for(let s=0;s<t.width;s++)for(let e=0;e<t.height;e++)for(let h=0;h<t.depth;h++)if(!i[s<<16|e<<8|h])this.list.push(new MapNode("SPECIAL.air.none",{x:s,y:e,z:h}));const r=new Map;for(const s of this.list)r.set(s.positionStr,s);for(const s of this.list){const e=[{x:s.x+1,y:s.y,z:s.z},{x:s.x-1,y:s.y,z:s.z},{x:s.x,y:s.y+1,z:s.z},{x:s.x,y:s.y-1,z:s.z},{x:s.x,y:s.y,z:s.z+1},{x:s.x,y:s.y,z:s.z-1}];for(const h of e){const n=`${h.x},${h.y},${h.z}`,a=r.get(n);if(a&&s.canLink(a,this))s.links.push(a)}}}at(t,i,r){if(!this.nodeMap){this.nodeMap=new Map;for(const e of this.list){const h=`${e.x},${e.y},${e.z}`;this.nodeMap.set(h,e)}}const s=`${t},${i},${r}`;return this.nodeMap.get(s)}clean(){for(const t of this.list){t.f=0;t.g=0;t.h=0;t.visited=null;t.parent=null;t.closed=null}}hasLineOfSight(t,i){const r=i.x-t.x,s=i.y-t.y,e=i.z-t.z,h=Math.max(Math.abs(r),Math.abs(s),Math.abs(e)),n=r/h,a=s/h,y=e/h;let{x:o,y:l,z:u}=t;for(let c=0;c<=h;c++){const f=this.at(Math.round(o),Math.round(l),Math.round(u));if(f&&f.isFull())return!1;o+=n;l+=a;u+=y}return!0}}export default MapNode;export{MapNode,NodeList};
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 s from"./env/globals.js";import{UserAgent as l}from"./constants/index.js";class i{url="";proxy="";binaryType="";maxRetries=5;connectionTimeout=5000;constructor(e,o){if(s.isBrowser&&o)throw Error("You cannot pass a proxy to a WebSocket in a browser.");this.url=e;this.proxy=o}async tryConnect(e=1){const o=new URL(this.url),r=async()=>{if(e===5)return!1;return await this.tryConnect(e+1)};try{this.socket=s.isBrowser?new s.WebSocket(this.url):new s.WebSocket(this.url,{proxy:this.proxy||null,headers:{"accept-encoding":"gzip, deflate, br, zstd","accept-language":"en-US,en;q=0.9","cache-control":"no-cache",connection:"Upgrade",origin:o.origin.replace("ws","http"),pragma:"no-cache","sec-websocket-extensions":"permessage-deflate; client_max_window_bits","user-agent":l}});if(this.binaryType)this.socket.binaryType=this.binaryType}catch(t){console.error(`Failed to connect on try ${e}, trying again...`,t);return await r()}if(this.onBeforeConnect)this.onBeforeConnect();return new Promise((t)=>{const n=setTimeout(async()=>{this.socket.close();t(await r())},this.connectionTimeout),c=async(a)=>{clearTimeout(n);console.error("WebSocket error",a);t(await r())};this.socket.addEventListener("open",async()=>{clearTimeout(n);this.socket.removeEventListener("error",c);t(!0)});this.socket.addEventListener("error",c)})}get onmessage(){return this.socket?.onmessage}set onmessage(e){if(this.socket)this.socket.onmessage=e;else console.error("set onmessage before socket existed")}get onclose(){return this.socket?.onclose}set onclose(e){if(this.socket)this.socket.onclose=e;else console.error("set onclose before socket existed")}get onerror(){return this.socket?.onerror}set onerror(e){if(this.socket)this.socket.onerror=e;else console.error("set onclose before socket existed")}send(e){return this.socket?.send(e)}close(e){return this.socket?.close(e)}}export default i;
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 u from"./env/globals.js";export const fetchMap=async(c,a)=>{if(!u.isIsolated&&typeof process<"u"){const{existsSync:i,mkdirSync:f,readFileSync:p,writeFileSync:o}=process.getBuiltinModule("node:fs"),{join:e}=process.getBuiltinModule("node:path"),{homedir:s}=process.getBuiltinModule("node:os"),t=e(s(),".yolkbot");if(!i(t))f(t);const l=e(t,"maps");if(!i(l))f(l);const r=e(l,`${c}-${a}.json`);if(i(r))return JSON.parse(p(r,"utf-8"));const z=await(await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${c}.json?${a}`)).json();o(r,JSON.stringify(z,null,4),{flag:"w+"});return z}return await(await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${c}.json?${a}`)).json()},initKotcZones=(c)=>{let a=0;const n={},i=[];for(const o of c){if(!n[o.x])n[o.x]={};if(!n[o.x][o.y])n[o.x][o.y]={};n[o.x][o.y][o.z]={zone:null}}const f=[{x:-1,z:0},{x:1,z:0},{x:0,z:-1},{x:0,z:1}],p=(o,e,s)=>n[o]&&n[o][e]&&n[o][e][s]?n[o][e][s]:null;for(const o of c)if(!n[o.x][o.y][o.z].zone){o.zone=++a;n[o.x][o.y][o.z].zone=o.zone;const e=[o];let s;do{s=0;for(const t of c)if(!n[t.x][t.y][t.z].zone)for(const l of f){const r=p(t.x+l.x,t.y,t.z+l.z);if(r&&r.zone===o.zone){s++;t.zone=o.zone;n[t.x][t.y][t.z].zone=o.zone;e.push(t);break}}}while(s>0);i.push(e)}return i};
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
+ };