/Tukui/modules/unitframes/plugins/oUF_DebuffHighlight/oUF_DebuffHighlight.lua

http://github.com/Asphyxia/Tukui · Lua · 152 lines · 126 code · 15 blank · 11 comment · 50 complexity · 76920dd38265b9dbc3be9bb0b80f527e MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. if C.unitframes.enable ~= true then return end
  3. local _, ns = ...
  4. local oUF = ns.oUF or oUF
  5. if not oUF then return end
  6. local playerClass = select(2,UnitClass("player"))
  7. local CanDispel = {
  8. PRIEST = { Magic = true, Disease = true, },
  9. SHAMAN = { Magic = false, Curse = true, },
  10. PALADIN = { Magic = false, Poison = true, Disease = true, },
  11. MAGE = { Curse = true, },
  12. DRUID = { Magic = false, Curse = true, Poison = true, }
  13. }
  14. local dispellist = CanDispel[playerClass] or {}
  15. local origColors = {}
  16. local origBorderColors = {}
  17. local origPostUpdateAura = {}
  18. local function GetDebuffType(unit, filter)
  19. if not UnitCanAssist("player", unit) then return nil end
  20. local i = 1
  21. while true do
  22. local _, _, texture, _, debufftype = UnitAura(unit, i, "HARMFUL")
  23. if not texture then break end
  24. if debufftype and not filter or (filter and dispellist[debufftype]) then
  25. return debufftype, texture
  26. end
  27. i = i + 1
  28. end
  29. end
  30. -- Return true if the talent matching the name of the spell given by (Credit Pitbull4)
  31. -- spellid has at least one point spent in it or false otherwise
  32. local function CheckForKnownTalent(spellid)
  33. local wanted_name = GetSpellInfo(spellid)
  34. if not wanted_name then return nil end
  35. local num_tabs = GetNumTalentTabs()
  36. for t=1, num_tabs do
  37. local num_talents = GetNumTalents(t)
  38. for i=1, num_talents do
  39. local name_talent, _, _, _, current_rank = GetTalentInfo(t,i)
  40. if name_talent and (name_talent == wanted_name) then
  41. if current_rank and (current_rank > 0) then
  42. return true
  43. else
  44. return false
  45. end
  46. end
  47. end
  48. end
  49. return false
  50. end
  51. local function CheckSpec(self, event, levels)
  52. -- Not interested in gained points from leveling
  53. if event == "CHARACTER_POINTS_CHANGED" and levels > 0 then return end
  54. --Check for certain talents to see if we can dispel magic or not
  55. if playerClass == "PALADIN" then
  56. --Check to see if we have the 'Sacred Cleansing' talent.
  57. if CheckForKnownTalent(53551) then
  58. dispellist.Magic = true
  59. else
  60. dispellist.Magic = false
  61. end
  62. elseif playerClass == "SHAMAN" then
  63. --Check to see if we have the 'Improved Cleanse Spirit' talent.
  64. if CheckForKnownTalent(77130) then
  65. dispellist.Magic = true
  66. else
  67. dispellist.Magic = false
  68. end
  69. elseif playerClass == "DRUID" then
  70. --Check to see if we have the 'Nature's Cure' talent.
  71. if CheckForKnownTalent(88423) then
  72. dispellist.Magic = true
  73. else
  74. dispellist.Magic = false
  75. end
  76. end
  77. end
  78. local function Update(object, event, unit)
  79. if object.unit ~= unit then return end
  80. local debuffType, texture = GetDebuffType(unit, object.DebuffHighlightFilter)
  81. if debuffType then
  82. local color = DebuffTypeColor[debuffType]
  83. if object.DebuffHighlightBackdrop then
  84. object:SetBackdropColor(color.r, color.g, color.b, object.DebuffHighlightAlpha or 1)
  85. elseif object.DebuffHighlightUseTexture then
  86. object.DebuffHighlight:SetTexture(texture)
  87. else
  88. object.DebuffHighlight:SetVertexColor(color.r, color.g, color.b, object.DebuffHighlightAlpha or .5)
  89. end
  90. else
  91. if object.DebuffHighlightBackdrop then
  92. local color = origColors[object]
  93. object:SetBackdropColor(color.r, color.g, color.b, color.a)
  94. color = origBorderColors[object]
  95. object:SetBackdropBorderColor(color.r, color.g, color.b, color.a)
  96. elseif object.DebuffHighlightUseTexture then
  97. object.DebuffHighlight:SetTexture(nil)
  98. else
  99. local color = origColors[object]
  100. object.DebuffHighlight:SetVertexColor(color.r, color.g, color.b, color.a)
  101. end
  102. end
  103. end
  104. local function Enable(object)
  105. -- if we're not highlighting this unit return
  106. if not object.DebuffHighlightBackdrop and not object.DebuffHighlight then
  107. return
  108. end
  109. -- if we're filtering highlights and we're not of the dispelling type, return
  110. if object.DebuffHighlightFilter and not CanDispel[playerClass] then
  111. return
  112. end
  113. -- make sure aura scanning is active for this object
  114. object:RegisterEvent("UNIT_AURA", Update)
  115. object:RegisterEvent("PLAYER_TALENT_UPDATE", CheckSpec)
  116. object:RegisterEvent("CHARACTER_POINTS_CHANGED", CheckSpec)
  117. if object.DebuffHighlightBackdrop then
  118. local r, g, b, a = object:GetBackdropColor()
  119. origColors[object] = { r = r, g = g, b = b, a = a}
  120. r, g, b, a = object:GetBackdropBorderColor()
  121. origBorderColors[object] = { r = r, g = g, b = b, a = a}
  122. elseif not object.DebuffHighlightUseTexture then -- color debuffs
  123. -- object.DebuffHighlight
  124. local r, g, b, a = object.DebuffHighlight:GetVertexColor()
  125. origColors[object] = { r = r, g = g, b = b, a = a}
  126. end
  127. return true
  128. end
  129. local function Disable(object)
  130. if object.DebuffHighlightBackdrop or object.DebuffHighlight then
  131. object:UnregisterEvent("UNIT_AURA", Update)
  132. object:UnregisterEvent("PLAYER_TALENT_UPDATE", CheckSpec)
  133. object:UnregisterEvent("CHARACTER_POINTS_CHANGED", CheckSpec)
  134. end
  135. end
  136. oUF:AddElement('DebuffHighlight', Update, Enable, Disable)
  137. for i, frame in ipairs(oUF.objects) do Enable(frame) end