yolkbot 0.1.0-alpha.57 → 0.1.0-alpha.59

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yolkbot",
3
3
  "description": "create a shell shockers (self) bot in under 10 lines.",
4
- "version": "0.1.0-alpha.57",
4
+ "version": "0.1.0-alpha.59",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
package/src/bot.js CHANGED
@@ -58,7 +58,7 @@ export class Bot {
58
58
  this.proxy = params.proxy || '';
59
59
 
60
60
  this.autoUpdate = params.doUpdate || true;
61
- this.updateInterval = params.updateInterval || 11;
61
+ this.updateInterval = params.updateInterval || 16.5;
62
62
 
63
63
  this._hooks = {};
64
64
  this._globalHooks = [];
@@ -228,19 +228,6 @@ export class Bot {
228
228
  this._dispatches.push(disp);
229
229
  }
230
230
 
231
- #drain() {
232
- for (let i = 0; i < this._dispatches.length; i++) {
233
- const disp = this._dispatches[i];
234
- if (disp.check(this)) {
235
- disp.execute(this);
236
- this._dispatches.splice(i, 1);
237
- return; // only 1 dispatch per update
238
- } else {
239
- // console.log("Dispatch failed", this.state.joinedGame, this.lastChatTime)
240
- }
241
- }
242
- }
243
-
244
231
  async createAccount(email, pass) {
245
232
  this.account.email = email;
246
233
  this.account.password = pass;
@@ -605,10 +592,20 @@ export class Bot {
605
592
  while (this._packetQueue.length > 0) this.#handlePacket(this._packetQueue.shift());
606
593
 
607
594
  // process dispatches
608
- if (this._dispatches.length > 0) this.#drain();
595
+ if (this._dispatches.length > 0) {
596
+ for (let i = 0; i < this._dispatches.length; i++) {
597
+ const disp = this._dispatches[i];
598
+ if (disp.check(this)) {
599
+ disp.execute(this);
600
+ this._dispatches.splice(i, 1);
601
+ break; // only 1 dispatch per update
602
+ }
603
+ }
604
+ }
609
605
 
610
606
  // process syncMe
611
- if (Date.now() - this.lastUpdateTime >= 50) {
607
+ const now = Date.now();
608
+ if (now - this.lastUpdateTime >= 50) {
612
609
  this.#emit('tick');
613
610
 
614
611
  // Send out update packet
@@ -625,7 +622,7 @@ export class Bot {
625
622
  }
626
623
  out.send(this.game.socket);
627
624
 
628
- this.lastUpdateTime = Date.now();
625
+ this.lastUpdateTime = now;
629
626
  this.state.shotsFired = 0;
630
627
  }
631
628
 
@@ -888,7 +885,7 @@ export class Bot {
888
885
  }
889
886
  }
890
887
 
891
- #processExternalSyncPacket() {
888
+ #processSyncThemPacket() {
892
889
  const id = CommIn.unPackInt8U();
893
890
  const x = CommIn.unPackFloat();
894
891
  const y = CommIn.unPackFloat();
@@ -1513,7 +1510,7 @@ export class Bot {
1513
1510
 
1514
1511
  switch (cmd) {
1515
1512
  case CommCode.syncThem:
1516
- this.#processExternalSyncPacket(packet);
1513
+ this.#processSyncThemPacket(packet);
1517
1514
  break;
1518
1515
 
1519
1516
  case CommCode.fire:
@@ -20,49 +20,51 @@ class NodeList {
20
20
  constructor(raw) {
21
21
  const now = Date.now();
22
22
  this.list = [];
23
-
24
- const addedPositions = [];
23
+ const addedPositions = new Set();
25
24
 
26
25
  for (const meshName of Object.keys(raw.data)) {
27
26
  for (const nodeData of raw.data[meshName]) {
28
- addedPositions.push(nodeData);
27
+ addedPositions.add(`${nodeData.x},${nodeData.y},${nodeData.z}`);
29
28
  this.add(new MapNode(meshName, nodeData));
30
29
  }
31
30
  }
32
31
 
33
- // data doesn't include air, but we need to include them anyway
34
- // addedPositions stores all the blocks with nodes - create a node for every block not in there.
35
- // width/height/depth are given by raw.width/height/depth
36
32
  for (let x = 0; x < raw.width; x++) {
37
33
  for (let y = 0; y < raw.height; y++) {
38
34
  for (let z = 0; z < raw.depth; z++) {
39
- if (!addedPositions.find(node => node.x == x && node.y == y && node.z == z)) {
40
- this.add(new MapNode('SPECIAL.fuckitweball.none', { x: x, y: y, z: z }));
35
+ const posKey = `${x},${y},${z}`;
36
+ if (!addedPositions.has(posKey)) {
37
+ this.add(new MapNode('SPECIAL.__yolkbot_air__.none', { x: x, y: y, z: z }));
41
38
  }
42
39
  }
43
40
  }
44
41
  }
45
42
 
43
+ const nodeMap = new Map();
46
44
  for (const node of this.list) {
47
- // add all nodes around it
48
- for (const other of this.list) {
49
- const dx = Math.abs(node.x - other.x);
50
- const dy = Math.abs(node.y - other.y);
51
- const dz = Math.abs(node.z - other.z);
52
- if (dx > 1 || dy > 1 || dz > 1) {
53
- continue;
54
- }
55
- if (other == this) {
56
- continue;
57
- }
58
- if (node.canLink(other, this)) {
59
- node.addLink(other);
45
+ nodeMap.set(node.positionStr(), node);
46
+ }
47
+
48
+ for (const node of this.list) {
49
+ const neighbors = [
50
+ { x: node.x + 1, y: node.y, z: node.z },
51
+ { x: node.x - 1, y: node.y, z: node.z },
52
+ { x: node.x, y: node.y + 1, z: node.z },
53
+ { x: node.x, y: node.y - 1, z: node.z },
54
+ { x: node.x, y: node.y, z: node.z + 1 },
55
+ { x: node.x, y: node.y, z: node.z - 1 }
56
+ ];
57
+
58
+ for (const neighborPos of neighbors) {
59
+ const neighborKey = `${neighborPos.x},${neighborPos.y},${neighborPos.z}`;
60
+ const neighborNode = nodeMap.get(neighborKey);
61
+ if (neighborNode && node.canLink(neighborNode, this)) {
62
+ node.addLink(neighborNode);
60
63
  }
61
64
  }
62
65
  }
63
66
 
64
67
  console.log(`NodeList created in ${Date.now() - now}ms`);
65
-
66
68
  }
67
69
 
68
70
  add(node) {