Quantcast

* Added experimental support for a "My Spells" filter on buffs

James Whitehead II [02-13-08 - 00:06]
* Added experimental support for a "My Spells" filter on buffs
Filename
PerfectRaid_Buffs.lua
diff --git a/PerfectRaid_Buffs.lua b/PerfectRaid_Buffs.lua
index a0ade7f..0341b31 100644
--- a/PerfectRaid_Buffs.lua
+++ b/PerfectRaid_Buffs.lua
@@ -112,6 +112,7 @@ local band = bit.band
 local buffs = {}
 local buffcache = {}
 local mybuffs = {}
+local mymask = {}

 local BIT_CURSE = 1
 local BIT_MAGIC = 2
@@ -136,23 +137,23 @@ function Buffs:UNIT_AURA(event, unit)
 	for i=1,40 do
 		local name,rank,texture,count,duration,timeleft = UnitBuff(unit, i)
 		if not name then break end
-		buffcache[name] = (buffcache[name] or 0) + 1
-		-- Flag this, if this is our buff
 		if timeleft then
 			mybuffs[name] = true
 		end
+
+		buffcache[name] = (buffcache[name] or 0) + 1
 	end

 	local debuffType
 	for i=1,40 do
 		local name,rank,texture,count,type,durating,timeleft = UnitDebuff(unit, i)
 		if not name and not type then break end
-		buffcache[name] = (buffcache[name] or 0) + 1
-		-- Flag this, if this is our debuff
 		if timeleft then
 			mybuffs[name] = true
 		end

+		buffcache[name] = (buffcache[name] or 0) + 1
+
 		if type and name ~= type then
 			buffcache[type] = (buffcache[type] or 0) + 1
 			debuffType = type
@@ -202,13 +203,21 @@ function Buffs:UNIT_AURA(event, unit)

 	for i,entry in ipairs(buffs) do
 		local checkcond = false
-		local num = buffcache[entry.buffname]
+		local buffname
+		if buffcache[entry.buffname] then
+			buffname = entry.buffname
+		elseif buffcache[entry.groupname or "nil"] then
+			buffname = entry.groupname
+		end
+
+		local num = buffcache[buffname]
+
 		if entry.missing then
-			if not buffcache[entry.buffname] and not buffcache[entry.groupname or "nil"] then
+			if not buffname then
 				checkcond = true
 			end
 		else
-			if buffcache[entry.buffname] or buffcache[entry.groupname or "nil"] then
+			if buffname then
 				checkcond = true
 			end
 		end
@@ -216,6 +225,7 @@ function Buffs:UNIT_AURA(event, unit)
 		local class = select(2, UnitClass(unit))
 		local conds = self.conditions
 		local group = raidLookup[unit]
+		local mine = mybuffs[buffname]

 		-- Handle the condition checking for the buff, taking strictness into account
 		if checkcond then
@@ -224,28 +234,53 @@ function Buffs:UNIT_AURA(event, unit)
 				local pass = true

 				for i,name in pairs(entry.cond) do
-					if conds[name] and not conds[name](unit, class, group) then
+					if conds[name] and not conds[name](unit, class, group, mine) then
 						pass = false
 					end
 				end

 				if pass then
 					if num and num > 1 then
+						local num = num
+						if mine and not mymask[buffname] then
+							num = num - 1
+						end
+
 						table.insert(work, entry.colortext .. "(" .. num .. ")")
 					else
-						table.insert(work, entry.colortext)
+						if mymask[buffname] and not mine then
+							-- Do nothing
+						else
+							table.insert(work, entry.colortext)
+						end
 					end
 				end
 			else
 				-- Simply iterate each of the conditions, and break when we match
 				for i,name in pairs(entry.cond) do
-					if conds[name] and conds[name](unit, class, group) then
+					if conds[name] and conds[name](unit, class, group, mine) then
 						if num and num > 1 then
+							local num = num
+							-- If the buff is mine, and it should be masked
+							-- A buff is masked when there is a "mine" filter set for it
+							if mine and not mymask[buffname] then
+								num = num - 1
+							end
+
 							table.insert(work, entry.colortext .. "(" .. num .. ")")
 						else
-							table.insert(work, entry.colortext)
+							-- If this is a single buff, check to see if its masked
+							if mymask[buffname] then
+								-- If this buff is mine, and this entry shows mine
+								if mine and entry.showmine then
+									table.insert(work, entry.colortext)
+								end
+							else
+								table.insert(work, entry.colortext)
+							end
 						end
-
+
+						-- Break out
 						break
 					end
 				end
@@ -528,7 +563,7 @@ function Buffs:CreateEditFrame(parent)
 	checks[19]:SetPoint("TOPLEFT", checks[13], "BOTTOMLEFT", 0, -10)
 	checks[19]:Show()

-	for i=20,21 do
+	for i=20,22 do
 		checks[i] = makeCheck(self.conditions[i])
 		checks[i]:SetPoint("TOPLEFT", checks[i-1], "TOPRIGHT", 60, 0)
 		checks[i]:Show()
@@ -656,6 +691,7 @@ end

 function Buffs:UpdateBuffTable()
 	for k,v in pairs(buffs) do buffs[k] = nil end
+	for k,v in pairs(mymask) do mymask[k] = nil end

 	for idx,entry in ipairs(PerfectRaid.db.profile.buffs) do
 		if not entry.disabled then
@@ -666,6 +702,14 @@ function Buffs:UpdateBuffTable()
 			tbl.missing = entry.missing
 			tbl.strict = entry.strict
 			tbl.cond = {string.split(",", entry.conds)}
+			if entry.conds:match("MySpell") then
+				tbl.showmine = true
+				mymask[tbl.buffname] = true
+				if entry.groupname then
+					mymask[tbl.groupname] = true
+				end
+			end
+
 			table.insert(buffs, tbl)
 		end
 	end
@@ -786,6 +830,7 @@ Buffs.conditions = {
 	["Group 7"] = function(u,c,g) return g == 7 end,
 	["Group 8"] = function(u,c,g) return g == 8 end,
 	["MyGroup"] = function(u,c,g) return g == raidLookup.player end,
+	["MySpell"] = function(u,c,g,m) return m end,
 }

 local work = {}