index.js 4.6 KB

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