comparison Modules/Events.lua @ 137:526036e4358f

Ticket 42 - In order to fix an issue with having multiple items that are the same base item with different enchants, all costs are now tracked against the base item instead of the exact item.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sat, 02 Oct 2010 19:21:56 -0700
parents 52e8cad9ccc4
children 828cd9bf919e
comparison
equal deleted inserted replaced
136:d3d5e82043d8 137:526036e4358f
266 266
267 local function distributeValue(self, totalValue, targetItems) 267 local function distributeValue(self, totalValue, targetItems)
268 268
269 local weights = {} 269 local weights = {}
270 local totalWeight = 0 270 local totalWeight = 0
271 for link, change in pairs(targetItems) do 271 for itemID, change in pairs(targetItems) do
272 --[[ 272 --[[
273 If something has never been seen on the AH, it must not be very valuable. 273 If something has never been seen on the AH, it must not be very valuable.
274 I'm using 1c so it doesn't have much weight and I can't get a devided by zero error. 274 I'm using 1c so it doesn't have much weight and I can't get a devided by zero error.
275 The only time I know that this is a problem is when crafting a BOP item, and it 275 The only time I know that this is a problem is when crafting a BOP item, and it
276 is always crafted 1 at a time, so a weight of 1 will work. 276 is always crafted 1 at a time, so a weight of 1 will work.
277 ]] 277 ]]
278 local ap = (ItemAuditor:GetAuctionPrice(link) or 1) * change 278 local ap = (ItemAuditor:GetAuctionPrice(itemID) or 1) * change
279 totalWeight = totalWeight + ap 279 totalWeight = totalWeight + ap
280 weights[link] = ap 280 weights[itemID] = ap
281 end 281 end
282 282
283 for link, change in pairs(targetItems) do 283 for itemID, change in pairs(targetItems) do
284 local value = totalValue * (weights[link]/totalWeight) 284 local value = totalValue * (weights[itemID]/totalWeight)
285 self:SaveValue(link, value, change) 285 self:SaveValue(itemID, value, change)
286 end 286 end
287 end 287 end
288 288
289 function ItemAuditor:UpdateAudit() 289 function ItemAuditor:UpdateAudit()
290 -- self:Debug("UpdateAudit " .. event) 290 -- self:Debug("UpdateAudit " .. event)
291 local currentInventory = self:GetCurrentInventory() 291 local currentInventory = self:GetCurrentInventory()
292 local diff = ItemAuditor:GetInventoryDiff(self.lastInventory, currentInventory) 292 local diff = ItemAuditor:GetInventoryDiff(self.lastInventory, currentInventory)
293 293
294 local positive, negative = {}, {} 294 local positive, negative = {}, {}
295 local positiveCount, negativeCount = 0, 0 295 local positiveCount, negativeCount = 0, 0
296 for item, count in pairs(diff.items) do 296 for itemID, count in pairs(diff.items) do
297 if count > 0 then 297 if count > 0 then
298 positive[item] = count 298 positive[itemID] = count
299 positiveCount = positiveCount + count 299 positiveCount = positiveCount + count
300 elseif count < 0 then 300 elseif count < 0 then
301 negative[item] = count 301 negative[itemID] = count
302 negativeCount = negativeCount + abs(count) 302 negativeCount = negativeCount + abs(count)
303 end 303 end
304 end 304 end
305 305
306 if positiveCount + negativeCount == 0 then 306 if positiveCount + negativeCount == 0 then
311 elseif diff.money > 0 and self:tcount(positive) > 0 and self:tcount(negative) == 0 then 311 elseif diff.money > 0 and self:tcount(positive) > 0 and self:tcount(negative) == 0 then
312 self:Debug("loot") 312 self:Debug("loot")
313 elseif abs(diff.money) > 0 and self:tcount(diff.items) == 1 and not self.mailOpen then 313 elseif abs(diff.money) > 0 and self:tcount(diff.items) == 1 and not self.mailOpen then
314 self:Debug("purchase or sale") 314 self:Debug("purchase or sale")
315 315
316 for link, count in pairs(diff.items) do 316 for itemID, count in pairs(diff.items) do
317 self:SaveValue(link, 0 - diff.money, count) 317 self:SaveValue(link, 0 - diff.money, itemID)
318 end 318 end
319 elseif self:tcount(diff.items) > 1 and self:tcount(positive) > 0 and self:tcount(negative) > 0 then 319 elseif self:tcount(diff.items) > 1 and self:tcount(positive) > 0 and self:tcount(negative) > 0 then
320 -- we must have created/converted something 320 -- we must have created/converted something
321 self:Debug("conversion") 321 self:Debug("conversion")
322 322
323 local totalChange = 0 323 local totalChange = 0
324 for link, change in pairs(negative) do 324 for itemID, change in pairs(negative) do
325 local _, itemCost, count = self:GetItemCost(link, change) 325 local _, itemCost, count = self:GetItemCost(itemID, change)
326 self:SaveValue(link, itemCost * change, change) 326 self:SaveValue(itemID, itemCost * change, change)
327 327
328 totalChange = totalChange + (itemCost * abs(change)) 328 totalChange = totalChange + (itemCost * abs(change))
329 end 329 end
330 totalChange = totalChange - diff.money 330 totalChange = totalChange - diff.money
331 331