Mercurial > wow > itemauditor
changeset 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 | 5da5d85cd714 |
files | .pkgmeta CHANGELOG.txt Core.lua Modules/Events.lua |
diffstat | 4 files changed, 49 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/.pkgmeta Sun Jul 11 09:24:33 2010 -0700 +++ b/.pkgmeta Wed Jul 14 00:28:44 2010 -0700 @@ -39,3 +39,5 @@ - LilSparkysWorkshop manual-changelog: CHANGELOG.txt + +enable-nolib-creation: no
--- a/CHANGELOG.txt Sun Jul 11 09:24:33 2010 -0700 +++ b/CHANGELOG.txt Wed Jul 14 00:28:44 2010 -0700 @@ -1,3 +1,7 @@ +2010-07-14 Asa Ayers <Asa.Ayers@Gmail.com> + +- Fixed Bug #9 - If existing items have 0c invested, increase them all to match the first transaction that changes their price. + 2010-07-11 Asa Ayers <Asa.Ayers@Gmail.com> - Fixed a bug with the mail where items get recorded by the mail scanner and the bag scanner.
--- a/Core.lua Sun Jul 11 09:24:33 2010 -0700 +++ b/Core.lua Wed Jul 14 00:28:44 2010 -0700 @@ -166,15 +166,22 @@ elseif mailType == "CODPayment" then itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end) - results[mailType][itemName] = (results[mailType][itemName] or 0) - msgMoney + results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) + results[mailType][itemName].total = results[mailType][itemName].total - msgMoney elseif mailType == "AHSuccess" then local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); - results[mailType][itemName] = (results[mailType][itemName] or 0) - deposit - buyout + consignment + results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) + results[mailType][itemName].total = results[mailType][itemName].total - deposit - buyout + consignment + elseif mailType == "AHWon" then local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); - results[mailType][itemName] = (results[mailType][itemName] or 0) + bid + results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) + results[mailType][itemName].total = results[mailType][itemName].total + bid + + local count = select(3, GetInboxItem(1,1)) + results[mailType][itemName].count = results[mailType][itemName].count + count elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then -- These should be handled when you pay the deposit at the AH else @@ -185,8 +192,8 @@ end for mailType, collection in pairs(results) do - for item, total in pairs(collection) do - self:Debug(format("|cFF00FF00MailScan|r: %s - %s - %s", mailType, item, total)) + for item, data in pairs(collection) do + self:Debug(format("|cFF00FF00MailScan|r: %s - %s - %s x %s", mailType, item, data.total, data.count)) end end @@ -246,14 +253,15 @@ end end -function addon:SaveValue(link, value) - self:Debug(format("SaveValue(%s, %s)", tostring(link), value)) +function addon:SaveValue(link, value, countChange) + self:Debug("SaveValue(%s, %s, %s)", tostring(link), value, (countChange or 'default')) + countChange = countChange or 0 local item = nil local realLink = self:GetSafeLink(link) local itemName = nil if realLink == nil then + itemName = link self:Debug('SaveValue: GetSafeLink failed, falling back to storing by name: ' .. tostring(itemName)) - itemName = link self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value item = {invested = self.db.factionrealm.item_account[itemName], count = 1} else @@ -263,6 +271,13 @@ itemName = GetItemInfo(realLink) end + if value > 0 and countChange > 0 and item.invested == value and item.count ~= countChange then + local costPerItem = value / countChange + value = costPerItem * item.count + item.invested = value + self:Print("You already owned %s %s with an unknown price, so they have also been updated to %s each", (item.count - countChange), itemName, self:FormatMoney(costPerItem)) + end + if abs(value) > 0 then if item.invested < 0 then if self.db.profile.messages.cost_updates then
--- 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.")