index.js 5.1 KB

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