index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Version 1.3.7
  2. // Based on true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
  3. 'use strict'
  4. const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 855604], // EU, NA, RU, TW, ?, ?, ?, TH
  5. BUFF_INVINCIBILITY = [1134, 6007], // Invincibility abnormality (Goddess Blessing, Phoenix)
  6. BUFF_NOSTRUM_TD = [4020, 4030], // Nostrum abnormality for Tanks and Damage Dealers (pleb, elite)
  7. BUFF_NOSTRUM_H = [4021, 4031], // Nostrum abnormality for Healers (pleb, elite)
  8. BUFF_CCB = [4610, 4612, 5020003], // Complete Crystalbind abnormality (12h, 1h, elite)
  9. RANDOM_MIN_MAX = [600000, 1500000], // Random Nostrum reapplication time (10 - 25 minutes)
  10. RANDOM_SHORT = [4000, 8000] // Random Nostrum reapplication time after loading (4 - 8 seconds)
  11. module.exports = function Essentials(mod) {
  12. const ELITE = mod.settings.elite,
  13. ITEM_PLEB_NOSTRUM = mod.settings.nostrum,
  14. ITEM_CCB = mod.settings.ccb
  15. mod.game.initialize("contract")
  16. let slot = null,
  17. timeoutNostrum = null,
  18. timeoutCCB = null,
  19. cooldown = 0,
  20. nextUse = 0,
  21. hasccb = false,
  22. enabled = true,
  23. iAmInvincible = false
  24. // ############# //
  25. // ### Hooks ### //
  26. // ############# //
  27. mod.game.on('enter_game', () => {
  28. hasccb = false
  29. mod.hookOnce('C_PLAYER_LOCATION', 'raw', () => {
  30. nextUse = Date.now() + randomNumber(RANDOM_SHORT)
  31. setTimeout(ccb, randomNumber(RANDOM_SHORT)) // check if you have a CCB shortly after moving for the first time
  32. })
  33. })
  34. mod.game.on('leave_loading_screen', () => {
  35. mod.hookOnce('C_PLAYER_LOCATION', 'raw', () => { nostrum() })
  36. })
  37. mod.game.me.on('die', () => {
  38. nextUse = 0
  39. nostrum()
  40. })
  41. mod.game.me.on('resurrect', () => { nostrum() })
  42. mod.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  43. for(let item of event.inventory)
  44. if(ITEMS_NOSTRUM.includes(item.item)) {
  45. slot = item.slot
  46. if(item.cooldown) cooldown = Date.now() + item.cooldown
  47. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  48. return true
  49. }
  50. })
  51. mod.hook('S_ABNORMALITY_BEGIN', 2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  52. mod.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  53. mod.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  54. // ################# //
  55. // ### Functions ### //
  56. // ################# //
  57. function abnormality(type, event) {
  58. if(mod.game.me.is(event.target)) {
  59. if(BUFF_NOSTRUM_TD.includes(event.id) || BUFF_NOSTRUM_H.includes(event.id)) {
  60. if(type === 'S_ABNORMALITY_END') {
  61. nextUse = 0
  62. nostrum()
  63. }
  64. }
  65. else if(BUFF_CCB.includes(event.id)) {
  66. hasccb = type !== 'S_ABNORMALITY_END'
  67. if(!hasccb) ccb()
  68. }
  69. else if(BUFF_INVINCIBILITY.includes(event.id)) {
  70. iAmInvincible = type !== 'S_ABNORMALITY_END'
  71. if(!iAmInvincible) {
  72. nextUse = 0
  73. nostrum()
  74. }
  75. }
  76. }
  77. }
  78. function nostrum() {
  79. clearTimeout(timeoutNostrum)
  80. if(mod.game.isIngame && mod.game.me.alive && !mod.game.isInLoadingScreen && !mod.game.me.mounted && !mod.game.contract.active && !mod.game.me.inBattleground && (slot || !ELITE) && !iAmInvincible)
  81. timeoutNostrum = setTimeout(useNostrum, nextUse - Date.now())
  82. }
  83. function ccb() {
  84. clearTimeout(timeoutCCB)
  85. if(!hasccb && mod.game.isIngame && mod.game.me.alive && !mod.game.isInLoadingScreen && !mod.game.me.mounted && !mod.game.contract.active && !mod.game.me.inBattleground) useItem(ITEM_CCB)
  86. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if we were busy
  87. }
  88. function useNostrum() {
  89. let time = Date.now()
  90. if(time >= cooldown) {
  91. if(enabled) {
  92. if(ELITE) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  93. else useItem(ITEM_PLEB_NOSTRUM)
  94. }
  95. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  96. nostrum()
  97. }
  98. else timeoutNostrum = setTimeout(useNostrum, cooldown - time)
  99. }
  100. function useItem(item) {
  101. if(!enabled) return
  102. mod.toServer('C_USE_ITEM', 3, {
  103. gameId: mod.game.me.gameId,
  104. id: item,
  105. dbid: 0,
  106. target: 0,
  107. amount: 1,
  108. dest: {x: 0, y: 0, z: 0},
  109. loc: {x: 0, y: 0, z: 0},
  110. w: 0,
  111. unk1: 0,
  112. unk2: 0,
  113. unk3: 0,
  114. unk4: 1
  115. })
  116. }
  117. function randomNumber([min, max]) {
  118. return Math.floor(Math.random() * (max - min + 1) + min)
  119. }
  120. // ################ //
  121. // ### Commands ### //
  122. // ################ //
  123. mod.command.add('essentials', () => {
  124. enabled = !enabled
  125. mod.command.message((enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  126. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  127. })
  128. }