annotate Core.lua @ 99:e9b903cf9b33

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