diff bossmods.lua @ 42:4f1e71f62776

Handle moving from one instance kill/loot into a new instance, and then getting loot from trash in the new instance before seeing any bosses.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Fri, 13 Jan 2012 01:12:36 +0000
parents d929c40cdb09
children fcc0d0ff5832
line wrap: on
line diff
--- a/bossmods.lua	Thu Jan 12 02:24:15 2012 +0000
+++ b/bossmods.lua	Fri Jan 13 01:12:36 2012 +0000
@@ -1,12 +1,13 @@
 local addon = select(2,...)
 
---[[
+--[==[
 Here's the control flow:
-(1) This file or another addon calls :register_boss_mod("Foo",register[,unregister])
+(1) This file or another addon calls
+       addon:register_boss_mod("Foo",register[,unregister])
 (2) When OL decides it's time to register with a boss mod, it calls
        register (addon, addon_do_boss)
     which should do whatever's needed.  This may happen more than once, if OL
-    is turned on/off, etc.
+    is turned on/off, etc.  It should return a true value if successful.
 (2b) If a boss mod is already in place,
        unregister (addon)
     will be called first, if such a function was given at the start.
@@ -21,7 +22,7 @@
 ------ Constants
 ------ Globals
 ------ Deadly Boss Mods
-]]
+]==]
 
 ------ Constants
 
@@ -42,7 +43,17 @@
 
 ------ Deadly Boss Mods
 do
+	local DBM
 	local location
+	local real_loadmod
+	-- When zoning into a raid instance not seen this session, make sure
+	-- we don't report a previous raid instance as current location.  DBM
+	-- has no callback event for this, so we do a small hook instead.
+	local function resetting_loadmod (...)
+		addon.latest_instance = nil
+		return real_loadmod(...)
+	end
+
 	local function DBMBossCallback (self, reason, mod, ...)
 		if (not self.rebroadcast) and (not self.enabled) then return end
 
@@ -56,6 +67,7 @@
 		end
 
 		local it = location or self.instance_tag()
+		self.latest_instance = it
 		location = nil
 
 		local duration = 0
@@ -80,23 +92,31 @@
 	local function callback(...) DBMBossCallback(addon,...) end
 
 	local function _registerDBM (self, OL_boss_worker)
-		if _G.DBM then
+		DBM = _G.DBM
+		if DBM then
 			local rev = tonumber(DBM.Revision) or 0
 			if rev < 1503 then
 				self.status_text = "|cffff1010Deadly Boss Mods must be version 1.26 or newer to work with Ouro Loot.|r"
 				return
 			end
 			addon_do_boss = OL_boss_worker
-			local r = _G.DBM:RegisterCallback("kill", callback)
-					  _G.DBM:RegisterCallback("wipe", callback)
-					  _G.DBM:RegisterCallback("pull", function() location = self.instance_tag() end)
+			local r = DBM:RegisterCallback("kill", callback)
+					  DBM:RegisterCallback("wipe", callback)
+					  DBM:RegisterCallback("pull", function() location = self.instance_tag() end)
+			real_loadmod = DBM.LoadMod
+			DBM.LoadMod = resetting_loadmod
 			return r > 0
 		else
 			self.status_text = "|cffff1010Ouro Loot cannot find Deadly Boss Mods, loot will not be grouped by boss.|r"
 		end
 	end
 
-	addon:register_boss_mod ("DBM", _registerDBM)
+	local function _unregisterDBM (self)
+		self.latest_instance = nil
+		DBM.LoadMod = real_loadmod 
+	end
+
+	addon:register_boss_mod ("DBM", _registerDBM, _unregisterDBM)
 end  -- DBM tie-ins