index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Version 1.3.0
  2. // Contains code from true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
  3. const Command = require('command')
  4. const ITEMS_NOSTRUM = [152898, 184659, 201005], // EU 152898, NA 184659, RU 201005
  5. BUFF_BLESSING = 1134,
  6. BUFF_NOSTRUM_TD = 4030, // Nostrum abnormality for Tanks and Damage Dealers
  7. BUFF_NOSTRUM_H = 4031, // Nostrum abnormality for Healers
  8. BUFF_CCB = 4610, // Complete Crystalbind abnormality
  9. BUFF_ConCB = 5020003, // Continuous Crystalbind abnormality
  10. RANDOM_MIN_MAX = [600000, 1500000], // Random Nostrum reapplication time (10 - 25 minutes)
  11. RANDOM_SHORT = [4000, 8000] // Random Nostrum reapplication time after loading (4 - 8 seconds)
  12. module.exports = function Essentials(dispatch) {
  13. let cid = null,
  14. slot = -1,
  15. timeout = null,
  16. timeoutCCB = null,
  17. cooldown = 0,
  18. nextUse = 0,
  19. bgZone = -1,
  20. alive = false,
  21. mounted = false,
  22. inContract = false,
  23. inBG = false,
  24. hasccb = false,
  25. enabled = true,
  26. iAmBlessed = false
  27. dispatch.hook('S_LOGIN', 1, event => {
  28. ({cid} = event)
  29. dispatch.hookOnce('C_PLAYER_LOCATION', 1, () => {
  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. dispatch.hook('S_RETURN_TO_LOBBY', 1, event => { nostrum(true) })
  35. dispatch.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  36. for(let item of event.inventory)
  37. if(ITEMS_NOSTRUM.includes(item.item)) {
  38. slot = item.slot
  39. if(item.cooldown) cooldown = Date.now() + item.cooldown
  40. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  41. return true
  42. }
  43. })
  44. dispatch.hook('S_ABNORMALITY_BEGIN', 2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  45. dispatch.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  46. dispatch.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  47. dispatch.hook('S_BATTLE_FIELD_ENTRANCE_INFO', 1, event => { bgZone = event.zone })
  48. dispatch.hook('S_LOAD_TOPO', 1, event => {
  49. nextUse = Date.now() + randomNumber(RANDOM_SHORT)
  50. mounted = inContract = false
  51. inBG = event.zone == bgZone
  52. nostrum(true)
  53. })
  54. dispatch.hook('S_SPAWN_ME', 1, event => {
  55. dispatch.hookOnce('C_PLAYER_LOCATION', 1, () => {
  56. nostrum(!(alive = event.alive))
  57. })
  58. })
  59. dispatch.hook('S_CREATURE_LIFE', 1, event => {
  60. if(event.target.equals(cid) && alive != event.alive) {
  61. setTimeout(() => {
  62. nostrum(!(alive = event.alive))
  63. }, 2000)
  64. if(!alive) {
  65. nextUse = 0
  66. mounted = inContract = false
  67. }
  68. }
  69. })
  70. dispatch.hook('S_MOUNT_VEHICLE', 1, mount.bind(null, true))
  71. dispatch.hook('S_UNMOUNT_VEHICLE', 1, mount.bind(null, false))
  72. dispatch.hook('S_REQUEST_CONTRACT', 1, contract.bind(null, true))
  73. dispatch.hook('S_ACCEPT_CONTRACT', 1, contract.bind(null, false))
  74. dispatch.hook('S_REJECT_CONTRACT', 1, contract.bind(null, false))
  75. dispatch.hook('S_CANCEL_CONTRACT', 1, contract.bind(null, false))
  76. function abnormality(type, event) {
  77. if(event.target.equals(cid) && (event.id == BUFF_NOSTRUM_TD || event.id == BUFF_NOSTRUM_H)) {
  78. if (type == 'S_ABNORMALITY_END') {
  79. nextUse = 0
  80. nostrum()
  81. }
  82. }
  83. if(event.target.equals(cid) && (event.id == BUFF_CCB || event.id == BUFF_ConCB)) {
  84. if (type == 'S_ABNORMALITY_END') {
  85. hasccb = false
  86. ccb()
  87. }
  88. else hasccb = true
  89. }
  90. if(event.target.equals(cid) && (event.id == BUFF_BLESSING)) {
  91. if (type == 'S_ABNORMALITY_END') {
  92. iAmBlessed = false
  93. nextUse = 0
  94. nostrum()
  95. }
  96. else {
  97. iAmBlessed = true
  98. }
  99. }
  100. }
  101. function mount(enter, event) {
  102. if(event.target.equals(cid)) nostrum(mounted = enter)
  103. }
  104. function contract(enter) {
  105. nostrum(inContract = enter)
  106. }
  107. function nostrum(disable) {
  108. clearTimeout(timeout)
  109. if(!disable && alive && !mounted && !inContract && !inBG && slot != -1 && !iAmBlessed) {
  110. timeout = setTimeout(useNostrum, nextUse - Date.now())
  111. }
  112. }
  113. function ccb() {
  114. clearTimeout(timeoutCCB)
  115. if(!hasccb && alive && !mounted && !inContract && !inBG) useCCB()
  116. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if you were busy
  117. }
  118. function useNostrum() {
  119. let time = Date.now()
  120. if(time >= cooldown) {
  121. if(enabled) dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  122. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  123. nostrum()
  124. }
  125. else timeout = setTimeout(useNostrum, cooldown - time)
  126. }
  127. function useCCB() {
  128. if(!enabled) return
  129. dispatch.toServer('C_USE_ITEM', 1, {
  130. ownerId: cid,
  131. item: 70000,
  132. id: 0,
  133. unk1: 0,
  134. unk2: 0,
  135. unk3: 0,
  136. unk4: 1,
  137. unk5: 0,
  138. unk6: 0,
  139. unk7: 0,
  140. x: 0,
  141. y: 0,
  142. z: 0,
  143. w: 0,
  144. unk8: 0,
  145. unk9: 0,
  146. unk10: 0,
  147. unk11: 1
  148. })
  149. }
  150. function randomNumber([min, max]) {
  151. return Math.floor(Math.random() * (max - min + 1) + min)
  152. }
  153. // ################# //
  154. // ### Chat Hook ### //
  155. // ################# //
  156. const command = Command(dispatch)
  157. command.add('essentials', () => {
  158. enabled = !enabled
  159. command.message('[Essentials] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  160. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  161. })
  162. }