index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Version 1.3.6
  2. // Based on 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. Config = require('./config_1-3-6')
  7. const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 855604], // EU, NA, RU, TW, ?, ?, ?, TH
  8. ELITE = Config.elite,
  9. ITEM_PLEB_NOSTRUM = Config.nostrum,
  10. ITEM_CCB = Config.ccb,
  11. BUFF_INVINCIBILITY = [1134, 6007], // Invincibility abnormality (Goddess Blessing, Phoenix)
  12. BUFF_NOSTRUM_TD = [4020, 4030], // Nostrum abnormality for Tanks and Damage Dealers (pleb, elite)
  13. BUFF_NOSTRUM_H = [4021, 4031], // Nostrum abnormality for Healers (pleb, elite)
  14. BUFF_CCB = [4610, 4612, 5020003], // Complete Crystalbind abnormality (12h, 1h, elite)
  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. game.initialize("contract")
  21. let slot = null,
  22. timeoutNostrum = null,
  23. timeoutCCB = null,
  24. cooldown = 0,
  25. nextUse = 0,
  26. hasccb = false,
  27. enabled = true,
  28. iAmInvincible = false
  29. // ############# //
  30. // ### Hooks ### //
  31. // ############# //
  32. game.on('enter_game', () => {
  33. hasccb = false
  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_loading_screen', () => {
  40. dispatch.hookOnce('C_PLAYER_LOCATION', 'raw', () => { nostrum() })
  41. })
  42. game.me.on('die', () => {
  43. nextUse = 0
  44. nostrum()
  45. })
  46. game.me.on('resurrect', () => { nostrum() })
  47. dispatch.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
  48. for(let item of event.inventory)
  49. if(ITEMS_NOSTRUM.includes(item.item)) {
  50. slot = item.slot
  51. if(item.cooldown) cooldown = Date.now() + item.cooldown
  52. item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
  53. return true
  54. }
  55. })
  56. dispatch.hook('S_ABNORMALITY_BEGIN', 2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
  57. dispatch.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
  58. dispatch.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
  59. // ################# //
  60. // ### Functions ### //
  61. // ################# //
  62. function abnormality(type, event) {
  63. if(game.me.is(event.target)) {
  64. if(BUFF_NOSTRUM_TD.includes(event.id) || BUFF_NOSTRUM_H.includes(event.id)) {
  65. if(type === 'S_ABNORMALITY_END') {
  66. nextUse = 0
  67. nostrum()
  68. }
  69. }
  70. else if(BUFF_CCB.includes(event.id)) {
  71. hasccb = type !== 'S_ABNORMALITY_END'
  72. if(!hasccb) ccb()
  73. }
  74. else if(BUFF_INVINCIBILITY.includes(event.id)) {
  75. iAmInvincible = type !== 'S_ABNORMALITY_END'
  76. if(!iAmInvincible) {
  77. nextUse = 0
  78. nostrum()
  79. }
  80. }
  81. }
  82. }
  83. function nostrum() {
  84. clearTimeout(timeoutNostrum)
  85. if(game.isIngame && game.me.alive && !game.isInLoadingScreen && !game.me.mounted && !game.contract.active && !game.me.inBattleground && slot && !iAmInvincible)
  86. timeoutNostrum = setTimeout(useNostrum, nextUse - Date.now())
  87. }
  88. function ccb() {
  89. clearTimeout(timeoutCCB)
  90. if(!hasccb && game.isIngame && game.me.alive && !game.isInLoadingScreen && !game.me.mounted && !game.contract.active && !game.me.inBattleground) useItem(ITEM_CCB)
  91. else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if we were busy
  92. }
  93. function useNostrum() {
  94. let time = Date.now()
  95. if(time >= cooldown) {
  96. if(enabled) {
  97. if(ELITE) dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
  98. else useItem(ITEM_PLEB_NOSTRUM)
  99. }
  100. nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
  101. nostrum()
  102. }
  103. else timeoutNostrum = setTimeout(useNostrum, cooldown - time)
  104. }
  105. function useItem(item) {
  106. if(!enabled) return
  107. dispatch.toServer('C_USE_ITEM', 3, {
  108. gameId: game.me.gameId,
  109. id: item,
  110. dbid: 0,
  111. target: 0,
  112. amount: 1,
  113. dest: {x: 0, y: 0, z: 0},
  114. loc: {x: 0, y: 0, z: 0},
  115. w: 0,
  116. unk1: 0,
  117. unk2: 0,
  118. unk3: 0,
  119. unk4: 1
  120. })
  121. }
  122. function randomNumber([min, max]) {
  123. return Math.floor(Math.random() * (max - min + 1) + min)
  124. }
  125. // ################ //
  126. // ### Commands ### //
  127. // ################ //
  128. command.add('essentials', () => {
  129. enabled = !enabled
  130. command.message('[Essentials] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
  131. console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
  132. })
  133. }