index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Version 2.0.4
  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. if(mod.proxyAuthor !== 'caali') {
  11. const options = require('./module').options
  12. if(options) {
  13. const settingsVersion = options.settingsVersion
  14. if(settingsVersion) {
  15. mod.settings = require('./' + (options.settingsMigrator || 'module_settings_migrator.js'))(mod.settings._version, settingsVersion, mod.settings)
  16. mod.settings._version = settingsVersion
  17. }
  18. }
  19. }
  20. mod.game.initialize("contract")
  21. let slot = null,
  22. interval = null,
  23. enabled = true,
  24. abnormalities = {},
  25. counter = 0,
  26. resetcount = null
  27. // ############# //
  28. // ### Hooks ### //
  29. // ############# //
  30. mod.game.on('enter_game', () => { setTimeout(start, 5000) })
  31. mod.game.on('leave_game', () => {
  32. stop()
  33. abnormalities = {}
  34. })
  35. mod.game.me.on('resurrect', () => {
  36. abnormalities = {}
  37. start()
  38. })
  39. mod.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  40. for(let item of event.inventory)
  41. if(ITEMS_NOSTRUM.includes(item.item)) {
  42. slot = item.slot
  43. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  44. return true
  45. }
  46. })
  47. mod.hook('S_ABNORMALITY_BEGIN', 3, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  48. mod.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  49. mod.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  50. if(mod.settings.log) {
  51. mod.hook('C_USE_ITEM', 3, event => {
  52. mod.command.message('Used item ID: ' + event.id)
  53. })
  54. }
  55. // ################# //
  56. // ### Functions ### //
  57. // ################# //
  58. function abnormality(type, event) {
  59. if(mod.game.me.is(event.target)) {
  60. if(type === 'S_ABNORMALITY_END')
  61. delete abnormalities[event.id]
  62. else abnormalities[event.id] = Date.now() + event.duration
  63. }
  64. }
  65. function abnormalityDuration(id) {
  66. if(!abnormalities[id]) return 0
  67. return abnormalities[id] - Date.now()
  68. }
  69. function checkItems() {
  70. for(let buff of BUFF_INVINCIBILITY) // Do not overwrite invincibility buff
  71. if(abnormalityDuration(buff) > 0) return
  72. useNostrum()
  73. useCCB()
  74. }
  75. function useNostrum() {
  76. for(let buff of BUFF_NOSTRUM) // Use Nostrum only when less than 5 minutes remaining
  77. if(abnormalityDuration(buff) > 300000 || !mod.settings.useNostrum) return
  78. if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active) return
  79. if(enabled) {
  80. if(slot) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  81. else useItem(mod.settings.nostrum)
  82. }
  83. }
  84. function useCCB() {
  85. for(let buff of BUFF_CCB) // Use CCB only when less than 10 minutes remaining
  86. if(abnormalityDuration(buff) > 600000 || !mod.settings.useCCB) return
  87. if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active) return
  88. if(enabled) useItem(mod.settings.ccb)
  89. }
  90. function useItem(item) {
  91. counter++
  92. if(counter > 5) {
  93. let missing = (item == mod.settings.nostrum) ? 'Nostrums' : 'Crystalbinds'
  94. enabled = false
  95. 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.')
  96. 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.')
  97. return
  98. }
  99. if(!resetcount) resetcount = setTimeout(() => { counter = 0; resetcount = null }, 15000)
  100. mod.toServer('C_USE_ITEM', 3, {
  101. gameId: mod.game.me.gameId,
  102. id: item,
  103. dbid: 0,
  104. target: 0,
  105. amount: 1,
  106. dest: {x: 0, y: 0, z: 0},
  107. loc: {x: 0, y: 0, z: 0},
  108. w: 0,
  109. unk1: 0,
  110. unk2: 0,
  111. unk3: 0,
  112. unk4: 1
  113. })
  114. }
  115. function start() {
  116. stop()
  117. interval = setInterval(checkItems, 1500)
  118. }
  119. function stop() {
  120. if (interval) {
  121. clearInterval(interval)
  122. interval = null
  123. }
  124. }
  125. // ################ //
  126. // ### Commands ### //
  127. // ################ //
  128. mod.command.add('essentials', () => {
  129. enabled = !enabled
  130. mod.command.message('Essentials ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  131. console.log('Essentials ' + (enabled ? 'enabled' : 'disabled'))
  132. })
  133. }