Broker_ConsolidatedBuffs.lua 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. -- Upvalues
  2. local _G = _G
  3. local bit, strsub, strlen, select, max = bit, strsub, strlen, select, max
  4. local addonName, addonNS = ...
  5. local LQT = LibStub('LibQTip-1.0')
  6. local LDB = LibStub("LibDataBroker-1.1")
  7. local LTT = LibStub("LibBabble-TalentTree-3.0"):GetLookupTable()
  8. local LCT = LibStub("LibBabble-CreatureType-3.0"):GetLookupTable()
  9. local LC = {} -- LOCALE CLASSES
  10. local CC = {} -- CLASS COLOR
  11. local classes_raw = {} -- conversion only
  12. FillLocalizedClassList(classes_raw)
  13. for token, localizedName in pairs(classes_raw) do
  14. local color = RAID_CLASS_COLORS[token];
  15. LC[token] = localizedName
  16. CC[token] = color.colorStr
  17. end
  18. local defaults = { -- http://www.wowhead.com/guide=1100/buffs-and-debuffs
  19. [1] = { -- Stats
  20. [1] = "Interface\\Icons\\spell_nature_regeneration",
  21. [2] = {
  22. {LC["DRUID"], CC["DRUID"]},
  23. {LC["MONK"], CC["MONK"]},
  24. {LC["PALADIN"], CC["PALADIN"]}
  25. },
  26. [3] = {LCT["Dog"], LCT["Gorilla"], LCT["Shale Spider"], LCT["Worm"]}
  27. },
  28. [2] = { -- Stamina
  29. [1] = "Interface\\Icons\\spell_holy_wordfortitude",
  30. [2] = {
  31. {LC["WARRIOR"], CC["WARRIOR"]},
  32. {LC["PRIEST"], CC["PRIEST"]},
  33. {LC["WARLOCK"], CC["WARLOCK"]}
  34. },
  35. [3] = {LCT["Bear"], LCT["Goat"], LCT["Rylak"], LCT["Silithid"]}
  36. },
  37. [3] = { --Attack Power
  38. [1] = "Interface\\Icons\\ability_warrior_battleshout",
  39. [2] = {
  40. {LC["DEATHKNIGHT"], CC["DEATHKNIGHT"]},
  41. {LC["WARRIOR"], CC["WARRIOR"]},
  42. {LC["HUNTER"], CC["HUNTER"]}
  43. },
  44. [3] = {}
  45. },
  46. [4] = { --Haste
  47. [1] = "Interface\\Icons\\spell_nature_bloodlust",
  48. [2] = {
  49. {LC["DEATHKNIGHT"].." "..STAT_DPS_SHORT, CC["DEATHKNIGHT"]},
  50. {LC["ROGUE"], CC["ROGUE"]},
  51. {LC["PRIEST"].." "..LTT["Shadow"], CC["PRIEST"]},
  52. {LC["SHAMAN"], CC["SHAMAN"]}
  53. },
  54. [3] = {LCT["Hyena"], LCT["Rylak"], LCT["Sporebat"], LCT["Wasp"]}
  55. },
  56. [5] = { --Spell Power
  57. [1] = "Interface\\Icons\\spell_holy_magicalsentry",
  58. [2] = {
  59. {LC["MAGE"], CC["MAGE"]},
  60. {LC["WARLOCK"], CC["WARLOCK"]}
  61. },
  62. [3] = {LCT["Serpent"], LCT["Silithid"], LCT["Water Strider"]}
  63. },
  64. [6] = { -- Critical Strike
  65. [1] = "Interface\\Icons\\spell_nature_unyeildingstamina",
  66. [2] = {
  67. {LC["MAGE"], CC["MAGE"]},
  68. {LC["DRUID"].." "..LTT["Feral"], CC["DRUID"]},
  69. {LC["MONK"].." "..STAT_CATEGORY_MELEE, CC["MONK"]}
  70. },
  71. [3] = {LCT["Devilsaur"], LCT["Quilen"], LCT["Raptor"], LCT["Shale Spider"], LCT["Water Strider"], LCT["Wolf"]}
  72. },
  73. [7] = { --Mastery
  74. [1] = "Interface\\Icons\\spell_holy_greaterblessingofkings",
  75. [2] = {
  76. {LC["DEATHKNIGHT"].." "..LTT["Blood"], CC["DEATHKNIGHT"]},
  77. {LC["SHAMAN"], CC["SHAMAN"]},
  78. {LC["DRUID"].." "..LTT["Balance"], CC["DRUID"]},
  79. {LC["PALADIN"], CC["PALADIN"]}
  80. },
  81. [3] = {LCT["Cat"], LCT["Hydra"], LCT["Spirit Beast"], LCT["Tallstrider"]}
  82. },
  83. [8] = { --Multistrike
  84. [1] = "Interface\\Icons\\inv_elemental_mote_air01",
  85. [2] = {
  86. {LC["ROGUE"], CC["ROGUE"]},
  87. {LC["PRIEST"].." "..LTT["Shadow"], CC["PRIEST"]},
  88. {LC["WARLOCK"], CC["WARLOCK"]},
  89. {LC["MONK"].." "..STAT_DPS_SHORT, CC["MONK"]}
  90. },
  91. [3] = {LCT["Bat"], LCT["Clefthoof"], LCT["Core Hound"], LCT["Dragonhawk"], LCT["Wind Serpent"]}
  92. },
  93. [9] = { --Versatility
  94. [1] = "Interface\\Icons\\spell_holy_mindvision",
  95. [2] = {
  96. {LC["DEATHKNIGHT"].." "..STAT_DPS_SHORT, CC["DEATHKNIGHT"]},
  97. {LC["WARRIOR"].." "..STAT_DPS_SHORT, CC["WARRIOR"]},
  98. {LC["DRUID"], CC["DRUID"]},
  99. {LC["PALADIN"].." "..STAT_DPS_SHORT, CC["PALADIN"]}
  100. },
  101. [3] = {LCT["Bird of Prey"], LCT["Boar"], LCT["Clefthoof"], LCT["Porcupine"], LCT["Ravager"], LCT["Stag"], LCT["Worm"]}
  102. }
  103. }
  104. local function classColorLocalized(color, spec)
  105. return "\124c".. color..spec.."\124r"
  106. end
  107. local function getCasterName(buffName)
  108. local unitCaster = select(8, _G.UnitBuff("player", buffName) )
  109. if unitCaster then
  110. -- Do we want translate the name of the player to "you"?
  111. -- Will add FOREIGN_SERVER_LABEL to the name if the player is from a other server. Connected Realms do not get the label
  112. -- if this is a problem change false to true, then all player not on your server will return as "Name-Realm"
  113. return _G.GetUnitName(unitCaster, true)
  114. else
  115. -- We can improve this *else* with this code from Dairyman: https://github.com/Dairyman/Broker_ConsolidatedBuffs/blob/who_cast_it_extra_column/Broker_ConsolidatedBuffs.lua#L113
  116. -- For now, I prefer to show something different indicating the unknown source of the buff.
  117. return _G.NOT_APPLICABLE
  118. end
  119. end
  120. local BrokerConsolidatedBuffs = LDB:NewDataObject("Broker_ConsolidatedBuffs", {
  121. type = "data source",
  122. text = "0/".._G.NUM_LE_RAID_BUFF_TYPES,
  123. value = "0/".._G.NUM_LE_RAID_BUFF_TYPES,
  124. icon = "Interface\\AddOns\\Broker_ConsolidatedBuffs\\BuffConsolidation", -- I can't use the default because is a combination texture :(
  125. label = "ConsolidatedBuffs",
  126. OnEnter = function(self)
  127. local tooltip = LQT:Acquire("Broker_ConsolidatedBuffsTooltip", 4, "LEFT", "LEFT", "LEFT", "LEFT")
  128. self.tooltip = tooltip
  129. local line = tooltip:AddHeader() -- Create an empty line
  130. tooltip:SetCell(line, 1, _G.CONSOLIDATE_BUFFS_TEXT, tooltip.headerFont, "LEFT", #tooltip.columns) -- Set value and change the col-span to the full tooltip width
  131. tooltip:AddLine(" ")
  132. tooltip:AddHeader(_G.STATISTICS, " ", _G.ALL_CLASSES, _G.PETS)
  133. tooltip:AddSeparator()
  134. --tooltip:AddLine(" ")
  135. -- http://wowprogramming.com/utils/xmlbrowser/live/FrameXML/BuffFrame.lua
  136. local buffmask = _G.GetRaidBuffInfo() or 0
  137. local mask = 1
  138. for i = 1, _G.NUM_LE_RAID_BUFF_TYPES do
  139. local name, rank, texture, duration, expiration, spellId, slot = _G.GetRaidBuffTrayAuraInfo(i)
  140. local c, who
  141. if name then
  142. c = "00FF00"
  143. who = getCasterName(name)
  144. else
  145. if bit.band(buffmask, mask) > 0 then
  146. c = "FF0000"
  147. else
  148. c = "888888"
  149. end
  150. end
  151. local classes = ""
  152. for ii = 1, #defaults[i][2] do
  153. classes = classes ..", ".. classColorLocalized(defaults[i][2][ii][2], defaults[i][2][ii][1])
  154. end
  155. local pets = ""
  156. for ii = 1, #defaults[i][3] do
  157. pets = pets ..", ".. defaults[i][3][ii]
  158. end
  159. tooltip:AddLine(
  160. "\124T"..defaults[i][1]..":0\124t \124cFF"..c.._G["RAID_BUFF_"..i]:gsub("-\n", "").."\124r",
  161. who or "",
  162. strsub(classes, 2),
  163. strsub(pets, 2)
  164. )
  165. mask = bit.lshift(mask, 1)
  166. end
  167. tooltip:SmartAnchorTo(self)
  168. tooltip:Show()
  169. end,
  170. OnLeave = function(self)
  171. LQT:Release(self.tooltip)
  172. self.tooltip = nil
  173. end,
  174. OnClick = function(button)
  175. local missing = ""
  176. local unavailable = ""
  177. local buffmask = _G.GetRaidBuffInfo() or 0
  178. local mask = 1
  179. for i = 1, _G.NUM_LE_RAID_BUFF_TYPES do
  180. if not _G.GetRaidBuffTrayAuraInfo(i) then
  181. if bit.band(buffmask, mask) > 0 then
  182. missing = missing .. _G["RAID_BUFF_"..i]:gsub("-\n", "") ..", "
  183. else
  184. unavailable = unavailable .. _G["RAID_BUFF_"..i]:gsub("-\n", "") ..", "
  185. end
  186. end
  187. mask = bit.lshift(mask, 1)
  188. end
  189. local channel = "SAY"
  190. if _G.IsInGroup(_G.LE_PARTY_CATEGORY_INSTANCE) then
  191. channel = "INSTANCE_CHAT"
  192. elseif _G.IsInRaid() then
  193. channel = "RAID"
  194. elseif _G.IsInGroup() then
  195. channel = "PARTY"
  196. end
  197. if missing ~= "" then
  198. _G.SendChatMessage(_G.ADDON_MISSING..": "..strsub(missing, 0, strlen(missing)-2), channel)
  199. end
  200. if unavailable ~= "" then
  201. _G.SendChatMessage(_G.UNAVAILABLE..": "..strsub(unavailable, 0, strlen(unavailable)-2), channel)
  202. end
  203. end
  204. })
  205. local function updateBuffs(self, event, unitID)
  206. if (unitID == "player" or event == "PLAYER_ENTERING_WORLD") then
  207. local c = 0
  208. for i = 1, _G.NUM_LE_RAID_BUFF_TYPES do
  209. if _G.GetRaidBuffTrayAuraInfo(i) then
  210. c = c + 1
  211. end
  212. end
  213. -- I'm gona keep the old code here. Becouse there is an issue with GetRaidBuffInfo()+versatility
  214. --and sometimes can appear 2/2 with 1 buff missing
  215. -- For example a party of Hunter+Druid. Hunter > AP, Druid > Stats+Vers. GRBI() report only Stats and AP.
  216. -- IMO is better to show 2/9 than 2/2 in this cases.
  217. --local buffcount = select(2, _G.GetRaidBuffInfo())
  218. --BrokerConsolidatedBuffs.text = c.."/"..max(c, buffcount)
  219. --BrokerConsolidatedBuffs.value = c.."/"..max(c, buffcount) -- for ElvUI datatexts
  220. -- old code, to be replaced by ^^^^^
  221. BrokerConsolidatedBuffs.text = c.."/"..NUM_LE_RAID_BUFF_TYPES
  222. BrokerConsolidatedBuffs.value = c.."/"..NUM_LE_RAID_BUFF_TYPES -- for ElvUI datatexts
  223. end
  224. end
  225. local frame = CreateFrame("Frame")
  226. frame:RegisterEvent("UNIT_AURA")
  227. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  228. frame:SetScript("OnEvent", updateBuffs)