Mercurial > wow > itemauditor
changeset 7:bbba2fae0f69
Removed some of the extra debugging that isn't neccessary any more and abtracted out the item ids so they can be cached.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Tue, 08 Jun 2010 11:19:16 -0700 |
parents | 5dddd73b2220 |
children | 0271e781b154 |
files | Core.lua Modules/Debug.lua Modules/Events.lua Modules/Options.lua Modules/Utils.lua |
diffstat | 5 files changed, 82 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Wed May 26 22:41:47 2010 -0700 +++ b/Core.lua Tue Jun 08 11:19:16 2010 -0700 @@ -62,20 +62,20 @@ for name, count in pairs(current.items) do if pastInventory.items[name] == nil then diff[name] = count - self:Debug("1 diff[" .. name .. "]=" .. diff[name]) + -- self:Debug("1 diff[" .. name .. "]=" .. diff[name]) elseif count - pastInventory.items[name] ~= 0 then diff[name] = count - pastInventory.items[name] - self:Debug("2 diff[" .. name .. "]=" .. diff[name]) + -- self:Debug("2 diff[" .. name .. "]=" .. diff[name]) end end for name, count in pairs(pastInventory.items) do if current.items[name] == nil then diff[name] = -count - self:Debug("3 diff[" .. name .. "]=" .. diff[name]) + -- self:Debug("3 diff[" .. name .. "]=" .. diff[name]) elseif current.items[name] - count ~= 0 then diff[name] = current.items[name] - pastInventory.items[name] - self:Debug("4 diff[" .. name .. "]=" .. diff[name]) + -- self:Debug("4 diff[" .. name .. "]=" .. diff[name]) end end @@ -102,7 +102,7 @@ for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex) if itemName ~= nil then - itemTypes[itemName] = (itemTypes[itemName] or 0) + count + itemTypdes[itemName] = (itemTypes[itemName] or 0) + count end end @@ -141,11 +141,15 @@ item_account[item] = (item_account[item] or 0) + value - self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(item_account[item]) .. "(change: " .. utils:FormatMoney(value) .. ")") + if abs(value) > 0 then + self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(item_account[item]) .. "(change: " .. utils:FormatMoney(value) .. ")") + end - if item_account[item] >= 0 then + if item_account[item] > 0 then self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(0)) item_account[item] = nil + elseif item_account[item] < 0 then + addon:GetItemCost(itemName) end end @@ -176,18 +180,21 @@ local invested = abs(self.db.factionrealm.item_account[itemName] or 0) if invested > 0 then - local _, itemLink = GetItemInfo (itemName); - local _, _, _, _, Id = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") - local count = Altoholic:GetItemCount(tonumber(Id)) - if countModifier ~= nil then - count = count - countModifier + local ItemID = utils:GetItemID(itemName) + if ItemID ~= nil then + local count = Altoholic:GetItemCount(tonumber(ItemID)) + if count == 0 then + self.db.factionrealm.item_account[itemName] = nil + self:Print("You ran out of " .. itemName .. " and never recovered " .. utils:FormatMoney(invested)) + end + + if countModifier ~= nil then + count = count - countModifier + end + if count > 0 then + return ceil(invested), ceil(invested/count), count + end end - if count == 0 then - self.db.factionrealm.item_account[itemName] = nil - self:Print("You ran out of " .. itemName .. "and never recovered " .. utils:FormatMoney(invested)) - return 0, 0, 0 - end - return ceil(invested), ceil(invested/count), count end return 0, 0, 0 end
--- a/Modules/Debug.lua Wed May 26 22:41:47 2010 -0700 +++ b/Modules/Debug.lua Tue Jun 08 11:19:16 2010 -0700 @@ -36,4 +36,4 @@ -DebugEventRegistration() \ No newline at end of file +-- DebugEventRegistration() \ No newline at end of file
--- a/Modules/Events.lua Wed May 26 22:41:47 2010 -0700 +++ b/Modules/Events.lua Tue Jun 08 11:19:16 2010 -0700 @@ -12,6 +12,7 @@ function addon:MAIL_SHOW() self:Debug("MAIL_SHOW") self.lastMailScan = self:ScanMail() + self:UnregisterEvent("MAIL_SHOW") self:RegisterEvent("MAIL_CLOSED") self:RegisterEvent("MAIL_INBOX_UPDATE") @@ -20,6 +21,7 @@ function addon:MAIL_CLOSED() addon:UnregisterEvent("MAIL_CLOSED") + self:MAIL_INBOX_UPDATE() self:UnregisterEvent("MAIL_INBOX_UPDATE") self:RegisterEvent("MAIL_SHOW") end @@ -28,6 +30,7 @@ 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) @@ -75,7 +78,7 @@ end function addon:UpdateAudit() - self:Debug("UpdateAudit") + -- self:Debug("UpdateAudit") local currentInventory = self:GetCurrentInventory() local diff = addon:GetInventoryDiff(self.lastInventory, currentInventory) -- this is only here for debugging @@ -94,9 +97,9 @@ end if diff.money > 0 and utils:tcount(positive) > 0 and utils:tcount(negative) == 0 then - self:Debug("loot") - elseif abs(diff.money) > 0 and utils:tcount(diff.items) == 1 then - self:Debug("purchase or sale") + -- self:Debug("loot") + elseif utils:tcount(diff.items) == 1 then + -- self:Debug("purchase or sale") for itemName, count in pairs(diff.items) do self:SaveValue(itemName, diff.money) @@ -105,7 +108,7 @@ if utils:tcount(positive) > 0 and utils:tcount(negative) > 0 then -- we must have created/converted something - self:Debug("conversion") + -- self:Debug("conversion") local totalChange = 0 for itemName, change in pairs(negative) do local _, itemCost, count = self:GetItemCost(itemName, change) @@ -114,14 +117,9 @@ totalChange = totalChange + abs(itemCost * change) end - self:Debug("totalChange") - self:Debug(totalChange) + local valuePerItem = totalChange / positiveCount - local valuePerItem = totalChange / positiveCount - self:Debug(valuePerItem ) for itemName, change in pairs(positive) do - self:Debug(itemName) - self:Debug(0-abs(valuePerItem * change)) self:SaveValue(itemName, 0-abs(valuePerItem * change)) end end
--- a/Modules/Options.lua Wed May 26 22:41:47 2010 -0700 +++ b/Modules/Options.lua Tue Jun 08 11:19:16 2010 -0700 @@ -37,13 +37,27 @@ LibStub("AceConfig-3.0"):RegisterOptionsTable("ItemAuditor", options, {"ia"}) end +local function pairsByKeys (t, f) + local a = {} + for n in pairs(t) do table.insert(a, n) end + table.sort(a, f) + local i = 0 -- iterator variable + local iter = function () -- iterator function + i = i + 1 + if a[i] == nil then return nil + else return a[i], t[a[i]] + end + end + return iter +end + function addon:DumpInfo() - self:Print("self.db.char") - DevTools_Dump(self.db.char) - self:Print("self.db.factionrealm") - DevTools_Dump(self.db.factionrealm) + for itemName, value in pairsByKeys(self.db.factionrealm.item_account) do + self:Print(itemName .. ": " .. utils:FormatMoney(value)) + end end + function addon:ShowOptionsGUI() InterfaceOptionsFrame_OpenToCategory(self.optionsFrame) end
--- a/Modules/Utils.lua Wed May 26 22:41:47 2010 -0700 +++ b/Modules/Utils.lua Tue Jun 08 11:19:16 2010 -0700 @@ -14,6 +14,35 @@ return prefix .. Altoholic:GetMoneyString(abs(money), WHITE, false) end + -- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called +local item_db = {} + +function addon:ReplaceItemCache(new_cache) + item_db = new_cache +end + +-- This will be reset every session +local tmp_item_cache = {} +function addon:GetItemID(itemName) + if item_db[itemName] ~= nil then + return item_db[itemName] + end + + if tmp_item_cache[itemName] == nil then + local _, itemLink = GetItemInfo (itemName); + if itemLink ~= nil then + local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") + tmp_item_cache[itemName] = tonumber(itemID) + end + end + + return tmp_item_cache[itemName] +end + +function addon:SaveItemID(itemName, id) + item_db[itemName] = tonumber(id) +end + local SubjectPatterns = { AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"),