yolkbot 1.4.8 → 1.5.1
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 +1 -1
- package/browser/build/global.js +1 -1
- package/browser/build/module.js +1 -1
- package/dist/api.d.ts +34 -16
- package/dist/api.js +164 -121
- package/dist/bot/GamePlayer.d.ts +2 -2
- package/dist/bot/GamePlayer.js +15 -5
- package/dist/bot.d.ts +121 -83
- package/dist/bot.js +624 -1077
- package/dist/comm/CommIn.js +14 -17
- package/dist/comm/CommOut.js +15 -15
- package/dist/constants/CommCode.js +1 -1
- package/dist/constants/findItemById.js +2 -1
- package/dist/constants/guns.d.ts +16 -41
- package/dist/constants/guns.js +137 -259
- package/dist/constants/index.d.ts +7 -9
- package/dist/constants/index.js +15 -13
- package/dist/dispatches/BanPlayerDispatch.d.ts +3 -1
- package/dist/dispatches/BootPlayerDispatch.d.ts +3 -1
- package/dist/dispatches/ChatDispatch.d.ts +3 -1
- package/dist/dispatches/ChatDispatch.js +3 -3
- package/dist/dispatches/FireDispatch.d.ts +3 -1
- package/dist/dispatches/GameOptionsDispatch.d.ts +3 -1
- package/dist/dispatches/GoToAmmoDispatch.d.ts +2 -0
- package/dist/dispatches/GoToAmmoDispatch.js +15 -16
- package/dist/dispatches/GoToCoopDispatch.d.ts +2 -0
- package/dist/dispatches/GoToCoopDispatch.js +19 -20
- package/dist/dispatches/GoToGrenadeDispatch.d.ts +2 -0
- package/dist/dispatches/GoToGrenadeDispatch.js +15 -16
- package/dist/dispatches/GoToPlayerDispatch.d.ts +3 -1
- package/dist/dispatches/GoToPlayerDispatch.js +16 -21
- package/dist/dispatches/GoToSpatulaDispatch.d.ts +2 -0
- package/dist/dispatches/GoToSpatulaDispatch.js +11 -14
- package/dist/dispatches/LookAtDispatch.d.ts +3 -1
- package/dist/dispatches/LookAtDispatch.js +8 -6
- package/dist/dispatches/LookAtPosDispatch.d.ts +3 -1
- package/dist/dispatches/LookAtPosDispatch.js +1 -1
- package/dist/dispatches/MeleeDispatch.d.ts +2 -0
- package/dist/dispatches/MeleeDispatch.js +4 -4
- package/dist/dispatches/MovementDispatch.d.ts +3 -1
- package/dist/dispatches/MovementDispatch.js +1 -1
- package/dist/dispatches/PauseDispatch.d.ts +2 -0
- package/dist/dispatches/ReloadDispatch.d.ts +2 -0
- package/dist/dispatches/ReloadDispatch.js +17 -10
- package/dist/dispatches/ReportPlayerDispatch.d.ts +4 -2
- package/dist/dispatches/ReportPlayerDispatch.js +8 -6
- package/dist/dispatches/ResetGameDispatch.d.ts +2 -0
- package/dist/dispatches/SaveLoadoutDispatch.d.ts +4 -2
- package/dist/dispatches/SaveLoadoutDispatch.js +9 -8
- package/dist/dispatches/SpawnDispatch.d.ts +2 -0
- package/dist/dispatches/SpawnDispatch.js +5 -1
- package/dist/dispatches/SwapWeaponDispatch.d.ts +3 -1
- package/dist/dispatches/SwapWeaponDispatch.js +1 -1
- package/dist/dispatches/SwitchTeamDispatch.d.ts +2 -0
- package/dist/dispatches/SwitchTeamDispatch.js +2 -1
- package/dist/dispatches/ThrowGrenadeDispatch.d.ts +3 -1
- package/dist/dispatches/index.d.ts +105 -182
- package/dist/dispatches/index.js +24 -25
- package/dist/enums.d.ts +154 -0
- package/dist/enums.js +114 -0
- package/dist/env/fetch.d.ts +15 -0
- package/dist/env/fetch.js +113 -79
- package/dist/env/globals.d.ts +9 -0
- package/dist/env/globals.js +11 -9
- package/dist/index.d.ts +31 -0
- package/dist/index.js +24 -14
- package/dist/packets/addPlayer.js +63 -0
- package/dist/packets/beginShellStreak.js +44 -0
- package/dist/packets/challengeCompleted.js +16 -0
- package/dist/packets/changeCharacter.js +46 -0
- package/dist/packets/chat.js +10 -0
- package/dist/packets/collectItem.js +26 -0
- package/dist/packets/die.js +40 -0
- package/dist/packets/endShellStreak.js +21 -0
- package/dist/packets/eventModifier.js +8 -0
- package/dist/packets/explode.js +19 -0
- package/dist/packets/fire.js +21 -0
- package/dist/packets/gameAction.js +33 -0
- package/dist/packets/gameJoined.js +64 -0
- package/dist/packets/gameOptions.js +27 -0
- package/dist/packets/hitMe.js +12 -0
- package/dist/packets/hitMeHardBoiled.js +18 -0
- package/dist/packets/hitThem.js +12 -0
- package/dist/packets/melee.js +8 -0
- package/dist/packets/metaGameState.js +62 -0
- package/dist/packets/pause.js +17 -0
- package/dist/packets/ping.js +19 -0
- package/dist/packets/playerInfo.js +15 -0
- package/dist/packets/reload.js +17 -0
- package/dist/packets/removePlayer.js +10 -0
- package/dist/packets/respawn.js +31 -0
- package/dist/packets/socketReady.js +16 -0
- package/dist/packets/spawnItem.js +11 -0
- package/dist/packets/swapWeapon.js +11 -0
- package/dist/packets/switchTeam.js +13 -0
- package/dist/packets/syncMe.js +25 -0
- package/dist/packets/syncThem.js +63 -0
- package/dist/packets/throwGrenade.js +17 -0
- package/dist/packets/updateBalance.js +8 -0
- package/dist/pathing/astar.js +33 -20
- package/dist/pathing/mapnode.d.ts +3 -1
- package/dist/pathing/mapnode.js +170 -65
- package/dist/socket.d.ts +21 -6
- package/dist/socket.js +48 -38
- package/dist/util.d.ts +4 -1
- package/dist/util.js +102 -44
- package/dist/wasm/bytes.d.ts +1 -1
- package/dist/wasm/bytes.js +1 -1
- package/dist/wasm/direct.d.ts +1 -1
- package/dist/wasm/direct.js +13 -13
- package/dist/wasm/legacy.d.ts +7 -6
- package/dist/wasm/legacy.js +14 -8
- package/package.json +43 -30
- package/dist/comm/index.d.ts +0 -12
- package/dist/comm/index.js +0 -11
- package/dist/constants/changelog.d.ts +0 -7
- package/dist/constants/housePromo.d.ts +0 -40
- package/dist/constants/language.d.ts +0 -3
- package/dist/constants/notices.d.ts +0 -4
- package/dist/constants/shellNews.d.ts +0 -12
- package/dist/constants/shellYoutube.d.ts +0 -12
- package/dist/constants/shopItems.d.ts +0 -15
- package/dist/constants/sounds.d.ts +0 -10
- package/dist/matchmaker.d.ts +0 -50
- package/dist/matchmaker.js +0 -141
- package/dist/pathing/binaryheap.d.ts +0 -18
- package/dist/pathing/binaryheap.js +0 -79
- package/dist/wasm/util.d.ts +0 -9
- package/dist/wasm/util.js +0 -19
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
const processRespawnPacket = (bot) => {
|
|
3
|
+
const id = CommIn.unPackInt8U();
|
|
4
|
+
const seed = CommIn.unPackInt16U();
|
|
5
|
+
const x = CommIn.unPackFloat();
|
|
6
|
+
const y = CommIn.unPackFloat();
|
|
7
|
+
const z = CommIn.unPackFloat();
|
|
8
|
+
const primaryRounds = CommIn.unPackInt8U();
|
|
9
|
+
const primaryStore = CommIn.unPackInt8U();
|
|
10
|
+
const secondaryRounds = CommIn.unPackInt8U();
|
|
11
|
+
const secondaryStore = CommIn.unPackInt8U();
|
|
12
|
+
const grenades = CommIn.unPackInt8U();
|
|
13
|
+
const player = bot.players[id];
|
|
14
|
+
if (player) {
|
|
15
|
+
player.playing = true;
|
|
16
|
+
player.randomSeed = seed;
|
|
17
|
+
if (player.weapons[0] && player.weapons[0].ammo)
|
|
18
|
+
player.weapons[0].ammo.rounds = primaryRounds;
|
|
19
|
+
if (player.weapons[0] && player.weapons[0].ammo)
|
|
20
|
+
player.weapons[0].ammo.store = primaryStore;
|
|
21
|
+
if (player.weapons[1] && player.weapons[1].ammo)
|
|
22
|
+
player.weapons[1].ammo.rounds = secondaryRounds;
|
|
23
|
+
if (player.weapons[1] && player.weapons[1].ammo)
|
|
24
|
+
player.weapons[1].ammo.store = secondaryStore;
|
|
25
|
+
player.grenades = grenades;
|
|
26
|
+
player.position = { x, y, z };
|
|
27
|
+
player.spawnShield = 120;
|
|
28
|
+
bot.$emit("playerRespawn", player);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export default processRespawnPacket;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import CommOut from "../comm/CommOut.js";
|
|
2
|
+
import CommCode from "../constants/CommCode.js";
|
|
3
|
+
import { Intents } from "../enums.js";
|
|
4
|
+
const processSocketReadyPacket = (bot) => {
|
|
5
|
+
const out = new CommOut;
|
|
6
|
+
out.packInt8(bot.intents.includes(Intents.OBSERVE_GAME) ? CommCode.observeGame : CommCode.joinGame);
|
|
7
|
+
out.packString(bot.game.raw.uuid);
|
|
8
|
+
out.packInt8(+bot.intents.includes(Intents.VIP_HIDE_BADGE));
|
|
9
|
+
out.packInt8(bot.state.weaponIdx || bot.account.loadout?.classIdx || 0);
|
|
10
|
+
out.packString(bot.state.name);
|
|
11
|
+
out.packInt32(bot.account.session);
|
|
12
|
+
out.packString(bot.account.sessionId);
|
|
13
|
+
out.packString(bot.account.firebaseId);
|
|
14
|
+
out.send(bot.game.socket);
|
|
15
|
+
};
|
|
16
|
+
export default processSocketReadyPacket;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
const processSpawnItemPacket = (bot) => {
|
|
3
|
+
const id = CommIn.unPackInt16U();
|
|
4
|
+
const type = CommIn.unPackInt8U();
|
|
5
|
+
const x = CommIn.unPackFloat();
|
|
6
|
+
const y = CommIn.unPackFloat();
|
|
7
|
+
const z = CommIn.unPackFloat();
|
|
8
|
+
bot.game.collectibles[type].push({ id, x, y, z });
|
|
9
|
+
bot.$emit("spawnItem", type, { x, y, z }, id);
|
|
10
|
+
};
|
|
11
|
+
export default processSpawnItemPacket;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
const processSwapWeaponPacket = (bot) => {
|
|
3
|
+
const id = CommIn.unPackInt8U();
|
|
4
|
+
const newWeaponId = CommIn.unPackInt8U();
|
|
5
|
+
const player = bot.players[id];
|
|
6
|
+
if (player) {
|
|
7
|
+
player.activeGun = newWeaponId;
|
|
8
|
+
bot.$emit("playerSwapWeapon", player, newWeaponId);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export default processSwapWeaponPacket;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
const processSwitchTeamPacket = (bot) => {
|
|
3
|
+
const id = CommIn.unPackInt8U();
|
|
4
|
+
const toTeam = CommIn.unPackInt8U();
|
|
5
|
+
const player = bot.players[id];
|
|
6
|
+
if (!player)
|
|
7
|
+
return;
|
|
8
|
+
const oldTeam = player.team;
|
|
9
|
+
player.team = toTeam;
|
|
10
|
+
player.streak = 0;
|
|
11
|
+
bot.$emit("playerSwitchTeam", player, oldTeam, toTeam);
|
|
12
|
+
};
|
|
13
|
+
export default processSwitchTeamPacket;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
const processSyncMePacket = (bot) => {
|
|
3
|
+
const id = CommIn.unPackInt8U();
|
|
4
|
+
const player = bot.players[id];
|
|
5
|
+
CommIn.unPackInt8U();
|
|
6
|
+
const serverStateIdx = CommIn.unPackInt8U();
|
|
7
|
+
const newX = CommIn.unPackFloat();
|
|
8
|
+
const newY = CommIn.unPackFloat();
|
|
9
|
+
const newZ = CommIn.unPackFloat();
|
|
10
|
+
bot.me.climbing = !!CommIn.unPackInt8U();
|
|
11
|
+
CommIn.unPackInt8U();
|
|
12
|
+
CommIn.unPackInt8U();
|
|
13
|
+
if (!player)
|
|
14
|
+
return;
|
|
15
|
+
bot.state.serverStateIdx = serverStateIdx;
|
|
16
|
+
const oldX = player.position.x;
|
|
17
|
+
const oldY = player.position.y;
|
|
18
|
+
const oldZ = player.position.z;
|
|
19
|
+
player.position.x = newX;
|
|
20
|
+
player.position.y = newY;
|
|
21
|
+
player.position.z = newZ;
|
|
22
|
+
if (oldX !== newX || oldY !== newY || oldZ !== newZ)
|
|
23
|
+
bot.$emit("playerMove", player, { x: oldX, y: oldY, z: oldZ }, { x: newX, y: newY, z: newZ });
|
|
24
|
+
};
|
|
25
|
+
export default processSyncMePacket;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
import { FramesBetweenSyncs, GameMode, Movement } from "../constants/index.js";
|
|
3
|
+
import { ZoneLeaveReason } from "../enums.js";
|
|
4
|
+
const processSyncThemPacket = (bot) => {
|
|
5
|
+
const id = CommIn.unPackInt8U();
|
|
6
|
+
const x = CommIn.unPackFloat();
|
|
7
|
+
const y = CommIn.unPackFloat();
|
|
8
|
+
const z = CommIn.unPackFloat();
|
|
9
|
+
const climbing = CommIn.unPackInt8U();
|
|
10
|
+
const player = bot.players[id];
|
|
11
|
+
if (!player || player.id === bot.me.id) {
|
|
12
|
+
for (let i2 = 0;i2 < FramesBetweenSyncs; i2++) {
|
|
13
|
+
CommIn.unPackInt8U();
|
|
14
|
+
CommIn.unPackRadU();
|
|
15
|
+
CommIn.unPackRad();
|
|
16
|
+
CommIn.unPackInt8U();
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
for (let i2 = 0;i2 < FramesBetweenSyncs; i2++) {
|
|
21
|
+
const controlKeys = CommIn.unPackInt8U();
|
|
22
|
+
player.jumping = !!(controlKeys & Movement.Jump);
|
|
23
|
+
player.scoping = !!(controlKeys & Movement.Scope);
|
|
24
|
+
const oldView = structuredClone(player.view);
|
|
25
|
+
player.view.yaw = CommIn.unPackRadU();
|
|
26
|
+
player.view.pitch = CommIn.unPackRad();
|
|
27
|
+
if (player.view.yaw !== oldView.yaw || player.view.pitch !== oldView.pitch)
|
|
28
|
+
bot.$emit("playerRotate", player, oldView, player.view);
|
|
29
|
+
player.scale = CommIn.unPackInt8U();
|
|
30
|
+
}
|
|
31
|
+
const px = player.position;
|
|
32
|
+
const posChanged = px.x !== x || px.y !== y || px.z !== z;
|
|
33
|
+
const climbingChanged = player.climbing !== climbing;
|
|
34
|
+
const didChange = posChanged || climbingChanged;
|
|
35
|
+
const oldPosition = didChange ? structuredClone(px) : null;
|
|
36
|
+
if (px.x !== x)
|
|
37
|
+
px.x = x;
|
|
38
|
+
if (px.z !== z)
|
|
39
|
+
px.z = z;
|
|
40
|
+
if (!player.jumping || Math.abs(px.y - y) > 0.5)
|
|
41
|
+
px.y = y;
|
|
42
|
+
if (climbingChanged)
|
|
43
|
+
player.climbing = climbing;
|
|
44
|
+
if (!didChange)
|
|
45
|
+
return;
|
|
46
|
+
bot.$emit("playerMove", player, oldPosition, px);
|
|
47
|
+
if (bot.game.gameModeId !== GameMode.KOTC)
|
|
48
|
+
return;
|
|
49
|
+
const zone = bot.game.kotc.activeZone;
|
|
50
|
+
const wasIn = !!player.inKotcZone;
|
|
51
|
+
if (!zone && wasIn) {
|
|
52
|
+
player.inKotcZone = false;
|
|
53
|
+
bot.$emit("playerLeaveZone", player, ZoneLeaveReason.RoundEnded);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
player.updateKotcZone(zone);
|
|
57
|
+
const nowIn = !!player.inKotcZone;
|
|
58
|
+
if (wasIn !== nowIn) {
|
|
59
|
+
player.inKotcZone = nowIn;
|
|
60
|
+
bot.$emit(nowIn ? "playerEnterZone" : "playerLeaveZone", player, nowIn ? null : ZoneLeaveReason.WalkedOut);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export default processSyncThemPacket;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
const processThrowGrenadePacket = (bot) => {
|
|
3
|
+
const id = CommIn.unPackInt8U();
|
|
4
|
+
const x = CommIn.unPackFloat();
|
|
5
|
+
const y = CommIn.unPackFloat();
|
|
6
|
+
const z = CommIn.unPackFloat();
|
|
7
|
+
const dx = CommIn.unPackFloat();
|
|
8
|
+
const dy = CommIn.unPackFloat();
|
|
9
|
+
const dz = CommIn.unPackFloat();
|
|
10
|
+
const player = bot.players[id];
|
|
11
|
+
if (player) {
|
|
12
|
+
if (player.grenades > 0)
|
|
13
|
+
player.grenades--;
|
|
14
|
+
bot.$emit("playerThrowGrenade", player, { x, y, z }, { x: dx, y: dy, z: dz });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export default processThrowGrenadePacket;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import CommIn from "../comm/CommIn.js";
|
|
2
|
+
const processUpdateBalancePacket = (bot) => {
|
|
3
|
+
const newBalance = CommIn.unPackInt32U();
|
|
4
|
+
const oldBalance = bot.account.eggBalance;
|
|
5
|
+
bot.account.eggBalance = newBalance;
|
|
6
|
+
bot.$emit("balanceUpdate", oldBalance, newBalance);
|
|
7
|
+
};
|
|
8
|
+
export default processUpdateBalancePacket;
|
package/dist/pathing/astar.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { BinaryHeap } from "./binaryheap.js";
|
|
2
1
|
export default class AStar {
|
|
3
2
|
constructor(list) {
|
|
4
3
|
this.list = list;
|
|
5
4
|
}
|
|
6
5
|
heuristic(pos1, pos2) {
|
|
7
|
-
|
|
6
|
+
const dx = Math.abs(pos1.x - pos2.x);
|
|
7
|
+
const dy = Math.abs(pos1.y - pos2.y);
|
|
8
|
+
const dz = Math.abs(pos1.z - pos2.z);
|
|
9
|
+
const dxz = Math.max(dx, dz);
|
|
10
|
+
return dy + dxz;
|
|
8
11
|
}
|
|
9
12
|
reversePath(node) {
|
|
10
13
|
const path = [];
|
|
@@ -17,36 +20,46 @@ export default class AStar {
|
|
|
17
20
|
}
|
|
18
21
|
path(start, end) {
|
|
19
22
|
this.list.clean();
|
|
20
|
-
const
|
|
21
|
-
const closedSet =
|
|
23
|
+
const openSet = [start];
|
|
24
|
+
const closedSet = new Set;
|
|
22
25
|
start.h = this.heuristic(start, end);
|
|
23
26
|
start.g = 0;
|
|
24
|
-
start.f = start.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
start.f = start.h;
|
|
28
|
+
start.visited = true;
|
|
29
|
+
let current;
|
|
30
|
+
while (openSet.length > 0) {
|
|
31
|
+
let lowestIdx = 0;
|
|
32
|
+
let lowestF = openSet[0].f;
|
|
33
|
+
let lowestG = openSet[0].g;
|
|
34
|
+
for (let i = 1;i < openSet.length; i++) {
|
|
35
|
+
const node = openSet[i];
|
|
36
|
+
if (node.f < lowestF || node.f === lowestF && node.g > lowestG) {
|
|
37
|
+
lowestF = node.f;
|
|
38
|
+
lowestG = node.g;
|
|
39
|
+
lowestIdx = i;
|
|
40
|
+
}
|
|
31
41
|
}
|
|
32
|
-
|
|
42
|
+
current = openSet[lowestIdx];
|
|
43
|
+
if (current === end)
|
|
44
|
+
return this.reversePath(current);
|
|
45
|
+
openSet[lowestIdx] = openSet[openSet.length - 1];
|
|
46
|
+
openSet.pop();
|
|
47
|
+
closedSet.add(current);
|
|
33
48
|
const neighbors = current.links;
|
|
34
49
|
for (let i = 0;i < neighbors.length; i++) {
|
|
35
50
|
const neighbor = neighbors[i];
|
|
36
|
-
if (closedSet.
|
|
51
|
+
if (closedSet.has(neighbor))
|
|
37
52
|
continue;
|
|
38
53
|
const tentativeGScore = current.g + 1;
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
if (!neighbor.visited || tentativeGScore < neighbor.g) {
|
|
55
|
+
const isNew = !neighbor.visited;
|
|
41
56
|
neighbor.visited = true;
|
|
42
57
|
neighbor.parent = current;
|
|
43
58
|
neighbor.g = tentativeGScore;
|
|
44
|
-
neighbor.h = this.heuristic(neighbor
|
|
59
|
+
neighbor.h = this.heuristic(neighbor, end);
|
|
45
60
|
neighbor.f = neighbor.g + neighbor.h;
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
else
|
|
49
|
-
heap.push(neighbor);
|
|
61
|
+
if (isNew)
|
|
62
|
+
openSet.push(neighbor);
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
65
|
}
|
|
@@ -14,6 +14,7 @@ declare class MapNode {
|
|
|
14
14
|
parent: MapNode | null;
|
|
15
15
|
closed: any | null;
|
|
16
16
|
links: MapNode[];
|
|
17
|
+
flatCenter: Position;
|
|
17
18
|
ry?: number;
|
|
18
19
|
|
|
19
20
|
constructor(meshType: string, data: { x: number; y: number; z: number; ry?: number });
|
|
@@ -25,7 +26,6 @@ declare class MapNode {
|
|
|
25
26
|
isStair(): boolean;
|
|
26
27
|
isAir(): boolean;
|
|
27
28
|
canLink(node: MapNode, list: NodeList): boolean;
|
|
28
|
-
flatCenter(): Position;
|
|
29
29
|
flatRadialDistance(position: Position): number;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -36,6 +36,8 @@ declare class NodeList {
|
|
|
36
36
|
constructor(raw: { data: Record<string, Array<{ x: number; y: number; z: number; ry?: number }>>, width: number, height: number, depth: number });
|
|
37
37
|
|
|
38
38
|
at(x: number, y: number, z: number): MapNode | undefined;
|
|
39
|
+
atObject(position: Position): MapNode | undefined;
|
|
40
|
+
|
|
39
41
|
clean(): void;
|
|
40
42
|
hasLineOfSight(bot: Position, target: Position): boolean;
|
|
41
43
|
}
|
package/dist/pathing/mapnode.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
const FORWARD_RY_WEDGE_MAPPING = Object.freeze({
|
|
2
|
+
0: { x: 0, z: -1 },
|
|
3
|
+
1: { x: -1, z: 0 },
|
|
4
|
+
2: { x: 0, z: 1 },
|
|
5
|
+
3: { x: 1, z: 0 }
|
|
6
|
+
});
|
|
7
|
+
const positionKey = (x, y, z) => (x & 255) << 16 | (y & 255) << 8 | z & 255;
|
|
8
|
+
|
|
1
9
|
class MapNode {
|
|
2
10
|
constructor(meshType, data) {
|
|
3
11
|
this.x = data.x;
|
|
4
12
|
this.y = data.y;
|
|
5
13
|
this.z = data.z;
|
|
6
|
-
this.
|
|
7
|
-
this.position = { x: this.x, y: this.y, z: this.z };
|
|
14
|
+
this.positionKey = positionKey(this.x, this.y, this.z);
|
|
8
15
|
this.meshType = meshType.split(".").pop();
|
|
9
16
|
this.f = 0;
|
|
10
17
|
this.g = 0;
|
|
@@ -13,12 +20,13 @@ class MapNode {
|
|
|
13
20
|
this.parent = null;
|
|
14
21
|
this.closed = null;
|
|
15
22
|
this.links = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
this.flatCenter = {
|
|
24
|
+
x: this.x + 0.5,
|
|
25
|
+
y: this.y,
|
|
26
|
+
z: this.z + 0.5
|
|
27
|
+
};
|
|
28
|
+
if (this.meshType === "wedge")
|
|
29
|
+
this.ry = data.ry ?? 0;
|
|
22
30
|
}
|
|
23
31
|
isFull() {
|
|
24
32
|
return this.meshType === "full";
|
|
@@ -38,6 +46,9 @@ class MapNode {
|
|
|
38
46
|
isAir() {
|
|
39
47
|
return this.meshType === "none";
|
|
40
48
|
}
|
|
49
|
+
isJumpPad() {
|
|
50
|
+
return this.meshType === "jump-pad";
|
|
51
|
+
}
|
|
41
52
|
canLink(node, list) {
|
|
42
53
|
const dx0 = this.x - node.x;
|
|
43
54
|
const dz0 = this.z - node.z;
|
|
@@ -45,103 +56,197 @@ class MapNode {
|
|
|
45
56
|
const dx = Math.abs(dx0);
|
|
46
57
|
const dy = Math.abs(dy0);
|
|
47
58
|
const dz = Math.abs(dz0);
|
|
48
|
-
if (dx + dy + dz === 0 || dx + dz > 1 || this.isFull() || node.isFull())
|
|
59
|
+
if (dx + dy + dz === 0 || dx + dz > 1 && !(dx === 2 && dz === 1 || dx === 1 && dz === 2 || dx === 2 && dz === 2) || this.isFull() || node.isFull())
|
|
49
60
|
return false;
|
|
50
61
|
const belowMe = list.at(this.x, this.y - 1, this.z);
|
|
51
62
|
const belowOther = list.at(node.x, node.y - 1, node.z);
|
|
52
63
|
if (!belowMe || !belowOther)
|
|
53
64
|
return false;
|
|
54
|
-
|
|
55
|
-
0
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
if (dy === 0 && belowMe.isFull() && belowOther.isFull()) {
|
|
66
|
+
if (dx === 2 && dz === 0 || dx === 0 && dz === 2) {
|
|
67
|
+
const midX = (this.x + node.x) / 2;
|
|
68
|
+
const midZ = (this.z + node.z) / 2;
|
|
69
|
+
const midNode = list.at(midX, this.y, midZ);
|
|
70
|
+
const midBelow = list.at(midX, this.y - 1, midZ);
|
|
71
|
+
const midAbove = list.at(midX, this.y + 1, midZ);
|
|
72
|
+
if (midBelow && midBelow.isAir()) {
|
|
73
|
+
if (midNode && midNode.isAir() && midAbove && midAbove.isAir()) {
|
|
74
|
+
const startHead = list.at(this.x, this.y + 1, this.z);
|
|
75
|
+
const endHead = list.at(node.x, node.y + 1, node.z);
|
|
76
|
+
if (startHead && startHead.isAir() && endHead && endHead.isAir()) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} else if (dx === 2 && dz === 1 || dx === 1 && dz === 2) {
|
|
82
|
+
const xDir = dx0 > 0 ? -1 : 1;
|
|
83
|
+
const zDir = dz0 > 0 ? -1 : 1;
|
|
84
|
+
const checks = dx === 2 ? [
|
|
85
|
+
[this.x + xDir, this.y, this.z],
|
|
86
|
+
[this.x + xDir, this.y, this.z + zDir]
|
|
87
|
+
] : [
|
|
88
|
+
[this.x, this.y, this.z + zDir],
|
|
89
|
+
[this.x + xDir, this.y, this.z + zDir]
|
|
90
|
+
];
|
|
91
|
+
let allClear = true;
|
|
92
|
+
for (const [x, y, z] of checks) {
|
|
93
|
+
const block = list.at(x, y, z);
|
|
94
|
+
const blockBelow = list.at(x, y - 1, z);
|
|
95
|
+
const blockAbove = list.at(x, y + 1, z);
|
|
96
|
+
if (!block || !block.isAir() || !blockBelow || !blockBelow.isAir() || !blockAbove || !blockAbove.isAir()) {
|
|
97
|
+
allClear = false;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (allClear) {
|
|
102
|
+
const startHead = list.at(this.x, this.y + 1, this.z);
|
|
103
|
+
const endHead = list.at(node.x, node.y + 1, node.z);
|
|
104
|
+
if (startHead && startHead.isAir() && endHead && endHead.isAir())
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
} else if (dx === 2 && dz === 2) {
|
|
108
|
+
const xDir = dx0 > 0 ? -1 : 1;
|
|
109
|
+
const zDir = dz0 > 0 ? -1 : 1;
|
|
110
|
+
const checks = [
|
|
111
|
+
[this.x + xDir, this.y, this.z + zDir],
|
|
112
|
+
[this.x + 2 * xDir, this.y, this.z + zDir],
|
|
113
|
+
[this.x + 2 * xDir, this.y, this.z + 2 * zDir]
|
|
114
|
+
];
|
|
115
|
+
let allClear = true;
|
|
116
|
+
for (const [x, y, z] of checks) {
|
|
117
|
+
const block = list.at(x, y, z);
|
|
118
|
+
const blockBelow = list.at(x, y - 1, z);
|
|
119
|
+
const blockAbove = list.at(x, y + 1, z);
|
|
120
|
+
if (!block || !block.isAir() || !blockBelow || !blockBelow.isAir() || !blockAbove || !blockAbove.isAir()) {
|
|
121
|
+
allClear = false;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (allClear) {
|
|
126
|
+
const startHead = list.at(this.x, this.y + 1, this.z);
|
|
127
|
+
const endHead = list.at(node.x, node.y + 1, node.z);
|
|
128
|
+
if (startHead && startHead.isAir() && endHead && endHead.isAir())
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const meSupported = belowMe.isFull() || this.isStair();
|
|
134
|
+
const otherSupported = belowOther.isFull() || belowOther.isStair() || node.isStair();
|
|
135
|
+
if (dy <= 2 && meSupported && otherSupported) {
|
|
136
|
+
if (this.meshType === "none") {
|
|
62
137
|
if (dy0 === 1 && node.canWalkThrough())
|
|
63
138
|
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)
|
|
139
|
+
if (belowMe.canWalkOn() || belowMe.isLadder() || belowMe.isStair()) {
|
|
140
|
+
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
141
|
return true;
|
|
67
|
-
}
|
|
68
142
|
}
|
|
69
143
|
return false;
|
|
70
|
-
|
|
144
|
+
} else if (this.meshType === "ladder") {
|
|
71
145
|
if (dy === 1 && node.canWalkThrough())
|
|
72
146
|
return true;
|
|
73
147
|
if (dy === 0 && belowMe.canWalkOn())
|
|
74
148
|
return true;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (this.x +
|
|
149
|
+
return node.meshType === "ladder" && (dy === 1 || belowMe.canWalkOn() && belowOther.canWalkOn());
|
|
150
|
+
} else if (this.meshType === "wedge") {
|
|
151
|
+
const forward = FORWARD_RY_WEDGE_MAPPING[this.ry];
|
|
152
|
+
const backward = { x: -forward.x, z: -forward.z };
|
|
153
|
+
if (this.x + forward.x === node.x && this.z + forward.z === node.z) {
|
|
154
|
+
if (this.y + 1 === node.y && node.canWalkThrough())
|
|
155
|
+
return true;
|
|
156
|
+
if (this.y === node.y && node.meshType === "wedge")
|
|
157
|
+
return true;
|
|
158
|
+
if (this.y + 1 === node.y && node.meshType === "wedge")
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
if (this.x + backward.x === node.x && this.z + backward.z === node.z) {
|
|
162
|
+
if ((this.y === node.y || this.y - 1 === node.y) && node.canWalkThrough())
|
|
163
|
+
return true;
|
|
164
|
+
if (this.y - 1 === node.y && (node.meshType === "wedge" || node.meshType === "none" && belowOther.isFull()))
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
if (node.canWalkThrough() && (belowOther.isFull() || belowOther.isStair()))
|
|
80
168
|
return true;
|
|
81
|
-
if (
|
|
169
|
+
if (node.isStair())
|
|
82
170
|
return true;
|
|
83
171
|
return false;
|
|
84
|
-
|
|
85
|
-
return false;
|
|
172
|
+
}
|
|
86
173
|
}
|
|
87
|
-
|
|
88
|
-
flatCenter() {
|
|
89
|
-
return {
|
|
90
|
-
x: this.x + 0.5,
|
|
91
|
-
y: this.y + 0,
|
|
92
|
-
z: this.z + 0.5
|
|
93
|
-
};
|
|
174
|
+
return false;
|
|
94
175
|
}
|
|
95
176
|
flatRadialDistance(position) {
|
|
96
|
-
|
|
97
|
-
return Math.hypot(pos.x - position.x, pos.z - position.z);
|
|
177
|
+
return Math.hypot(this.flatCenter.x - position.x, this.flatCenter.z - position.z);
|
|
98
178
|
}
|
|
99
179
|
}
|
|
180
|
+
const NEIGHBOR_OFFSETS = [
|
|
181
|
+
[1, 0, 0],
|
|
182
|
+
[-1, 0, 0],
|
|
183
|
+
[0, 1, 0],
|
|
184
|
+
[0, -1, 0],
|
|
185
|
+
[0, 0, 1],
|
|
186
|
+
[0, 0, -1],
|
|
187
|
+
[1, 0, 1],
|
|
188
|
+
[1, 0, -1],
|
|
189
|
+
[-1, 0, 1],
|
|
190
|
+
[-1, 0, -1],
|
|
191
|
+
[1, 1, 0],
|
|
192
|
+
[-1, 1, 0],
|
|
193
|
+
[0, 1, 1],
|
|
194
|
+
[0, 1, -1],
|
|
195
|
+
[1, -1, 0],
|
|
196
|
+
[-1, -1, 0],
|
|
197
|
+
[0, -1, 1],
|
|
198
|
+
[0, -1, -1],
|
|
199
|
+
[2, 0, 0],
|
|
200
|
+
[-2, 0, 0],
|
|
201
|
+
[0, 0, 2],
|
|
202
|
+
[0, 0, -2],
|
|
203
|
+
[2, 0, 1],
|
|
204
|
+
[2, 0, -1],
|
|
205
|
+
[-2, 0, 1],
|
|
206
|
+
[-2, 0, -1],
|
|
207
|
+
[1, 0, 2],
|
|
208
|
+
[1, 0, -2],
|
|
209
|
+
[-1, 0, 2],
|
|
210
|
+
[-1, 0, -2],
|
|
211
|
+
[2, 0, 2],
|
|
212
|
+
[2, 0, -2],
|
|
213
|
+
[-2, 0, 2],
|
|
214
|
+
[-2, 0, -2]
|
|
215
|
+
];
|
|
100
216
|
|
|
101
217
|
class NodeList {
|
|
102
218
|
list = [];
|
|
219
|
+
nodeMap = null;
|
|
103
220
|
constructor(raw) {
|
|
104
|
-
const addedPositions =
|
|
105
|
-
for (const meshName of Object.keys(raw.data))
|
|
221
|
+
const addedPositions = new Set;
|
|
222
|
+
for (const meshName of Object.keys(raw.data)) {
|
|
106
223
|
for (const nodeData of raw.data[meshName]) {
|
|
107
|
-
addedPositions
|
|
224
|
+
addedPositions.add(positionKey(nodeData.x, nodeData.y, nodeData.z));
|
|
108
225
|
this.list.push(new MapNode(meshName, nodeData));
|
|
109
226
|
}
|
|
227
|
+
}
|
|
110
228
|
for (let x = 0;x < raw.width; x++)
|
|
111
229
|
for (let y = 0;y < raw.height; y++)
|
|
112
230
|
for (let z = 0;z < raw.depth; z++)
|
|
113
|
-
if (!addedPositions
|
|
231
|
+
if (!addedPositions.has(positionKey(x, y, z)))
|
|
114
232
|
this.list.push(new MapNode("SPECIAL.air.none", { x, y, z }));
|
|
115
|
-
|
|
233
|
+
this.nodeMap = new Map;
|
|
116
234
|
for (const node of this.list)
|
|
117
|
-
nodeMap.set(node.
|
|
235
|
+
this.nodeMap.set(node.positionKey, node);
|
|
118
236
|
for (const node of this.list) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
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);
|
|
237
|
+
for (const [dx, dy, dz] of NEIGHBOR_OFFSETS) {
|
|
238
|
+
const neighborKey = positionKey(node.x + dx, node.y + dy, node.z + dz);
|
|
239
|
+
const neighborNode = this.nodeMap.get(neighborKey);
|
|
130
240
|
if (neighborNode && node.canLink(neighborNode, this))
|
|
131
241
|
node.links.push(neighborNode);
|
|
132
242
|
}
|
|
133
243
|
}
|
|
134
244
|
}
|
|
135
245
|
at(x, y, z) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.nodeMap.set(key, node);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const key = `${x},${y},${z}`;
|
|
144
|
-
return this.nodeMap.get(key);
|
|
246
|
+
return this.nodeMap?.get(positionKey(x, y, z));
|
|
247
|
+
}
|
|
248
|
+
atObject({ x, y, z }) {
|
|
249
|
+
return this.nodeMap?.get(positionKey(Math.floor(x), Math.floor(y), Math.floor(z)));
|
|
145
250
|
}
|
|
146
251
|
clean() {
|
|
147
252
|
for (const node of this.list) {
|
|
@@ -166,7 +271,7 @@ class NodeList {
|
|
|
166
271
|
let z = bot.z;
|
|
167
272
|
for (let i = 0;i <= steps; i++) {
|
|
168
273
|
const node = this.at(Math.round(x), Math.round(y), Math.round(z));
|
|
169
|
-
if (node
|
|
274
|
+
if (node?.isFull())
|
|
170
275
|
return false;
|
|
171
276
|
x += xStep;
|
|
172
277
|
y += yStep;
|
package/dist/socket.d.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
type Data = string | Buffer | ArrayBuffer | Buffer[];
|
|
2
2
|
|
|
3
|
+
interface yolkwsParams {
|
|
4
|
+
proxy?: string;
|
|
5
|
+
errorLogger?: (...args: any[]) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
declare class yolkws {
|
|
4
|
-
|
|
9
|
+
connected: boolean;
|
|
10
|
+
autoReconnect: boolean;
|
|
11
|
+
|
|
12
|
+
url: string;
|
|
13
|
+
proxy: string | undefined;
|
|
14
|
+
|
|
15
|
+
binaryType: string;
|
|
16
|
+
|
|
17
|
+
connectionTimeout: number;
|
|
18
|
+
|
|
19
|
+
constructor(url: string, params?: yolkwsParams);
|
|
5
20
|
|
|
6
|
-
tryConnect($tries?: number): Promise<
|
|
21
|
+
tryConnect($tries?: number): Promise<boolean>;
|
|
7
22
|
|
|
8
|
-
onmessage: (data: Data) => void;
|
|
9
23
|
onopen: () => void;
|
|
10
|
-
|
|
11
|
-
|
|
24
|
+
onmessage: (event: MessageEvent) => void;
|
|
25
|
+
onclose: (event: CloseEvent) => void;
|
|
26
|
+
onerror: (event: Event) => void;
|
|
12
27
|
|
|
13
28
|
send(data: Data): void;
|
|
14
|
-
close(
|
|
29
|
+
close(data?: number): void;
|
|
15
30
|
}
|
|
16
31
|
|
|
17
32
|
export default yolkws;
|