Mercurial > wow > itemauditor
diff Modules/Events.lua @ 26:75d917ccd942
Fixed Bug #9 - If existing items have 0c invested, increase them all to match the first transaction that changes their price.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Wed, 14 Jul 2010 00:28:44 -0700 |
parents | 554b30908b33 |
children | f5d384fe7e4a |
line wrap: on
line diff
--- a/Modules/Events.lua Sun Jul 11 09:24:33 2010 -0700 +++ b/Modules/Events.lua Wed Jul 14 00:28:44 2010 -0700 @@ -30,17 +30,29 @@ self:RegisterEvent("MAIL_SHOW") end +local storedCountDiff function addon:MAIL_INBOX_UPDATE() self:Debug("MAIL_INBOX_UPDATE") local newScan = addon:ScanMail() local diff for mailType, collection in pairs(self.lastMailScan) do newScan[mailType] = (newScan[mailType] or {}) - for item, total in pairs(collection) do - - diff = total - (newScan[mailType][item] or 0) - if diff ~= 0 then - self:SaveValue(item, diff) + for itemName, data in pairs(collection) do + newScan[mailType][itemName] = (newScan[mailType][itemName] or {total=0,count=0}) + local totalDiff = data.total - newScan[mailType][itemName].total + local countDiff = data.count - newScan[mailType][itemName].count + --[[ + In one update the item will be taken and in the following update the invoice + will be gone. I need to store the item difference in order ot pass it into + SaveValue. + ]] + if countDiff ~= 0 then + storedCountDiff = countDiff + end + + if totalDiff ~= 0 then + self:SaveValue(itemName, totalDiff, storedCountDiff) + storedCountDiff = 0 end end @@ -112,7 +124,7 @@ self:Debug("purchase or sale") for link, count in pairs(diff.items) do - self:SaveValue(link, 0 - diff.money) + self:SaveValue(link, 0 - diff.money, count) end elseif self:tcount(diff.items) > 1 and self:tcount(positive) > 0 and self:tcount(negative) > 0 then -- we must have created/converted something @@ -121,7 +133,7 @@ local totalChange = 0 for link, change in pairs(negative) do local _, itemCost, count = self:GetItemCost(link, change) - self:SaveValue(link, itemCost * change) + self:SaveValue(link, itemCost * change, change) totalChange = totalChange + (itemCost * abs(change)) end @@ -129,7 +141,7 @@ local valuePerItem = totalChange / positiveCount for link, change in pairs(positive) do - self:SaveValue(link, valuePerItem * change) + self:SaveValue(link, valuePerItem * change, change) end else self:Debug("No match in UpdateAudit.")