diff Core.lua @ 98:b29441cd130d

Ticket 30 (related to #23) - ItemAuditor is back to counting items in the mailbox, but will subtract items purchased from the AH or COD mail from its item counts.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 19 Aug 2010 22:53:54 -0700
parents 693f664aad2b
children e6292f1a0cf3
line wrap: on
line diff
--- a/Core.lua	Sat Aug 14 06:23:41 2010 -0700
+++ b/Core.lua	Thu Aug 19 22:53:54 2010 -0700
@@ -9,14 +9,8 @@
 	end
 end
 
-local WHITE		= "|cFFFFFFFF"
-local RED		= "|cFFFF0000"
-local GREEN		= "|cFF00FF00"
-local YELLOW	= "|cFFFFFF00"
-local ORANGE	= "|cFFFF7F00"
-local TEAL		= "|cFF00FF9A"
-local GOLD		= "|cFFFFD700"
-
+local allMailboxes = {}
+local myMailbox = {}
 
 ItemAuditor.Options = {
 	handler = ItemAuditor,
@@ -72,10 +66,17 @@
 			item_account = {},
 			items = {},
 			outbound_cod = {},
+			mailbox = {}
 		},
 	}
 	self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true)
-	
+
+	allMailboxes = self.db.factionrealm.mailbox
+	if not allMailboxes[UnitName("player")] then
+		allMailboxes[UnitName("player")] = {}
+	end
+	myMailbox = allMailboxes[UnitName("player")]
+
 	self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ItemAuditor", "ItemAuditor")
 	
 	LibStub("AceConfig-3.0"):RegisterOptionsTable("ItemAuditor", ItemAuditor.Options, {"ia"})
@@ -329,7 +330,7 @@
 			results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
 			results[mailType][itemName].total = results[mailType][itemName].total + bid
 			
-			local count = select(3, GetInboxItem(1,1))
+			local count = select(3, GetInboxItem(mailIndex,1))
 			results[mailType][itemName].count = results[mailType][itemName].count + count
 		elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then
 			-- These should be handled when you pay the deposit at the AH
@@ -339,26 +340,35 @@
 		end
 
 	end
-	
+
+	wipe(myMailbox)
 	for mailType, collection in pairs(results) do
+		myMailbox[mailType] = {}
 		for item, data in pairs(collection) do
-			self:Debug(format("|cFF00FF00MailScan|r: %s - %s - %s x %s", mailType, item, data.total, data.count))
+			myMailbox[mailType][item] = {
+				total = data.total,
+				count = data.count,
+			}
+			-- self:Print(format("|cFF00FF00MailScan|r: %s - %s - %s x %s", mailType, item, data.total, data.count))
 		end
 	end
-	
 	return results   
 end
 
 function ItemAuditor:GetItemCount(searchID)
-	local itemCounts = {}
-	local count = 0
-	for _, character in pairs(DataStore:GetCharacters()) do
-		bags, bank = DataStore:GetContainerItemCount(character, searchID)
+	local count = Altoholic:GetItemCount(searchID)
+	local itemName = GetItemInfo(searchID)
+	for character, mailbox in pairs(allMailboxes) do
+		for type, items in pairs(mailbox) do
+			if type == 'AHWon' or type == 'COD' then
+				for name, data in pairs(items) do
+					if name == itemName then
+						count = count - data.count
 
-		count = count + bags + bank
-			+ (DataStore:GetAuctionHouseItemCount(character, searchID) or 0)
-			+ (DataStore:GetInventoryItemCount(character, searchID) or 0)
-			+ (DataStore:GetCurrencyItemCount(character, searchID) or 0)
+					end
+				end
+			end
+		end
 	end
 	return count
 end