index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // Version 1.3.2
  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', 10, event => {
  28. cid = event.gameId
  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', 'raw', () => { 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', 3, 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', 2, event => {
  55. dispatch.hookOnce('C_PLAYER_LOCATION', 'raw', () => {
  56. nostrum(!(alive = event.alive))
  57. })
  58. })
  59. dispatch.hook('S_CREATURE_LIFE', 2, event => {
  60. if(event.gameId.equals(cid) && alive != event.alive) {
  61. nostrum(!(alive = event.alive))
  62. if(!alive) {
  63. nextUse = 0
  64. mounted = inContract = false
  65. }
  66. }
  67. })
  68. dispatch.hook('S_MOUNT_VEHICLE', 2, mount.bind(null, true))
  69. dispatch.hook('S_UNMOUNT_VEHICLE', 2, mount.bind(null, false))
  70. dispatch.hook('S_REQUEST_CONTRACT', 1, contract.bind(null, true))
  71. dispatch.hook('S_ACCEPT_CONTRACT', 1, contract.bind(null, false))
  72. dispatch.hook('S_REJECT_CONTRACT', 1, contract.bind(null, false))
  73. dispatch.hook('S_CANCEL_CONTRACT', 1, contract.bind(null, false))
  74. function abnormality(type, event) {
  75. if(event.target.equals(cid) && (event.id == BUFF_NOSTRUM_TD || event.id == BUFF_NOSTRUM_H)) {
  76. if (type == 'S_ABNORMALITY_END') {
  77. nextUse = 0
  78. nostrum()
  79. }
  80. }
  81. if(event.target.equals(cid) && (event.id == BUFF_CCB || event.id == BUFF_ConCB)) {
  82. if (type == 'S_ABNORMALITY_END') {
  83. hasccb = false
  84. ccb()
  85. }
  86. else hasccb = true
  87. }
  88. if(event.target.equals(cid) && (event.id == BUFF_BLESSING)) {
  89. if (type == 'S_ABNORMALITY_END') {
  90. iAmBlessed = false
  91. nextUse = 0
  92. nostrum()
  93. }
  94. else {
  95. iAmBlessed = true
  96. }
  97. }
  98. }
  99. function mount(enter, event) {
  100. if(event.gameId.equals(cid)) nostrum(mounted = enter)
  101. }
  102. function contract(enter) {
  103. nostrum(inContract = enter)
  104. }
  105. function nostrum(disable) {
  106. clearTimeout(timeout)
  107. if(!disable && alive && !mounted && !inContract && !inBG && slot != -1 && !iAmBlessed) {
  108. timeout = setTimeout(useNostrum, nextUse - Date.now())
  109. }
  110. }
  111. function ccb() {
  112. clearTimeout(timeoutCCB)
  113. if(!hasccb && alive && !mounted && !inContract && !inBG) useCCB()
  114. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if you were busy
  115. }
  116. function useNostrum() {
  117. let time = Date.now()
  118. if(time >= cooldown) {
  119. if(enabled) dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  120. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  121. nostrum()
  122. }
  123. else timeout = setTimeout(useNostrum, cooldown - time)
  124. }
  125. function useCCB() {
  126. if(!enabled) return
  127. dispatch.toServer('C_USE_ITEM', 2, {
  128. ownerId: cid,
  129. id: 70000,
  130. uniqueId: 0,
  131. targetId: 0,
  132. amount: 1,
  133. targetX: 0,
  134. targetY: 0,
  135. targetZ: 0,
  136. x: 0,
  137. y: 0,
  138. z: 0,
  139. w: 0,
  140. unk1: 0,
  141. unk2: 0,
  142. unk3: 0,
  143. unk4: 1
  144. })
  145. }
  146. function randomNumber([min, max]) {
  147. return Math.floor(Math.random() * (max - min + 1) + min)
  148. }
  149. // ################# //
  150. // ### Chat Hook ### //
  151. // ################# //
  152. const command = Command(dispatch)
  153. command.add('essentials', () => {
  154. enabled = !enabled
  155. command.message('[Essentials] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  156. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  157. })
  158. }