yolkbot 0.1.1-alpha.40 → 0.1.1-alpha.42
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 +2 -2
- package/package.json +8 -21
- package/src/api.js +1 -1
- package/src/bot/GamePlayer.js +1 -1
- package/src/bot.js +5 -5
- package/src/dispatches/BootPlayerDispatch.js +6 -2
- package/src/dispatches/ChatDispatch.js +7 -2
- package/src/dispatches/GameOptionsDispatch.js +20 -2
- package/src/dispatches/MeleeDispatch.js +6 -4
- package/src/dispatches/PauseDispatch.js +7 -3
- package/src/dispatches/ReloadDispatch.js +5 -2
- package/src/dispatches/ReportPlayerDispatch.js +7 -2
- package/src/dispatches/SaveLoadoutDispatch.js +10 -5
- package/src/dispatches/SpawnDispatch.js +5 -2
- package/src/dispatches/SwapWeaponDispatch.js +7 -2
- package/src/dispatches/SwitchTeamDispatch.js +5 -2
- package/src/dispatches/ThrowGrenadeDispatch.js +6 -2
- package/src/matchmaker.js +2 -5
- package/src/pathing/astar.js +7 -25
- package/src/pathing/binaryheap.js +6 -6
- package/src/pathing/mapnode.js +4 -50
- package/src/socket.js +1 -1
- package/browser/build/global.js +0 -8
- package/browser/build/module.js +0 -8
- package/src/dispatches/LookDispatch2.js +0 -18
- package/src/packet.js +0 -128
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<h1>yolkbot</h1>
|
|
3
3
|
<h3>creating bots in 10 lines since 2025</h3>
|
|
4
4
|
<p>
|
|
5
|
-
<a href='https://github.com/
|
|
5
|
+
<a href='https://github.com/yolkorg/yolkbot'>github</a> |
|
|
6
6
|
<a href='https://yolkbot.villainsrule.xyz'>documentation</a> |
|
|
7
7
|
<a href='https://npmjs.com/yolkbot'>npm</a> |
|
|
8
8
|
<a href='https://discord.gg/gYugVUCaMr'>discord</a>
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
<h3 align='center'>credits</h3>
|
|
24
24
|
|
|
25
25
|
<p align='center'>
|
|
26
|
-
this
|
|
26
|
+
this codebase was written by <a href='https://github.com/villainsrule'>1ust</a> with large contributions from <a href='https://github.com/enbyte'>hijinks</a> :trollface: <br>
|
|
27
27
|
special thanks to BWD for leaking the source, which made development 100x easier ❤️
|
|
28
28
|
</p>
|
package/package.json
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yolkbot",
|
|
3
|
-
"description": "create a shell shockers
|
|
4
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"description": "create a shell shockers bot in under 10 lines.",
|
|
4
|
+
"version": "0.1.1-alpha.42",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shell shockers",
|
|
7
7
|
"shellshock.io",
|
|
8
8
|
"blue wizard",
|
|
9
9
|
"yolkbot"
|
|
10
10
|
],
|
|
11
|
-
"homepage": "https://github.com/
|
|
11
|
+
"homepage": "https://github.com/yolkorg/yolkbot#readme",
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/yolkorg/yolkbot/issues"
|
|
14
14
|
},
|
|
15
|
-
"author": "
|
|
16
|
-
"contributors": [
|
|
17
|
-
"1ust"
|
|
18
|
-
],
|
|
15
|
+
"author": "1ust",
|
|
16
|
+
"contributors": ["hijinks"],
|
|
19
17
|
"repository": {
|
|
20
18
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/yolkorg/yolkbot.git"
|
|
22
20
|
},
|
|
23
21
|
"type": "module",
|
|
24
22
|
"files": [
|
|
@@ -41,7 +39,6 @@
|
|
|
41
39
|
"import": "./src/matchmaker.js",
|
|
42
40
|
"types": "./src/types/matchmaker.d.ts"
|
|
43
41
|
},
|
|
44
|
-
"./packets": "./src/packet.js",
|
|
45
42
|
"./pathing/*": "./src/pathing/*.js",
|
|
46
43
|
"./pathing/*.js": "./src/pathing/*.js",
|
|
47
44
|
"./bot": {
|
|
@@ -94,16 +91,6 @@
|
|
|
94
91
|
"globals": "^15.15.0"
|
|
95
92
|
},
|
|
96
93
|
"scripts": {
|
|
97
|
-
"lint": "eslint --fix"
|
|
98
|
-
"prod": "./prod.sh",
|
|
99
|
-
"test": "./build.sh"
|
|
100
|
-
},
|
|
101
|
-
"imports": {
|
|
102
|
-
"#api": "./src/api.js",
|
|
103
|
-
"#bot": "./src/bot.js",
|
|
104
|
-
"#constants": "./src/constants/index.js",
|
|
105
|
-
"#dispatch/*": "./src/dispatches/*",
|
|
106
|
-
"#matchmaker": "./src/matchmaker.js",
|
|
107
|
-
"#packet": "./src/packet.js"
|
|
94
|
+
"lint": "eslint --fix"
|
|
108
95
|
}
|
|
109
96
|
}
|
package/src/api.js
CHANGED
|
@@ -2,7 +2,7 @@ import axios from 'axios';
|
|
|
2
2
|
|
|
3
3
|
import yolkws from './socket.js';
|
|
4
4
|
|
|
5
|
-
import { FirebaseKey, ProxiesEnabled, UserAgent } from '
|
|
5
|
+
import { FirebaseKey, ProxiesEnabled, UserAgent } from './constants/index.js';
|
|
6
6
|
|
|
7
7
|
let SocksProxyAgent;
|
|
8
8
|
if (ProxiesEnabled) SocksProxyAgent = (await import('smallsocks')).SocksProxyAgent;
|
package/src/bot/GamePlayer.js
CHANGED
package/src/bot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createAccount, loginAnonymously, loginWithCredentials, loginWithRefreshToken, queryServices } from '
|
|
1
|
+
import { createAccount, loginAnonymously, loginWithCredentials, loginWithRefreshToken, queryServices } from './api.js';
|
|
2
2
|
|
|
3
3
|
import CommIn from './comm/CommIn.js';
|
|
4
4
|
import CommOut from './comm/CommOut.js';
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
PlayTypes,
|
|
24
24
|
ProxiesEnabled,
|
|
25
25
|
ShellStreaks
|
|
26
|
-
} from '
|
|
26
|
+
} from './constants/index.js';
|
|
27
27
|
|
|
28
28
|
import LookAtPosDispatch from './dispatches/LookAtPosDispatch.js';
|
|
29
29
|
import MovementDispatch from './dispatches/MovementDispatch.js';
|
|
@@ -363,7 +363,7 @@ export class Bot {
|
|
|
363
363
|
this.matchmaker.off('msg', listener);
|
|
364
364
|
|
|
365
365
|
this.game.raw = mes;
|
|
366
|
-
this.game.code =
|
|
366
|
+
this.game.code = mes.id;
|
|
367
367
|
|
|
368
368
|
resolve();
|
|
369
369
|
}
|
|
@@ -636,7 +636,7 @@ export class Bot {
|
|
|
636
636
|
}
|
|
637
637
|
|
|
638
638
|
update() {
|
|
639
|
-
if (!this.state.joinedGame) throw new Error('
|
|
639
|
+
if (!this.state.joinedGame) throw new Error('You cannot call update() if the bot is not in a game.');
|
|
640
640
|
|
|
641
641
|
// process pathfinding
|
|
642
642
|
if (this.pathing.followingPath && this.intents.includes(this.Intents.PATHFINDING)) this.#processPathfinding();
|
|
@@ -1210,7 +1210,7 @@ export class Bot {
|
|
|
1210
1210
|
}
|
|
1211
1211
|
|
|
1212
1212
|
// secondary, always cluck9mm
|
|
1213
|
-
if (player.weapons[1] && player.weapons[
|
|
1213
|
+
if (player.weapons[1] && player.weapons[1].ammo) {
|
|
1214
1214
|
player.weapons[1].ammo.rounds = player.weapons[1].ammo.capacity;
|
|
1215
1215
|
player.weapons[1].ammo.store = player.weapons[1].ammo.storeMax;
|
|
1216
1216
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class BootPlayerDispatch {
|
|
4
5
|
constructor(uniqueId) {
|
|
@@ -10,7 +11,10 @@ export class BootPlayerDispatch {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
execute(bot) {
|
|
13
|
-
|
|
14
|
+
const out = CommOut.getBuffer();
|
|
15
|
+
out.packInt8(CommCode.bootPlayer);
|
|
16
|
+
out.packString(this.uniqueId);
|
|
17
|
+
out.send(bot.game.socket);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class ChatDispatch {
|
|
4
5
|
constructor(msg, noLimit = false) {
|
|
@@ -17,7 +18,11 @@ export class ChatDispatch {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
execute(bot) {
|
|
20
|
-
|
|
21
|
+
const out = CommOut.getBuffer();
|
|
22
|
+
out.packInt8(CommCode.chat);
|
|
23
|
+
out.packString(this.msg);
|
|
24
|
+
out.send(bot.game.socket);
|
|
25
|
+
|
|
21
26
|
bot.lastChatTime = Date.now();
|
|
22
27
|
}
|
|
23
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
const regenScale = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4];
|
|
4
5
|
|
|
@@ -21,7 +22,24 @@ export class GameOptionsDispatch {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
execute(bot) {
|
|
24
|
-
|
|
25
|
+
const flags =
|
|
26
|
+
(bot.game.options.locked ? 1 : 0) |
|
|
27
|
+
(bot.game.options.noTeamChange ? 2 : 0) |
|
|
28
|
+
(bot.game.options.noTeamShuffle ? 4 : 0);
|
|
29
|
+
|
|
30
|
+
const out = CommOut.getBuffer();
|
|
31
|
+
|
|
32
|
+
out.packInt8(CommCode.gameOptions);
|
|
33
|
+
out.packInt8(bot.game.options.gravity * 4);
|
|
34
|
+
out.packInt8(bot.game.options.damage * 4);
|
|
35
|
+
out.packInt8(bot.game.options.healthRegen * 4);
|
|
36
|
+
out.packInt8(flags);
|
|
37
|
+
|
|
38
|
+
bot.game.options.weaponsDisabled.forEach((v) => {
|
|
39
|
+
out.packInt8(v ? 1 : 0);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
out.send(bot.game.socket);
|
|
25
43
|
}
|
|
26
44
|
}
|
|
27
45
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class MeleeDispatch {
|
|
4
5
|
check(bot) {
|
|
@@ -6,17 +7,18 @@ export class MeleeDispatch {
|
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
execute(bot) {
|
|
9
|
-
|
|
10
|
+
const out = CommOut.getBuffer();
|
|
11
|
+
out.packInt8(CommCode.melee);
|
|
12
|
+
out.send(bot.game.socket);
|
|
13
|
+
|
|
10
14
|
bot.usingMelee = true;
|
|
11
15
|
|
|
12
16
|
// gameloop every 33.33 (repeating) ms, 17 ticks, so 566.61 is the closest you get
|
|
13
17
|
setTimeout(() => {
|
|
14
|
-
// new ChatDispatch('end melee, start swap gun').execute(player);
|
|
15
18
|
bot.usingMelee = false
|
|
16
19
|
bot.swappingGun = true
|
|
17
20
|
|
|
18
21
|
setTimeout(() => {
|
|
19
|
-
// new ChatDispatch('end swap gun').execute(player);
|
|
20
22
|
bot.swappingGun = false
|
|
21
23
|
}, 0.5 * bot.me.weapons[0].equipTime)
|
|
22
24
|
}, 566.61);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class PauseDispatch {
|
|
4
5
|
check(bot) {
|
|
@@ -6,8 +7,11 @@ export class PauseDispatch {
|
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
execute(bot) {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const out = CommOut.getBuffer();
|
|
11
|
+
out.packInt8(CommCode.pause);
|
|
12
|
+
out.send(bot.game.socket);
|
|
13
|
+
|
|
14
|
+
setTimeout(() => bot.me.playing = false, 3000);
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class ReloadDispatch {
|
|
4
5
|
check(bot) {
|
|
@@ -6,7 +7,9 @@ export class ReloadDispatch {
|
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
execute(bot) {
|
|
9
|
-
|
|
10
|
+
const out = CommOut.getBuffer();
|
|
11
|
+
out.packInt8(CommCode.reload);
|
|
12
|
+
out.send(bot.game.socket);
|
|
10
13
|
|
|
11
14
|
const playerActiveWeapon = bot.me.weapons[bot.me.activeGun];
|
|
12
15
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class ReportPlayerDispatch {
|
|
4
5
|
constructor(idOrName, reasons = {}) {
|
|
@@ -39,7 +40,11 @@ export class ReportPlayerDispatch {
|
|
|
39
40
|
|
|
40
41
|
if (!target) throw new Error('target player for ReportPlayerDispatch not found')
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
const out = CommOut.getBuffer();
|
|
44
|
+
out.packInt8(CommCode.reportPlayer);
|
|
45
|
+
out.packString(target);
|
|
46
|
+
out.packInt8(this.reasonInt);
|
|
47
|
+
out.send(bot.game.socket);
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* eslint-disable stylistic/max-len */
|
|
2
2
|
|
|
3
|
-
import { queryServices } from '
|
|
4
|
-
import { findItemById, GunList, ItemTypes } from '
|
|
3
|
+
import { queryServices } from '../api.js';
|
|
4
|
+
import { findItemById, GunList, ItemTypes } from '../constants/index.js';
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import CommOut from '../comm/CommOut.js';
|
|
7
|
+
import { CommCode } from '../constants/codes.js';
|
|
7
8
|
|
|
8
9
|
const isDefault = (itemId) => findItemById(itemId) && findItemById(itemId).unlock == 'default';
|
|
9
10
|
const isType = (itemId, type) => findItemById(itemId) && findItemById(itemId).item_type_id == type;
|
|
@@ -89,8 +90,12 @@ export class SaveLoadoutDispatch {
|
|
|
89
90
|
bot.account.loadout = loadout;
|
|
90
91
|
|
|
91
92
|
saveLoadout.then(() => {
|
|
92
|
-
if (bot.state.joinedGame)
|
|
93
|
-
|
|
93
|
+
if (bot.state.joinedGame) {
|
|
94
|
+
const out = CommOut.getBuffer();
|
|
95
|
+
out.packInt8(CommCode.changeCharacter);
|
|
96
|
+
out.packInt8(this.changes?.classIdx || bot.me.selectedGun);
|
|
97
|
+
out.send(bot.game.socket);
|
|
98
|
+
}
|
|
94
99
|
|
|
95
100
|
const findCosmetics = bot.intents.includes(bot.Intents.COSMETIC_DATA);
|
|
96
101
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class SpawnDispatch {
|
|
4
5
|
check(bot) {
|
|
@@ -8,7 +9,9 @@ export class SpawnDispatch {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
execute(bot) {
|
|
11
|
-
|
|
12
|
+
const out = CommOut.getBuffer();
|
|
13
|
+
out.packInt8(CommCode.requestRespawn);
|
|
14
|
+
out.send(bot.game.socket);
|
|
12
15
|
|
|
13
16
|
bot.lastSpawnedTime = Date.now();
|
|
14
17
|
bot.me.playing = true;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class SwapWeaponDispatch {
|
|
4
5
|
check(bot) {
|
|
@@ -7,7 +8,11 @@ export class SwapWeaponDispatch {
|
|
|
7
8
|
|
|
8
9
|
execute(bot) {
|
|
9
10
|
bot.me.activeGun = +!bot.me.activeGun;
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
const out = CommOut.getBuffer();
|
|
13
|
+
out.packInt8(CommCode.swapWeapon);
|
|
14
|
+
out.packInt8(bot.me.activeGun);
|
|
15
|
+
out.send(bot.game.socket);
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class SwitchTeamDispatch {
|
|
4
5
|
check(bot) {
|
|
@@ -24,7 +25,9 @@ export class SwitchTeamDispatch {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
execute(bot) {
|
|
27
|
-
|
|
28
|
+
const out = CommOut.getBuffer();
|
|
29
|
+
out.packInt8(CommCode.switchTeam);
|
|
30
|
+
out.send(bot.game.socket);
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from '../comm/CommOut.js';
|
|
2
|
+
import { CommCode } from '../constants/codes.js';
|
|
2
3
|
|
|
3
4
|
export class ThrowGrenadeDispatch {
|
|
4
5
|
constructor(power = 1) {
|
|
@@ -15,7 +16,10 @@ export class ThrowGrenadeDispatch {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
execute(bot) {
|
|
18
|
-
|
|
19
|
+
const out = CommOut.getBuffer();
|
|
20
|
+
out.packInt8(CommCode.throwGrenade);
|
|
21
|
+
out.packFloat(this.power);
|
|
22
|
+
out.send(bot.game.socket);
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
|
package/src/matchmaker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { loginAnonymously } from '
|
|
2
|
-
import { GameModes, PlayTypes, ProxiesEnabled } from '
|
|
1
|
+
import { loginAnonymously } from './api.js';
|
|
2
|
+
import { GameModes, PlayTypes, ProxiesEnabled } from './constants/index.js';
|
|
3
3
|
|
|
4
4
|
import yolkws from './socket.js';
|
|
5
5
|
|
|
@@ -15,9 +15,6 @@ export class Matchmaker {
|
|
|
15
15
|
|
|
16
16
|
#forceClose = false;
|
|
17
17
|
|
|
18
|
-
// sessionId: string, a custom session id
|
|
19
|
-
// proxy: a socks5 proxy string
|
|
20
|
-
// instance: a custom game instance
|
|
21
18
|
constructor(params = {}) {
|
|
22
19
|
if (!params.instance) params.instance = 'shellshock.io';
|
|
23
20
|
|
package/src/pathing/astar.js
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
import { NodeList } from './mapnode.js';
|
|
2
1
|
import { BinaryHeap } from './binaryheap.js';
|
|
3
2
|
|
|
4
|
-
function printPath(path) {
|
|
5
|
-
for (const item of path) {
|
|
6
|
-
console.log(item.position);
|
|
7
|
-
}
|
|
8
|
-
} // have it your way eslint
|
|
9
|
-
|
|
10
3
|
export default class AStar {
|
|
11
4
|
constructor(list) {
|
|
12
5
|
this.list = list;
|
|
13
|
-
|
|
14
|
-
if (!typeof list == NodeList) {
|
|
15
|
-
throw new Error('AStar requires a NodeList');
|
|
16
|
-
}
|
|
17
6
|
}
|
|
18
7
|
|
|
19
|
-
heuristic(pos1, pos2) {
|
|
8
|
+
heuristic(pos1, pos2) {
|
|
20
9
|
return Math.abs(pos1.x - pos2.x) + Math.abs(pos1.y - pos2.y) + Math.abs(pos1.z - pos2.z);
|
|
21
10
|
}
|
|
22
11
|
|
|
23
12
|
reversePath(node) {
|
|
24
13
|
const path = [];
|
|
14
|
+
|
|
25
15
|
while (node.parent) {
|
|
26
16
|
path.push(node);
|
|
27
17
|
node = node.parent;
|
|
@@ -35,7 +25,6 @@ export default class AStar {
|
|
|
35
25
|
this.list.clean();
|
|
36
26
|
|
|
37
27
|
const heap = new BinaryHeap(node => node.f);
|
|
38
|
-
|
|
39
28
|
const closedSet = [];
|
|
40
29
|
|
|
41
30
|
start.h = this.heuristic(start, end);
|
|
@@ -48,9 +37,7 @@ export default class AStar {
|
|
|
48
37
|
const current = heap.pop();
|
|
49
38
|
|
|
50
39
|
if (current === end) {
|
|
51
|
-
// console.log('done with astar - path found')
|
|
52
40
|
const val = this.reversePath(current);
|
|
53
|
-
printPath(val);
|
|
54
41
|
return val;
|
|
55
42
|
}
|
|
56
43
|
|
|
@@ -61,29 +48,24 @@ export default class AStar {
|
|
|
61
48
|
for (let i = 0; i < neighbors.length; i++) {
|
|
62
49
|
const neighbor = neighbors[i];
|
|
63
50
|
|
|
64
|
-
if (closedSet.includes(neighbor))
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
51
|
+
if (closedSet.includes(neighbor)) continue;
|
|
67
52
|
|
|
68
53
|
const tentativeGScore = current.g + 1;
|
|
69
54
|
const visited = neighbor.visited;
|
|
55
|
+
|
|
70
56
|
if (!visited || tentativeGScore < neighbor.g) {
|
|
71
57
|
neighbor.visited = true;
|
|
72
58
|
neighbor.parent = current;
|
|
73
59
|
neighbor.g = tentativeGScore;
|
|
74
60
|
neighbor.h = this.heuristic(neighbor.position, end.position);
|
|
75
61
|
neighbor.f = neighbor.g + neighbor.h;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
heap.rescoreElement(neighbor);
|
|
80
|
-
}
|
|
62
|
+
|
|
63
|
+
if (!visited) heap.push(neighbor);
|
|
64
|
+
else heap.rescoreElement(neighbor);
|
|
81
65
|
}
|
|
82
66
|
}
|
|
83
67
|
}
|
|
84
68
|
|
|
85
|
-
// console.log('done with astar - no path found')
|
|
86
|
-
// return null if no path has been found
|
|
87
69
|
return null
|
|
88
70
|
}
|
|
89
71
|
}
|
|
@@ -34,13 +34,13 @@ class BinaryHeap {
|
|
|
34
34
|
// To remove a value, we must search through the array to find
|
|
35
35
|
// it.
|
|
36
36
|
for (let i = 0; i < length; i++) {
|
|
37
|
-
if (this.content[i] != node)
|
|
37
|
+
if (this.content[i] != node) continue;
|
|
38
38
|
// When it is found, the process seen in 'pop' is repeated
|
|
39
39
|
// to fill up the hole.
|
|
40
40
|
const end = this.content.pop();
|
|
41
41
|
// If the element we popped was the one we needed to remove,
|
|
42
42
|
// we're done.
|
|
43
|
-
if (i == length - 1)
|
|
43
|
+
if (i == length - 1) break;
|
|
44
44
|
// Otherwise, we replace the removed element with the popped
|
|
45
45
|
// one, and allow it to float up or sink down as appropriate.
|
|
46
46
|
this.content[i] = end;
|
|
@@ -63,7 +63,7 @@ class BinaryHeap {
|
|
|
63
63
|
const parentN = Math.floor((n + 1) / 2) - 1, parent = this.content[parentN];
|
|
64
64
|
// If the parent has a lesser score, things are in order and we
|
|
65
65
|
// are done.
|
|
66
|
-
if (score >= this.scoreFunction(parent))
|
|
66
|
+
if (score >= this.scoreFunction(parent)) break;
|
|
67
67
|
|
|
68
68
|
// Otherwise, swap the parent with the current element and
|
|
69
69
|
// continue.
|
|
@@ -94,16 +94,16 @@ class BinaryHeap {
|
|
|
94
94
|
const child1 = this.content[child1N];
|
|
95
95
|
child1Score = this.scoreFunction(child1);
|
|
96
96
|
// If the score is less than our element's, we need to swap.
|
|
97
|
-
if (child1Score < elemScore)
|
|
97
|
+
if (child1Score < elemScore) swap = child1N;
|
|
98
98
|
}
|
|
99
99
|
// Do the same checks for the other child.
|
|
100
100
|
if (child2N < length) {
|
|
101
101
|
const child2 = this.content[child2N], child2Score = this.scoreFunction(child2);
|
|
102
|
-
if (child2Score < (swap == null ? elemScore : child1Score))
|
|
102
|
+
if (child2Score < (swap == null ? elemScore : child1Score)) swap = child2N;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// No need to swap further, we are done.
|
|
106
|
-
if (swap == null)
|
|
106
|
+
if (swap == null) break;
|
|
107
107
|
|
|
108
108
|
// Otherwise, swap and continue.
|
|
109
109
|
this.content[n] = this.content[swap];
|
package/src/pathing/mapnode.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
/* eslint-disable stylistic/max-len */
|
|
2
|
-
/*function stringifyCircular(obj) {
|
|
3
|
-
const cache = [];
|
|
4
|
-
return JSON.stringify(obj, (_, value) => {
|
|
5
|
-
if (typeof value === 'object' && value !== null) {
|
|
6
|
-
|
|
7
|
-
// Duplicate reference found, discard key
|
|
8
|
-
if (cache.includes(value)) {
|
|
9
|
-
return '* Circular';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Store value in our collection
|
|
13
|
-
cache.push(value);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
}, 4);
|
|
17
|
-
}*/
|
|
18
2
|
|
|
19
3
|
class NodeList {
|
|
20
4
|
constructor(raw) {
|
|
@@ -27,7 +11,7 @@ class NodeList {
|
|
|
27
11
|
(nodeData.x << 16) |
|
|
28
12
|
(nodeData.y << 8) |
|
|
29
13
|
(nodeData.z))] = true;
|
|
30
|
-
this.
|
|
14
|
+
this.list.push(new MapNode(meshName, nodeData));
|
|
31
15
|
}
|
|
32
16
|
}
|
|
33
17
|
|
|
@@ -39,7 +23,7 @@ class NodeList {
|
|
|
39
23
|
(y << 8) |
|
|
40
24
|
(z)
|
|
41
25
|
)]) {
|
|
42
|
-
this.
|
|
26
|
+
this.list.push(new MapNode('SPECIAL.air.none', { x: x, y: y, z: z }));
|
|
43
27
|
}
|
|
44
28
|
}
|
|
45
29
|
}
|
|
@@ -70,14 +54,6 @@ class NodeList {
|
|
|
70
54
|
}
|
|
71
55
|
}
|
|
72
56
|
|
|
73
|
-
add(node) {
|
|
74
|
-
this.list.push(node);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
remove(node) {
|
|
78
|
-
this.list.splice(this.list.indexOf(node), 1);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
57
|
at(x, y, z) {
|
|
82
58
|
if (!this.nodeMap) {
|
|
83
59
|
this.nodeMap = new Map();
|
|
@@ -119,9 +95,7 @@ class NodeList {
|
|
|
119
95
|
|
|
120
96
|
for (let i = 0; i <= steps; i++) {
|
|
121
97
|
const node = this.at(Math.round(x), Math.round(y), Math.round(z));
|
|
122
|
-
if (node && node.isSolid())
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
98
|
+
if (node && node.isSolid()) return false;
|
|
125
99
|
x += xStep;
|
|
126
100
|
y += yStep;
|
|
127
101
|
z += zStep;
|
|
@@ -186,10 +160,6 @@ class MapNode {
|
|
|
186
160
|
return this.meshType == 'none';
|
|
187
161
|
}
|
|
188
162
|
|
|
189
|
-
canPassThroughOnAllFaces() {
|
|
190
|
-
return this.isAir();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
163
|
canLink(node, list) {
|
|
194
164
|
const dx0 = this.x - node.x;
|
|
195
165
|
const dz0 = this.z - node.z;
|
|
@@ -205,10 +175,7 @@ class MapNode {
|
|
|
205
175
|
|
|
206
176
|
const belowMe = list.at(this.x, this.y - 1, this.z);
|
|
207
177
|
const belowOther = list.at(node.x, node.y - 1, node.z);
|
|
208
|
-
|
|
209
|
-
if (!belowMe || !belowOther) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
178
|
+
if (!belowMe || !belowOther) return false;
|
|
212
179
|
|
|
213
180
|
const FORWARD_RY_WEDGE_MAPPING = {
|
|
214
181
|
0: { x: 0, z: -1 },
|
|
@@ -243,14 +210,6 @@ class MapNode {
|
|
|
243
210
|
}
|
|
244
211
|
}
|
|
245
212
|
|
|
246
|
-
trueCenter() {
|
|
247
|
-
return {
|
|
248
|
-
x: this.x + 0.5,
|
|
249
|
-
y: this.y + 0.5,
|
|
250
|
-
z: this.z + 0.5
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
213
|
flatCenter() {
|
|
255
214
|
return {
|
|
256
215
|
x: this.x + 0.5,
|
|
@@ -264,11 +223,6 @@ class MapNode {
|
|
|
264
223
|
return Math.hypot(pos.x - position.x, pos.z - position.z);
|
|
265
224
|
}
|
|
266
225
|
|
|
267
|
-
floorCollides(position) {
|
|
268
|
-
const posFloor = Object.entries(position).map(entry => Math.floor(entry[1]));
|
|
269
|
-
return this.x == posFloor[0] && this.y == posFloor[1] && this.z == posFloor[2];
|
|
270
|
-
}
|
|
271
|
-
|
|
272
226
|
positionStr() {
|
|
273
227
|
return `${this.x},${this.y},${this.z}`;
|
|
274
228
|
}
|