PageRenderTime 103ms CodeModel.GetById 60ms app.highlight 8ms RepoModel.GetById 32ms app.codeStats 0ms

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

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