annotate Core.lua @ 101:53147a647e28

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