index.js 5.4 KB

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