yolkbot 0.1.0-alpha.59 → 0.1.0-alpha.60

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.59",
4
+ "version": "0.1.0-alpha.60",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
package/src/bot.js CHANGED
@@ -222,6 +222,22 @@ export class Bot {
222
222
  activeNode: null,
223
223
  activeNodeIdx: 0
224
224
  }
225
+
226
+ if (this.intents.includes(this.Intents.PLAYER_HEALTH)) this.healthIntervalId = setInterval(() => {
227
+ if (!this.players) return;
228
+
229
+ for (const player of Object.values(this.players)) {
230
+ if (player.playing && player.hp > 0) {
231
+ const regenSpeed = 0.1 * (this.game.isPrivate ? this.game.options.healthRegen : 1);
232
+
233
+ if (player.streakRewards.includes(ShellStreaks.OverHeal)) {
234
+ player.hp = Math.max(100, player.hp - regenSpeed);
235
+ } else {
236
+ player.hp = Math.min(100, player.hp + regenSpeed);
237
+ }
238
+ }
239
+ }
240
+ }, 33);
225
241
  }
226
242
 
227
243
  dispatch(disp) {
@@ -259,12 +275,12 @@ export class Bot {
259
275
 
260
276
  #processLoginData(loginData) {
261
277
  if (typeof loginData == 'string') {
262
- this.#emit('authFail', loginData);
278
+ this.emit('authFail', loginData);
263
279
  return false;
264
280
  }
265
281
 
266
282
  if (loginData.banRemaining) {
267
- this.#emit('banned', loginData.banRemaining);
283
+ this.emit('banned', loginData.banRemaining);
268
284
  return false;
269
285
  }
270
286
 
@@ -299,7 +315,7 @@ export class Bot {
299
315
  instance: this.instance
300
316
  });
301
317
 
302
- this.matchmaker.on('authFail', (data) => this.#emit('authFail', data));
318
+ this.matchmaker.on('authFail', (data) => this.emit('authFail', data));
303
319
 
304
320
  await this.matchmaker.getRegions();
305
321
  }
@@ -519,7 +535,7 @@ export class Bot {
519
535
 
520
536
  this.game.socket.onclose = (e) => {
521
537
  // console.log('Game socket closed:', e.code, Object.entries(CloseCode).filter(([, v]) => v == e.code));
522
- this.#emit('close', e.code);
538
+ this.emit('close', e.code);
523
539
  }
524
540
  }
525
541
 
@@ -606,7 +622,7 @@ export class Bot {
606
622
  // process syncMe
607
623
  const now = Date.now();
608
624
  if (now - this.lastUpdateTime >= 50) {
609
- this.#emit('tick');
625
+ this.emit('tick');
610
626
 
611
627
  // Send out update packet
612
628
  const out = CommOut.getBuffer();
@@ -644,7 +660,7 @@ export class Bot {
644
660
  // these are auth-related codes (liveCallbacks doesn't run during auth)
645
661
  #mustBeInstant = ['authFail', 'banned'];
646
662
 
647
- #emit(event, ...args) {
663
+ emit(event, ...args) {
648
664
  if (this._hooks[event]) {
649
665
  for (const cb of this._hooks[event]) {
650
666
  if (this.#mustBeInstant.includes(event)) cb(...args);
@@ -753,7 +769,7 @@ export class Bot {
753
769
  const player = this.players[Object.keys(this.players).find(p => this.players[p].id == id)];
754
770
  // console.log(`Player ${player.name}: ${text} (flags: ${msgFlags})`);
755
771
  // console.log(`Their position: ${player.position.x}, ${player.position.y}, ${player.position.z}`);
756
- this.#emit('chat', player, text, msgFlags);
772
+ this.emit('chat', player, text, msgFlags);
757
773
  }
758
774
 
759
775
  #processAddPlayerPacket() {
@@ -811,31 +827,14 @@ export class Bot {
811
827
  playerData.gameData_.private = CommIn.unPackInt8U();
812
828
  playerData.gameData_.gameType = CommIn.unPackInt8U();
813
829
 
814
- if (!this.players[playerData.id_]) {
830
+ if (!this.players[playerData.id_])
815
831
  this.players[playerData.id_] = new GamePlayer(playerData.id_, playerData.team_, playerData);
816
832
 
817
- const player = this.players[playerData.id_];
818
-
819
- if (player.playing && this.intents.includes(this.Intents.PLAYER_HEALTH)) {
820
- player.healthInterval = setInterval(() => {
821
- if (player.hp < 1) return;
822
-
823
- const regenSpeed = 0.1 * (this.game.isPrivate ? this.game.options.healthRegen : 1);
824
-
825
- if (player.streakRewards.includes(ShellStreaks.OverHeal)) {
826
- player.hp = Math.max(100, player.hp - regenSpeed);
827
- } else {
828
- player.hp = Math.min(100, player.hp + regenSpeed);
829
- }
830
- }, 33);
831
- }
832
- }
833
-
834
833
  if (this.me.id == playerData.id_) {
835
834
  this.me = this.players[playerData.id_];
836
835
  }
837
836
 
838
- this.#emit('playerJoin', this.players[playerData.id_]);
837
+ this.emit('playerJoin', this.players[playerData.id_]);
839
838
  }
840
839
 
841
840
  #processRespawnPacket() {
@@ -862,24 +861,7 @@ export class Bot {
862
861
  player.grenades = grenades;
863
862
  player.position = { x: x, y: y, z: z };
864
863
  // console.log(`Player ${player.name} respawned at ${x}, ${y}, ${z}`);
865
- this.#emit('playerRespawn', player);
866
-
867
- if (this.intents.includes(this.Intents.PLAYER_HEALTH)) {
868
- if (player.healthInterval)
869
- clearInterval(player.healthInterval);
870
-
871
- player.healthInterval = setInterval(() => {
872
- if (player.hp < 1) return;
873
-
874
- const regenSpeed = 0.1 * (this.game.isPrivate ? this.game.options[GameOptionFlags.healthRegen] : 1);
875
-
876
- if (player.streakRewards.includes(ShellStreaks.OverHeal)) {
877
- player.hp = Math.max(100, player.hp - regenSpeed);
878
- } else {
879
- player.hp = Math.min(100, player.hp + regenSpeed);
880
- }
881
- }, 33);
882
- }
864
+ this.emit('playerRespawn', player);
883
865
  } else {
884
866
  // console.log(`Player ${id} not found. (me: ${this.me.id}) (respawn)`);
885
867
  }
@@ -947,7 +929,7 @@ export class Bot {
947
929
  const player = this.players[id];
948
930
  if (player) {
949
931
  player.playing = false;
950
- this.#emit('playerPause', player);
932
+ this.emit('playerPause', player);
951
933
  }
952
934
  }
953
935
 
@@ -958,7 +940,7 @@ export class Bot {
958
940
  const player = this.players[id];
959
941
  if (player) {
960
942
  player.activeGun = newWeaponId;
961
- this.#emit('playerSwapWeapon', player, newWeaponId);
943
+ this.emit('playerSwapWeapon', player, newWeaponId);
962
944
  }
963
945
  }
964
946
 
@@ -983,7 +965,7 @@ export class Bot {
983
965
  if (killer) { killer.kills++; }
984
966
  // console.log(`Player ${killer.name} is on a streak of ${killer.kills} kills.`);
985
967
 
986
- this.#emit('playerDeath', killed, killer); // killed, killer
968
+ this.emit('playerDeath', killed, killer); // killed, killer
987
969
  }
988
970
 
989
971
  #processFirePacket() {
@@ -997,7 +979,7 @@ export class Bot {
997
979
 
998
980
  if (playerWeapon && playerWeapon.ammo) {
999
981
  playerWeapon.ammo.rounds--;
1000
- this.#emit('playerFire', player, playerWeapon);
982
+ this.emit('playerFire', player, playerWeapon);
1001
983
  }
1002
984
  }
1003
985
 
@@ -1010,7 +992,7 @@ export class Bot {
1010
992
 
1011
993
  this.game.collectables[type].push({ id, x, y, z });
1012
994
 
1013
- this.#emit('spawnItem', type, id, { x, y, z });
995
+ this.emit('spawnItem', type, id, { x, y, z });
1014
996
  }
1015
997
 
1016
998
  #processCollectPacket() {
@@ -1027,7 +1009,7 @@ export class Bot {
1027
1009
  const playerWeapon = player.weapons[applyToWeaponIdx];
1028
1010
  if (playerWeapon && playerWeapon.ammo) {
1029
1011
  playerWeapon.ammo.store = Math.min(playerWeapon.ammo.storeMax, playerWeapon.ammo.store + playerWeapon.ammo.pickup);
1030
- this.#emit('collectAmmo', player, playerWeapon);
1012
+ this.emit('collectAmmo', player, playerWeapon);
1031
1013
  }
1032
1014
  }
1033
1015
 
@@ -1035,7 +1017,7 @@ export class Bot {
1035
1017
  player.grenades++;
1036
1018
  if (player.grenades > 3) player.grenades = 3
1037
1019
 
1038
- this.#emit('collectGrenade', player);
1020
+ this.emit('collectGrenade', player);
1039
1021
  }
1040
1022
  }
1041
1023
 
@@ -1049,7 +1031,7 @@ export class Bot {
1049
1031
  const oldHP = player.hp;
1050
1032
  player.hp = hp;
1051
1033
 
1052
- this.#emit('playerDamaged', player, oldHP, player.hp);
1034
+ this.emit('playerDamaged', player, oldHP, player.hp);
1053
1035
  }
1054
1036
 
1055
1037
  #processHitMePacket() {
@@ -1061,7 +1043,7 @@ export class Bot {
1061
1043
  const oldHp = this.me.hp;
1062
1044
  this.me.hp = hp;
1063
1045
 
1064
- this.#emit('selfDamaged', oldHp, this.me.hp);
1046
+ this.emit('selfDamaged', oldHp, this.me.hp);
1065
1047
  }
1066
1048
 
1067
1049
  #processSyncMePacket() {
@@ -1091,7 +1073,7 @@ export class Bot {
1091
1073
  player.position.z = newZ;
1092
1074
 
1093
1075
  if (oldX != newX || oldY != newY || oldZ != newZ) {
1094
- this.#emit('selfMoved', player, { x: oldX, y: oldY, z: oldZ }, { x: newX, y: newY, z: newZ });
1076
+ this.emit('selfMoved', player, { x: oldX, y: oldY, z: oldZ }, { x: newX, y: newY, z: newZ });
1095
1077
  }
1096
1078
  }
1097
1079
 
@@ -1107,7 +1089,7 @@ export class Bot {
1107
1089
 
1108
1090
  delete this.players[id.toString()];
1109
1091
 
1110
- this.#emit('playerLeave', removedPlayer);
1092
+ this.emit('playerLeave', removedPlayer);
1111
1093
  }
1112
1094
 
1113
1095
  #processGameStatePacket() {
@@ -1130,7 +1112,7 @@ export class Bot {
1130
1112
  controlledByTeam: controlledByTeam
1131
1113
  };
1132
1114
 
1133
- this.#emit('gameStateChange', this.game);
1115
+ this.emit('gameStateChange', this.game);
1134
1116
  } else if (this.game.gameModeId == GameModes.kotc) {
1135
1117
  this.game.stage = CommIn.unPackInt8U(); // constants.CoopStates
1136
1118
  this.game.zoneNumber = CommIn.unPackInt8U(); // a number to represent which 'active zone' kotc is using
@@ -1145,7 +1127,7 @@ export class Bot {
1145
1127
  this.game.capturePercent = this.game.captureProgress / 1000; // progress of the capture as a percentage
1146
1128
  this.game.activeZone = this.game.map.zones ? this.game.map.zones[this.game.zoneNumber - 1] : null;
1147
1129
 
1148
- this.#emit('gameStateChange', this.game);
1130
+ this.emit('gameStateChange', this.game);
1149
1131
  } else if (this.game.gameModeId == GameModes.team) {
1150
1132
  this.game.teamScore[1] = CommIn.unPackInt16U();
1151
1133
  this.game.teamScore[2] = CommIn.unPackInt16U();
@@ -1217,7 +1199,7 @@ export class Bot {
1217
1199
  break;
1218
1200
  }
1219
1201
 
1220
- this.#emit('playerBeginStreak', player, ksType);
1202
+ this.emit('playerBeginStreak', player, ksType);
1221
1203
  }
1222
1204
 
1223
1205
  #processEndStreakPacket() {
@@ -1236,7 +1218,7 @@ export class Bot {
1236
1218
  player.streakRewards = player.streakRewards.filter((r) => r != ksType);
1237
1219
  }
1238
1220
 
1239
- this.#emit('playerEndStreak', ksType, player);
1221
+ this.emit('playerEndStreak', ksType, player);
1240
1222
  }
1241
1223
 
1242
1224
  #processHitShieldPacket() {
@@ -1251,9 +1233,9 @@ export class Bot {
1251
1233
 
1252
1234
  if (this.me.hpShield <= 0) {
1253
1235
  this.me.streakRewards = this.me.streakRewards.filter((r) => r != ShellStreaks.HardBoiled);
1254
- this.#emit('selfShieldLost');
1236
+ this.emit('selfShieldLost');
1255
1237
  } else {
1256
- this.#emit('selfShieldHit', this.me.hpShield);
1238
+ this.emit('selfShieldHit', this.me.hpShield);
1257
1239
  }
1258
1240
  }
1259
1241
 
@@ -1282,7 +1264,7 @@ export class Bot {
1282
1264
  this.game.options.weaponsDisabled = Array.from({ length: 7 }, () => CommIn.unPackInt8U() === 1);
1283
1265
  this.game.options.mustUseSecondary = this.game.options.weaponsDisabled.every((v) => v);
1284
1266
 
1285
- this.#emit('gameOptionsChange', oldOptions, this.game.options);
1267
+ this.emit('gameOptionsChange', oldOptions, this.game.options);
1286
1268
  return false;
1287
1269
  }
1288
1270
 
@@ -1291,7 +1273,7 @@ export class Bot {
1291
1273
 
1292
1274
  if (action == GameActions.pause) {
1293
1275
  // console.log('settings changed, gameOwner changed game settings, force paused');
1294
- this.#emit('gameForcePause');
1276
+ this.emit('gameForcePause');
1295
1277
  setTimeout(() => this.me.playing = false, 3000);
1296
1278
  }
1297
1279
 
@@ -1319,7 +1301,7 @@ export class Bot {
1319
1301
  this.game.capturePercent = 0.0;
1320
1302
  }
1321
1303
 
1322
- this.#emit('gameReset');
1304
+ this.emit('gameReset');
1323
1305
  }
1324
1306
  }
1325
1307
 
@@ -1330,7 +1312,7 @@ export class Bot {
1330
1312
 
1331
1313
  this.ping = Date.now() - this.lastPingTime;
1332
1314
 
1333
- this.#emit('pingUpdate', oldPing, this.ping);
1315
+ this.emit('pingUpdate', oldPing, this.ping);
1334
1316
 
1335
1317
  setTimeout(() => {
1336
1318
  const out = CommOut.getBuffer();
@@ -1352,7 +1334,7 @@ export class Bot {
1352
1334
  player.team = toTeam;
1353
1335
  player.kills = 0;
1354
1336
 
1355
- this.#emit('playerSwitchTeam', player, oldTeam, toTeam);
1337
+ this.emit('playerSwitchTeam', player, oldTeam, toTeam);
1356
1338
  }
1357
1339
 
1358
1340
  #processChangeCharacterPacket() {
@@ -1396,8 +1378,8 @@ export class Bot {
1396
1378
  player.selectedGun = weaponIndex;
1397
1379
  player.weapons[0] = new GunList[weaponIndex]();
1398
1380
 
1399
- if (oldWeaponIdx !== player.selectedGun) this.#emit('playerChangeGun', player, oldWeaponIdx, player.selectedGun);
1400
- if (oldCharacter !== player.character) this.#emit('playerChangeCharacter', player, oldCharacter, player.character);
1381
+ if (oldWeaponIdx !== player.selectedGun) this.emit('playerChangeGun', player, oldWeaponIdx, player.selectedGun);
1382
+ if (oldCharacter !== player.character) this.emit('playerChangeCharacter', player, oldCharacter, player.character);
1401
1383
  }
1402
1384
  }
1403
1385
 
@@ -1406,28 +1388,23 @@ export class Bot {
1406
1388
  const oldBalance = this.account.eggBalance;
1407
1389
 
1408
1390
  this.account.eggBalance = newBalance;
1409
- this.#emit('balanceUpdate', newBalance - oldBalance, newBalance);
1391
+ this.emit('balanceUpdate', newBalance - oldBalance, newBalance);
1410
1392
  }
1411
1393
 
1412
1394
  #processRespawnDeniedPacket() {
1413
1395
  this.me.playing = false;
1414
- this.#emit('selfRespawnFail');
1396
+ this.emit('selfRespawnFail');
1415
1397
  }
1416
1398
 
1417
1399
  #processMeleePacket() {
1418
1400
  const id = CommIn.unPackInt8U();
1419
1401
  const player = this.players[id];
1420
1402
 
1421
- if (player) this.#emit('playerMelee', player);
1403
+ if (player) this.emit('playerMelee', player);
1422
1404
  }
1423
1405
 
1424
- // we do this since reload doesn't get emitted for the bot itself
1425
- // so we simulate it when calling a reload dispatch
1426
- processReloadPacket(customPlayer, iUnderstandThisIsForInternalUseOnlyAndIShouldNotBeCallingThis) {
1427
- if (!iUnderstandThisIsForInternalUseOnlyAndIShouldNotBeCallingThis)
1428
- throw new Error('processReloadPacket is exposed for internal use only. do not call it.');
1429
-
1430
- const id = customPlayer || CommIn.unPackInt8U();
1406
+ #processReloadPacket() {
1407
+ const id = CommIn.unPackInt8U();
1431
1408
  const player = this.players[id];
1432
1409
 
1433
1410
  if (!player) return;
@@ -1444,7 +1421,7 @@ export class Bot {
1444
1421
  playerActiveWeapon.ammo.store -= newRounds;
1445
1422
  }
1446
1423
 
1447
- this.#emit('playerReload', player, playerActiveWeapon);
1424
+ this.emit('playerReload', player, playerActiveWeapon);
1448
1425
  }
1449
1426
 
1450
1427
  #processGameRequestOptionsPacket() {
@@ -1478,8 +1455,8 @@ export class Bot {
1478
1455
  if (this.intents.includes(this.Intents.COSMETIC_DATA))
1479
1456
  item = findItemById(item);
1480
1457
 
1481
- if (itemType == ItemTypes.Grenade) this.#emit('grenadeExploded', item, { x, y, z }, damage, radius);
1482
- else this.#emit('rocketHit', { x, y, z }, damage, radius);
1458
+ if (itemType == ItemTypes.Grenade) this.emit('grenadeExploded', item, { x, y, z }, damage, radius);
1459
+ else this.emit('rocketHit', { x, y, z }, damage, radius);
1483
1460
  }
1484
1461
 
1485
1462
  #processThrowGrenadePacket() {
@@ -1495,7 +1472,7 @@ export class Bot {
1495
1472
 
1496
1473
  if (player) {
1497
1474
  player.grenades--;
1498
- this.#emit('playerThrowGrenade', player, { x, y, z }, { x: dx, y: dy, z: dz });
1475
+ this.emit('playerThrowGrenade', player, { x, y, z }, { x: dx, y: dy, z: dz });
1499
1476
  }
1500
1477
  }
1501
1478
 
@@ -1598,7 +1575,7 @@ export class Bot {
1598
1575
  break;
1599
1576
 
1600
1577
  case CommCode.reload:
1601
- this.processReloadPacket(null, true);
1578
+ this.#processReloadPacket();
1602
1579
  break;
1603
1580
 
1604
1581
  case CommCode.explode:
@@ -1849,6 +1826,23 @@ export class Bot {
1849
1826
 
1850
1827
  return result;
1851
1828
  }
1829
+
1830
+ quit(noCleanup = false) {
1831
+ if (this.intents.includes(this.Intents.PLAYER_HEALTH))
1832
+ clearInterval(this.healthIntervalId);
1833
+
1834
+ clearInterval(this.updateInterval);
1835
+
1836
+ this.game.socket.close();
1837
+ this.matchmaker.close();
1838
+
1839
+ if (!noCleanup) {
1840
+ delete this.account;
1841
+ delete this.game;
1842
+ delete this.me;
1843
+ delete this.players;
1844
+ }
1845
+ }
1852
1846
  }
1853
1847
 
1854
1848
  export default Bot;
@@ -8,7 +8,19 @@ export class ReloadDispatch {
8
8
  execute(bot) {
9
9
  new packet.ReloadPacket().execute(bot.game.socket);
10
10
 
11
- bot.processReloadPacket(bot.me.id, true);
11
+ const playerActiveWeapon = bot.me.weapons[bot.me.activeGun];
12
+
13
+ if (playerActiveWeapon.ammo) {
14
+ const newRounds = Math.min(
15
+ Math.min(playerActiveWeapon.ammo.capacity, playerActiveWeapon.ammo.reload) - playerActiveWeapon.ammo.rounds,
16
+ playerActiveWeapon.ammo.store
17
+ );
18
+
19
+ playerActiveWeapon.ammo.rounds += newRounds;
20
+ playerActiveWeapon.ammo.store -= newRounds;
21
+ }
22
+
23
+ bot.emit('playerReload', bot.me, playerActiveWeapon);
12
24
 
13
25
  const activeWeapon = bot.me.weapons[bot.me.activeGun];
14
26
  const isLongTime = activeWeapon.ammo.rounds < 1;