yolkbot 1.4.5 → 1.4.6

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 (112) hide show
  1. package/browser/build/global.js +1 -1
  2. package/browser/build/module.js +1 -1
  3. package/dist/api.js +200 -1
  4. package/dist/bot/GamePlayer.js +74 -1
  5. package/dist/bot.js +1679 -1
  6. package/dist/comm/CommIn.js +79 -1
  7. package/dist/comm/CommOut.js +60 -1
  8. package/dist/comm/index.js +11 -1
  9. package/dist/constants/CloseCode.js +27 -1
  10. package/dist/constants/CommCode.js +53 -1
  11. package/dist/constants/challenges.js +1821 -1
  12. package/dist/constants/findItemById.js +2 -3
  13. package/dist/constants/guns.js +277 -1
  14. package/dist/constants/index.js +139 -1
  15. package/dist/constants/items.js +45042 -1
  16. package/dist/constants/maps.js +1263 -1
  17. package/dist/constants/regions.js +30 -1
  18. package/dist/dispatches/BanPlayerDispatch.js +32 -1
  19. package/dist/dispatches/BootPlayerDispatch.js +21 -1
  20. package/dist/dispatches/ChatDispatch.js +32 -1
  21. package/dist/dispatches/FireDispatch.js +15 -1
  22. package/dist/dispatches/GameOptionsDispatch.js +66 -1
  23. package/dist/dispatches/GoToAmmoDispatch.js +38 -1
  24. package/dist/dispatches/GoToCoopDispatch.js +38 -1
  25. package/dist/dispatches/GoToGrenadeDispatch.js +38 -1
  26. package/dist/dispatches/GoToPlayerDispatch.js +39 -1
  27. package/dist/dispatches/GoToSpatulaDispatch.js +26 -1
  28. package/dist/dispatches/LookAtDispatch.js +35 -1
  29. package/dist/dispatches/LookAtPosDispatch.js +29 -1
  30. package/dist/dispatches/MeleeDispatch.js +26 -1
  31. package/dist/dispatches/MovementDispatch.js +26 -1
  32. package/dist/dispatches/PauseDispatch.js +18 -1
  33. package/dist/dispatches/ReloadDispatch.js +28 -1
  34. package/dist/dispatches/ReportPlayerDispatch.js +42 -1
  35. package/dist/dispatches/ResetGameDispatch.js +19 -1
  36. package/dist/dispatches/SaveLoadoutDispatch.js +105 -1
  37. package/dist/dispatches/SpawnDispatch.js +22 -1
  38. package/dist/dispatches/SwapWeaponDispatch.js +25 -1
  39. package/dist/dispatches/SwitchTeamDispatch.js +33 -1
  40. package/dist/dispatches/ThrowGrenadeDispatch.js +21 -1
  41. package/dist/dispatches/index.js +74 -1
  42. package/dist/env/fetch.js +97 -10
  43. package/dist/env/globals.js +15 -1
  44. package/dist/index.js +14 -2
  45. package/dist/matchmaker.js +141 -1
  46. package/dist/pathing/astar.js +55 -1
  47. package/dist/pathing/binaryheap.js +79 -1
  48. package/dist/pathing/mapnode.js +179 -1
  49. package/dist/socket.js +97 -1
  50. package/dist/util.js +68 -1
  51. package/dist/wasm/bytes.js +8 -1
  52. package/dist/wasm/direct.js +84 -1
  53. package/dist/wasm/legacy.js +170 -1
  54. package/dist/wasm/util.js +19 -1
  55. package/package.json +38 -39
  56. /package/dist/{types/api.d.ts → api.d.ts} +0 -0
  57. /package/dist/{types/bot → bot}/GamePlayer.d.ts +0 -0
  58. /package/dist/{types/bot.d.ts → bot.d.ts} +0 -0
  59. /package/dist/{types/comm → comm}/CommIn.d.ts +0 -0
  60. /package/dist/{types/comm → comm}/CommOut.d.ts +0 -0
  61. /package/dist/{types/comm → comm}/index.d.ts +0 -0
  62. /package/dist/{types/constants → constants}/CloseCode.d.ts +0 -0
  63. /package/dist/{types/constants → constants}/CommCode.d.ts +0 -0
  64. /package/dist/{types/constants → constants}/challenges.d.ts +0 -0
  65. /package/dist/{types/constants → constants}/changelog.d.ts +0 -0
  66. /package/dist/{types/constants → constants}/findItemById.d.ts +0 -0
  67. /package/dist/{types/constants → constants}/guns.d.ts +0 -0
  68. /package/dist/{types/constants → constants}/housePromo.d.ts +0 -0
  69. /package/dist/{types/constants → constants}/index.d.ts +0 -0
  70. /package/dist/{types/constants → constants}/items.d.ts +0 -0
  71. /package/dist/{types/constants → constants}/language.d.ts +0 -0
  72. /package/dist/{types/constants → constants}/maps.d.ts +0 -0
  73. /package/dist/{types/constants → constants}/notices.d.ts +0 -0
  74. /package/dist/{types/constants → constants}/regions.d.ts +0 -0
  75. /package/dist/{types/constants → constants}/shellNews.d.ts +0 -0
  76. /package/dist/{types/constants → constants}/shellYoutube.d.ts +0 -0
  77. /package/dist/{types/constants → constants}/shopItems.d.ts +0 -0
  78. /package/dist/{types/constants → constants}/sounds.d.ts +0 -0
  79. /package/dist/{types/dispatches → dispatches}/BanPlayerDispatch.d.ts +0 -0
  80. /package/dist/{types/dispatches → dispatches}/BootPlayerDispatch.d.ts +0 -0
  81. /package/dist/{types/dispatches → dispatches}/ChatDispatch.d.ts +0 -0
  82. /package/dist/{types/dispatches → dispatches}/FireDispatch.d.ts +0 -0
  83. /package/dist/{types/dispatches → dispatches}/GameOptionsDispatch.d.ts +0 -0
  84. /package/dist/{types/dispatches → dispatches}/GoToAmmoDispatch.d.ts +0 -0
  85. /package/dist/{types/dispatches → dispatches}/GoToCoopDispatch.d.ts +0 -0
  86. /package/dist/{types/dispatches → dispatches}/GoToGrenadeDispatch.d.ts +0 -0
  87. /package/dist/{types/dispatches → dispatches}/GoToPlayerDispatch.d.ts +0 -0
  88. /package/dist/{types/dispatches → dispatches}/GoToSpatulaDispatch.d.ts +0 -0
  89. /package/dist/{types/dispatches → dispatches}/LookAtDispatch.d.ts +0 -0
  90. /package/dist/{types/dispatches → dispatches}/LookAtPosDispatch.d.ts +0 -0
  91. /package/dist/{types/dispatches → dispatches}/MeleeDispatch.d.ts +0 -0
  92. /package/dist/{types/dispatches → dispatches}/MovementDispatch.d.ts +0 -0
  93. /package/dist/{types/dispatches → dispatches}/PauseDispatch.d.ts +0 -0
  94. /package/dist/{types/dispatches → dispatches}/ReloadDispatch.d.ts +0 -0
  95. /package/dist/{types/dispatches → dispatches}/ReportPlayerDispatch.d.ts +0 -0
  96. /package/dist/{types/dispatches → dispatches}/ResetGameDispatch.d.ts +0 -0
  97. /package/dist/{types/dispatches → dispatches}/SaveLoadoutDispatch.d.ts +0 -0
  98. /package/dist/{types/dispatches → dispatches}/SpawnDispatch.d.ts +0 -0
  99. /package/dist/{types/dispatches → dispatches}/SwapWeaponDispatch.d.ts +0 -0
  100. /package/dist/{types/dispatches → dispatches}/SwitchTeamDispatch.d.ts +0 -0
  101. /package/dist/{types/dispatches → dispatches}/ThrowGrenadeDispatch.d.ts +0 -0
  102. /package/dist/{types/dispatches → dispatches}/index.d.ts +0 -0
  103. /package/dist/{types/matchmaker.d.ts → matchmaker.d.ts} +0 -0
  104. /package/dist/{types/pathing → pathing}/astar.d.ts +0 -0
  105. /package/dist/{types/pathing → pathing}/binaryheap.d.ts +0 -0
  106. /package/dist/{types/pathing → pathing}/mapnode.d.ts +0 -0
  107. /package/dist/{types/socket.d.ts → socket.d.ts} +0 -0
  108. /package/dist/{types/util.d.ts → util.d.ts} +0 -0
  109. /package/dist/{types/wasm → wasm}/bytes.d.ts +0 -0
  110. /package/dist/{types/wasm → wasm}/direct.d.ts +0 -0
  111. /package/dist/{types/wasm → wasm}/legacy.d.ts +0 -0
  112. /package/dist/{types/wasm → wasm}/util.d.ts +0 -0
