index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Version 2.0.0
  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, ?, ?, ?, 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. // ############# //
  16. // ### Hooks ### //
  17. // ############# //
  18. mod.game.on('enter_game', () => { start() })
  19. mod.game.on('leave_game', () => { stop() })
  20. mod.game.me.on('resurrect', () => { start() })
  21. mod.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  22. for(let item of event.inventory)
  23. if(ITEMS_NOSTRUM.includes(item.item)) {
  24. slot = item.slot
  25. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  26. return true
  27. }
  28. })
  29. mod.hook('S_ABNORMALITY_BEGIN', mod.base.majorPatchVersion >= 75 ? 3:2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  30. mod.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  31. mod.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  32. if(mod.settings.log) {
  33. mod.hook('C_USE_ITEM', 3, event => {
  34. mod.command.message('Used item ID: ' + event.id)
  35. })
  36. }
  37. // ################# //
  38. // ### Functions ### //
  39. // ################# //
  40. function abnormality(type, event) {
  41. if(mod.game.me.is(event.target)) {
  42. if(type === 'S_ABNORMALITY_END')
  43. delete abnormalities[event.id]
  44. else abnormalities[event.id] = Date.now() + event.duration
  45. }
  46. }
  47. function abnormalityDuration(id) {
  48. if(!abnormalities[id]) return 0
  49. return abnormalities[id] - Date.now()
  50. }
  51. function checkItems() {
  52. for(let buff of BUFF_INVINCIBILITY) // Do not overwrite invincibility buff
  53. if(abnormalityDuration(buff) > 0) return
  54. useNostrum()
  55. useCCB()
  56. }
  57. function useNostrum() {
  58. for(let buff of BUFF_NOSTRUM) // Use Nostrum only when less than 5 minutes remaining
  59. if(abnormalityDuration(buff) > 300000 || !mod.settings.useNostrum) return
  60. if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active || (mod.settings.elite && !slot)) return
  61. if(enabled) {
  62. if(slot) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  63. else useItem(mod.settings.nostrum)
  64. }
  65. }
  66. function useCCB() {
  67. for(let buff of BUFF_CCB) // Use CCB only when less than 10 minutes remaining
  68. if(abnormalityDuration(buff) > 600000 || !mod.settings.useCCB) return
  69. if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active) return
  70. if(enabled) useItem(mod.settings.ccb)
  71. }
  72. function useItem(item) {
  73. mod.toServer('C_USE_ITEM', 3, {
  74. gameId: mod.game.me.gameId,
  75. id: item,
  76. dbid: 0,
  77. target: 0,
  78. amount: 1,
  79. dest: {x: 0, y: 0, z: 0},
  80. loc: {x: 0, y: 0, z: 0},
  81. w: 0,
  82. unk1: 0,
  83. unk2: 0,
  84. unk3: 0,
  85. unk4: 1
  86. })
  87. }
  88. function start() {
  89. stop()
  90. interval = setInterval(checkItems, 1000)
  91. }
  92. function stop() {
  93. if (interval) {
  94. clearInterval(interval)
  95. interval = null
  96. }
  97. abnormalities = {}
  98. }
  99. // ################ //
  100. // ### Commands ### //
  101. // ################ //
  102. mod.command.add('essentials', () => {
  103. enabled = !enabled
  104. mod.command.message((enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  105. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  106. })
  107. }