index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const config = require('./config.json');
  2. module.exports = function Loot(dispatch) {
  3. let auto = config.modes.auto || false,
  4. enabled = config.modes.easy || true,
  5. lootInterval = auto ? setInterval(tryLootAll, 250) : null,
  6. location;
  7. let blacklist = config.blacklist || [8000, 8001, 8002, 8005, 8018, 8025, 8023];
  8. let loot = {};
  9. let commands = {
  10. auto: {
  11. alias: ['auto', 'autoloot', 'toggle'],
  12. run: function() {
  13. auto = !auto;
  14. message(`Autoloot mode toggled: ${auto}`);
  15. if(auto){
  16. lootInterval = setInterval(tryLootAll, 250);
  17. }
  18. else
  19. clearInterval(lootInterval);
  20. }
  21. },
  22. enable: {
  23. alias: ['enable', 'on'],
  24. run: function() {
  25. enabled = true;
  26. message('Easy looting is enabled.');
  27. }
  28. },
  29. disable: {
  30. alias: ['disable', 'off'],
  31. run: function() {
  32. enabled = false;
  33. message('Easy looting is disabled.');
  34. }
  35. }
  36. }
  37. dispatch.hook('C_CHAT', 1, (event) => {
  38. if(!event.message.includes('!loot'))
  39. return;
  40. let command = event.message.replace(/<\/?[^<>]*>/gi, '').split(' ');
  41. if(command.length > 1) {
  42. for(let cmd in commands) {
  43. if(commands[cmd].alias.indexOf(command[1].toString()) > -1)
  44. commands[cmd].run();
  45. }
  46. }
  47. return false;
  48. });
  49. dispatch.hook('S_LOAD_TOPO', 1, (event) => {
  50. loot = {};
  51. });
  52. dispatch.hook('C_PLAYER_LOCATION', 1, (event) => {
  53. location = event;
  54. });
  55. dispatch.hook('S_SPAWN_DROPITEM', 1, (event) => {
  56. if(!(blacklist.indexOf(event.item) > -1)) loot[event.id.toString()] = event;
  57. });
  58. dispatch.hook('C_TRY_LOOT_DROPITEM', 1, (event) => {
  59. if(enabled) tryLootAll();
  60. });
  61. dispatch.hook('S_DESPAWN_DROPITEM', 1, (event) => {
  62. if(event.id.toString() in loot) delete loot[event.id.toString()];
  63. });
  64. function tryLootAll() {
  65. for(let item in loot) {
  66. if(location)
  67. if(Math.abs(loot[item].x - location.x1) < 120 && Math.abs(loot[item].y - location.y1) < 120)
  68. dispatch.toServer('C_TRY_LOOT_DROPITEM', 1, {
  69. id: loot[item].id
  70. });
  71. }
  72. }
  73. function message(msg) {
  74. dispatch.toClient('S_CHAT', 1, {
  75. channel: 24,
  76. authorID: 0,
  77. unk1: 0,
  78. gm: 0,
  79. unk2: 0,
  80. authorName: '',
  81. message: ' (autoloot) ' + msg
  82. });
  83. }
  84. }