@@ -1 +1,30 @@
1
- export const Regions=[{id:"germany",sub:"egs-static-live-germany-287o43bv"},{id:"santiago",sub:"egs-static-live-santiago-1s5w3cdc"},{id:"singapore",sub:"egs-static-live-singapore-5r545eei"},{id:"sydney",sub:"egs-static-live-sydney-302pa99o"},{id:"uscentral",sub:"egs-static-live-uscentral-451sa2ap"},{id:"useast",sub:"egs-static-live-useast-191w3fe4"},{id:"uswest",sub:"egs-static-live-uswest-192r5xds"}];
1
+ export const Regions = [
2
+ {
3
+ id: "germany",
4
+ sub: "egs-static-live-germany-287o43bv"
5
+ },
6
+ {
7
+ id: "santiago",
8
+ sub: "egs-static-live-santiago-1s5w3cdc"
9
+ },
10
+ {
11
+ id: "singapore",
12
+ sub: "egs-static-live-singapore-5r545eei"
13
+ },
14
+ {
15
+ id: "sydney",
16
+ sub: "egs-static-live-sydney-302pa99o"
17
+ },
18
+ {
19
+ id: "uscentral",
20
+ sub: "egs-static-live-uscentral-451sa2ap"
21
+ },
22
+ {
23
+ id: "useast",
24
+ sub: "egs-static-live-useast-191w3fe4"
25
+ },
26
+ {
27
+ id: "uswest",
28
+ sub: "egs-static-live-uswest-192r5xds"
29
+ }
30
+ ];
@@ -1 +1,32 @@
1
- import n from"../comm/CommOut.js";import i from"../constants/CommCode.js";import{BanDuration as o}from"../constants/index.js";export class BanPlayerDispatch{constructor(e,t,r=""){this.uniqueId=e;this.duration=t;this.reason=r}validate(e){if(typeof this.uniqueId!=="string"||typeof this.reason!=="string")return!1;if(typeof this.duration!=="number"||!Object.values(o).some((t)=>this.duration===t))return!1;if(!(e.account.adminRoles&4))return!1;return!0}check(){return!0}execute(e){const t=new n;t.packInt8(i.banPlayer);t.packString(this.uniqueId);t.packString(this.reason);t.packInt8(this.duration);t.send(e.game.socket)}}export default BanPlayerDispatch;
1
+ import CommOut from "../comm/CommOut.js";
2
+ import CommCode from "../constants/CommCode.js";
3
+ import { BanDuration } from "../constants/index.js";
4
+
5
+ export class BanPlayerDispatch {
6
+ constructor(uniqueId, duration, reason = "") {
7
+ this.uniqueId = uniqueId;
8
+ this.duration = duration;
9
+ this.reason = reason;
10
+ }
11
+ validate(bot) {
12
+ if (typeof this.uniqueId !== "string" || typeof this.reason !== "string")
13
+ return false;
14
+ if (typeof this.duration !== "number" || !Object.values(BanDuration).some((d) => this.duration === d))
15
+ return false;
16
+ if (!(bot.account.adminRoles & 4))
17
+ return false;
18
+ return true;
19
+ }
20
+ check() {
21
+ return true;
22
+ }
23
+ execute(bot) {
24
+ const out = new CommOut;
25
+ out.packInt8(CommCode.banPlayer);
26
+ out.packString(this.uniqueId);
27
+ out.packString(this.reason);
28
+ out.packInt8(this.duration);
29
+ out.send(bot.game.socket);
30
+ }
31
+ }
32
+ export default BanPlayerDispatch;
@@ -1 +1,21 @@
1
- import u from"../comm/CommOut.js";import r from"../constants/CommCode.js";export class BootPlayerDispatch{constructor(e){this.uniqueId=e}validate(e){return typeof this.uniqueId==="string"&&e.game.isGameOwner&&Object.values(e.players).find((t)=>t.uniqueId===this.uniqueId)}check(){return!0}execute(e){const t=new u;t.packInt8(r.bootPlayer);t.packString(this.uniqueId);t.send(e.game.socket)}}export default BootPlayerDispatch;
1
+ import CommOut from "../comm/CommOut.js";
2
+ import CommCode from "../constants/CommCode.js";
3
+
4
+ export class BootPlayerDispatch {
5
+ constructor(uniqueId) {
6
+ this.uniqueId = uniqueId;
7
+ }
8
+ validate(bot) {
9
+ return typeof this.uniqueId === "string" && bot.game.isGameOwner && Object.values(bot.players).find((player) => player.uniqueId === this.uniqueId);
10
+ }
11
+ check() {
12
+ return true;
13
+ }
14
+ execute(bot) {
15
+ const out = new CommOut;
16
+ out.packInt8(CommCode.bootPlayer);
17
+ out.packString(this.uniqueId);
18
+ out.send(bot.game.socket);
19
+ }
20
+ }
21
+ export default BootPlayerDispatch;
@@ -1 +1,32 @@
1
- import s from"../comm/CommOut.js";import r from"../constants/CommCode.js";export class ChatDispatch{constructor(e){this.msg=e}validate(){if(typeof this.msg!=="string")return!1;if(this.msg.length<1||this.msg.length>64)return!1;return!0}check(e){if(!e.state?.inGame)return!1;if(!e.game.isPrivate&&!e.account.adminRoles&&e.state.chatLines>=2)return!1;if(!e.game.isPrivate&&!e.account.emailVerified&&!e.account.isAged)return!1;return!0}execute(e){e.state.chatLines++;const t=new s;t.packInt8(r.chat);t.packString(this.msg);t.send(e.game.socket)}}export default ChatDispatch;
1
+ import CommOut from "../comm/CommOut.js";
2
+ import CommCode from "../constants/CommCode.js";
3
+
4
+ export class ChatDispatch {
5
+ constructor(msg) {
6
+ this.msg = msg;
7
+ }
8
+ validate() {
9
+ if (typeof this.msg !== "string")
10
+ return false;
11
+ if (this.msg.length < 1 || this.msg.length > 64)
12
+ return false;
13
+ return true;
14
+ }
15
+ check(bot) {
16
+ if (!bot.state?.inGame)
17
+ return false;
18
+ if (!bot.game.isPrivate && !bot.account.adminRoles && bot.state.chatLines >= 2)
19
+ return false;
20
+ if (!bot.game.isPrivate && !bot.account.emailVerified && !bot.account.isAged)
21
+ return false;
22
+ return true;
23
+ }
24
+ execute(bot) {
25
+ bot.state.chatLines++;
26
+ const out = new CommOut;
27
+ out.packInt8(CommCode.chat);
28
+ out.packString(this.msg);
29
+ out.send(bot.game.socket);
30
+ }
31
+ }
32
+ export default ChatDispatch;
@@ -1 +1,15 @@
1
- export class FireDispatch{constructor(e){this.amount=e||1}validate(){return this.amount>=1}check(e){return e.me.playing&&!e.state.reloading&&!e.state.swappingGun&&!e.state.usingMelee&&e.me.weapons[e.me.activeGun].ammo.rounds>=this.amount}execute(e){e.state.shotsFired+=this.amount||1}}export default FireDispatch;
1
+ export class FireDispatch {
2
+ constructor(amount) {
3
+ this.amount = amount || 1;
4
+ }
5
+ validate() {
6
+ return this.amount >= 1;
7
+ }
8
+ check(bot) {
9
+ return bot.me.playing && !bot.state.reloading && !bot.state.swappingGun && !bot.state.usingMelee && bot.me.weapons[bot.me.activeGun].ammo.rounds >= this.amount;
10
+ }
11
+ execute(bot) {
12
+ bot.state.shotsFired += this.amount || 1;
13
+ }
14
+ }
15
+ export default FireDispatch;
@@ -1 +1,66 @@
1
- const i=Array.from({length:4},(a,e)=>(e+1)*0.25),t=Array.from({length:9},(a,e)=>e*0.25),o=Array.from({length:17},(a,e)=>e*0.25),s=(a,e)=>typeof a>"u"?e:a;export class GameOptionsDispatch{constructor(a){this.changes=a}#e(a){const e={};e.gravity=s(this.changes.gravity,a.game.options.gravity);e.damage=s(this.changes.damage,a.game.options.damage);e.healthRegen=s(this.changes.healthRegen,a.game.options.healthRegen);e.locked=s(this.changes.locked,a.game.options.locked);e.noTeamChange=s(this.changes.noTeamChange,a.game.options.noTeamChange);e.noTeamShuffle=s(this.changes.noTeamShuffle,a.game.options.noTeamShuffle);e.weaponsDisabled=[s(this.changes.disableEggk,a.game.options.weaponsDisabled[0]),s(this.changes.disableScrambler,a.game.options.weaponsDisabled[1]),s(this.changes.disableFreeRanger,a.game.options.weaponsDisabled[2]),s(this.changes.disableRPG,a.game.options.weaponsDisabled[3]),s(this.changes.disableWhipper,a.game.options.weaponsDisabled[4]),s(this.changes.disableCrackshot,a.game.options.weaponsDisabled[5]),s(this.changes.disableTriHard,a.game.options.weaponsDisabled[6])];if(this.changes.toDisable&&Array.isArray(this.changes.toDisable))this.changes.toDisable.forEach((n)=>e.weaponsDisabled[n]=!0);if(this.changes.toEnable&&Array.isArray(this.changes.toEnable))this.changes.toEnable.forEach((n)=>e.weaponsDisabled[n]=!1);if(this.changes.rawWeaponsDisabled&&Array.isArray(this.changes.rawWeaponsDisabled)&&this.changes.rawWeaponsDisabled.length===7)e.weaponsDisabled=this.changes.rawWeaponsDisabled.map((n)=>!!n);e.mustUseSecondary=e.weaponsDisabled.every((n)=>n);return e}validate(a){const e=this.#e(a);if(!i.includes(e.gravity))return!1;if(!t.includes(e.damage))return!1;if(!o.includes(e.healthRegen))return!1;if(typeof e.locked!=="boolean")return!1;if(typeof e.noTeamChange!=="boolean")return!1;if(typeof e.noTeamShuffle!=="boolean")return!1;if(!Array.isArray(e.weaponsDisabled))return!1;if(e.weaponsDisabled.length!==7)return!1;if(e.weaponsDisabled.some((n)=>typeof n!=="boolean"))return!1;return!0}check(a){return a.game.isGameOwner}execute(a){a.game.options=this.#e(a);a.updateGameOptions()}}export default GameOptionsDispatch;
1
+ const gravityScale = Array.from({ length: 4 }, (_, i) => (i + 1) * 0.25);
2
+ const damageScale = Array.from({ length: 9 }, (_, i) => i * 0.25);
3
+ const regenScale = Array.from({ length: 17 }, (_, i) => i * 0.25);
4
+ const whichever = (arg1, arg2) => typeof arg1 === "undefined" ? arg2 : arg1;
5
+
6
+ export class GameOptionsDispatch {
7
+ constructor(changes) {
8
+ this.changes = changes;
9
+ }
10
+ #constructFinalOutput(bot) {
11
+ const output = {};
12
+ output.gravity = whichever(this.changes.gravity, bot.game.options.gravity);
13
+ output.damage = whichever(this.changes.damage, bot.game.options.damage);
14
+ output.healthRegen = whichever(this.changes.healthRegen, bot.game.options.healthRegen);
15
+ output.locked = whichever(this.changes.locked, bot.game.options.locked);
16
+ output.noTeamChange = whichever(this.changes.noTeamChange, bot.game.options.noTeamChange);
17
+ output.noTeamShuffle = whichever(this.changes.noTeamShuffle, bot.game.options.noTeamShuffle);
18
+ output.weaponsDisabled = [
19
+ whichever(this.changes.disableEggk, bot.game.options.weaponsDisabled[0]),
20
+ whichever(this.changes.disableScrambler, bot.game.options.weaponsDisabled[1]),
21
+ whichever(this.changes.disableFreeRanger, bot.game.options.weaponsDisabled[2]),
22
+ whichever(this.changes.disableRPG, bot.game.options.weaponsDisabled[3]),
23
+ whichever(this.changes.disableWhipper, bot.game.options.weaponsDisabled[4]),
24
+ whichever(this.changes.disableCrackshot, bot.game.options.weaponsDisabled[5]),
25
+ whichever(this.changes.disableTriHard, bot.game.options.weaponsDisabled[6])
26
+ ];
27
+ if (this.changes.toDisable && Array.isArray(this.changes.toDisable))
28
+ this.changes.toDisable.forEach((idx) => output.weaponsDisabled[idx] = true);
29
+ if (this.changes.toEnable && Array.isArray(this.changes.toEnable))
30
+ this.changes.toEnable.forEach((idx) => output.weaponsDisabled[idx] = false);
31
+ if (this.changes.rawWeaponsDisabled && Array.isArray(this.changes.rawWeaponsDisabled) && this.changes.rawWeaponsDisabled.length === 7)
32
+ output.weaponsDisabled = this.changes.rawWeaponsDisabled.map((v) => !!v);
33
+ output.mustUseSecondary = output.weaponsDisabled.every((v) => v);
34
+ return output;
35
+ }
36
+ validate(bot) {
37
+ const wouldBe = this.#constructFinalOutput(bot);
38
+ if (!gravityScale.includes(wouldBe.gravity))
39
+ return false;
40
+ if (!damageScale.includes(wouldBe.damage))
41
+ return false;
42
+ if (!regenScale.includes(wouldBe.healthRegen))
43
+ return false;
44
+ if (typeof wouldBe.locked !== "number" && typeof wouldBe.locked !== "boolean")
45
+ return false;
46
+ if (typeof wouldBe.noTeamChange !== "number" && typeof wouldBe.noTeamChange !== "boolean")
47
+ return false;
48
+ if (typeof wouldBe.noTeamShuffle !== "number" && typeof wouldBe.noTeamShuffle !== "boolean")
49
+ return false;
50
+ if (!Array.isArray(wouldBe.weaponsDisabled))
51
+ return false;
52
+ if (wouldBe.weaponsDisabled.length !== 7)
53
+ return false;
54
+ if (wouldBe.weaponsDisabled.some((weapon) => typeof weapon !== "number" && typeof weapon !== "boolean"))
55
+ return false;
56
+ return true;
57
+ }
58
+ check(bot) {
59
+ return bot.game.isGameOwner;
60
+ }
61
+ execute(bot) {
62
+ bot.game.options = this.#constructFinalOutput(bot);
63
+ bot.updateGameOptions();
64
+ }
65
+ }
66
+ export default GameOptionsDispatch;
@@ -1 +1,38 @@
1
- import g from"../pathing/astar.js";export class GoToAmmoDispatch{validate(t){return t.intents.includes(t.Intents.PATHFINDING)}check(t){return t.me.playing&&t.game.collectables[0].length}execute(t){this.pather=new g(t.pathing.nodeList);let n=200,a=null;for(const e of t.game.collectables[0]){const i=e.x-t.me.position.x,s=e.y-t.me.position.y,o=e.z-t.me.position.z,r=Math.sqrt(i*i+s*s+o*o);if(r<n){n=r;a=e}}const c=Object.entries(t.me.position).map((e)=>Math.floor(e[1])),h=Object.entries(a).map((e)=>Math.floor(e[1])),p=t.pathing.nodeList.at(...c),l=t.pathing.nodeList.at(...h);t.pathing.activePath=this.pather.path(p,l);if(!t.pathing.activePath)return t.processError("no path found");if(t.pathing.activePath.length<2)return t.processError("path too short");t.pathing.followingPath=!0;t.pathing.activeNode=t.pathing.activePath[1];t.pathing.activeNodeIdx=1}}export default GoToAmmoDispatch;
1
+ import AStar from "../pathing/astar.js";
2
+
3
+ export class GoToAmmoDispatch {
4
+ validate(bot) {
5
+ return bot.intents.includes(bot.Intents.PATHFINDING);
6
+ }
7
+ check(bot) {
8
+ return bot.me.playing && bot.game.collectables[0].length;
9
+ }
10
+ execute(bot) {
11
+ this.pather = new AStar(bot.pathing.nodeList);
12
+ let minDistance = 200;
13
+ let closestAmmo = null;
14
+ for (const ammo of bot.game.collectables[0]) {
15
+ const dx = ammo.x - bot.me.position.x;
16
+ const dy = ammo.y - bot.me.position.y;
17
+ const dz = ammo.z - bot.me.position.z;
18
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
19
+ if (distance < minDistance) {
20
+ minDistance = distance;
21
+ closestAmmo = ammo;
22
+ }
23
+ }
24
+ const position = Object.entries(bot.me.position).map((entry) => Math.floor(entry[1]));
25
+ const targetPos = Object.entries(closestAmmo).map((entry) => Math.floor(entry[1]));
26
+ const myNode = bot.pathing.nodeList.at(...position);
27
+ const targetNode = bot.pathing.nodeList.at(...targetPos);
28
+ bot.pathing.activePath = this.pather.path(myNode, targetNode);
29
+ if (!bot.pathing.activePath)
30
+ return bot.processError("no path found");
31
+ if (bot.pathing.activePath.length < 2)
32
+ return bot.processError("path too short");
33
+ bot.pathing.followingPath = true;
34
+ bot.pathing.activeNode = bot.pathing.activePath[1];
35
+ bot.pathing.activeNodeIdx = 1;
36
+ }
37
+ }
38
+ export default GoToAmmoDispatch;
@@ -1 +1,38 @@
1
- import d from"../pathing/astar.js";export class GoToCoopDispatch{validate(t){return t.intents.includes(t.Intents.PATHFINDING)}check(t){return t.me.playing&&t.game.zoneNumber&&t.game.activeZone}execute(t){this.pather=new d(t.pathing.nodeList);let n=200,a=null;for(const e of t.game.activeZone){const i=e.x-t.me.position.x,s=e.y-t.me.position.y,o=e.z-t.me.position.z,r=Math.sqrt(i*i+s*s+o*o);if(r<n){n=r;a=e}}const c=Object.entries(t.me.position).map((e)=>Math.floor(e[1])),h=Object.entries(a).map((e)=>Math.floor(e[1])),p=t.pathing.nodeList.at(...c),g=t.pathing.nodeList.at(...h);t.pathing.activePath=this.pather.path(p,g);if(!t.pathing.activePath)return t.processError("no path found");if(t.pathing.activePath.length<2)return t.processError("path too short");t.pathing.followingPath=!0;t.pathing.activeNode=t.pathing.activePath[1];t.pathing.activeNodeIdx=1}}export default GoToCoopDispatch;
1
+ import AStar from "../pathing/astar.js";
2
+
3
+ export class GoToCoopDispatch {
4
+ validate(bot) {
5
+ return bot.intents.includes(bot.Intents.PATHFINDING);
6
+ }
7
+ check(bot) {
8
+ return bot.me.playing && bot.game.zoneNumber && bot.game.activeZone;
9
+ }
10
+ execute(bot) {
11
+ this.pather = new AStar(bot.pathing.nodeList);
12
+ let minDistance = 200;
13
+ let closestZone = null;
14
+ for (const zone of bot.game.activeZone) {
15
+ const dx = zone.x - bot.me.position.x;
16
+ const dy = zone.y - bot.me.position.y;
17
+ const dz = zone.z - bot.me.position.z;
18
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
19
+ if (distance < minDistance) {
20
+ minDistance = distance;
21
+ closestZone = zone;
22
+ }
23
+ }
24
+ const position = Object.entries(bot.me.position).map((entry) => Math.floor(entry[1]));
25
+ const targetPos = Object.entries(closestZone).map((entry) => Math.floor(entry[1]));
26
+ const myNode = bot.pathing.nodeList.at(...position);
27
+ const targetNode = bot.pathing.nodeList.at(...targetPos);
28
+ bot.pathing.activePath = this.pather.path(myNode, targetNode);
29
+ if (!bot.pathing.activePath)
30
+ return bot.processError("no path found");
31
+ if (bot.pathing.activePath.length < 2)
32
+ return bot.processError("path too short");
33
+ bot.pathing.followingPath = true;
34
+ bot.pathing.activeNode = bot.pathing.activePath[1];
35
+ bot.pathing.activeNodeIdx = 1;
36
+ }
37
+ }
38
+ export default GoToCoopDispatch;
@@ -1 +1,38 @@
1
- import g from"../pathing/astar.js";export class GoToGrenadeDispatch{validate(t){return t.intents.includes(t.Intents.PATHFINDING)}check(t){return t.me.playing&&t.game.collectables[1].length}execute(t){this.pather=new g(t.pathing.nodeList);let n=200,a=null;for(const e of t.game.collectables[1]){const i=e.x-t.me.position.x,s=e.y-t.me.position.y,r=e.z-t.me.position.z,o=Math.sqrt(i*i+s*s+r*r);if(o<n){n=o;a=e}}const c=Object.entries(t.me.position).map((e)=>Math.floor(e[1])),h=Object.entries(a).map((e)=>Math.floor(e[1])),p=t.pathing.nodeList.at(...c),l=t.pathing.nodeList.at(...h);t.pathing.activePath=this.pather.path(p,l);if(!t.pathing.activePath)return t.processError("no path found");if(t.pathing.activePath.length<2)return t.processError("path too short");t.pathing.followingPath=!0;t.pathing.activeNode=t.pathing.activePath[1];t.pathing.activeNodeIdx=1}}export default GoToGrenadeDispatch;
1
+ import AStar from "../pathing/astar.js";
2
+
3
+ export class GoToGrenadeDispatch {
4
+ validate(bot) {
5
+ return bot.intents.includes(bot.Intents.PATHFINDING);
6
+ }
7
+ check(bot) {
8
+ return bot.me.playing && bot.game.collectables[1].length;
9
+ }
10
+ execute(bot) {
11
+ this.pather = new AStar(bot.pathing.nodeList);
12
+ let minDistance = 200;
13
+ let closestGrenade = null;
14
+ for (const grenade of bot.game.collectables[1]) {
15
+ const dx = grenade.x - bot.me.position.x;
16
+ const dy = grenade.y - bot.me.position.y;
17
+ const dz = grenade.z - bot.me.position.z;
18
+ const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
19
+ if (distance < minDistance) {
20
+ minDistance = distance;
21
+ closestGrenade = grenade;
22
+ }
23
+ }
24
+ const position = Object.entries(bot.me.position).map((entry) => Math.floor(entry[1]));
25
+ const targetPos = Object.entries(closestGrenade).map((entry) => Math.floor(entry[1]));
26
+ const myNode = bot.pathing.nodeList.at(...position);
27
+ const targetNode = bot.pathing.nodeList.at(...targetPos);
28
+ bot.pathing.activePath = this.pather.path(myNode, targetNode);
29
+ if (!bot.pathing.activePath)
30
+ return bot.processError("no path found");
31
+ if (bot.pathing.activePath.length < 2)
32
+ return bot.processError("path too short");
33
+ bot.pathing.followingPath = true;
34
+ bot.pathing.activeNode = bot.pathing.activePath[1];
35
+ bot.pathing.activeNodeIdx = 1;
36
+ }
37
+ }
38
+ export default GoToGrenadeDispatch;
@@ -1 +1,39 @@
1
- import h from"../pathing/astar.js";export class GoToPlayerDispatch{idOrName;constructor(t){this.idOrName=t}validate(t){if(!t.intents.includes(t.Intents.PATHFINDING))return!1;if(!this.idOrName)return!1;return!!(t.players[this.idOrName.toString()]||t.players.find((i)=>i.name===this.idOrName))}check(t){if(!t.me.playing)return!1;const e=t.players[this.idOrName.toString()]||t.players.find((i)=>i.name===this.idOrName);return e&&e.playing&&e.position&&e.position.x}execute(t){this.pather=new h(t.pathing.nodeList);const e=t.players[this.idOrName.toString()]||t.players.find((a)=>a.name===this.idOrName),i=Object.entries(t.me.position).map((a)=>Math.floor(a[1])),r=Object.entries(e.position).map((a)=>Math.floor(a[1])),n=t.pathing.nodeList.at(...i),s=t.pathing.nodeList.at(...r);t.pathing.activePath=this.pather.path(n,s);if(!t.pathing.activePath)return t.processError("no path found");if(t.pathing.activePath.length<2)return t.processError("path too short");t.pathing.followingPath=!0;t.pathing.activeNode=t.pathing.activePath[1];t.pathing.activeNodeIdx=1}}export default GoToPlayerDispatch;
1
+ import AStar from "../pathing/astar.js";
2
+
3
+ export class GoToPlayerDispatch {
4
+ idOrName;
5
+ constructor(idOrName) {
6
+ this.idOrName = idOrName;
7
+ }
8
+ validate(bot) {
9
+ if (!bot.intents.includes(bot.Intents.PATHFINDING))
10
+ return false;
11
+ if (!this.idOrName)
12
+ return false;
13
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
14
+ return !!target;
15
+ }
16
+ check(bot) {
17
+ if (!bot.me.playing)
18
+ return false;
19
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
20
+ return target && target.playing && target.position && target.position.x;
21
+ }
22
+ execute(bot) {
23
+ this.pather = new AStar(bot.pathing.nodeList);
24
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
25
+ const position = Object.entries(bot.me.position).map((entry) => Math.floor(entry[1]));
26
+ const targetPos = Object.entries(target.position).map((entry) => Math.floor(entry[1]));
27
+ const myNode = bot.pathing.nodeList.at(...position);
28
+ const targetNode = bot.pathing.nodeList.at(...targetPos);
29
+ bot.pathing.activePath = this.pather.path(myNode, targetNode);
30
+ if (!bot.pathing.activePath)
31
+ return bot.processError("no path found");
32
+ if (bot.pathing.activePath.length < 2)
33
+ return bot.processError("path too short");
34
+ bot.pathing.followingPath = true;
35
+ bot.pathing.activeNode = bot.pathing.activePath[1];
36
+ bot.pathing.activeNodeIdx = 1;
37
+ }
38
+ }
39
+ export default GoToPlayerDispatch;
@@ -1 +1,26 @@
1
- import s from"../pathing/astar.js";export class GoToSpatulaDispatch{validate(t){return t.intents.includes(t.Intents.PATHFINDING)}check(t){return t.me.playing&&t.game.spatula&&t.game.spatula.coords&&t.game.spatula.coords.x}execute(t){this.pather=new s(t.pathing.nodeList);const e=Object.entries(t.me.position).map((a)=>Math.floor(a[1])),n=Object.entries(t.game.spatula.coords).map((a)=>Math.floor(a[1])),i=t.pathing.nodeList.at(...e),r=t.pathing.nodeList.at(...n);t.pathing.activePath=this.pather.path(i,r);if(!t.pathing.activePath)return t.processError("no path found");if(t.pathing.activePath.length<2)return t.processError("path too short");t.pathing.followingPath=!0;t.pathing.activeNode=t.pathing.activePath[1];t.pathing.activeNodeIdx=1}}export default GoToSpatulaDispatch;
1
+ import AStar from "../pathing/astar.js";
2
+
3
+ export class GoToSpatulaDispatch {
4
+ validate(bot) {
5
+ return bot.intents.includes(bot.Intents.PATHFINDING);
6
+ }
7
+ check(bot) {
8
+ return bot.me.playing && bot.game.spatula && bot.game.spatula.coords && bot.game.spatula.coords.x;
9
+ }
10
+ execute(bot) {
11
+ this.pather = new AStar(bot.pathing.nodeList);
12
+ const position = Object.entries(bot.me.position).map((entry) => Math.floor(entry[1]));
13
+ const targetPos = Object.entries(bot.game.spatula.coords).map((entry) => Math.floor(entry[1]));
14
+ const myNode = bot.pathing.nodeList.at(...position);
15
+ const targetNode = bot.pathing.nodeList.at(...targetPos);
16
+ bot.pathing.activePath = this.pather.path(myNode, targetNode);
17
+ if (!bot.pathing.activePath)
18
+ return bot.processError("no path found");
19
+ if (bot.pathing.activePath.length < 2)
20
+ return bot.processError("path too short");
21
+ bot.pathing.followingPath = true;
22
+ bot.pathing.activeNode = bot.pathing.activePath[1];
23
+ bot.pathing.activeNodeIdx = 1;
24
+ }
25
+ }
26
+ export default GoToSpatulaDispatch;
@@ -1 +1,35 @@
1
- const o=(t,i)=>(t%i+i)%i,c=Math.PI*2,e=(t)=>Math.round(t*8192)/8192,p=(t)=>e(o(Math.atan2(-t.x,-t.z),c)),h=(t)=>e(Math.atan2(t.y,Math.hypot(t.x,t.z)));export class LookAtDispatch{idOrName;constructor(t){this.idOrName=t}validate(t){return!!(t.players[this.idOrName.toString()]||t.players.find((a)=>a.name===this.idOrName))}check(t){if(!t.me.playing)return!1;const i=t.players[this.idOrName.toString()]||t.players.find((a)=>a.name===this.idOrName);return i&&i.playing&&i.position&&i.position.x}execute(t){const i=t.players[this.idOrName.toString()]||t.players.find((r)=>r.name===this.idOrName),a={x:i.position.x-t.me.position.x,y:i.position.y-t.me.position.y-0.05,z:i.position.z-t.me.position.z},n=p(a),s=h(a);t.state.yaw=n;t.state.pitch=s}}export default LookAtDispatch;
1
+ const mod = (n, m) => (n % m + m) % m;
2
+ const PI2 = Math.PI * 2;
3
+ const setPrecision = (value) => Math.round(value * 8192) / 8192;
4
+ const calculateYaw = (pos) => setPrecision(mod(Math.atan2(-pos.x, -pos.z), PI2));
5
+ const calculatePitch = (pos) => setPrecision(Math.atan2(pos.y, Math.hypot(pos.x, pos.z)));
6
+
7
+ export class LookAtDispatch {
8
+ idOrName;
9
+ constructor(idOrName) {
10
+ this.idOrName = idOrName;
11
+ }
12
+ validate(bot) {
13
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
14
+ return !!target;
15
+ }
16
+ check(bot) {
17
+ if (!bot.me.playing)
18
+ return false;
19
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
20
+ return target && target.playing && target.position && target.position.x;
21
+ }
22
+ execute(bot) {
23
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
24
+ const directionVector = {
25
+ x: target.position.x - bot.me.position.x,
26
+ y: target.position.y - bot.me.position.y - 0.05,
27
+ z: target.position.z - bot.me.position.z
28
+ };
29
+ const yaw = calculateYaw(directionVector);
30
+ const pitch = calculatePitch(directionVector);
31
+ bot.state.yaw = yaw;
32
+ bot.state.pitch = pitch;
33
+ }
34
+ }
35
+ export default LookAtDispatch;
@@ -1 +1,29 @@
1
- const i=(t,s)=>(t%s+s)%s,e=Math.PI*2,o=(t)=>Math.round(t*8192)/8192,n=(t)=>o(i(Math.atan2(-t.x,-t.z),e)),h=(t)=>o(Math.atan2(t.y,Math.hypot(t.x,t.z)));export class LookAtPosDispatch{constructor(t){this.pos=t}validate(){return this.pos&&this.pos.x&&this.pos.y&&this.pos.z}check(t){return t.me.playing}execute(t){const s={x:this.pos.x-t.me.position.x,y:this.pos.y-t.me.position.y,z:this.pos.z-t.me.position.z},c=n(s),a=h(s);t.state.yaw=c;t.state.pitch=a}}export default LookAtPosDispatch;
1
+ const mod = (n, m) => (n % m + m) % m;
2
+ const PI2 = Math.PI * 2;
3
+ const setPrecision = (value) => Math.round(value * 8192) / 8192;
4
+ const calculateYaw = (pos) => setPrecision(mod(Math.atan2(-pos.x, -pos.z), PI2));
5
+ const calculatePitch = (pos) => setPrecision(Math.atan2(pos.y, Math.hypot(pos.x, pos.z)));
6
+
7
+ export class LookAtPosDispatch {
8
+ constructor(pos) {
9
+ this.pos = pos;
10
+ }
11
+ validate() {
12
+ return this.pos && this.pos.x && this.pos.y && this.pos.z;
13
+ }
14
+ check(bot) {
15
+ return bot.me.playing;
16
+ }
17
+ execute(bot) {
18
+ const directionVector = {
19
+ x: this.pos.x - bot.me.position.x,
20
+ y: this.pos.y - bot.me.position.y,
21
+ z: this.pos.z - bot.me.position.z
22
+ };
23
+ const yaw = calculateYaw(directionVector);
24
+ const pitch = calculatePitch(directionVector);
25
+ bot.state.yaw = yaw;
26
+ bot.state.pitch = pitch;
27
+ }
28
+ }
29
+ export default LookAtPosDispatch;
@@ -1 +1,26 @@
1
- import z from"../comm/CommOut.js";import A from"../constants/CommCode.js";import{GunEquipTime as B}from"../constants/index.js";export class MeleeDispatch{validate(){return!0}check(f){return f.me.playing&&!f.state.reloading&&!f.state.swappingGun&&!f.state.usingMelee}execute(f){const w=new z;w.packInt8(A.melee);w.send(f.game.socket);f.usingMelee=!0;setTimeout(()=>{f.usingMelee=!1;f.swappingGun=!0;setTimeout(()=>{f.swappingGun=!1},0.5*B)},566.6666666666667)}}export default MeleeDispatch;
1
+ import CommOut from "../comm/CommOut.js";
2
+ import CommCode from "../constants/CommCode.js";
3
+ import { GunEquipTime } from "../constants/index.js";
4
+
5
+ export class MeleeDispatch {
6
+ validate() {
7
+ return true;
8
+ }
9
+ check(bot) {
10
+ return bot.me.playing && !bot.state.reloading && !bot.state.swappingGun && !bot.state.usingMelee;
11
+ }
12
+ execute(bot) {
13
+ const out = new CommOut;
14
+ out.packInt8(CommCode.melee);
15
+ out.send(bot.game.socket);
16
+ bot.usingMelee = true;
17
+ setTimeout(() => {
18
+ bot.usingMelee = false;
19
+ bot.swappingGun = true;
20
+ setTimeout(() => {
21
+ bot.swappingGun = false;
22
+ }, 0.5 * GunEquipTime);
23
+ }, 100 / 3 * 17);
24
+ }
25
+ }
26
+ export default MeleeDispatch;
@@ -1 +1,26 @@
1
- import{Movement as t}from"../constants/index.js";export class MovementDispatch{constructor(e){if(typeof e==="number")this.inputKeys=e;else if(typeof e==="object")this.inputKeys=e.reduce((r,i)=>r|i,0)}validate(){if(typeof this.inputKeys!=="number")return!1;if(this.inputKeys&t.Forward&&this.inputKeys&t.Backward)return!1;if(this.inputKeys&t.Left&&this.inputKeys&t.Right)return!1;return!0}check(e){return e.me.playing}execute(e){e.state.controlKeys=this.inputKeys}}export default MovementDispatch;
1
+ import { Movement } from "../constants/index.js";
2
+
3
+ export class MovementDispatch {
4
+ constructor(inputKeys) {
5
+ if (typeof inputKeys === "number")
6
+ this.inputKeys = inputKeys;
7
+ else if (typeof inputKeys === "object")
8
+ this.inputKeys = inputKeys.reduce((a, b) => a | b, 0);
9
+ }
10
+ validate() {
11
+ if (typeof this.inputKeys !== "number")
12
+ return false;
13
+ if (this.inputKeys & Movement.Forward && this.inputKeys & Movement.Backward)
14
+ return false;
15
+ if (this.inputKeys & Movement.Left && this.inputKeys & Movement.Right)
16
+ return false;
17
+ return true;
18
+ }
19
+ check(bot) {
20
+ return bot.me.playing;
21
+ }
22
+ execute(bot) {
23
+ bot.state.controlKeys = this.inputKeys;
24
+ }
25
+ }
26
+ export default MovementDispatch;
@@ -1 +1,18 @@
1
- import m from"../comm/CommOut.js";import o from"../constants/CommCode.js";export class PauseDispatch{validate(){return!0}check(e){return e.me.playing}execute(e){const t=new m;t.packInt8(o.pause);t.send(e.game.socket);setTimeout(()=>e.me.playing=!1,3000)}}export default PauseDispatch;
1
+ import CommOut from "../comm/CommOut.js";
2
+ import CommCode from "../constants/CommCode.js";
3
+
4
+ export class PauseDispatch {
5
+ validate() {
6
+ return true;
7
+ }
8
+ check(bot) {
9
+ return bot.me.playing;
10
+ }
11
+ execute(bot) {
12
+ const out = new CommOut;
13
+ out.packInt8(CommCode.pause);
14
+ out.send(bot.game.socket);
15
+ setTimeout(() => bot.me.playing = false, 3000);
16
+ }
17
+ }
18
+ export default PauseDispatch;
@@ -1 +1,28 @@
1
- import s from"../comm/CommOut.js";import r from"../constants/CommCode.js";export class ReloadDispatch{validate(){return!0}check(e){return e.me.playing&&!e.state.reloading&&!e.state.swappingGun&&!e.state.usingMelee}execute(e){const o=new s;o.packInt8(r.reload);o.send(e.game.socket);const a=e.me.weapons[e.me.activeGun];if(a.ammo){const n=Math.min(Math.min(a.ammo.capacity,a.ammo.reload)-a.ammo.rounds,a.ammo.store);a.ammo.rounds+=n;a.ammo.store-=n}e.emit("playerReload",e.me,a);const m=e.me.weapons[e.me.activeGun],t=m.ammo.rounds<1;e.state.reloading=!0;setTimeout(()=>e.state.reloading=!1,t?m.longReloadTime:m.shortReloadTime)}}export default ReloadDispatch;
1
+ import CommOut from "../comm/CommOut.js";
2
+ import CommCode from "../constants/CommCode.js";
3
+
4
+ export class ReloadDispatch {
5
+ validate() {
6
+ return true;
7
+ }
8
+ check(bot) {
9
+ return bot.me.playing && !bot.state.reloading && !bot.state.swappingGun && !bot.state.usingMelee;
10
+ }
11
+ execute(bot) {
12
+ const out = new CommOut;
13
+ out.packInt8(CommCode.reload);
14
+ out.send(bot.game.socket);
15
+ const playerActiveWeapon = bot.me.weapons[bot.me.activeGun];
16
+ if (playerActiveWeapon.ammo) {
17
+ const newRounds = Math.min(Math.min(playerActiveWeapon.ammo.capacity, playerActiveWeapon.ammo.reload) - playerActiveWeapon.ammo.rounds, playerActiveWeapon.ammo.store);
18
+ playerActiveWeapon.ammo.rounds += newRounds;
19
+ playerActiveWeapon.ammo.store -= newRounds;
20
+ }
21
+ bot.emit("playerReload", bot.me, playerActiveWeapon);
22
+ const activeWeapon = bot.me.weapons[bot.me.activeGun];
23
+ const isLongTime = activeWeapon.ammo.rounds < 1;
24
+ bot.state.reloading = true;
25
+ setTimeout(() => bot.state.reloading = false, isLongTime ? activeWeapon.longReloadTime : activeWeapon.shortReloadTime);
26
+ }
27
+ }
28
+ export default ReloadDispatch;
@@ -1 +1,42 @@
1
- import x from"../comm/CommOut.js";import z from"../constants/CommCode.js";export class ReportPlayerDispatch{constructor(q,v={}){this.idOrName=q;this.reasons=[!!v.cheating,!!v.harassment,!!v.offensive,!!v.other];if(!this.reasons.includes(!0))this.reasons[3]=!0;for(let k=0;k<this.reasons.length;k++)if(this.reasons[k]===!0)this.reasonInt|=1<<k}validate(q){if(this.reasons.every((k)=>k===!1))return!1;if(!(q.players[this.idOrName.toString()]||q.players.find((k)=>k.name===this.idOrName)))return!1;return!0}check(q){if(!q.state.inGame)return!1;return!!(q.players[this.idOrName.toString()]||q.players.find((k)=>k.name===this.idOrName))}execute(q){const v=q.players[this.idOrName.toString()]||q.players.find((w)=>w.name===this.idOrName),k=new x;k.packInt8(z.reportPlayer);k.packString(v.uniqueId);k.packInt8(this.reasonInt);k.send(q.game.socket)}}export default ReportPlayerDispatch;
1
+ import CommOut from "../comm/CommOut.js";
2
+ import CommCode from "../constants/CommCode.js";
3
+
4
+ export class ReportPlayerDispatch {
5
+ constructor(idOrName, reasons = {}) {
6
+ this.idOrName = idOrName;
7
+ this.reasons = [
8
+ !!reasons.cheating,
9
+ !!reasons.harassment,
10
+ !!reasons.offensive,
11
+ !!reasons.other
12
+ ];
13
+ if (!this.reasons.includes(true))
14
+ this.reasons[3] = true;
15
+ for (let i = 0;i < this.reasons.length; i++)
16
+ if (this.reasons[i] === true)
17
+ this.reasonInt |= 1 << i;
18
+ }
19
+ validate(bot) {
20
+ if (this.reasons.every((reason) => reason === false))
21
+ return false;
22
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
23
+ if (!target)
24
+ return false;
25
+ return true;
26
+ }
27
+ check(bot) {
28
+ if (!bot.state.inGame)
29
+ return false;
30
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
31
+ return !!target;
32
+ }
33
+ execute(bot) {
34
+ const target = bot.players[this.idOrName.toString()] || bot.players.find((player) => player.name === this.idOrName);
35
+ const out = new CommOut;
36
+ out.packInt8(CommCode.reportPlayer);
37
+ out.packString(target.uniqueId);
38
+ out.packInt8(this.reasonInt);
39
+ out.send(bot.game.socket);
40
+ }
41
+ }
42
+ export default ReportPlayerDispatch;