annotate Core.lua @ 87:26f45b6e8d4d

Removed some debugging code and added some code to prevent ItemAuditor from crashing if debug code gets released.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sun, 08 Aug 2010 07:57:45 -0700
parents 8d5ad3b71f6f
children fab2c4341602
rev   line source
Asa@63 1 local ItemAuditor = select(2, ...)
Asa@63 2 ItemAuditor = LibStub("AceAddon-3.0"):NewAddon(ItemAuditor, "ItemAuditor", "AceEvent-3.0", "AceBucket-3.0")
Asa@65 3 --@debug@
Asa@65 4 _G['ItemAuditor'] = ItemAuditor
Asa@65 5 --@end-debug@
Asa@0 6
Asa@87 7 if not DevTools_Dump then
Asa@87 8 function DevTools_Dump()
Asa@87 9 end
Asa@87 10 end
Asa@87 11
Asa@0 12 local WHITE = "|cFFFFFFFF"
Asa@0 13 local RED = "|cFFFF0000"
Asa@0 14 local GREEN = "|cFF00FF00"
Asa@0 15 local YELLOW = "|cFFFFFF00"
Asa@0 16 local ORANGE = "|cFFFF7F00"
Asa@0 17 local TEAL = "|cFF00FF9A"
Asa@0 18 local GOLD = "|cFFFFD700"
Asa@0 19
Asa@67 20
Asa@67 21 ItemAuditor.Options = {
Asa@67 22 handler = ItemAuditor,
Asa@67 23 name = "ItemAuditor @project-version@",
Asa@67 24 type = 'group',
Asa@67 25 args = {
Asa@67 26 options = {
Asa@67 27 type = "execute",
Asa@67 28 name = "options",
Asa@67 29 desc = "Show Blizzard's options GUI",
Asa@67 30 func = "ShowOptionsGUI",
Asa@67 31 guiHidden = true,
Asa@67 32 },
Asa@67 33 debug = {
Asa@67 34 type = "execute",
Asa@67 35 name = "debug",
Asa@67 36 desc = "Shows the debug frame",
Asa@67 37 func = function() ItemAuditor_DebugFrame:Show() end,
Asa@67 38 guiHidden = true,
Asa@67 39 },
Asa@67 40 suspend = {
Asa@67 41 type = "toggle",
Asa@67 42 name = "suspend",
Asa@67 43 desc = "Suspends ItemAuditor",
Asa@67 44 get = "IsEnabled",
Asa@67 45 set = "SetEnabled",
Asa@67 46 guiHidden = true,
Asa@67 47 },
Asa@67 48 },
Asa@67 49 }
Asa@67 50
Asa@63 51 function ItemAuditor:OnInitialize()
Asa@0 52 local DB_defaults = {
Asa@0 53 char = {
Asa@13 54 ah = 1,
Asa@13 55 use_quick_auctions = false,
Asa@20 56 crafting_threshold = 1,
Asa@20 57 auction_threshold = 0.15,
Asa@71 58 qa_extra = 0,
Asa@55 59 output_chat_frame = nil,
Asa@0 60 },
Asa@16 61 profile = {
Asa@16 62 messages = {
Asa@16 63 cost_updates = true,
Asa@20 64 queue_skip = false,
Asa@23 65 },
Asa@63 66 ItemAuditor_enabled = true,
Asa@70 67 queue_destination = nil,
Asa@72 68 disabled_deciders = {},
Asa@16 69 },
Asa@0 70 factionrealm = {
Asa@8 71 item_account = {},
Asa@8 72 items = {},
Asa@39 73 outbound_cod = {},
Asa@0 74 },
Asa@0 75 }
Asa@0 76 self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true)
Asa@0 77
Asa@67 78 self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ItemAuditor", "ItemAuditor")
Asa@67 79
Asa@67 80 LibStub("AceConfig-3.0"):RegisterOptionsTable("ItemAuditor", ItemAuditor.Options, {"ia"})
Asa@38 81 ItemAuditor:RegisterFrame(ItemAuditor_DebugFrame)
Asa@23 82
Asa@86 83 LibStub("AceConsole-3.0"):RegisterChatCommand('rl', ReloadUI)
Asa@86 84
Asa@65 85 --@debug@
Asa@59 86 -- ItemAuditor_DebugFrame:Show()
Asa@59 87 -- self:CreateFrame('tab_crafting')
Asa@74 88 self:RegisterEvent("TRADE_SKILL_SHOW", function()
Asa@74 89 ItemAuditor:CreateFrame('tab_crafting')
Asa@74 90 end)
Asa@65 91 --@end-debug@
Asa@0 92 end
Asa@0 93
Asa@67 94
Asa@67 95
Asa@38 96 local registeredEvents = {}
Asa@63 97 local originalRegisterEvent = ItemAuditor.RegisterEvent
Asa@63 98 function ItemAuditor:RegisterEvent(event, callback, arg)
Asa@38 99 registeredEvents[event] = true
Asa@38 100 if arg ~= nil then
Asa@38 101 return originalRegisterEvent(self, event, callback, arg)
Asa@38 102 elseif callback ~= nil then
Asa@38 103 return originalRegisterEvent(self, event, callback)
Asa@38 104 else
Asa@38 105 return originalRegisterEvent(self, event)
Asa@38 106 end
Asa@38 107 end
Asa@38 108
Asa@63 109 local originalUnregisterEvent = ItemAuditor.UnregisterEvent
Asa@63 110 function ItemAuditor:UnregisterEvent(event)
Asa@38 111 registeredEvents[event] = nil
Asa@38 112 return originalUnregisterEvent(self, event)
Asa@38 113 end
Asa@38 114
Asa@63 115 function ItemAuditor:UnregisterAllEvents()
Asa@38 116 for event in pairs(registeredEvents) do
Asa@38 117 self:UnregisterEvent(event)
Asa@38 118 end
Asa@38 119 end
Asa@38 120
Asa@38 121 local registeredFrames = {}
Asa@63 122 function ItemAuditor:RegisterFrame(frame)
Asa@38 123 tinsert(registeredFrames, frame)
Asa@38 124 end
Asa@38 125
Asa@63 126 function ItemAuditor:HideAllFrames()
Asa@38 127 for key, frame in pairs(registeredFrames) do
Asa@38 128 if frame then
Asa@38 129 frame:Hide()
Asa@38 130 end
Asa@38 131 end
Asa@38 132 end
Asa@38 133
Asa@63 134 function ItemAuditor:ConvertItems()
Asa@8 135 for itemName, value in pairs(self.db.factionrealm.item_account) do
Asa@15 136 local itemID = self:GetItemID(itemName)
Asa@8 137 if itemID ~= nil then
Asa@8 138 self:GetItem('item:' .. itemID)
Asa@8 139 end
Asa@8 140 if value == 0 then
Asa@8 141 self.db.factionrealm.item_account[itemName] = nil
Asa@8 142 end
Asa@8 143 end
Asa@8 144
Asa@8 145 for link, data in pairs(self.db.factionrealm.items) do
Asa@8 146 if self:GetItem(link).count == 0 or self:GetItem(link).invested == 0 then
Asa@8 147 self:RemoveItem(link)
Asa@8 148 end
Asa@10 149 end
Asa@10 150
Asa@12 151 self:RefreshQAGroups()
Asa@12 152 end
Asa@12 153
Asa@65 154 -- Options doesn't exist when this file is created the first time, so getOptions will
Asa@65 155 -- make one call to :GetModule and return the result and replace itself with a
Asa@65 156 -- function that simply returns the same object. The permanent solution will probably be
Asa@65 157 -- to move :Print to a different module.
Asa@65 158 local function getOptions()
Asa@65 159 local Options = ItemAuditor:GetModule("Options")
Asa@65 160 getOptions = function() return Options end
Asa@65 161 return Options
Asa@65 162 end
Asa@65 163
Asa@24 164 local printPrefix = "|cFFA3CEFFItemAuditor|r: "
Asa@63 165 function ItemAuditor:Print(message, ...)
Asa@24 166 message = format(message, ...)
Asa@65 167 getOptions().GetSelectedChatWindow():AddMessage( printPrefix .. tostring(message))
Asa@16 168 end
Asa@16 169
Asa@81 170 local bankOpen = false
Asa@81 171
Asa@81 172 function ItemAuditor:BankFrameChanged(event)
Asa@81 173 bankOpen = (event == 'BANKFRAME_OPENED')
Asa@81 174 ItemAuditor:UpdateCurrentInventory()
Asa@81 175 end
Asa@81 176
Asa@80 177 local function scanBag(bagID, i)
Asa@80 178 bagSize=GetContainerNumSlots(bagID)
Asa@80 179 for slotID = 0, bagSize do
Asa@80 180 local link= GetContainerItemLink(bagID, slotID);
Asa@80 181 link = link and ItemAuditor:GetSafeLink(link)
Asa@80 182
Asa@80 183 if link ~= nil and i[link] == nil then
Asa@81 184 i[link] = GetItemCount(link, bankOpen);
Asa@80 185 end
Asa@80 186 end
Asa@80 187 end
Asa@80 188
Asa@63 189 function ItemAuditor:GetCurrentInventory()
Asa@8 190 local i = {}
Asa@8 191 local bagID
Asa@8 192 local slotID
Asa@8 193
Asa@8 194 for bagID = 0, NUM_BAG_SLOTS do
Asa@80 195 scanBag(bagID, i)
Asa@8 196 end
Asa@80 197
Asa@81 198 if bankOpen then
Asa@81 199 scanBag(BANK_CONTAINER, i)
Asa@81 200 for bagID = NUM_BAG_SLOTS+1, NUM_BANKBAGSLOTS do
Asa@81 201 scanBag(bagID, i)
Asa@81 202 end
Asa@80 203 end
Asa@80 204
Asa@8 205 return {items = i, money = GetMoney()}
Asa@0 206 end
Asa@0 207
Asa@63 208 function ItemAuditor:GetInventoryDiff(pastInventory, current)
Asa@8 209 if current == nil then
Asa@8 210 current = self:GetCurrentInventory()
Asa@8 211 end
Asa@8 212 local diff = {}
Asa@8 213
Asa@8 214 for link, count in pairs(current.items) do
Asa@8 215 if pastInventory.items[link] == nil then
Asa@8 216 diff[link] = count
Asa@23 217 self:Debug("1 diff[" .. link .. "]=" .. diff[link])
Asa@8 218 elseif count - pastInventory.items[link] ~= 0 then
Asa@8 219 diff[link] = count - pastInventory.items[link]
Asa@23 220 self:Debug("2 diff[" .. link .. "]=" .. diff[link])
Asa@8 221 end
Asa@8 222 end
Asa@8 223
Asa@8 224 for link, count in pairs(pastInventory.items) do
Asa@8 225 if current.items[link] == nil then
Asa@8 226 diff[link] = -count
Asa@23 227 self:Debug("3 diff[" .. link .. "]=" .. diff[link])
Asa@8 228 elseif current.items[link] - count ~= 0 then
Asa@8 229 diff[link] = current.items[link] - pastInventory.items[link]
Asa@23 230 self:Debug("4 diff[" .. link .. "]=" .. diff[link])
Asa@8 231 end
Asa@8 232 end
Asa@8 233
Asa@8 234 local moneyDiff = current.money - pastInventory.money
Asa@23 235 if abs(moneyDiff) > 0 then
Asa@23 236 self:Debug("moneyDiff: " .. moneyDiff)
Asa@23 237 end
Asa@8 238
Asa@8 239 return {items = diff, money = moneyDiff}
Asa@0 240 end
Asa@0 241
Asa@39 242 local inboundCOD = {}
Asa@39 243 local skipMail = {}
Asa@63 244 function ItemAuditor:ScanMail()
Asa@0 245 local results = {}
Asa@39 246 local CODPaymentRegex = gsub(COD_PAYMENT, "%%s", "(.*)")
Asa@39 247
Asa@0 248 for mailIndex = 1, GetInboxNumItems() or 0 do
Asa@39 249 local sender, msgSubject, msgMoney, msgCOD, daysLeft, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex))
Asa@15 250 local mailType = self:GetMailType(msgSubject)
Asa@6 251
Asa@39 252 local mailSignature = msgSubject .. '-' .. msgMoney .. '-' .. msgCOD .. '-' .. daysLeft
Asa@39 253
Asa@6 254 results[mailType] = (results[mailType] or {})
Asa@6 255
Asa@39 256 if skipMail[mailSignature] ~= nil then
Asa@39 257 -- do nothing
Asa@39 258 elseif mailType == "NonAHMail" and msgCOD > 0 then
Asa@6 259 mailType = 'COD'
Asa@6 260 results[mailType] = (results[mailType] or {})
Asa@5 261
Asa@5 262 local itemTypes = {}
Asa@5 263 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do
Asa@5 264 local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex)
Asa@5 265 if itemName ~= nil then
Asa@39 266 itemTypes[itemName] = (itemTypes[itemName] or 0) + count
Asa@5 267 end
Asa@5 268 end
Asa@5 269
Asa@15 270 if self:tcount(itemTypes) == 1 then
Asa@5 271 for itemName, count in pairs(itemTypes) do
Asa@39 272 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
Asa@39 273 results[mailType][itemName].total = results[mailType][itemName].total + msgCOD
Asa@39 274
Asa@39 275 if inboundCOD[mailSignature] == nil then
Asa@39 276 results[mailType][itemName].count = results[mailType][itemName].count + count
Asa@39 277 inboundCOD[mailSignature] = (inboundCOD[mailSignature] or 0) + count
Asa@39 278 else
Asa@39 279 results[mailType][itemName].count = inboundCOD[mailSignature]
Asa@39 280 end
Asa@39 281
Asa@39 282
Asa@5 283 end
Asa@5 284 else
Asa@5 285 self:Debug("Don't know what to do with more than one item type on COD mail.")
Asa@5 286 end
Asa@6 287 elseif mailType == "CODPayment" then
Asa@39 288 -- /dump ItemAuditor.db.factionrealm.outbound_cod
Asa@39 289 self:Debug(msgSubject)
Asa@39 290 self:Debug(CODPaymentRegex)
Asa@39 291 local outboundSubject = select(3, msgSubject:find(CODPaymentRegex))
Asa@39 292 local trackID
Asa@39 293 if outboundSubject ~= nil then
Asa@39 294 self:Debug(outboundSubject)
Asa@45 295 trackID = select(3, outboundSubject:find('[[]IA: (%d*)[]]'))
Asa@39 296
Asa@39 297 if trackID ~= nil then
Asa@45 298 trackID = tonumber(trackID)
Asa@45 299 self:Debug('COD ID: %s', trackID)
Asa@39 300 local cod = self.db.factionrealm.outbound_cod[trackID]
Asa@39 301 if cod == nil then
Asa@39 302 skipMail[mailSignature] = true
Asa@39 303 self:Print("WARNING: {%s} has an invalid ItemAuditor tracking number.", msgSubject)
Asa@39 304 else
Asa@39 305 itemName = trackID .. "|" .. cod['link']
Asa@39 306
Asa@39 307
Asa@39 308 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
Asa@39 309 results[mailType][itemName].total = results[mailType][itemName].total - msgMoney
Asa@39 310 results[mailType][itemName].count = results[mailType][itemName].count - cod.count
Asa@39 311 end
Asa@39 312 end
Asa@39 313 end
Asa@5 314
Asa@39 315 if trackID == nil then
Asa@39 316 skipMail[mailSignature] = true
Asa@39 317 self:Print("WARNING: {%s} is a COD payment but doesn't have an ItemAuditor tracking number.", msgSubject)
Asa@39 318 end
Asa@5 319
Asa@0 320 elseif mailType == "AHSuccess" then
Asa@0 321 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
Asa@26 322 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
Asa@26 323 results[mailType][itemName].total = results[mailType][itemName].total - deposit - buyout + consignment
Asa@26 324
Asa@0 325
Asa@0 326 elseif mailType == "AHWon" then
Asa@0 327 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex);
Asa@26 328 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0})
Asa@26 329 results[mailType][itemName].total = results[mailType][itemName].total + bid
Asa@26 330
Asa@26 331 local count = select(3, GetInboxItem(1,1))
Asa@26 332 results[mailType][itemName].count = results[mailType][itemName].count + count
Asa@5 333 elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then
Asa@0 334 -- These should be handled when you pay the deposit at the AH
Asa@0 335 else
Asa@24 336 -- self:Debug("Unhandled mail type: " .. mailType)
Asa@24 337 -- self:Debug(msgSubject)
Asa@0 338 end
Asa@0 339
Asa@0 340 end
Asa@23 341
Asa@23 342 for mailType, collection in pairs(results) do
Asa@26 343 for item, data in pairs(collection) do
Asa@26 344 self:Debug(format("|cFF00FF00MailScan|r: %s - %s - %s x %s", mailType, item, data.total, data.count))
Asa@23 345 end
Asa@23 346 end
Asa@23 347
Asa@0 348 return results
Asa@0 349 end
Asa@0 350
Asa@82 351 function ItemAuditor:GetItemCount(searchID)
Asa@82 352 local itemCounts = {}
Asa@82 353 local count = 0
Asa@82 354 for _, character in pairs(DataStore:GetCharacters()) do
Asa@82 355 bags, bank = DataStore:GetContainerItemCount(character, searchID)
Asa@82 356
Asa@82 357 count = count + bags + bank
Asa@84 358 + (DataStore:GetAuctionHouseItemCount(character, searchID) or 0)
Asa@84 359 + (DataStore:GetInventoryItemCount(character, searchID) or 0)
Asa@84 360 + (DataStore:GetCurrencyItemCount(character, searchID) or 0)
Asa@82 361 end
Asa@82 362 return count
Asa@82 363 end
Asa@82 364
Asa@63 365 function ItemAuditor:GetItem(link, viewOnly)
Asa@9 366 if viewOnly == nil then
Asa@9 367 viewOnly = false
Asa@9 368 end
Asa@8 369
Asa@9 370 local itemName = nil
Asa@9 371 if self:GetSafeLink(link) == nil then
Asa@9 372 itemName = link
Asa@9 373 else
Asa@9 374 link = self:GetSafeLink(link)
Asa@9 375 itemName = GetItemInfo(link)
Asa@9 376 end
Asa@9 377
Asa@12 378
Asa@9 379 if self.db.factionrealm.item_account[itemName] ~= nil then
Asa@65 380 self.db.factionrealm.items[link] = {
Asa@82 381 count = ItemAuditor:GetItemCount(self:GetIDFromLink(link)),
Asa@8 382 invested = abs(self.db.factionrealm.item_account[itemName] or 0),
Asa@8 383 }
Asa@8 384 self.db.factionrealm.item_account[itemName] = nil
Asa@8 385 end
Asa@8 386
Asa@65 387 if viewOnly == false and self.db.factionrealm.items[link] == nil then
Asa@24 388
Asa@65 389 self.db.factionrealm.items[link] = {
Asa@82 390 count = ItemAuditor:GetItemCount(self:GetIDFromLink(link)),
Asa@9 391 invested = abs(self.db.factionrealm.item_account[itemName] or 0),
Asa@9 392 }
Asa@9 393
Asa@9 394 end
Asa@9 395
Asa@65 396 if self.db.factionrealm.items[link] ~= nil then
Asa@82 397 self.db.factionrealm.items[link].count = ItemAuditor:GetItemCount(self:GetIDFromLink(link))
Asa@45 398
Asa@65 399 if self.db.factionrealm.items[link].invested == nil then
Asa@65 400 self.db.factionrealm.items[link].invested = 0
Asa@45 401 end
Asa@37 402 end
Asa@37 403
Asa@65 404 if viewOnly == true and self.db.factionrealm.items[link] == nil then
Asa@9 405 return {count = 0, invested = 0}
Asa@9 406 elseif viewOnly == true then
Asa@28 407
Asa@65 408 return {count = self.db.factionrealm.items[link].count, invested = self.db.factionrealm.items[link].invested}
Asa@9 409 end
Asa@37 410
Asa@28 411
Asa@28 412
Asa@65 413 return self.db.factionrealm.items[link]
Asa@8 414 end
Asa@8 415
Asa@63 416 function ItemAuditor:RemoveItem(link)
Asa@9 417 self.db.factionrealm.item_account[link] = nil
Asa@9 418 link = self:GetSafeLink(link)
Asa@9 419 if link ~= nil then
Asa@63 420 local item = ItemAuditor:GetItem(link)
Asa@35 421 item.invested = 0
Asa@24 422 else
Asa@24 423 self:Debug('Failed to convert link' .. tostring(link))
Asa@9 424 end
Asa@8 425 end
Asa@8 426
Asa@63 427 function ItemAuditor:SaveValue(link, value, countChange)
Asa@26 428 self:Debug("SaveValue(%s, %s, %s)", tostring(link), value, (countChange or 'default'))
Asa@26 429 countChange = countChange or 0
Asa@9 430 local item = nil
Asa@9 431 local realLink = self:GetSafeLink(link)
Asa@9 432 local itemName = nil
Asa@9 433 if realLink == nil then
Asa@26 434 itemName = link
Asa@23 435 self:Debug('SaveValue: GetSafeLink failed, falling back to storing by name: ' .. tostring(itemName))
Asa@9 436 self.db.factionrealm.item_account[itemName] = (self.db.factionrealm.item_account[itemName] or 0) + value
Asa@9 437 item = {invested = self.db.factionrealm.item_account[itemName], count = 1}
Asa@9 438 else
Asa@23 439
Asa@9 440 item = self:GetItem(realLink)
Asa@9 441 item.invested = item.invested + value
Asa@9 442 itemName = GetItemInfo(realLink)
Asa@9 443 end
Asa@8 444
Asa@26 445 if value > 0 and countChange > 0 and item.invested == value and item.count ~= countChange then
Asa@26 446 local costPerItem = value / countChange
Asa@26 447 value = costPerItem * item.count
Asa@26 448 item.invested = value
Asa@26 449 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))
Asa@26 450 end
Asa@26 451
Asa@7 452 if abs(value) > 0 then
Asa@22 453 if item.invested < 0 then
Asa@16 454 if self.db.profile.messages.cost_updates then
Asa@16 455 self:Print(format("Updated price of %s from %s to %s. %sYou just made a profit of %s.", itemName, self:FormatMoney(item.invested - value), self:FormatMoney(0), GREEN, self:FormatMoney(abs(item.invested))))
Asa@16 456 end
Asa@12 457 self:RemoveItem(link)
Asa@12 458 -- This doesn't work when you mail the only copy of an item you have to another character.
Asa@12 459 --[[
Asa@82 460 elseif item.count == 0 and realLink and ItemAuditor:GetItemCount(self:GetIDFromLink(realLink)) then
Asa@15 461 self:Print("You ran out of " .. itemName .. " and never recovered " .. self:FormatMoney(item.invested))
Asa@12 462 self:RemoveItem(link)
Asa@12 463 ]]
Asa@16 464 else
Asa@16 465 if self.db.profile.messages.cost_updates then
Asa@16 466 self:Print(format("Updated price of %s from %s to %s. (total change:%s)", itemName, self:FormatMoney(item.invested - value), self:FormatMoney(item.invested), self:FormatMoney(value)))
Asa@16 467 end
Asa@12 468 end
Asa@0 469 end
Asa@10 470
Asa@10 471 if realLink ~= nil then
Asa@63 472 ItemAuditor:UpdateQAThreshold(realLink)
Asa@10 473 end
Asa@35 474 UpdateInvestedData()
Asa@10 475 end
Asa@12 476
Asa@0 477
Asa@63 478 function ItemAuditor:WatchBags()
Asa@4 479 if self.watch_handle == nil then
Asa@63 480 ItemAuditor:UpdateCurrentInventory()
Asa@23 481 self.watch_handle = self:RegisterBucketEvent({"BAG_UPDATE", "PLAYER_MONEY"}, 0.3, "UpdateAudit")
Asa@4 482 end
Asa@0 483 end
Asa@0 484
Asa@63 485 function ItemAuditor:UnwatchBags()
Asa@4 486 if self.watch_handle ~= nil then
Asa@4 487 self:UnregisterBucket(self.watch_handle)
Asa@4 488 self.watch_handle = nil
Asa@4 489 end
Asa@0 490 end
Asa@0 491
Asa@9 492
Asa@63 493 function ItemAuditor:GetSafeLink(link)
Asa@9 494 local newLink = nil
Asa@9 495
Asa@24 496 if link and link == string.match(link, '.-:[-0-9]+[:0-9]*') then
Asa@24 497 newLink = link
Asa@24 498 elseif link then
Asa@9 499 newLink = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h")
Asa@9 500 end
Asa@9 501 if newLink == nil then
Asa@9 502 local itemID = self:GetItemID(link)
Asa@9 503 if itemID ~= nil then
Asa@9 504 _, newLink = GetItemInfo(itemID)
Asa@9 505 return self:GetSafeLink(newLink)
Asa@9 506 end
Asa@9 507 end
Asa@9 508 return newLink and string.gsub(newLink, ":0:0:0:0:0:0", "")
Asa@9 509 end
Asa@9 510
Asa@63 511 function ItemAuditor:GetIDFromLink(link)
Asa@9 512 local _, _, _, _, Id = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
Asa@9 513 return tonumber(Id)
Asa@9 514 end
Asa@9 515
Asa@63 516 function ItemAuditor:GetItemCost(link, countModifier)
Asa@9 517 local item = self:GetItem(link, true)
Asa@8 518
Asa@9 519 if item.invested > 0 then
Asa@9 520 local count = item.count
Asa@9 521
Asa@9 522 if countModifier ~= nil then
Asa@9 523 count = count - countModifier
Asa@0 524 end
Asa@9 525 if count > 0 then
Asa@45 526 return ceil(item.invested), ceil(item.invested/count), count
Asa@9 527 end
Asa@9 528
Asa@0 529 end
Asa@82 530 return 0, 0, ItemAuditor:GetItemCount(ItemAuditor:GetIDFromLink(link))
Asa@0 531 end