index.js 5.0 KB

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