Mercurial > wow > itemauditor
diff Modules/Events.lua @ 51:84bfb5469189
Merged and closed ticket7
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Wed, 21 Jul 2010 01:22:30 -0700 |
parents | 9ff6a3b02332 |
children | 9c95158236d1 |
line wrap: on
line diff
--- a/Modules/Events.lua Tue Jul 20 00:20:15 2010 -0700 +++ b/Modules/Events.lua Wed Jul 21 01:22:30 2010 -0700 @@ -224,6 +224,29 @@ self.lastInventory = self:GetCurrentInventory() end +local function distributeValue(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 + function addon:UpdateAudit() -- self:Debug("UpdateAudit " .. event) local currentInventory = self:GetCurrentInventory() @@ -266,11 +289,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