Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.32 KB | None | 0 0
  1. function MaintainTrackedAuras()
  2. for k, v in pairs(aura_env.cons) do
  3. if aura_env.config.trackedGroup["consTracked"][k] == false then
  4. aura_env.cons[k] = {-1}
  5. end
  6. end
  7.  
  8. for k, v in pairs(aura_env.wbs) do
  9. if aura_env.config.trackedGroup["wbTracked"][k] == false then
  10. aura_env.wbs[k] = {-1}
  11. end
  12. end
  13. end
  14.  
  15. function MaintainCustomOptions()
  16. aura_env.buff_removal = aura_env.config.optionGroup.buffRemoval
  17. aura_env.buffer = aura_env.config.optionGroup.bufferOption
  18. aura_env.blacklist = UpdateBlacklist()
  19. aura_env.dropdown = aura_env.config.optionGroup["isDropdown"]
  20. aura_env.announcerAuto = aura_env.config.optionGroup["announcerAuto"]
  21. aura_env.announcerTracked = aura_env.config.optionGroup["announcerTracked"]
  22. MaintainTrackedAuras()
  23. end
  24.  
  25. function MaintainGlobals()
  26. GetTrackedCons = aura_env.cons
  27. GetTrackedWbs = aura_env.wbs
  28. GetBlacklist = aura_env.blacklist
  29. GetDropdown = aura_env.dropdown
  30. GetAnnounceAuto = aura_env.announcerAuto
  31. GetAnnounceTracked = aura_env.announcerTracked
  32. GetAurasTotal = aura_env.aurasTotal
  33. end
  34.  
  35. function MaintainState()
  36. aura_env.enchantCount = CountEnchants()
  37. aura_env.enchantsPushed = CountEnchantsPushed()
  38. aura_env.buffCount = CountBuffs()
  39. aura_env.aurasTotal = aura_env.enchantCount - aura_env.enchantsPushed + aura_env.buffCount
  40. aura_env.openSlots = 32 - aura_env.aurasTotal
  41. aura_env.buffsMax = 32 - aura_env.enchantCount + aura_env.enchantsPushed
  42. MaintainGlobals()
  43. end
  44.  
  45. function GetItemId(invId)
  46. itemLink = GetInventoryItemLink("player", invId)
  47. if itemLink ~= nil then
  48. local _, _, _, _, itemId, Enchant = string.find(itemLink,
  49. "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*):?(%d*):?(%-?%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
  50. return itemId
  51. end
  52. return -1
  53. end
  54.  
  55. function GetItemEnchant(invId)
  56. itemLink = GetInventoryItemLink("player", invId)
  57. if itemLink ~= nil then
  58. local _, _, _, _, _, Enchant = string.find(itemLink,
  59. "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*):?(%d*):?(%-?%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
  60. return Enchant
  61. end
  62. return -1
  63. end
  64.  
  65. function GetItemEnchantWeapon(invId)
  66. itemLink = GetInventoryItemLink("player", invId)
  67. if itemLink ~= nil then
  68. local hasMainHandEnchant, mainHandExpiration, mainHandCharges, mainHandEnchantID, hasOffHandEnchant, offHandExpiration, offHandCharges, offHandEnchantId = GetWeaponEnchantInfo()
  69. if invId == INVSLOT_MAINHAND then
  70. return mainHandEnchantID
  71. else
  72. return offHandEnchantId
  73. end
  74.  
  75. end
  76. return -1
  77. end
  78.  
  79. function IsEnchanted(itemLink)
  80. local _, _, _, _, itemId, Enchant = string.find(itemLink,
  81. "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*):?(%d*):?(%-?%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
  82. if Enchant == "" then return false else return true end
  83. end
  84.  
  85. function IsEnchantedWeapon(InventorySlotName)
  86. local hasMainHandEnchant, mainHandExpiration, mainHandCharges, mainHandEnchantID, hasOffHandEnchant, offHandExpiration, offHandCharges, offHandEnchantId = GetWeaponEnchantInfo()
  87. if (InventorySlotName == INVSLOT_MAINHAND and tonumber(mainHandEnchantID) == 2506) or (InventorySlotName == INVSLOT_OFFHAND and (tonumber(offHandEnchantId) == 2506 or tonumber(offHandEnchantId) == 1704)) then return true else return false end
  88. end
  89.  
  90. function UpdateBlacklist()
  91. blacklistTable = {}
  92. for k,v in pairs(aura_env.spells) do
  93. if aura_env.config.blacklistGroup["buffsBlacklist"][k] then
  94. blacklistTable[aura_env.spells[k]] = 1
  95. end
  96. end
  97. return blacklistTable
  98. end
  99.  
  100. function GetFirstBuff()
  101. if next(aura_env.buffOrder) ~= nil then
  102. local t = aura_env.buffOrder[1]
  103. return aura_env.buffs[t]
  104. else
  105. return "No buffs"
  106. end
  107. end
  108.  
  109. function AddStance(buffTable)
  110. if UnitClass(UnitName("player")) == "Warrior" then
  111. buffTable[math.huge] = "Stance"
  112. end
  113. end
  114.  
  115. function AddTracking(buffTable)
  116. if GetTrackingTexture() ~= nil then
  117. buffTable[math.huge] = "Tracking"
  118. end
  119. end
  120.  
  121. function AddEnchants(buffTable)
  122. local enchantAdded = 0
  123. local enchantBuffNames = {
  124. [INVSLOT_HEAD] = "Head Enchant",
  125. [INVSLOT_LEGS] = "Legs Enchant",
  126. [INVSLOT_FEET] = "Mithril Spurs",
  127. [INVSLOT_MAINHAND] = "MH Ele",
  128. [INVSLOT_OFFHAND] = "OH Ele/Spike",
  129. }
  130.  
  131. local function AddEnchant(InventorySlotName, buffTable)
  132. local itemLink = GetInventoryItemLink("player", InventorySlotName)
  133. local enchantId = GetItemEnchant(InventorySlotName)
  134.  
  135. if InventorySlotName == INVSLOT_FEET then
  136. if tonumber(enchantId) == 464 then
  137. if itemLink ~= nil then
  138. if IsEnchanted(itemLink) then
  139. enchantAdded = enchantAdded + 1
  140. if enchantAdded <= CountEnchants() - CountEnchantsPushed() then
  141. buffTable[aura_env.items[InventorySlotName][1]] = enchantBuffNames[InventorySlotName]
  142. end
  143. end
  144. end
  145. end
  146. else
  147. if itemLink ~= nil then
  148. if IsEnchanted(itemLink) or IsEnchantedWeapon(InventorySlotName) then
  149. enchantAdded = enchantAdded + 1
  150. if enchantAdded <= CountEnchants() - CountEnchantsPushed() then
  151. buffTable[aura_env.items[InventorySlotName][1]] = enchantBuffNames[InventorySlotName]
  152. end
  153. end
  154. end
  155. end
  156. end
  157.  
  158.  
  159. for k,v in pairs(aura_env.items) do
  160. AddEnchant(k, buffTable)
  161. end
  162.  
  163. end
  164.  
  165. function CreateBuffTable()
  166. local buffTable = {}
  167.  
  168. for i=1,40 do
  169. local name, _, _, _, duration, expirationTime, _, _, _, spellId = UnitBuff("player",i)
  170. if name and duration > 0 then
  171. buffTable[(expirationTime - duration)] = name
  172. end
  173. if name and duration == 0 then
  174. buffTable[GetTime()+spellId] = name
  175. end
  176. end
  177.  
  178. AddStance(buffTable)
  179. AddTracking(buffTable)
  180. AddEnchants(buffTable)
  181.  
  182. return buffTable
  183. end
  184.  
  185. function GetSortedBuffTable(tbl)
  186. local sortedTimeTable = {}
  187.  
  188. for k,v in pairs(tbl) do
  189. if k ~= nil then
  190. table.insert(sortedTimeTable, k)
  191. end
  192. end
  193.  
  194. table.sort(sortedTimeTable)
  195.  
  196. return sortedTimeTable
  197. end
  198.  
  199. function CountEnchants()
  200. local enchants = 0
  201.  
  202. for InventorySlot,v in pairs(aura_env.items) do
  203. local enchantId = GetItemEnchant(InventorySlot)
  204. local itemLink = GetInventoryItemLink("player", InventorySlot)
  205. if itemLink ~= nil then
  206. if tonumber(InventorySlot) == INVSLOT_MAINHAND or tonumber(InventorySlot) == INVSLOT_OFFHAND then
  207. if IsEnchantedWeapon(InventorySlot) then
  208. enchants = enchants + 1
  209. end
  210. else
  211. if IsEnchanted(itemLink) then
  212. if InventorySlot == INVSLOT_FEET then
  213. if tonumber(enchantId) == 464 then
  214. enchants = enchants + 1
  215. end
  216. else
  217. enchants = enchants + 1
  218. end
  219. end
  220. end
  221. end
  222. end
  223.  
  224. return enchants
  225. end
  226.  
  227. function CountBuffs()
  228. local count = 0
  229. if UnitClass(UnitName("player")) == "Warrior" then count = count + 1 end
  230. if GetTrackingTexture() ~= nil then count = count + 1 end
  231.  
  232. for i=1,40 do
  233. local name, icon, _, _, _, etime = UnitBuff("player",i)
  234. if name then
  235. count = count + 1
  236. end
  237. end
  238.  
  239. return count
  240. end
  241.  
  242. function CountEnchantsPushed()
  243. local counter = 32 - (CountBuffs() + CountEnchants())
  244. local enchantsPushed = 0
  245. if counter < 0 then enchantsPushed = abs(counter) end
  246. return enchantsPushed
  247. end
  248.  
  249. function GetBuffIdx(buffName)
  250. for i=1,40 do
  251. local name = UnitBuff("player",i)
  252. if name == buffName then
  253. return i
  254. end
  255. end
  256. return -1
  257. end
  258.  
  259. function GetAuraDur(name, buff)
  260. if buff then
  261. _, _, _, _, _, etime = WA_GetUnitBuff("player", name)
  262. else
  263. _, _, _, _, _, etime = WA_GetUnitDebuff("player", name)
  264. end
  265.  
  266. local timestamp = GetTime()
  267. local tmp = etime or ""
  268.  
  269. if string.len(tmp) > 0 then
  270. secs = etime-timestamp
  271. mins = math.floor(secs/60)
  272.  
  273. if mins == 0 then
  274. time = math.floor(secs) .. " secs"
  275. else
  276. time = mins .. " mins"
  277. end
  278.  
  279. tmp = " (" .. time .. ")"
  280. end
  281.  
  282. return tmp
  283. end
  284.  
  285. function isNextTracked()
  286.  
  287. for k, _ in pairs(aura_env.wbs) do
  288. if aura_env.wbs[k][1] == aura_env.buffNext then
  289. return true
  290. end
  291. end
  292.  
  293. for k, _ in pairs(aura_env.cons) do
  294. if aura_env.cons[k][1] == aura_env.buffNext then
  295. return true
  296. end
  297. end
  298.  
  299. return false
  300. end
  301.  
  302. function GetSuffix (n)
  303. local lastTwo, lastOne = n % 100, n % 10
  304. if lastTwo > 3 and lastTwo < 21 then return "th" end
  305. if lastOne == 1 then return "st" end
  306. if lastOne == 2 then return "nd" end
  307. if lastOne == 3 then return "rd" end
  308. return "th"
  309. end
  310.  
  311. function Nth (n) return n .. GetSuffix(n) end
  312.  
  313. function GetTableEntries(tbl)
  314. local count = 0
  315. for _ in pairs(tbl) do count = count + 1 end
  316. return count
  317. end
  318.  
  319. ---------------------------------- String functions for display
  320. function FindBuff(buffName) -- shitty abstraction
  321.  
  322. local key = 0;
  323. for k,v in pairs(aura_env.buffs) do
  324. if v == buffName then
  325. key = k
  326. end
  327. end
  328.  
  329. if key > 0 then
  330. for k,v in pairs(aura_env.buffOrder) do
  331. if v == key then
  332. if k == 1 then
  333. return ("|cffFF8000" .. Nth(k) .. "|r")
  334. else
  335. return ("|cff00FF00" .. Nth(k) .. "|r")
  336. end
  337. end
  338. end
  339. end
  340.  
  341. if WA_GetUnitDebuff("player", buffName) ~= nil then return ("|cffFF8000DEBUFF|r") end
  342.  
  343. return "|cffFF0000N/A|r"
  344. end
  345.  
  346. function GetBuffNextString()
  347. if isNextTracked() then
  348. return ("|cffFF0000" .. aura_env.buffNext .. "|r"):upper()
  349. else
  350. return ("|cff00FF00" .. aura_env.buffNext .. "|r"):upper()
  351. end
  352. end
  353.  
  354. function GetBuffRemovalString()
  355. if (aura_env.buffsMax - aura_env.buffCount) <= aura_env.buffer and not UnitAffectingCombat("player") and aura_env.config.optionGroup.buffRemoval then
  356. return "|cffFF8000ACTIVE|r"
  357. elseif (aura_env.buffsMax - aura_env.buffCount) == 0 and not UnitAffectingCombat("player") and aura_env.config.optionGroup.buffRemoval then
  358. return "|cffFF0000ACTIVE|r"
  359. else
  360. return "|cff00FF00INACTIVE|r"
  361. end
  362. end
  363.  
  364. function GetBuffCountString()
  365. if (aura_env.buffsMax - aura_env.buffCount) <= aura_env.buffer then
  366. return "|cffFF8000" .. aura_env.buffCount .. "|r"
  367. elseif (aura_env.buffsMax - aura_env.buffCount) == 0 then
  368. return "|cffFF0000" .. aura_env.buffCount .. "|r"
  369. else
  370. return "|cff00FF00" .. aura_env.buffCount .. "|r"
  371. end
  372. end
  373.  
  374. function GetEnchantString()
  375. local activeEnchants = aura_env.enchantCount - aura_env.enchantsPushed
  376. if (activeEnchants) < aura_env.enchantCount then
  377. return "|cffff0000" .. activeEnchants .. "|r"
  378. else
  379. return "|cff00FF00" .. activeEnchants .. "|r"
  380. end
  381. end
  382.  
  383. function BuildTrackedString(tbl)
  384. local tmp = "\n"
  385. for i=1,GetTableEntries(tbl),1 do
  386. local wb = tbl[i]
  387. if wb[1] ~= -1 then
  388. tmp = tmp .. "\n" .. wb[2] .. ": " .. FindBuff(wb[1]) .. GetAuraDur(wb[1], wb[3])
  389. end
  390. end
  391.  
  392. if string.len(tmp) == 1 then tmp = "" end
  393.  
  394. return tmp
  395. end
  396.  
  397. -- Blacklisted Auras. Must match the corresponding Custom Option.
  398. -- Key = idx in custom options, v[1] = aura name
  399. aura_env.spells = {
  400. [1] = "Thorns",
  401. [2] = "Arcane Intellect",
  402. [3] = "Arcane Brilliance",
  403. [4] = "Amplify Magic",
  404. [5] = "Dampen Magic",
  405. [6] = "Shadow Protection",
  406. [7] = "Divine Spirit",
  407. [8] = "Prayer of Spirit",
  408. [9] = "Fear Ward",
  409. [10] = "Water Breathing",
  410. [11] = "Water Walking",
  411. [12] = "Unending Breath",
  412. [13] = "Detect Invisibility",
  413. [14] = "Battle Shout",
  414. [15] = "Juju Flurry",
  415. [16] = "Blessing of Might",
  416. [17] = "Blessing of Kings",
  417. [18] = "Blessing of Salvation",
  418. [19] = "Blessing of Wisdom",
  419. [20] = "Blessing of Light",
  420. [21] = "Blessing of Sanctuary",
  421. [22] = "Greater Blessing of Might",
  422. [23] = "Greater Blessing of Kings",
  423. [24] = "Greater Blessing of Salvation",
  424. [25] = "Greater Blessing of Wisdom",
  425. [26] = "Greater Blessing of Light",
  426. [27] = "Greater Blessing of Sanctuary",
  427. [28] = "Renew",
  428. [29] = "Rejuvenation",
  429. [30] = "Regrowth",
  430. [31] = "Power Word: Shield",
  431. [32] = "Detect Greater Invisibility",
  432. }
  433. -- Tracked Consumables. Must match the corresponding Custom Option.
  434. -- Key = idx in custom options, v[1] = aura name, v[2] = name displayed in tracker, v[3] = buff/debuff
  435. aura_env.cons = {
  436. [1] = {"Flask of the Titans","FLASK", true},
  437. [2] = {"Distilled Wisdom","FLASK", true},
  438. [3] = {"Supreme Power","FLASK", true},
  439. [4] = {"Juju Flurry","JJ FLURRY", true},
  440. [5] = {"Juju Might","JJ MIGHT", true},
  441. [6] = {"Juju Power","JJ POWER", true},
  442. [7] = {"Rage of Ages","BL", true},
  443. [8] = {"Spirit of Boar","BL", true},
  444. [9] = {"Strike of the Scorpok","BL", true},
  445. [10] = {"Infallible Mind","BL", true},
  446. [11] = {"Elixir of the Mongoose","MONGOOSE", true},
  447. [12] = {"Greater Arcane Elixir","ARCANE", true},
  448. [13] = {"Shadow Power","SHADOWPOWER", true},
  449. [14] = {"Spirit of Zanza","ZANZA", true},
  450. [15] = {"Swiftness of Zanza","ZANZA", true},
  451. [16] = {"Winterfall Firewater","WF", true},
  452. [17] = {"Increased Agility","FOOD", true},
  453. [18] = {"Blessed Sunfruit","FOOD", true},
  454. [19] = {"Increased Intellect","FOOD", true},
  455. [20] = {"Mana Regeneration","FOOD", true}, -- Will break when mageblood is added to the game, fix with id's
  456. [21] = {"Well Fed","FOOD", true},
  457. [22] = {"Rumsey Rum Black Label","RUMSEY", true},
  458. [23] = {"Kreeg's Stout Beatdown","KREEG", true},
  459. [24] = {"Gordok Green Grog","GORDOK", true},
  460. [25] = {"Health II","FORT", true},
  461. [26] = {"Regeneration","TROLL", true},
  462. [27] = {"Greater Armor","SUP DEFENSE", true},
  463. }
  464. -- Tracked World Buffs. Must match the corresponding Custom Option.
  465. -- Key = idx in custom options, v[1] = aura name, v[2] = name displayed in tracker, v[3] = buff/debuff
  466. aura_env.wbs = {
  467. [1] = {"Songflower Serenade","SF", true},
  468. [2] = {"Rallying Cry of the Dragonslayer","ONY", true},
  469. [3] = {"Warchief's Blessing","WCB", true},
  470. [4] = {"Fengus' Ferocity","DM AP", true},
  471. [5] = {"Slip'kik's Savvy","DM CRIT", true},
  472. [6] = {"Mol'dar's Moxie","DM STAM", true},
  473. [7] = {"Fury of Ragnaros","BRD", true},
  474. [8] = {"Blessing of Blackfathom","BFD", false},
  475. [9] = {"Resist Fire", "FR", true},
  476. [10] = {"Arcane Might", "STRAT", true},
  477. }
  478. aura_env.tradeClosed = true
  479. local timeAtLogin = GetTime()
  480. aura_env.items = {
  481. [INVSLOT_HEAD] = {timeAtLogin + INVSLOT_HEAD,GetItemId(INVSLOT_HEAD),GetItemEnchant(INVSLOT_HEAD)},
  482. [INVSLOT_LEGS] = {timeAtLogin + INVSLOT_LEGS,GetItemId(INVSLOT_LEGS),GetItemEnchant(INVSLOT_LEGS)},
  483. [INVSLOT_FEET] = {timeAtLogin + INVSLOT_FEET,GetItemId(INVSLOT_FEET),GetItemEnchant(INVSLOT_FEET)},
  484. [INVSLOT_MAINHAND] = {timeAtLogin + INVSLOT_MAINHAND,GetItemId(INVSLOT_MAINHAND),GetItemEnchantWeapon(INVSLOT_MAINHAND)},
  485. [INVSLOT_OFFHAND] = {timeAtLogin + INVSLOT_OFFHAND,GetItemId(INVSLOT_OFFHAND),GetItemEnchant(INVSLOT_OFFHAND)},
  486. }
  487. MaintainCustomOptions()
  488. MaintainState()
  489. aura_env.buffs = CreateBuffTable()
  490. aura_env.buffOrder = GetSortedBuffTable(aura_env.buffs)
  491. aura_env.buffNext = GetFirstBuff()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement