# HG changeset patch # User Asa Ayers # Date 1274566991 25200 # Node ID c940b527ccab79a57d8d65702b0f2187b8252761 # Parent bbcf818681714a2fa960b590c7cd2f0f8988d959 Fixed Milling. Disenchating will probably have to be fixed the same way diff -r bbcf81868171 -r c940b527ccab Core.lua --- 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) diff -r bbcf81868171 -r c940b527ccab Modules/Events.lua --- 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