Mercurial > wow > itemauditor
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 24:554b30908b33 | 26:75d917ccd942 |
|---|---|
| 28 self:MAIL_INBOX_UPDATE() | 28 self:MAIL_INBOX_UPDATE() |
| 29 self:UnregisterEvent("MAIL_INBOX_UPDATE") | 29 self:UnregisterEvent("MAIL_INBOX_UPDATE") |
| 30 self:RegisterEvent("MAIL_SHOW") | 30 self:RegisterEvent("MAIL_SHOW") |
| 31 end | 31 end |
| 32 | 32 |
| 33 local storedCountDiff | |
| 33 function addon:MAIL_INBOX_UPDATE() | 34 function addon:MAIL_INBOX_UPDATE() |
| 34 self:Debug("MAIL_INBOX_UPDATE") | 35 self:Debug("MAIL_INBOX_UPDATE") |
| 35 local newScan = addon:ScanMail() | 36 local newScan = addon:ScanMail() |
| 36 local diff | 37 local diff |
| 37 for mailType, collection in pairs(self.lastMailScan) do | 38 for mailType, collection in pairs(self.lastMailScan) do |
| 38 newScan[mailType] = (newScan[mailType] or {}) | 39 newScan[mailType] = (newScan[mailType] or {}) |
| 39 for item, total in pairs(collection) do | 40 for itemName, data in pairs(collection) do |
| 40 | 41 newScan[mailType][itemName] = (newScan[mailType][itemName] or {total=0,count=0}) |
| 41 diff = total - (newScan[mailType][item] or 0) | 42 local totalDiff = data.total - newScan[mailType][itemName].total |
| 42 if diff ~= 0 then | 43 local countDiff = data.count - newScan[mailType][itemName].count |
| 43 self:SaveValue(item, diff) | 44 --[[ |
| 45 In one update the item will be taken and in the following update the invoice | |
| 46 will be gone. I need to store the item difference in order ot pass it into | |
| 47 SaveValue. | |
| 48 ]] | |
| 49 if countDiff ~= 0 then | |
| 50 storedCountDiff = countDiff | |
| 51 end | |
| 52 | |
| 53 if totalDiff ~= 0 then | |
| 54 self:SaveValue(itemName, totalDiff, storedCountDiff) | |
| 55 storedCountDiff = 0 | |
| 44 end | 56 end |
| 45 | 57 |
| 46 end | 58 end |
| 47 end | 59 end |
| 48 | 60 |
| 110 self:Debug("loot") | 122 self:Debug("loot") |
| 111 elseif abs(diff.money) > 0 and self:tcount(diff.items) == 1 then | 123 elseif abs(diff.money) > 0 and self:tcount(diff.items) == 1 then |
| 112 self:Debug("purchase or sale") | 124 self:Debug("purchase or sale") |
| 113 | 125 |
| 114 for link, count in pairs(diff.items) do | 126 for link, count in pairs(diff.items) do |
| 115 self:SaveValue(link, 0 - diff.money) | 127 self:SaveValue(link, 0 - diff.money, count) |
| 116 end | 128 end |
| 117 elseif self:tcount(diff.items) > 1 and self:tcount(positive) > 0 and self:tcount(negative) > 0 then | 129 elseif self:tcount(diff.items) > 1 and self:tcount(positive) > 0 and self:tcount(negative) > 0 then |
| 118 -- we must have created/converted something | 130 -- we must have created/converted something |
| 119 self:Debug("conversion") | 131 self:Debug("conversion") |
| 120 | 132 |
| 121 local totalChange = 0 | 133 local totalChange = 0 |
| 122 for link, change in pairs(negative) do | 134 for link, change in pairs(negative) do |
| 123 local _, itemCost, count = self:GetItemCost(link, change) | 135 local _, itemCost, count = self:GetItemCost(link, change) |
| 124 self:SaveValue(link, itemCost * change) | 136 self:SaveValue(link, itemCost * change, change) |
| 125 | 137 |
| 126 totalChange = totalChange + (itemCost * abs(change)) | 138 totalChange = totalChange + (itemCost * abs(change)) |
| 127 end | 139 end |
| 128 | 140 |
| 129 local valuePerItem = totalChange / positiveCount | 141 local valuePerItem = totalChange / positiveCount |
| 130 | 142 |
| 131 for link, change in pairs(positive) do | 143 for link, change in pairs(positive) do |
| 132 self:SaveValue(link, valuePerItem * change) | 144 self:SaveValue(link, valuePerItem * change, change) |
| 133 end | 145 end |
| 134 else | 146 else |
| 135 self:Debug("No match in UpdateAudit.") | 147 self:Debug("No match in UpdateAudit.") |
| 136 end | 148 end |
| 137 | 149 |
