comparison Modules/Events.lua @ 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 1ff3b83b104c
children 9ff6a3b02332
comparison
equal deleted inserted replaced
45:a66f6fc57cfb 46:5e981c1df761
222 222
223 function addon:UpdateCurrentInventory() 223 function addon:UpdateCurrentInventory()
224 self.lastInventory = self:GetCurrentInventory() 224 self.lastInventory = self:GetCurrentInventory()
225 end 225 end
226 226
227 local function distributeValueByAHValue(self, totalValue, targetItems)
228
229 local weights = {}
230 local totalWeight = 0
231 for link, change in pairs(targetItems) do
232 --[[
233 If something has never been seen on the AH, it must not be very valuable.
234 I'm using 1c so it doesn't have much weight and I can't get a devided by zero error.
235 The only time I know that this is a problem is when crafting a BOP item, and it
236 is always crafted 1 at a time, so a weight of 1 will work.
237 ]]
238 local ap = (addon:GetAuctionPrice(link) or 1)
239 totalWeight = totalWeight + ap
240 weights[link] = ap
241 end
242
243 local valuePerPoint = totalValue / totalWeight
244
245 for link, change in pairs(targetItems) do
246 self:SaveValue(link, weights[link] * valuePerPoint, change)
247 end
248 end
249
250 local function distributeValue(self, totalValue, targetItems)
251 if true then
252 return distributeValueByAHValue(self, totalValue, targetItems)
253 else
254 local valuePerItem = totalChange / positiveCount
255
256 for link, change in pairs(targetItems) do
257 self:SaveValue(link, valuePerItem * change, change)
258 end
259 end
260 end
261
227 function addon:UpdateAudit() 262 function addon:UpdateAudit()
228 -- self:Debug("UpdateAudit " .. event) 263 -- self:Debug("UpdateAudit " .. event)
229 local currentInventory = self:GetCurrentInventory() 264 local currentInventory = self:GetCurrentInventory()
230 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) 265 local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory)
231 266
264 self:SaveValue(link, itemCost * change, change) 299 self:SaveValue(link, itemCost * change, change)
265 300
266 totalChange = totalChange + (itemCost * abs(change)) 301 totalChange = totalChange + (itemCost * abs(change))
267 end 302 end
268 303
269 local valuePerItem = totalChange / positiveCount 304 distributeValue(self, totalChange, positive)
270
271 for link, change in pairs(positive) do
272 self:SaveValue(link, valuePerItem * change, change)
273 end
274 else 305 else
275 self:Debug("No match in UpdateAudit.") 306 self:Debug("No match in UpdateAudit.")
276 end 307 end
277 308
278 self.lastInventory = currentInventory 309 self.lastInventory = currentInventory