annotate Core.lua @ 111:1cb0027da35c

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