Quantcast

Prune auras from GUIDs that are no longer in the group.

Johnny C. Lam [03-16-13 - 08:04]
Prune auras from GUIDs that are no longer in the group.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@782 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleGUID.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index fd121a8..cce0910 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -102,19 +102,33 @@ function RemoveAurasForGUID(guid)
 		Ovale.refreshNeeded[unitId] = true
 	end
 end
+
+function RemoveAurasForMissingUnits()
+	-- Remove all auras from GUIDs that can no longer be referenced by a unit ID,
+	-- i.e., not in the group or not targeted by anyone in the group or focus.
+	for guid in pairs(OvaleAura_aura) do
+		if not OvaleGUID:GetUnitId(guid) then
+			RemoveAurasForGUID(guid)
+		end
+	end
+end
 --</private-static-methods>

 --<public-static-methods>
 function OvaleAura:OnEnable()
 	playerGUID = OvaleGUID.player
 	self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
+	self:RegisterEvent("PLAYER_ENTERING_WORLD")
 	self:RegisterEvent("UNIT_AURA")
+	self:RegisterMessage("Ovale_GroupChanged", RemoveAurasForMissingUnits)
 	self:RegisterMessage("Ovale_InactiveUnit", RemoveAurasForGUID)
 end

 function OvaleAura:OnDisable()
 	self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
+	self:UnregisterEvent("PLAYER_ENTERING_WORLD")
 	self:UnregisterEvent("UNIT_AURA")
+	self:UnregisterMessage("Ovale_GroupChanged")
 	self:UnregisterMessage("Ovale_InactiveUnit")
 end

@@ -142,6 +156,11 @@ function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
 	end
 end

+function OvaleAura:PLAYER_ENTERING_WORLD(event)
+	RemoveAurasForMissingUnits()
+	auraPool:Drain()
+end
+
 function OvaleAura:UNIT_AURA(event, unitId)
 	if unitId == "player" then
 		self:UpdateAuras("player", playerGUID)
@@ -150,7 +169,6 @@ function OvaleAura:UNIT_AURA(event, unitId)
 	end
 end

--- Private methods
 function OvaleAura:UpdateAuras(unitId, unitGUID)
 	OvaleAura_serial = OvaleAura_serial + 1

diff --git a/OvaleGUID.lua b/OvaleGUID.lua
index 9f654ae..d6939e5 100644
--- a/OvaleGUID.lua
+++ b/OvaleGUID.lua
@@ -108,6 +108,7 @@ function OvaleGUID:GROUP_ROSTER_UPDATE(event)
 		self:UpdateWithTarget("raid"..i)
 		self:UpdateWithTarget("raidpet"..i)
 	end
+	self:SendMessage("Ovale_GroupChanged")
 end

 function OvaleGUID:UNIT_PET(event, unitId)
@@ -120,6 +121,7 @@ function OvaleGUID:UNIT_PET(event, unitId)
 	elseif unitId == "player" then
 		self:UpdateWithTarget("pet")
 	end
+	self:SendMessage("Ovale_GroupChanged")
 end

 function OvaleGUID:ARENA_OPPONENT_UPDATE(event)