Quantcast

* Debuff highlighting should now work properly, please report any bugs to me

James Whitehead II [01-25-08 - 07:39]
* Debuff highlighting should now work properly, please report any bugs to me
Filename
PerfectRaid_Buffs.lua
PerfectRaid_Highlight.lua
diff --git a/PerfectRaid_Buffs.lua b/PerfectRaid_Buffs.lua
index 462edea..3fa3cfa 100644
--- a/PerfectRaid_Buffs.lua
+++ b/PerfectRaid_Buffs.lua
@@ -108,6 +108,7 @@ function Buffs:ShowButton(button)
 	self:UNIT_AURA(nil, unit)
 end

+local band = bit.band
 local buffs = {}
 local buffcache = {}
 local mybuffs = {}
@@ -117,7 +118,7 @@ local BIT_MAGIC = 2
 local BIT_POISON = 4
 local BIT_DISEASE = 8

-local debuffstatus = setmetatable({}, {__index=function(t,k) t[k] = 0; return 0 end})
+local debuffstatus = setmetatable({}, {__index=function(t,k) rawset(t,k,0); return 0 end})

 local work = {}
 function Buffs:UNIT_AURA(event, unit)
@@ -156,38 +157,41 @@ function Buffs:UNIT_AURA(event, unit)
 	local status = debuffstatus[unit]

 	-- Disease
-	if buffcache.Disease and status < BIT_DISEASE then
-		debuffstatus[unit] = debuffstatus[unit] + BIT_DISEASE
+	if buffcache.Disease and band(status, BIT_DISEASE) == 0 then
+		status = status + BIT_DISEASE
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Disease")
-	elseif status >= BIT_DISEASE then
-		debuffstatus[unit] = debuffstatus[unit] - BIT_DISEASE
+	elseif not buffcache.Disease and band(status, BIT_DISEASE) > 0 then
+		status = status - BIT_DISEASE
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Disease")
 	end

-	if buffcache.Poison and status < BIT_POISON then
-		debuffstatus[unit] = debuffstatus[unit] + BIT_POISON
+	if buffcache.Poison and band(status, BIT_POISON) == 0 then
+		status = status + BIT_POISON
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Poison")
-	elseif status >= BIT_POISON then
-		debuffstatus[unit] = debuffstatus[unit] - BIT_POISON
+	elseif not buffcache.Poison and band(status, BIT_POISON) > 0 then
+		status = status - BIT_POISON
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Poison")
 	end

-	if buffcache.Magic and status < BIT_MAGIC then
-		debuffstatus[unit] = debuffstatus[unit] + BIT_MAGIC
+	if buffcache.Magic and band(status, BIT_MAGIC) == 0 then
+		status = status + BIT_MAGIC
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Magic")
-	elseif status >= BIT_MAGIC then
-		debuffstatus[unit] = debuffstatus[unit] - BIT_MAGIC
+	elseif not buffcache.Magic and band(status, BIT_MAGIC) > 0 then
+		status = status - BIT_MAGIC
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Magic")
 	end

-	if buffcache.Curse and status < BIT_CURSE then
-		debuffstatus[unit] = debuffstatus[unit] + BIT_CURSE
+	if buffcache.Curse and band(status, BIT_CURSE) == 0 then
+		status = status + BIT_CURSE
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Curse")
-	elseif status >= BIT_CURSE then
-		debuffstatus[unit] = debuffstatus[unit] - BIT_CURSE
+	elseif not buffcache.Curse and band(status, BIT_CURSE) > 0 then
+		status = status - BIT_CURSE
 		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Curse")
 	end

+	-- Update the status
+	debuffstatus[unit] = status
+
 	for k,v in pairs(work) do work[k] = nil end

 	for i,entry in ipairs(buffs) do
diff --git a/PerfectRaid_Highlight.lua b/PerfectRaid_Highlight.lua
index 23596da..a470ef7 100644
--- a/PerfectRaid_Highlight.lua
+++ b/PerfectRaid_Highlight.lua
@@ -88,7 +88,7 @@ local BIT_MAGIC = 2
 local BIT_POISON = 4
 local BIT_DISEASE = 8

-local status = setmetatable({}, {__index=function(t,k) t[k] = 0; return 0 end})
+local status = setmetatable({}, {__index=function(t,k) rawset(t,k,0); return 0 end})

 function Highlight:PERFECTRAID_DEBUFFTYPE_GAINED(msg, unit, type)
 	if type == "Disease" then
@@ -100,6 +100,8 @@ function Highlight:PERFECTRAID_DEBUFFTYPE_GAINED(msg, unit, type)
 	elseif type == "Curse" then
 		status[unit] = status[unit] + BIT_CURSE
 	end
+
+	self:UpdateUnit(unit)
 end

 function Highlight:PERFECTRAID_DEBUFFTYPE_LOST(msg, unit, type)
@@ -116,25 +118,32 @@ function Highlight:PERFECTRAID_DEBUFFTYPE_LOST(msg, unit, type)
 	if status[unit] < 0 then
 		status[unit] = 0
 	end
+
+	self:UpdateUnit(unit)
 end

+local band = bit.band
+local function checkbit(num, bit) return band(num, bit) == bit end
 function Highlight:UpdateUnit(unit, frame)
 	-- Check to see if we need to change the backdrop
 	local opt = PerfectRaid.db.profile.highlight

-	local r,g,b,a
+	if not unit and frame then
+		unit = frame:GetAttribute("unit")
+	end
+
+	local r,g,b,a = 0,0,0,0
 	local statnum = status[unit]
-
-	if opt.disease and statnum > BIT_DISEASE then
+
+	-- Color the frame properly
+	if opt.disease and checkbit(statnum, BIT_DISEASE) then
 		r,g,b,a = 0.6,0.4,0,0.7
-	elseif opt.poison and statnum > BIT_POISON then
+	elseif opt.poison and checkbit(statnum, BIT_POISON) then
 		r,g,b,a = 0,0.6,0,0.7
-	elseif opt.magic and statnum > BIT_MAGIC then
+	elseif opt.magic and checkbit(statnum, BIT_MAGIC) then
 		r,g,b,a = 0.2,0.6,1,0.7
-	elseif opt.curse and statnum > BIT_CURSE then
+	elseif opt.curse and checkbit(statnum, BIT_CURSE) then
 		r,g,b,a = 0.6,0,1,0.7
-	else
-		r,g,b,a = 0,0,0,0
 	end

 	if frame then