changeset 46:5e981c1df761 ticket7

Changed the way items are converted to be weighted by AH value. there are no options yet.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Tue, 20 Jul 2010 00:12:44 -0700
parents a66f6fc57cfb
children 9ff6a3b02332
files Modules/DisplayInvested.lua Modules/Events.lua
diffstat 2 files changed, 37 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Modules/DisplayInvested.lua	Tue Jul 20 00:09:54 2010 -0700
+++ b/Modules/DisplayInvested.lua	Tue Jul 20 00:12:44 2010 -0700
@@ -98,7 +98,7 @@
 		
 		ItemAuditor:SaveValue(link, newValue-investedTotal, 0)
 	end
-	StaticPopup_Show ("ItemAuditor_NewPrice", link, 'two');
+	StaticPopup_Show ("ItemAuditor_NewPrice");
 end
 
 local function displayMoney(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...)
--- a/Modules/Events.lua	Tue Jul 20 00:09:54 2010 -0700
+++ b/Modules/Events.lua	Tue Jul 20 00:12:44 2010 -0700
@@ -224,6 +224,41 @@
 	self.lastInventory = self:GetCurrentInventory()
 end
 
+local function distributeValueByAHValue(self, totalValue, targetItems)
+	
+	local weights = {}
+	local totalWeight = 0
+	for link, change in pairs(targetItems) do
+		--[[ 
+			If something has never been seen on the AH, it must not be very valuable.
+			I'm using 1c so it doesn't have much weight and I can't get a devided by zero error.
+			The only time I know that this is a problem is when crafting a BOP item, and it 
+			is always crafted 1 at a time, so a weight of 1 will work.
+		]]
+		local ap = (addon:GetAuctionPrice(link) or 1)
+		totalWeight = totalWeight + ap
+		weights[link] = ap
+	end
+	
+	local valuePerPoint = totalValue / totalWeight
+	
+	for link, change in pairs(targetItems) do
+		self:SaveValue(link, weights[link] * valuePerPoint, change)
+	end
+end
+
+local function distributeValue(self, totalValue, targetItems)
+	if true then
+		return distributeValueByAHValue(self, totalValue, targetItems)
+	else
+		local valuePerItem = totalChange / positiveCount
+			
+		for link, change in pairs(targetItems) do
+			self:SaveValue(link, valuePerItem * change, change)
+		end
+	end
+end
+
 function addon:UpdateAudit()
 	-- self:Debug("UpdateAudit " .. event)
 	local currentInventory = self:GetCurrentInventory()
@@ -266,11 +301,7 @@
 			totalChange = totalChange + (itemCost * abs(change))
 		end
 		
-		local valuePerItem = totalChange / positiveCount
-		
-		for link, change in pairs(positive) do
-			self:SaveValue(link, valuePerItem * change, change)
-		end
+		distributeValue(self, totalChange, positive)
 	else
 		self:Debug("No match in UpdateAudit.")
 	end