index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Version 1.3.10
  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_game', () => {
  35. if (timeoutNostrum) {
  36. clearInterval(timeoutNostrum)
  37. timeoutNostrum = null
  38. }
  39. if (timeoutCCB) {
  40. clearInterval(timeoutCCB)
  41. timeoutCCB = null
  42. }
  43. })
  44. mod.game.on('leave_loading_screen', () => {
  45. mod.hookOnce('C_PLAYER_LOCATION', 'raw', () => { nostrum() })
  46. })
  47. mod.game.me.on('die', () => {
  48. nextUse = 0
  49. nostrum()
  50. })
  51. mod.game.me.on('resurrect', () => { nostrum() })
  52. mod.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  53. for(let item of event.inventory)
  54. if(ITEMS_NOSTRUM.includes(item.item)) {
  55. slot = item.slot
  56. if(item.cooldown) cooldown = Date.now() + item.cooldown
  57. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  58. return true
  59. }
  60. })
  61. mod.hook('S_ABNORMALITY_BEGIN', mod.base.majorPatchVersion >= 75 ? 3:2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  62. mod.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  63. mod.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  64. // ################# //
  65. // ### Functions ### //
  66. // ################# //
  67. function abnormality(type, event) {
  68. if(mod.game.me.is(event.target)) {
  69. if(BUFF_NOSTRUM_TD.includes(event.id) || BUFF_NOSTRUM_H.includes(event.id)) {
  70. if(type === 'S_ABNORMALITY_END') {
  71. nextUse = 0
  72. nostrum()
  73. }
  74. }
  75. else if(BUFF_CCB.includes(event.id)) {
  76. hasccb = type !== 'S_ABNORMALITY_END'
  77. if(!hasccb) ccb()
  78. }
  79. else if(BUFF_INVINCIBILITY.includes(event.id)) {
  80. iAmInvincible = type !== 'S_ABNORMALITY_END'
  81. if(!iAmInvincible) {
  82. nextUse = 0
  83. nostrum()
  84. }
  85. }
  86. }
  87. }
  88. function nostrum() {
  89. clearTimeout(timeoutNostrum)
  90. 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)
  91. timeoutNostrum = setTimeout(useNostrum, nextUse - Date.now())
  92. }
  93. function ccb() {
  94. clearTimeout(timeoutCCB)
  95. 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)
  96. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if we were busy
  97. }
  98. function useNostrum() {
  99. let time = Date.now()
  100. if(time >= cooldown) {
  101. if(enabled) {
  102. if(ELITE) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  103. else useItem(ITEM_PLEB_NOSTRUM)
  104. }
  105. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  106. nostrum()
  107. }
  108. else timeoutNostrum = setTimeout(useNostrum, cooldown - time)
  109. }
  110. function useItem(item) {
  111. if(!enabled) return
  112. mod.toServer('C_USE_ITEM', 3, {
  113. gameId: mod.game.me.gameId,
  114. id: item,
  115. dbid: 0,
  116. target: 0,
  117. amount: 1,
  118. dest: {x: 0, y: 0, z: 0},
  119. loc: {x: 0, y: 0, z: 0},
  120. w: 0,
  121. unk1: 0,
  122. unk2: 0,
  123. unk3: 0,
  124. unk4: 1
  125. })
  126. }
  127. function randomNumber([min, max]) {
  128. return Math.floor(Math.random() * (max - min + 1) + min)
  129. }
  130. // ################ //
  131. // ### Commands ### //
  132. // ################ //
  133. mod.command.add('essentials', () => {
  134. enabled = !enabled
  135. mod.command.message((enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  136. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  137. })
  138. }