index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // Version 1.3.3
  2. // Contains code from true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
  3. 'use strict'
  4. const Command = require('command'),
  5. GameState = require('tera-game-state')
  6. const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 855604], // EU, NA, RU, TW, ?, ?, ?, TH
  7. ITEM_CCB = 70000,
  8. BUFF_BLESSING = 1134,
  9. BUFF_NOSTRUM_TD = 4030, // Nostrum abnormality for Tanks and Damage Dealers
  10. BUFF_NOSTRUM_H = 4031, // Nostrum abnormality for Healers
  11. BUFF_CCB = 4610, // Complete Crystalbind abnormality
  12. BUFF_ConCB = 5020003, // Continuous Crystalbind abnormality
  13. RANDOM_MIN_MAX = [600000, 1500000], // Random Nostrum reapplication time (10 - 25 minutes)
  14. RANDOM_SHORT = [4000, 8000] // Random Nostrum reapplication time after loading (4 - 8 seconds)
  15. module.exports = function Essentials(dispatch) {
  16. const command = Command(dispatch),
  17. game = GameState(dispatch)
  18. let gameId = null,
  19. slot = -1,
  20. timeout = null,
  21. timeoutCCB = null,
  22. cooldown = 0,
  23. nextUse = 0,
  24. bgZone = -1,
  25. alive = false,
  26. mounted = false,
  27. inContract = false,
  28. inBG = false,
  29. hasccb = false,
  30. enabled = true,
  31. iAmBlessed = false
  32. // ############# //
  33. // ### Hooks ### //
  34. // ############# //
  35. game.on('enter_game', () => {
  36. gameId = game.me.gameId
  37. dispatch.hookOnce('C_PLAYER_LOCATION', 'raw', () => {
  38. nextUse = Date.now() + randomNumber(RANDOM_SHORT)
  39. setTimeout(ccb, randomNumber(RANDOM_SHORT)) // check if you have a CCB shortly after moving for the first time
  40. })
  41. })
  42. game.on('enter_character_lobby', () => { nostrum(true) })
  43. game.on('enter_loading_screen', () => {
  44. mounted = inContract = false
  45. inBG = game.me.zone == bgZone
  46. nostrum(true)
  47. })
  48. game.on('leave_loading_screen', () => {
  49. dispatch.hookOnce('C_PLAYER_LOCATION', 'raw', () => {
  50. nostrum(!(alive = game.me.alive))
  51. })
  52. })
  53. dispatch.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  54. for(let item of event.inventory)
  55. if(ITEMS_NOSTRUM.includes(item.item)) {
  56. slot = item.slot
  57. if(item.cooldown) cooldown = Date.now() + item.cooldown
  58. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  59. return true
  60. }
  61. })
  62. dispatch.hook('S_ABNORMALITY_BEGIN', 2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  63. dispatch.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  64. dispatch.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  65. dispatch.hook('S_BATTLE_FIELD_ENTRANCE_INFO', 1, event => { bgZone = event.zone })
  66. dispatch.hook('S_CREATURE_LIFE', 2, event => {
  67. if(game.me.is(event.gameId) && alive != event.alive) {
  68. nostrum(!(alive = event.alive))
  69. if(!alive) {
  70. nextUse = 0
  71. mounted = inContract = false
  72. }
  73. }
  74. })
  75. dispatch.hook('S_MOUNT_VEHICLE', 2, mount.bind(null, true))
  76. dispatch.hook('S_UNMOUNT_VEHICLE', 2, mount.bind(null, false))
  77. dispatch.hook('S_REQUEST_CONTRACT', 1, contract.bind(null, true))
  78. dispatch.hook('S_ACCEPT_CONTRACT', 1, contract.bind(null, false))
  79. dispatch.hook('S_REJECT_CONTRACT', 1, contract.bind(null, false))
  80. dispatch.hook('S_CANCEL_CONTRACT', 1, contract.bind(null, false))
  81. // ################# //
  82. // ### Functions ### //
  83. // ################# //
  84. function abnormality(type, event) {
  85. if(game.me.is(event.target) && (event.id == BUFF_NOSTRUM_TD || event.id == BUFF_NOSTRUM_H)) {
  86. if (type == 'S_ABNORMALITY_END') {
  87. nextUse = 0
  88. nostrum()
  89. }
  90. }
  91. if(game.me.is(event.target) && (event.id == BUFF_CCB || event.id == BUFF_ConCB)) {
  92. if (type == 'S_ABNORMALITY_END') {
  93. hasccb = false
  94. ccb()
  95. }
  96. else hasccb = true
  97. }
  98. if(game.me.is(event.target) && event.id == BUFF_BLESSING) {
  99. if (type == 'S_ABNORMALITY_END') {
  100. iAmBlessed = false
  101. nextUse = 0
  102. nostrum()
  103. }
  104. else iAmBlessed = true
  105. }
  106. }
  107. function mount(enter, event) {
  108. if(game.me.is(event.gameId)) nostrum(mounted = enter)
  109. }
  110. function contract(enter) {
  111. nostrum(inContract = enter)
  112. }
  113. function nostrum(disable) {
  114. clearTimeout(timeout)
  115. if(!disable && alive && !mounted && !inContract && !inBG && slot != -1 && !iAmBlessed)
  116. timeout = setTimeout(useNostrum, nextUse - Date.now())
  117. }
  118. function ccb() {
  119. clearTimeout(timeoutCCB)
  120. if(!hasccb && alive && !mounted && !inContract && !inBG) useItem(ITEM_CCB)
  121. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if you were busy
  122. }
  123. function useNostrum() {
  124. let time = Date.now()
  125. if(time >= cooldown) {
  126. if(enabled) dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  127. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  128. nostrum()
  129. }
  130. else timeout = setTimeout(useNostrum, cooldown - time)
  131. }
  132. function useItem(item) {
  133. if(!enabled) return
  134. dispatch.toServer('C_USE_ITEM', 2, {
  135. ownerId: gameId,
  136. id: item,
  137. uniqueId: 0,
  138. targetId: 0,
  139. amount: 1,
  140. targetX: 0,
  141. targetY: 0,
  142. targetZ: 0,
  143. x: 0,
  144. y: 0,
  145. z: 0,
  146. w: 0,
  147. unk1: 0,
  148. unk2: 0,
  149. unk3: 0,
  150. unk4: 1
  151. })
  152. }
  153. function randomNumber([min, max]) {
  154. return Math.floor(Math.random() * (max - min + 1) + min)
  155. }
  156. // ################ //
  157. // ### Commands ### //
  158. // ################ //
  159. command.add('essentials', () => {
  160. enabled = !enabled
  161. command.message('[Essentials] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  162. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  163. })
  164. }