annotate Core.lua @ 143:4d7955b2d240

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