annotate Core.lua @ 94:4ec8611d9466

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