changeset 4:c940b527ccab

Fixed Milling. Disenchating will probably have to be fixed the same way
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sat, 22 May 2010 15:23:11 -0700
parents bbcf81868171
children 7d0f4ebedf8c
files Core.lua Modules/Events.lua
diffstat 2 files changed, 46 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Sat May 22 11:34:19 2010 -0700
+++ b/Core.lua	Sat May 22 15:23:11 2010 -0700
@@ -131,23 +131,29 @@
 	end
 end
 
+local defaultBagDelay = 0.2
+
 function addon:WatchBags(delay)
-   if self.watch_handle == nil then
-	delay = delay or 0.2
-	self.lastInventory = self:GetCurrentInventory()
-	self.watch_handle = self:RegisterBucketEvent({"BAG_UPDATE", "PLAYER_MONEY"}, delay, "UpdateAudit")
-   end
+	delay = delay or defaultBagDelay
+	if delay ~= self.currentBagDelay  then
+		self:UnwatchBags()
+	end
+
+	if self.watch_handle == nil then
+		self.currentBagDelay = delay
+		self:Debug("currentBagDelay = " .. delay)
+		addon:UpdateCurrentInventory()
+		self.watch_handle = self:RegisterBucketEvent({"BAG_UPDATE", "PLAYER_MONEY"}, self.currentBagDelay, "UpdateAudit")
+	end
 end
 
 function addon:UnwatchBags()
-   if self.watch_handle ~= nil then
-      self:UnregisterBucket(self.watch_handle)
-      self.watch_handle = nil
-   end
+	if self.watch_handle ~= nil then
+		self:UnregisterBucket(self.watch_handle)
+		self.watch_handle = nil
+	end
 end
 
-
-
 function addon:GetItemCost(itemName, countModifier)
 	local invested = abs(self.db.factionrealm.item_account[itemName] or 0)
 	
--- a/Modules/Events.lua	Sat May 22 11:34:19 2010 -0700
+++ b/Modules/Events.lua	Sat May 22 15:23:11 2010 -0700
@@ -5,6 +5,7 @@
 
 function addon:PLAYER_ENTERING_WORLD()
 	self:RegisterEvent("MAIL_SHOW")
+	self:RegisterEvent("UNIT_SPELLCAST_START")
 	self:WatchBags()
 end
  
@@ -41,14 +42,37 @@
 	self.lastMailScan = newScan
 end
 
-function addon:UNIT_SPELLCAST_SENT(target, spell)
-	if target == "player" and spell = "Milling" then
-	
+function addon:UNIT_SPELLCAST_START(event, target, spell)
+	if target == "player" and spell == "Milling" then
+		self:UnwatchBags()
+		self:UpdateCurrentInventory()
+		self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
+		self:RegisterEvent("LOOT_CLOSED")
 	end
 end
 
-function addon:UNIT_SPELLCAST_INTERRUPTED(target, spell)
+--[[ 
+	The item should be destroyed before this point, so the last inventory check
+	needs to be kept so it can be combined with the up coming loot.
+ ]]
+function addon:LOOT_CLOSED()
+	self:UnregisterEvent("LOOT_CLOSED")
+	self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
+	local inventory = self.lastInventory
+	self:WatchBags()
+	self.lastInventory = inventory 
+end
 
+function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell)
+	if target == "player" and spell == "Milling" then
+		self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
+		self:UnregisterEvent("LOOT_CLOSED")
+		self:WatchBags()
+	end
+end
+
+function addon:UpdateCurrentInventory()
+	self.lastInventory = self:GetCurrentInventory()
 end
 
 function addon:UpdateAudit()
@@ -102,4 +126,5 @@
 	end
 	
 	self.lastInventory = currentInventory
+	addon:WatchBags()
 end
\ No newline at end of file