changeset 5:7d0f4ebedf8c

work in progress: I added Prospecting and Disenchanting and AHOutbid mail and I also changed the initialization to quit forcing debug every time ItemAuditor loads and have begun to implement the COD mail scanning.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 26 May 2010 21:26:24 -0700
parents c940b527ccab
children 5dddd73b2220
files Core.lua Modules/Events.lua
diffstat 2 files changed, 39 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Sat May 22 15:23:11 2010 -0700
+++ b/Core.lua	Wed May 26 21:26:24 2010 -0700
@@ -24,8 +24,6 @@
 	}
 	self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true)
 	
-	self.db.char.debug = true
-	
 	self:RegisterOptions()
 	
 	self:RegisterEvent("PLAYER_ENTERING_WORLD")
@@ -93,22 +91,34 @@
 		local sender, msgSubject, msgMoney, msgCOD, _, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex))
 		local mailType = Postal:GetMailType(msgSubject)
 
-		if mailType == "NonAHMail" then
+		if mailType == "NonAHMail" and msgCOD > 0 then
 			-- Don't know how to handle these yet
+			
+			local itemTypes = {}
+			for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do
+				local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex)
+				if itemName ~= nil then
+					itemTypes[itemName] = (itemTypes[itemName] or 0) + count
+				end
+			end
+			
+			if utils:tcount(itemTypes) == 1 then
+				for itemName, count in pairs(itemTypes) do
+					results[itemName] = (results[itemName] or 0) - msgCOD
+				end
+			else
+				self:Debug("Don't know what to do with more than one item type on COD mail.")
+			end
+			
+			
 		elseif mailType == "AHSuccess" then
 			local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
-			if results[itemName] == nil then
-				results[itemName] = 0
-			end
-			results[itemName] = results[itemName] + deposit + buyout - consignment
+			results[itemName] = (results[itemName] or 0) + deposit + buyout - consignment
 
 		elseif mailType == "AHWon" then
 			local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
-			if results[itemName] == nil then
-				results[itemName] = 0
-			end
-			results[itemName] = results[itemName] - bid
-		elseif mailType == "AHExpired" or mailType == "AHCancelled" then
+			results[itemName] = (results[itemName] or 0) - bid
+		elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then
 			-- These should be handled when you pay the deposit at the AH
 		else
 			self:Debug("Unhandled mail type: " .. mailType)
--- a/Modules/Events.lua	Sat May 22 15:23:11 2010 -0700
+++ b/Modules/Events.lua	Wed May 26 21:26:24 2010 -0700
@@ -43,7 +43,7 @@
 end
 
 function addon:UNIT_SPELLCAST_START(event, target, spell)
-	if target == "player" and spell == "Milling" then
+	if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then
 		self:UnwatchBags()
 		self:UpdateCurrentInventory()
 		self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
@@ -64,7 +64,7 @@
 end
 
 function addon:UNIT_SPELLCAST_INTERRUPTED(event, target, spell)
-	if target == "player" and spell == "Milling" then
+	if target == "player" and spell == "Milling" or spell == "Prospecting" or spell == "Disenchanting" then
 		self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
 		self:UnregisterEvent("LOOT_CLOSED")
 		self:WatchBags()
@@ -82,24 +82,27 @@
 	-- this is only here for debugging
 	self.lastdiff = diff
 	
-	if abs(diff.money) > 0 and utils:tcount(diff.items) == 1 then
+	local positive, negative = {}, {}
+	local positiveCount, negativeCount = 0, 0
+	for item, count in pairs(diff.items) do
+		if count > 0 then
+			positive[item] = count
+			positiveCount = positiveCount + count
+		elseif count < 0 then
+			negative[item] = count
+			negativeCount = negativeCount + abs(count)
+		end
+	end
+	
+	if diff.money > 0 and utils:tcount(positive) > 0 and utils:tcount(negative) == 0 then
+		self:Debug("loot")
+	elseif abs(diff.money) > 0 and utils:tcount(diff.items) == 1 then
 		self:Debug("purchase or sale")
 		
 		for itemName, count in pairs(diff.items) do
 			self:SaveValue(itemName, diff.money)
 		end
 	elseif utils:tcount(diff.items) > 1 then
-		local positive, negative = {}, {}
-		local positiveCount, negativeCount = 0, 0
-		for item, count in pairs(diff.items) do
-			if count > 0 then
-				positive[item] = count
-				positiveCount = positiveCount + count
-			elseif count < 0 then
-				negative[item] = count
-				negativeCount = negativeCount + abs(count)
-			end
-		end
 		
 		if utils:tcount(positive) > 0 and utils:tcount(negative) > 0 then
 			-- we must have created/converted something