changeset 10:c79ede3c7b82

Updated version and added a dependency on my modified API for QuickAuctions. Next I need to make that dependency optional
author Asa Ayers <Asa.Ayers@Gmail.com>
date Fri, 25 Jun 2010 22:03:44 -0700
parents 374dd1a90d02
children 03e2d9edc344
files Core.lua ItemAuditor.toc Modules/Events.lua Modules/Tooltip.lua
diffstat 4 files changed, 57 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Core.lua	Fri Jun 25 01:17:58 2010 -0700
+++ b/Core.lua	Fri Jun 25 22:03:44 2010 -0700
@@ -21,8 +21,8 @@
 		},
 		factionrealm = {
 			item_account = {},
-			
 			items = {},
+			AHCut = 0.05,
 		},
 	}
 	self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true)
@@ -49,6 +49,11 @@
 		if self:GetItem(link).count == 0 or self:GetItem(link).invested == 0 then
 			self:RemoveItem(link)
 		end
+		-- addon:UpdateQAThreshold(link)
+	end
+	
+	for groupName in pairs(QAAPI:GetGroups()) do
+		self:UpdateQAGroup(groupName)
 	end
 end
 
@@ -61,6 +66,7 @@
 		bagSize=GetContainerNumSlots(bagID)
 		for slotID = 0, bagSize do
 			local link= GetContainerItemLink(bagID, slotID);
+			link = link and self:GetSafeLink(link)
 
 			if link ~= nil and i[link] == nil then
 				i[link] = GetItemCount(link);
@@ -181,7 +187,7 @@
 		local itemName = GetItemInfo(link)
 	
 		self.items[link] = {
-			count = Altoholic:GetItemCount(self:GetIDFromLink(link)),
+			count =  Altoholic:GetItemCount(self:GetIDFromLink(link)),
 			invested = abs(self.db.factionrealm.item_account[itemName] or 0),
 		}
 		
@@ -194,6 +200,7 @@
 	elseif viewOnly == true then
 		return {count = self.items[link].count, invested = self.items[link].invested}
 	end
+	self.items[link].count =  Altoholic:GetItemCount(self:GetIDFromLink(link))
 	return self.items[link]
 end
 
@@ -217,16 +224,11 @@
 	local itemName = nil
 	if realLink == nil then
 		itemName = link
-		
 		self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value
-		
 		item = {invested = self.db.factionrealm.item_account[itemName], count = 1}
 	else
-	
 		item = self:GetItem(realLink)
-	
 		item.invested = item.invested + value
-		
 		itemName = GetItemInfo(realLink)
 	end
 	
@@ -234,13 +236,52 @@
 		self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(item.invested) .. "(change: " .. utils:FormatMoney(value) .. ")")
 	end
 	
-	if item.invested <= 0 then
+	if abs(value) > 0 and item.invested <= 0 then
 		self:Debug("Updated price of " .. itemName .. " to " .. utils:FormatMoney(0))
 		self:RemoveItem(link)
-	elseif item.count == 0 then 
+	elseif item.count == 0 and ItemAuditor:GetCurrentInventory() > 0 then 
 		self:Print("You ran out of " .. itemName .. " and never recovered " .. utils:FormatMoney(item.invested))
 		self:RemoveItem(link)
 	end
+	
+	if realLink ~= nil then
+		addon:UpdateQAThreshold(realLink)
+	end
+end
+--[[
+	
+	ItemAuditor:UpdateQAThreshold("item:42646")
+]]
+function addon:UpdateQAThreshold(link)
+	_, link= GetItemInfo(link)
+	
+	self:UpdateQAGroup(QAAPI:GetItemGroup(link))
+end
+
+function addon:UpdateQAGroup(groupName)
+	if groupName then
+		local threshold = 10000
+		
+		for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
+			local totalCost, itemCost, itemCount = ItemAuditor:GetItemCost(link, 0)
+			
+			if itemCost > threshold then
+				threshold = itemCost 
+			end
+		end
+		
+		-- Adding the cost of mailing every item once.
+		threshold = threshold + 30
+		
+		-- add my minimum profit margin 15%
+		threshold = threshold * 1.15
+		
+		-- add AH Cut
+		local keep = 1 - self.db.factionrealm.AHCut
+		threshold = threshold/keep
+		
+		QAAPI:SetGroupThreshold(groupName, ceil(threshold))
+	end
 end
 
 local defaultBagDelay = 0.2
@@ -273,7 +314,7 @@
 function addon:GetSafeLink(link)
 	local newLink = nil
 
-	if link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then
+	if link and link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then
 		newLink = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h")
 	end
 	if newLink == nil then
--- a/ItemAuditor.toc	Fri Jun 25 01:17:58 2010 -0700
+++ b/ItemAuditor.toc	Fri Jun 25 22:03:44 2010 -0700
@@ -1,10 +1,10 @@
-## Interface: 30200
+## Interface: 30300
 ## Title: Item Auditor
 ## Notes: This will keep track of how much you have paid per item in your inventory
 ## Author: Asa Ayers <Asa.Ayers@Gmail.com>
 ## Version: 0.1
 ## SavedVariables: ItemAuditorDB
-## Dependencies: Altoholic, DevTools
+## Dependencies: Altoholic, DevTools, QuickAuctions
 
 embeds.xml
 
--- a/Modules/Events.lua	Fri Jun 25 01:17:58 2010 -0700
+++ b/Modules/Events.lua	Fri Jun 25 22:03:44 2010 -0700
@@ -80,7 +80,7 @@
 end
 
 function addon:UpdateAudit()
-	self:Debug("UpdateAudit")
+	-- self:Debug("UpdateAudit")
 	local currentInventory = self:GetCurrentInventory()
 	local diff =  addon:GetInventoryDiff(self.lastInventory, currentInventory)
 	-- this is only here for debugging
@@ -101,7 +101,7 @@
 	if diff.money > 0 and utils:tcount(positive) > 0 and utils:tcount(negative) == 0 then
 		-- self:Debug("loot")
 	elseif utils:tcount(diff.items) == 1 then
-		self:Debug("purchase or sale")
+		-- self:Debug("purchase or sale")
 		
 		for link, count in pairs(diff.items) do
 			self:SaveValue(link, 0 - diff.money)
@@ -111,6 +111,7 @@
 		if utils:tcount(positive) > 0 and utils:tcount(negative) > 0 then
 			-- we must have created/converted something
 			-- self:Debug("conversion")
+			
 			local totalChange = 0
 			for link, change in pairs(negative) do
 				local _, itemCost, count = self:GetItemCost(link, change)
--- a/Modules/Tooltip.lua	Fri Jun 25 01:17:58 2010 -0700
+++ b/Modules/Tooltip.lua	Fri Jun 25 22:03:44 2010 -0700
@@ -13,7 +13,7 @@
 
 	local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
 	
-	local AHCut = 0.05
+	local AHCut = ItemAuditor.db.factionrealm.AHCut
 	local keep = 1 - AHCut
 
 	if investedTotal > 0 then