index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Version 2.0.2
  2. // Based on true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
  3. // Based on true-everful-nostrum by Caali https://github.com/caali-hackerman
  4. 'use strict'
  5. const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 855604], // EU, NA, RU, TW, ?, ?, JP , TH
  6. BUFF_NOSTRUM = [4020, 4021, 4022, 4023, 4030, 4031, 4032, 4044], // Nostrum abnormalities
  7. BUFF_CCB = [4610, 4611, 4612, 4613, 4615, 4616, 4950, 5000003, 5020003], // Complete Crystalbind abnormalities
  8. BUFF_INVINCIBILITY = [1134, 6007] // Invincibility abnormalities on resurrection
  9. module.exports = function Essentials(mod) {
  10. mod.game.initialize("contract")
  11. let slot = null,
  12. interval = null,
  13. enabled = true,
  14. abnormalities = {},
  15. counter = 0,
  16. resetcount = null
  17. // ############# //
  18. // ### Hooks ### //
  19. // ############# //
  20. mod.game.on('enter_game', () => { setTimeout(start, 5000) })
  21. mod.game.on('leave_game', () => {
  22. stop()
  23. abnormalities = {}
  24. })
  25. mod.game.me.on('resurrect', () => {
  26. abnormalities = {}
  27. start()
  28. })
  29. mod.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  30. for(let item of event.inventory)
  31. if(ITEMS_NOSTRUM.includes(item.item)) {
  32. slot = item.slot
  33. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  34. return true
  35. }
  36. })
  37. mod.hook('S_ABNORMALITY_BEGIN', mod.base.majorPatchVersion >= 75 ? 3:2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  38. mod.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  39. mod.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  40. if(mod.settings.log) {
  41. mod.hook('C_USE_ITEM', 3, event => {
  42. mod.command.message('Used item ID: ' + event.id)
  43. })
  44. }
  45. // ################# //
  46. // ### Functions ### //
  47. // ################# //
  48. function abnormality(type, event) {
  49. if(mod.game.me.is(event.target)) {
  50. if(type === 'S_ABNORMALITY_END')
  51. delete abnormalities[event.id]
  52. else abnormalities[event.id] = Date.now() + event.duration
  53. }
  54. }
  55. function abnormalityDuration(id) {
  56. if(!abnormalities[id]) return 0
  57. return abnormalities[id] - Date.now()
  58. }
  59. function checkItems() {
  60. for(let buff of BUFF_INVINCIBILITY) // Do not overwrite invincibility buff
  61. if(abnormalityDuration(buff) > 0) return
  62. useNostrum()
  63. useCCB()
  64. }
  65. function useNostrum() {
  66. for(let buff of BUFF_NOSTRUM) // Use Nostrum only when less than 5 minutes remaining
  67. if(abnormalityDuration(buff) > 300000 || !mod.settings.useNostrum) return
  68. if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active) return
  69. if(enabled) {
  70. if(slot) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  71. else useItem(mod.settings.nostrum)
  72. }
  73. }
  74. function useCCB() {
  75. for(let buff of BUFF_CCB) // Use CCB only when less than 10 minutes remaining
  76. if(abnormalityDuration(buff) > 600000 || !mod.settings.useCCB) return
  77. if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active) return
  78. if(enabled) useItem(mod.settings.ccb)
  79. }
  80. function useItem(item) {
  81. counter++
  82. if(counter > 5) {
  83. let missing = (item == mod.settings.nostrum) ? 'Nostrums' : 'Crystalbinds'
  84. enabled = false
  85. mod.command.message('You ran out of ' + missing + ' (ID: ' + item + '). Essentials has been disabled. Please restock and enable the module again by typing "essentials" in this chat.')
  86. console.log('You ran out of ' + missing + ' (ID: ' + item + '). Essentials has been disabled. Please restock and enable the module again by typing "essentials" in proxy chat.')
  87. return
  88. }
  89. if(!resetcount) resetcount = setTimeout(() => { counter = 0; resetcount = null }, 15000)
  90. mod.toServer('C_USE_ITEM', 3, {
  91. gameId: mod.game.me.gameId,
  92. id: item,
  93. dbid: 0,
  94. target: 0,
  95. amount: 1,
  96. dest: {x: 0, y: 0, z: 0},
  97. loc: {x: 0, y: 0, z: 0},
  98. w: 0,
  99. unk1: 0,
  100. unk2: 0,
  101. unk3: 0,
  102. unk4: 1
  103. })
  104. }
  105. function start() {
  106. stop()
  107. interval = setInterval(checkItems, 1500)
  108. }
  109. function stop() {
  110. if (interval) {
  111. clearInterval(interval)
  112. interval = null
  113. }
  114. }
  115. // ################ //
  116. // ### Commands ### //
  117. // ################ //
  118. mod.command.add('essentials', () => {
  119. enabled = !enabled
  120. mod.command.message('Essentials ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  121. console.log('Essentials ' + (enabled ? 'enabled' : 'disabled'))
  122. })
  123. }