index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // based on true-everful-nostrum by https://github.com/pinkipi
  2. const HIDE_DURATION = false,
  3. HIDE_MESSAGE = false
  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. const sysmsg = require('tera-data-parser').sysmsg
  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 = 0
  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. if(HIDE_MESSAGE)
  32. dispatch.hook('S_SYSTEM_MESSAGE', 1, event => {
  33. let msg = event.message.split('\x0b'),
  34. type = msg[0].startsWith('@') ? sysmsg.map.code[msg[0].slice(1)] : ''
  35. if(type == 'SMT_ITEM_USED' || type == 'SMT_CANT_USE_ITEM_COOLTIME') {
  36. let obj = {}
  37. for(let i = 2; i < msg.length; i += 2) obj[msg[i - 1]] = msg[i]
  38. for(let item of ITEMS_NOSTRUM)
  39. if(obj.ItemName == '@item:' + item) return false
  40. }
  41. })
  42. dispatch.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  43. for(let item of event.inventory)
  44. if(ITEMS_NOSTRUM.includes(item.item)) {
  45. slot = item.slot
  46. if(item.cooldown) cooldown = Date.now() + item.cooldown
  47. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  48. return true
  49. }
  50. })
  51. dispatch.hook('S_ABNORMALITY_BEGIN', 1, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  52. dispatch.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  53. dispatch.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  54. dispatch.hook('S_BATTLE_FIELD_ENTRANCE_INFO', 1, event => { bgZone = event.zone })
  55. dispatch.hook('S_LOAD_TOPO', 1, event => {
  56. nextUse = 0
  57. mounted = inContract = false
  58. inBG = event.zone == bgZone
  59. nostrum(true)
  60. })
  61. dispatch.hook('S_SPAWN_ME', 1, event => { nostrum(!(alive = event.alive)) })
  62. dispatch.hook('S_CREATURE_LIFE', 1, event => {
  63. if(event.target.equals(cid) && alive != event.alive) {
  64. nostrum(!(alive = event.alive))
  65. if(!alive) {
  66. nextUse = 0
  67. mounted = inContract = false
  68. }
  69. }
  70. })
  71. dispatch.hook('S_MOUNT_VEHICLE', 1, mount.bind(null, true))
  72. dispatch.hook('S_UNMOUNT_VEHICLE', 1, mount.bind(null, false))
  73. dispatch.hook('S_REQUEST_CONTRACT', 1, contract.bind(null, true))
  74. dispatch.hook('S_ACCEPT_CONTRACT', 1, contract.bind(null, false))
  75. dispatch.hook('S_REJECT_CONTRACT', 1, contract.bind(null, false))
  76. dispatch.hook('S_CANCEL_CONTRACT', 1, contract.bind(null, false))
  77. function abnormality(type, event) {
  78. if(event.target.equals(cid) && (event.id == BUFF_NOSTRUM_TD || event.id == BUFF_NOSTRUM_H)) {
  79. nextUse = type == 'S_ABNORMALITY_END' ? 0 : Date.now() + Math.floor(event.duration / 2)
  80. nostrum()
  81. if(HIDE_DURATION) {
  82. if(type == 'S_ABNORMALITY_BEGIN') {
  83. event.duration = 0
  84. return true
  85. }
  86. if(type == 'S_ABNORMALITY_REFRESH') return false
  87. }
  88. }
  89. if(event.target.equals(cid) && (event.id == BUFF_CCB)) {
  90. if (type == 'S_ABNORMALITY_BEGIN') {
  91. hasccb = true
  92. }
  93. if (type == 'S_ABNORMALITY_END') {
  94. hasccb = false
  95. ccb()
  96. }
  97. if(HIDE_DURATION) {
  98. if(type == 'S_ABNORMALITY_BEGIN') {
  99. event.duration = 0
  100. return true
  101. }
  102. if(type == 'S_ABNORMALITY_REFRESH') return false
  103. }
  104. }
  105. }
  106. function mount(enter, event) {
  107. if(event.target.equals(cid)) nostrum(mounted = enter)
  108. }
  109. function contract(enter) {
  110. nostrum(inContract = enter)
  111. }
  112. function nostrum(disable) {
  113. clearTimeout(timeout)
  114. if(!disable && alive && !mounted && !inContract && !inBG && slot != -1) timeout = setTimeout(useNostrum, nextUse - Date.now())
  115. }
  116. function ccb() {
  117. clearTimeout(timeoutCCB)
  118. if(!hasccb && alive && !mounted && !inContract && !inBG) useCCB()
  119. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if you were busy
  120. }
  121. function useNostrum() {
  122. if(!enabled) return
  123. let time = Date.now()
  124. if(time >= cooldown) {
  125. dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  126. nextUse = Date.now() + 1000
  127. nostrum()
  128. }
  129. else timeout = setTimeout(useNostrum, cooldown - time)
  130. }
  131. function useCCB() {
  132. if(!enabled) return
  133. dispatch.toServer('C_USE_ITEM', 1, {
  134. ownerId: cid,
  135. item: 70000,
  136. id: 0,
  137. unk1: 0,
  138. unk2: 0,
  139. unk3: 0,
  140. unk4: 1,
  141. unk5: 0,
  142. unk6: 0,
  143. unk7: 0,
  144. x: 0,
  145. y: 0,
  146. z: 0,
  147. w: 0,
  148. unk8: 0,
  149. unk9: 0,
  150. unk10: 0,
  151. unk11: 1
  152. })
  153. }
  154. // ################# //
  155. // ### Chat Hook ### //
  156. // ################# //
  157. dispatch.hook('C_WHISPER', 1, (event) => {
  158. if(event.target.toUpperCase() === "!essentials".toUpperCase()) {
  159. if (/^<FONT>on?<\/FONT>$/i.test(event.message)) {
  160. enabled = true
  161. message('Essentials <font color="#00EE00">enabled</font>.')
  162. }
  163. else if (/^<FONT>off?<\/FONT>$/i.test(event.message)) {
  164. enabled = false
  165. message('Essentials <font color="#DC143C">disabled</font>.')
  166. }
  167. else message('Commands: "on" (enable Essentials),'
  168. + ' "off" (disable Essentials)'
  169. )
  170. return false
  171. }
  172. })
  173. function message(msg) {
  174. dispatch.toClient('S_WHISPER', 1, {
  175. player: cid,
  176. unk1: 0,
  177. gm: 0,
  178. unk2: 0,
  179. author: '!Essentials',
  180. recipient: player,
  181. message: msg
  182. })
  183. }
  184. }