index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. BUFF_GODDESS = 1134
  9. module.exports = function Essentials(dispatch) {
  10. let cid = null,
  11. player = '',
  12. slot = -1,
  13. timeout = null,
  14. timeoutCCB = null,
  15. cooldown = 0,
  16. nextUse = 0,
  17. bgZone = -1,
  18. alive = false,
  19. mounted = false,
  20. inContract = false,
  21. inBG = false,
  22. hasccb = false,
  23. enabled = true
  24. dispatch.hook('S_LOGIN', 1, event => {
  25. ({cid} = event)
  26. player = event.name
  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', 1, 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. }, 1900)
  58. if(!alive) {
  59. nextUse = 0
  60. mounted = inContract = false
  61. }
  62. }
  63. })
  64. dispatch.hook('C_USE_ITEM', (event) => {
  65. if(event.item == 200529 || event.item == 60260 || event.item == 160322)
  66. nostrum(true)
  67. })
  68. dispatch.hook('S_MOUNT_VEHICLE', 1, mount.bind(null, true))
  69. dispatch.hook('S_UNMOUNT_VEHICLE', 1, 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)) {
  82. if (type == 'S_ABNORMALITY_BEGIN') {
  83. hasccb = true
  84. }
  85. else if (type == 'S_ABNORMALITY_END') {
  86. hasccb = false
  87. ccb()
  88. }
  89. }
  90. if(event.target.equals(cid) && (event.id == BUFF_GODDESS)) {
  91. if(type == 'S_ABNORMALITY_BEGIN') {
  92. nostrum(true)
  93. }
  94. else if (type == 'S_ABNORMALITY_END') {
  95. nostrum()
  96. }
  97. }
  98. }
  99. function mount(enter, event) {
  100. if(event.target.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) {
  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. if(!enabled) return
  118. let time = Date.now()
  119. if(time >= cooldown) {
  120. dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  121. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  122. nostrum()
  123. }
  124. else timeout = setTimeout(useNostrum, cooldown - time)
  125. }
  126. function useCCB() {
  127. if(!enabled) return
  128. dispatch.toServer('C_USE_ITEM', 1, {
  129. ownerId: cid,
  130. item: 70000,
  131. id: 0,
  132. unk1: 0,
  133. unk2: 0,
  134. unk3: 0,
  135. unk4: 1,
  136. unk5: 0,
  137. unk6: 0,
  138. unk7: 0,
  139. x: 0,
  140. y: 0,
  141. z: 0,
  142. w: 0,
  143. unk8: 0,
  144. unk9: 0,
  145. unk10: 0,
  146. unk11: 1
  147. })
  148. }
  149. function randomNumber([min, max]) {
  150. return Math.floor(Math.random() * (max - min + 1) + min)
  151. }
  152. // ################# //
  153. // ### Chat Hook ### //
  154. // ################# //
  155. dispatch.hook('C_WHISPER', 1, (event) => {
  156. if(event.target.toUpperCase() === "!essentials".toUpperCase()) {
  157. if (/^<FONT>on?<\/FONT>$/i.test(event.message)) {
  158. enabled = true
  159. message('Essentials <font color="#56B4E9">enabled</font>.')
  160. }
  161. else if (/^<FONT>off?<\/FONT>$/i.test(event.message)) {
  162. enabled = false
  163. message('Essentials <font color="#E69F00">disabled</font>.')
  164. }
  165. else message('Commands:<br>'
  166. + ' "on" (enable Essentials),<br>'
  167. + ' "off" (disable Essentials)'
  168. )
  169. return false
  170. }
  171. })
  172. function message(msg) {
  173. dispatch.toClient('S_WHISPER', 1, {
  174. player: cid,
  175. unk1: 0,
  176. gm: 0,
  177. unk2: 0,
  178. author: '!Essentials',
  179. recipient: player,
  180. message: msg
  181. })
  182. }
  183. dispatch.hook('C_CHAT', 1, event => {
  184. if(/^<FONT>!essentials<\/FONT>$/i.test(event.message)) {
  185. if(!enabled) {
  186. enabled = true
  187. message('Essentials <font color="#56B4E9">enabled</font>.')
  188. console.log('Essentials enabled.')
  189. }
  190. else {
  191. enabled = false
  192. message('Essentials <font color="#E69F00">disabled</font>.')
  193. console.log('Essentials disabled.')
  194. }
  195. return false
  196. }
  197. })
  198. }