/Tukui/modules/unitframes/plugins/oUF_RaidDebuffs/oUF_RaidDebuffs.lua

http://github.com/Asphyxia/Tukui · Lua · 278 lines · 230 code · 38 blank · 10 comment · 66 complexity · 050037714c20ebd521168996933a9c4f MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. -- yleaf (yaroot@gmail.com)
  3. if C.unitframes.enable ~= true or C.unitframes.raidunitdebuffwatch ~= true then return end
  4. local _, ns = ...
  5. local oUF = ns.oUF or oUF
  6. local addon = {}
  7. ns.oUF_RaidDebuffs = addon
  8. if not _G.oUF_RaidDebuffs then
  9. _G.oUF_RaidDebuffs = addon
  10. end
  11. local debuff_data = {}
  12. addon.DebuffData = debuff_data
  13. addon.ShowDispelableDebuff = true
  14. addon.FilterDispellableDebuff = true
  15. addon.MatchBySpellName = true
  16. addon.priority = 10
  17. local function add(spell)
  18. if addon.MatchBySpellName and type(spell) == 'number' then
  19. spell = GetSpellInfo(spell)
  20. end
  21. debuff_data[spell] = addon.priority
  22. addon.priority = addon.priority + 1
  23. end
  24. function addon:RegisterDebuffs(t)
  25. for _, v in next, t do
  26. add(v)
  27. end
  28. end
  29. function addon:ResetDebuffData()
  30. wipe(debuff_data)
  31. addon.priority = 10
  32. end
  33. local DispellColor = {
  34. ['Magic'] = {.2, .6, 1},
  35. ['Curse'] = {.6, 0, 1},
  36. ['Disease'] = {.6, .4, 0},
  37. ['Poison'] = {0, .6, 0},
  38. ['none'] = {unpack(C.media.bordercolor)},
  39. }
  40. local DispellPriority = {
  41. ['Magic'] = 4,
  42. ['Curse'] = 3,
  43. ['Disease'] = 2,
  44. ['Poison'] = 1,
  45. }
  46. local DispellFilter
  47. do
  48. local dispellClasses = {
  49. ['PRIEST'] = {
  50. ['Magic'] = true,
  51. ['Disease'] = true,
  52. },
  53. ['SHAMAN'] = {
  54. ['Magic'] = false,
  55. ['Curse'] = true,
  56. },
  57. ['PALADIN'] = {
  58. ['Poison'] = true,
  59. ['Magic'] = false,
  60. ['Disease'] = true,
  61. },
  62. ['MAGE'] = {
  63. ['Curse'] = true,
  64. },
  65. ['DRUID'] = {
  66. ['Magic'] = false,
  67. ['Curse'] = true,
  68. ['Poison'] = true,
  69. },
  70. }
  71. DispellFilter = dispellClasses[select(2, UnitClass('player'))] or {}
  72. end
  73. -- Return true if the talent matching the name of the spell given by (Credit Pitbull4)
  74. -- spellid has at least one point spent in it or false otherwise
  75. local function CheckForKnownTalent(spellid)
  76. local wanted_name = GetSpellInfo(spellid)
  77. if not wanted_name then return nil end
  78. local num_tabs = GetNumTalentTabs()
  79. for t=1, num_tabs do
  80. local num_talents = GetNumTalents(t)
  81. for i=1, num_talents do
  82. local name_talent, _, _, _, current_rank = GetTalentInfo(t,i)
  83. if name_talent and (name_talent == wanted_name) then
  84. if current_rank and (current_rank > 0) then
  85. return true
  86. else
  87. return false
  88. end
  89. end
  90. end
  91. end
  92. return false
  93. end
  94. local function CheckSpec(self, event, levels)
  95. -- Not interested in gained points from leveling
  96. if event == "CHARACTER_POINTS_CHANGED" and levels > 0 then return end
  97. --Check for certain talents to see if we can dispel magic or not
  98. if select(2, UnitClass('player')) == "PALADIN" then
  99. --Check to see if we have the 'Sacred Cleansing' talent.
  100. if CheckForKnownTalent(53551) then
  101. DispellFilter.Magic = true
  102. else
  103. DispellFilter.Magic = false
  104. end
  105. elseif select(2, UnitClass('player')) == "SHAMAN" then
  106. --Check to see if we have the 'Improved Cleanse Spirit' talent.
  107. if CheckForKnownTalent(77130) then
  108. DispellFilter.Magic = true
  109. else
  110. DispellFilter.Magic = false
  111. end
  112. elseif select(2, UnitClass('player')) == "DRUID" then
  113. --Check to see if we have the 'Nature's Cure' talent.
  114. if CheckForKnownTalent(88423) then
  115. DispellFilter.Magic = true
  116. else
  117. DispellFilter.Magic = false
  118. end
  119. end
  120. end
  121. local function formatTime(s)
  122. if s > 60 then
  123. return format('%dm', s/60), s%60
  124. elseif s < 1 then
  125. return format("%.1f", s), s - floor(s)
  126. else
  127. return format('%d', s), s - floor(s)
  128. end
  129. end
  130. local abs = math.abs
  131. local function OnUpdate(self, elapsed)
  132. self.elapsed = (self.elapsed or 0) + elapsed
  133. if self.elapsed >= 0.1 then
  134. local timeLeft = self.endTime - GetTime()
  135. if self.reverse then timeLeft = abs((self.endTime - GetTime()) - self.duration) end
  136. if timeLeft > 0 then
  137. local text = formatTime(timeLeft)
  138. self.time:SetText(text)
  139. else
  140. self:SetScript('OnUpdate', nil)
  141. self.time:Hide()
  142. end
  143. self.elapsed = 0
  144. end
  145. end
  146. local function UpdateDebuff(self, name, icon, count, debuffType, duration, endTime, spellId)
  147. local f = self.RaidDebuffs
  148. if name then
  149. f.icon:SetTexture(icon)
  150. f.icon:Show()
  151. f.duration = duration
  152. if f.count then
  153. if count and (count > 0) then
  154. f.count:SetText(count)
  155. f.count:Show()
  156. else
  157. f.count:Hide()
  158. end
  159. end
  160. if spellId and T.ReverseTimer[spellId] then
  161. f.reverse = true
  162. else
  163. f.reverse = nil
  164. end
  165. if f.time then
  166. if duration and (duration > 0) then
  167. f.endTime = endTime
  168. f.nextUpdate = 0
  169. f:SetScript('OnUpdate', OnUpdate)
  170. f.time:Show()
  171. else
  172. f:SetScript('OnUpdate', nil)
  173. f.time:Hide()
  174. end
  175. end
  176. if f.cd then
  177. if duration and (duration > 0) then
  178. f.cd:SetCooldown(endTime - duration, duration)
  179. f.cd:Show()
  180. else
  181. f.cd:Hide()
  182. end
  183. end
  184. local c = DispellColor[debuffType] or DispellColor.none
  185. f:SetBackdropBorderColor(c[1], c[2], c[3])
  186. f:Show()
  187. else
  188. f:Hide()
  189. end
  190. end
  191. local function Update(self, event, unit)
  192. if unit ~= self.unit then return end
  193. local _name, _icon, _count, _dtype, _duration, _endTime, _spellId
  194. local _priority, priority = 0
  195. for i = 1, 40 do
  196. local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, i, 'HARMFUL')
  197. if (not name) then break end
  198. if addon.ShowDispelableDebuff and debuffType then
  199. if addon.FilterDispellableDebuff then
  200. DispellPriority[debuffType] = DispellPriority[debuffType] + addon.priority --Make Dispell buffs on top of Boss Debuffs
  201. priority = DispellFilter[debuffType] and DispellPriority[debuffType]
  202. else
  203. priority = DispellPriority[debuffType]
  204. end
  205. if priority and (priority > _priority) then
  206. _priority, _name, _icon, _count, _dtype, _duration, _endTime, _spellId = priority, name, icon, count, debuffType, duration, expirationTime, spellId
  207. end
  208. end
  209. priority = debuff_data[addon.MatchBySpellName and name or spellId]
  210. if priority and (priority > _priority) then
  211. _priority, _name, _icon, _count, _dtype, _duration, _endTime, _spellId = priority, name, icon, count, debuffType, duration, expirationTime, spellId
  212. end
  213. end
  214. UpdateDebuff(self, _name, _icon, _count, _dtype, _duration, _endTime, _spellId)
  215. --Reset the DispellPriority
  216. DispellPriority = {
  217. ['Magic'] = 4,
  218. ['Curse'] = 3,
  219. ['Disease'] = 2,
  220. ['Poison'] = 1,
  221. }
  222. end
  223. local function Enable(self)
  224. if self.RaidDebuffs then
  225. self:RegisterEvent('UNIT_AURA', Update)
  226. return true
  227. end
  228. --Need to run these always
  229. self:RegisterEvent("PLAYER_TALENT_UPDATE", CheckSpec)
  230. self:RegisterEvent("CHARACTER_POINTS_CHANGED", CheckSpec)
  231. end
  232. local function Disable(self)
  233. if self.RaidDebuffs then
  234. self:UnregisterEvent('UNIT_AURA', Update)
  235. self.RaidDebuffs:Hide()
  236. end
  237. self:UnregisterEvent("PLAYER_TALENT_UPDATE", CheckSpec)
  238. self:UnregisterEvent("CHARACTER_POINTS_CHANGED", CheckSpec)
  239. end
  240. oUF:AddElement('RaidDebuffs', Update, Enable, Disable)