annotate Core.lua @ 86:8d5ad3b71f6f

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