Guest User

Untitled

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