annotate Modules/ArtifactPower.lua @ 135:4979b5cca6de

- Fixed lua error from newly obtained artifacts
author Nenue
date Thu, 25 Jan 2018 20:58:10 -0500
parents 86621c60512b
children 414e37af1b1b
rev   line source
Nenue@97 1 -- Veneer
Nenue@97 2 -- ArtifactPower.lua
Nenue@97 3 -- Created: 1/15/2017 11:44 PM
Nenue@97 4 -- %file-revision%
Nenue@97 5 --
Nenue@97 6
Nenue@97 7 local print = DEVIAN_WORKSPACE and function(...) print('VnAP', ...) end or nop
Nenue@97 8 VeneerArtifactPowerMixin = {
Nenue@99 9 numItems = 0,
Nenue@99 10 Tokens = {},
Nenue@101 11 cache = {},
Nenue@101 12 fishingCache = {},
Nenue@101 13 scanQueue = {},
Nenue@119 14 worldQuestAP = 0,
Nenue@119 15 worldQuestItems = {},
Nenue@99 16 ItemButtons = {},
Nenue@121 17 anchorGroup = 'TOP',
Nenue@122 18 anchorPoint = 'TOPLEFT',
Nenue@116 19 anchorPriority = 3,
Nenue@121 20 anchorFrom = 'BOTTOMLEFT',
Nenue@115 21 moduleName = 'Artifactor',
Nenue@115 22 HideCombat = true
Nenue@97 23 }
Nenue@122 24
Nenue@122 25 VeneerArtifactButtonMixin = {}
Nenue@122 26 local Artifact = VeneerArtifactButtonMixin
Nenue@122 27
Nenue@101 28 local defaultSettings = {
Nenue@101 29 firstUse = true,
Nenue@101 30 autoHide = true,
Nenue@101 31 }
Nenue@116 32 local Module = VeneerArtifactPowerMixin
Nenue@122 33 local BAGS_TO_SCAN = {BACKPACK_CONTAINER}
Nenue@97 34 local TOOLTIP_NAME = 'VeneerAPScanner'
Nenue@123 35 local XP_INSET = 1
Nenue@123 36 local XP_WIDTH = 4
Nick@111 37 local FISHING_MAX_TRAITS = 24
Nenue@116 38 local WEAPON_MAX_TRAITS = 92
Nenue@116 39 local FRAME_PADDING = 4
Nenue@116 40 local EQUIPPED_SIZE = 64
Nick@111 41 local BUTTON_SIZE = 48
Nenue@99 42 local FRAME_LIST = {'ContainerFrame1', 'BankFrame'}
Nenue@99 43 local BAG_FRAMES = {'ContainerFrame1'}
Nenue@129 44 local BANK_FRAMES = {'BankFrame' }
Nenue@129 45 local ZONE_ID_ARGUS = 1184
Nenue@129 46 local ZONE_ID_BROKEN_ISLE = 1007
Nenue@99 47
Nenue@116 48 function Module:OnLoad()
Nenue@97 49 self:RegisterEvent('BAG_UPDATE') -- use to obtain bag IDs to scan
Nenue@97 50 self:RegisterEvent('BAG_UPDATE_DELAYED') -- use to trigger actual scan activity
Nenue@122 51 self:RegisterEvent('BANKFRAME_OPENED') -- bank info available
Nenue@122 52 self:RegisterEvent('BANKFRAME_CLOSED') --
Nenue@122 53 self:RegisterEvent('ARTIFACT_UPDATE') -- visible data change
Nenue@122 54 self:RegisterEvent('ARTIFACT_XP_UPDATE') -- xp for equipped artifact
Nenue@122 55 self:RegisterEvent('PLAYER_REGEN_ENABLED') -- combat
Nenue@122 56 self:RegisterEvent('PLAYER_REGEN_DISABLED') --
Nenue@122 57 self:RegisterEvent('PLAYER_ENTERING_WORLD') -- zone/instance transfer
Nick@108 58 self:RegisterEvent('ITEM_LOCK_CHANGED') -- use to clear bag slot cache data
Nenue@115 59 Veneer:AddHandler(self)
Nenue@97 60 SLASH_VENEER_AP1 = "/vap"
Nenue@97 61 SLASH_VENEER_AP2 = "/veneerap"
Nenue@98 62 SlashCmdList.VENEER_AP = function(arg)
Nenue@98 63 if arg == 'fishing' then
Nenue@98 64 if VeneerData.ArtifactPower.EnableFishing then
Nenue@98 65 VeneerData.ArtifactPower.EnableFishing = nil
Nenue@98 66 else
Nenue@98 67 VeneerData.ArtifactPower.EnableFishing = true
Nenue@98 68 end
Nenue@98 69 self:Print('Show Underlight Angler:', (VeneerData.ArtifactPower.EnableFishing and 'ON' or 'OFF'))
Nenue@98 70 self:Update()
Nick@108 71 elseif arg == 'reset' then
Nick@108 72 if self.db then
Nick@108 73 table.wipe(self.db.cache)
Nick@108 74 table.wipe(self.db.fishingCache)
Nick@108 75 end
Nick@108 76 self:Print('Cache data reset.')
Nick@108 77 self:Update()
Nenue@122 78 elseif arg:match('item') then
Nenue@122 79 print('name', arg:match("^item (%S.+)"))
Nenue@122 80 print('num', arg:match("Hitem:(%d+)"))
Nenue@122 81 local linkOrID = arg:match("item:(%d+)") or arg:match("^item (%S+)")
Nenue@122 82 if linkOrID then
Nenue@122 83 local name, etc = GetItemInfo(linkOrID)
Nenue@122 84 end
Nenue@122 85
Nenue@98 86 else
Nenue@122 87
Nenue@98 88 self:Show()
Nenue@98 89 end
Nenue@97 90 end
Nenue@97 91
Nenue@97 92 self.tooltip = CreateFrame('GameTooltip', TOOLTIP_NAME, self, 'GameTooltipTemplate')
Nenue@99 93
Nenue@97 94
Nenue@97 95 end
Nick@108 96 local ShortNumberString = function (value)
Nenue@122 97 if value >= 1000000000 then
Nenue@122 98
Nenue@122 99 return tostring(floor(value/10000000)/100) .. 'B'
Nenue@122 100 elseif value >= 1000000 then
Nenue@116 101 return tostring(floor(value/100000)/10) .. 'M'
Nenue@116 102 elseif value >= 100000 then
Nick@108 103 return tostring(floor(value/1000)) .. 'k'
Nick@108 104 elseif value >= 1000 then
Nick@108 105 return tostring(floor(value/100)/10) .. 'k'
Nick@108 106 else
Nick@108 107 return value
Nick@108 108 end
Nick@108 109 end
Nenue@97 110
Nenue@102 111
Nenue@102 112 local IsBagnonOpen = function()
Nenue@102 113 return ((BagnonFramebank and BagnonFramebank:IsShown()) or (BagnonFrameinventory and BagnonFrameinventory:IsShown()))
Nenue@102 114 end
Nenue@99 115 local addonCompatibility = {
Nenue@99 116 ['Bagnon'] = {
Nenue@99 117 BagFrames = {'BagnonFrameinventory'},
Nenue@99 118 BankFrames = {'BagnonFramebank'},
Nenue@102 119 FrameMethods = {
Nenue@103 120 ['Hide'] = IsBagnonOpen,
Nenue@103 121 ['Show'] = IsBagnonOpen
Nenue@102 122 },
Nenue@103 123 PostHooks = {},
Nenue@99 124 MethodClass = 'Bagnon',
Nenue@102 125 MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'},
Nenue@102 126
Nenue@99 127 }
Nenue@97 128 }
Nenue@97 129
Nenue@103 130
Nenue@103 131
Nenue@103 132 local queued_hooks = {}
Nenue@103 133 local function CreateHook(...)
Nenue@103 134 if select('#', ...) >= 2 then
Nenue@103 135 tinsert(queued_hooks, {...})
Nenue@103 136 end
Nenue@103 137 if not InCombatLockdown() then
Nenue@103 138 local info = tremove(queued_hooks)
Nenue@103 139 while info do
Nick@111 140 --[[local oFunc = tremove(info, #info)
Nick@111 141 local args = info
Nick@111 142
Nick@111 143 local func = function(...)
Nick@111 144 print('|cFFFF0088Callback:|r', unpack(args))
Nick@111 145
Nick@111 146 oFunc(...)
Nick@111 147 end
Nick@111 148 print('hooking', unpack(info), oFunc, func)
Nick@111 149 hooksecurefunc(unpack(info), func)
Nick@111 150 --]]
Nenue@103 151 hooksecurefunc(unpack(info))
Nenue@103 152 info = tremove(queued_hooks)
Nenue@103 153 end
Nenue@103 154
Nenue@103 155 end
Nenue@103 156 end
Nenue@103 157
Nenue@102 158 local function AddFrameHooks(frame, args)
Nenue@102 159 for funcName, func in pairs(args.FrameMethods) do
Nenue@102 160 print('binding', frame:GetName(), funcName, 'to', tostring(func))
Nenue@103 161 CreateHook(frame, funcName, function()
Nick@111 162 print(frame:GetName(), funcName, 'hook')
Nenue@103 163 VeneerArtifactPower:TryToShow()
Nenue@103 164 end)
Nenue@102 165 end
Nenue@102 166 end
Nenue@102 167 local PENDING_HOOKS = {}
Nenue@119 168 local guid = UnitGUID('player')
Nenue@102 169
Nenue@102 170 local function RegisterInventoryFrame(name, listType, args)
Nenue@102 171 print('register', name, 'as inventory frame type =', (listType == BAG_FRAMES) and 'bags' or 'bank')
Nenue@102 172 tinsert(FRAME_LIST, name)
Nenue@102 173 tinsert(listType, name)
Nenue@102 174 if _G[name] then
Nenue@102 175 AddFrameHooks(_G[name], args)
Nenue@102 176 else
Nenue@102 177 PENDING_HOOKS[name] = args
Nenue@102 178 end
Nenue@102 179 end
Nenue@102 180
Nenue@116 181 function Module:Setup()
Nenue@97 182 print(self:GetName()..':Setup()')
Nenue@119 183 guid = UnitGUID('player')
Nenue@97 184 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings
Nenue@101 185 self.db = VeneerData.ArtifactPower
Nenue@101 186 self.db[guid] = self.db[guid] or {}
Nenue@101 187 self.db.cache = self.db.cache or {}
Nenue@101 188 self.db.fishingCache = self.db.fishingCache or {}
Nenue@101 189
Nenue@101 190 for i, data in pairs(self.cache) do
Nenue@101 191 -- bring in anything found before player data is active
Nenue@101 192 self.db.cache[i] = data
Nenue@101 193 end
Nenue@101 194 for i, data in pairs(self.fishingCache) do
Nenue@101 195 self.db.fishingCache[i] = data
Nenue@101 196 end
Nenue@101 197
Nenue@101 198 self.profile = self.db[guid]
Nick@108 199 self.profile.cache = self.profile.cache or {}
Nick@108 200 self.profile.cache.bagItems = self.profile.cache.bagItems or {}
Nick@108 201 self.profile.cache.bags = self.profile.cache.bags or {}
Nick@108 202 self.profile.cache.fishing = self.profile.cache.fishing or {}
Nick@108 203 self.profile.cache.items = self.profile.cache.items or {}
Nenue@97 204 self.profile.bagslots = self.profile.bagslots or {}
Nenue@97 205 self.profile.artifacts = self.profile.artifacts or {}
Nenue@97 206 self.updateSummary = true
Nick@108 207 self.cache = self.profile.cache
Nenue@97 208
Nenue@101 209 VeneerArtifactPowerTimer:SetScript('OnUpdate', function()
Nenue@101 210 self:OnUpdate()
Nenue@101 211 end)
Nenue@101 212
Nenue@99 213 local DoTryToShow = function()
Nick@111 214
Nenue@99 215 self:TryToShow()
Nenue@99 216 end
Nenue@103 217 CreateHook("OpenBackpack", DoTryToShow)
Nenue@103 218 CreateHook("CloseBackpack", DoTryToShow)
Nenue@99 219
Nenue@97 220 -- Bagnon compatibility
Nenue@97 221 -- todo: ArkInventory, Elv, etc
Nenue@99 222 for addon, args in pairs(addonCompatibility) do
Nenue@99 223 if IsAddOnLoaded(addon) then
Nenue@102 224
Nenue@99 225 for _, name in ipairs(args.BagFrames) do
Nenue@102 226 RegisterInventoryFrame(name, BAG_FRAMES, args)
Nenue@99 227 end
Nenue@99 228 for _, name in ipairs(args.BankFrames) do
Nenue@102 229 RegisterInventoryFrame(name, BANK_FRAMES, args)
Nenue@99 230 end
Nenue@102 231
Nenue@102 232 -- should only specify non-secure functions in this table
Nenue@99 233 for _, name in ipairs(args.PostHooks) do
Nenue@99 234 local oFunc = _G[name]
Nenue@103 235 print('hook entry', name, tostring(oFunc))
Nenue@103 236 CreateHook(name, function(...)
Nenue@103 237 print('|cFFFF0088' .. name .. '|r', ..., 'original', tostring(oFunc))
Nenue@99 238 oFunc(...)
Nenue@99 239 self:TryToShow()
Nenue@103 240 end)
Nenue@99 241 end
Nenue@99 242 local frame = _G[args.MethodClass]
Nenue@99 243 if frame then
Nenue@103 244 print()
Nenue@99 245 for _, name in ipairs(args.MethodHooks) do
Nenue@103 246 CreateHook(frame, name, DoTryToShow)
Nenue@99 247 end
Nenue@97 248 end
Nenue@97 249 end
Nenue@97 250 end
Nenue@101 251
Nenue@101 252 if self.db.firstUse then
Nenue@101 253 self.db.firstUse = nil
Nenue@101 254
Nenue@101 255 end
Nenue@99 256 end
Nenue@97 257
Nenue@97 258 local UNDERLIGHT_ANGLER_ID = 133755
Nenue@97 259
Nenue@116 260 function Module:ResetCache()
Nick@111 261 table.wipe(self.cache.items)
Nick@111 262 table.wipe(self.cache.fishing)
Nick@111 263 table.wipe(self.cache.bags)
Nick@111 264 table.wipe(self.cache.bagItems)
Nick@111 265 self:ScanAllBags()
Nick@111 266 end
Nick@111 267
Nenue@116 268 function Module:QueueBag(containerID)
Nenue@97 269 containerID = tonumber(containerID)
Nenue@97 270 if not containerID then
Nenue@97 271 return
Nenue@97 272 end
Nenue@97 273
Nenue@97 274 if not tContains(BAGS_TO_SCAN, containerID) then
Nenue@97 275 print(' queueing', containerID, type(containerID), #BAGS_TO_SCAN , 'in line')
Nenue@97 276 BAGS_TO_SCAN[#BAGS_TO_SCAN + 1] = containerID
Nenue@97 277 end
Nenue@97 278 end
Nenue@97 279
Nenue@116 280 function Module:Reanchor()
Nenue@99 281 if Veneer then
Nenue@99 282 Veneer:DynamicReanchor()
Nenue@99 283 end
Nenue@99 284 end
Nenue@99 285
Nenue@116 286 function Module:OnShow()
Nenue@99 287 print('|cFFFFFF00OnShow()|r')
Nenue@102 288
Nenue@102 289 for name, args in pairs(PENDING_HOOKS) do
Nenue@102 290 if _G[name] then
Nenue@102 291 AddFrameHooks(_G[name], args)
Nenue@102 292 PENDING_HOOKS[name] = nil
Nenue@102 293 end
Nenue@102 294 end
Nenue@102 295
Nenue@119 296 self:UpdateWorldQuestsAP()
Nenue@119 297 self:RegisterEvent('QUEST_LOG_UPDATE')
Nenue@119 298 self.enabled = true
Nenue@102 299
Nenue@99 300 self:ScanAllBags()
Nenue@99 301 self:Reanchor()
Nenue@97 302 end
Nenue@116 303 function Module:OnHide()
Nick@111 304 print('|cFF88FF00OnHide()|r', debugstack())
Nenue@119 305 self:UnregisterEvent('QUEST_LOG_UPDATE')
Nenue@99 306 self:Reanchor()
Nenue@97 307 end
Nenue@116 308 function Module:OnEnter()
Nenue@97 309
Nenue@97 310 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
Nenue@97 311
Nenue@99 312
Nenue@97 313 GameTooltip:AddLine(self.bagAP)
Nenue@97 314 GameTooltip:AddLine(self.bankAP)
Nenue@97 315
Nenue@97 316 end
Nenue@97 317
Nenue@116 318 function Module:TryToShow()
Nenue@99 319
Nenue@125 320 --print('|cFFFFFF00TryToShow()')
Nenue@99 321
Nenue@99 322 if not InCombatLockdown() then
Nenue@99 323 for _, name in ipairs(FRAME_LIST) do
Nenue@125 324 --print('test:', name, (_G[name] and _G[name]:IsShown()))
Nick@111 325 if _G[name] and _G[name]:IsVisible() then
Nenue@99 326 if self:IsShown() then
Nenue@99 327 self:Update()
Nenue@99 328 else
Nenue@99 329 self:Show()
Nenue@99 330 end
Nenue@99 331 return
Nenue@99 332 end
Nenue@99 333 end
Nenue@99 334 end
Nenue@99 335
Nenue@125 336 --print('failed tests')
Nenue@99 337 self:Hide()
Nenue@99 338 end
Nenue@99 339
Nenue@99 340
Nenue@116 341 function Module:OnEvent(event, ...)
Nenue@125 342 --print('|cFF00FF88OnEvent()', event, ...)
Nenue@99 343 if event == 'PLAYER_ENTERING_WORLD' then
Nenue@99 344 self:TryToShow()
Nenue@99 345 elseif event == 'BAG_UPDATE' then
Nenue@97 346 local containerID = ...
Nenue@97 347 self:QueueBag(containerID)
Nick@108 348 elseif event == 'ITEM_LOCK_CHANGED' then
Nick@108 349
Nick@108 350 local containerID, slotID = ...
Nick@108 351
Nick@108 352 if self.cache.bags[containerID] and self.cache.bags[containerID][slotID] then
Nick@108 353 self.cache.bags[containerID][slotID] = nil
Nick@108 354 self.cache.fishing[containerID][slotID] = nil
Nick@108 355 end
Nick@108 356
Nick@108 357
Nenue@97 358 elseif event == 'PLAYER_BANKSLOTS_CHANGED' then
Nenue@99 359 self:ScanAllBags()
Nenue@97 360 elseif event == 'BAG_UPDATE_DELAYED' then
Nenue@99 361 if not self.firstHit then
Nenue@122 362 -- prevent double call from login
Nenue@99 363 self.firstHit = true
Nenue@99 364 else
Nenue@99 365 self:ScanAllBags()
Nenue@99 366 end
Nenue@97 367 elseif event == 'BANKFRAME_OPENED' then
Nenue@97 368 self.bankAccess = true
Nenue@99 369 self:ScanAllBags()
Nenue@97 370 elseif event == 'BANKFRAME_CLOSED' then
Nenue@99 371 self.bankAccess = nil
Nenue@97 372 elseif event == 'ARTIFACT_UPDATE' then
Nenue@98 373 local newItem = ...
Nenue@98 374 if newItem then
Nenue@98 375 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetArtifactInfo()
Nenue@122 376 self:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 377 --self:ScanAllBags(self.bankAccess)
Nenue@98 378 end
Nenue@125 379 self:UpdateArtifactButtons()
Nenue@98 380 elseif event == 'ARTIFACT_XP_UPDATE' then
Nenue@98 381 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetEquippedArtifactInfo()
Nenue@122 382 self:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 383 --self:ScanAllBags(self.bankAccess)
Nenue@125 384 self:UpdateArtifactButtons()
Nenue@97 385 elseif event == 'PLAYER_REGEN_ENABLED' then
Nenue@103 386
Nenue@103 387 if self.queuedScan then
Nenue@103 388 self:ScanAllBags(self.backAccess)
Nenue@103 389 else
Nenue@103 390 self:TryToShow()
Nenue@97 391 end
Nenue@97 392
Nenue@103 393 if #queued_hooks >= 1 then
Nenue@103 394 CreateHook()
Nenue@103 395 end
Nenue@119 396 elseif event == 'QUEST_LOG_UPDATE' then
Nenue@119 397 self:UpdateWorldQuestsAP()
Nenue@97 398 elseif event == 'PLAYER_REGEN_DISABLED' then
Nenue@97 399 self:Hide()
Nenue@97 400 end
Nenue@97 401 end
Nenue@97 402
Nenue@133 403 local hasShownHeaderTip
Nenue@116 404 function Module:OnUpdate()
Nenue@101 405 if #self.scanQueue >= 1 then
Nenue@101 406 local scanInfo = tremove(self.scanQueue, 1)
Nick@111 407 end
Nick@111 408 if IsShiftKeyDown() then
Nick@111 409 self.Refresh:Show()
Nick@111 410 else
Nick@111 411 self.Refresh:Hide()
Nick@111 412 end
Nenue@101 413
Nenue@133 414 if self.SummaryHeader:IsMouseOver() and self:IsShown() then
Nenue@133 415 if not hasShownHeaderTip then
Nenue@133 416 hasShownHeaderTip = true
Nenue@133 417 GameTooltip:SetOwner(self, 'ANCHOR_BOTTOM')
Nenue@133 418 GameTooltip:AddLine("World Quests")
Nenue@133 419
Nenue@133 420 for zone, data in pairs(self.apQuests) do
Nenue@133 421
Nenue@133 422 if #data >= 1 then
Nenue@133 423 GameTooltip:AddLine(zone)
Nenue@133 424 for i, quest in ipairs(data) do
Nenue@133 425
Nenue@133 426 if IsQuestComplete(quest[1]) then
Nenue@133 427 GameTooltip:AddDoubleLine(quest[2], ShortNumberString(quest[3]), 0.5,0.5,0.5, 0.5,0.5,0.5)
Nenue@133 428 else
Nenue@133 429 GameTooltip:AddDoubleLine(quest[2], ShortNumberString(quest[3]), 1,1,1, 0,1,0)
Nenue@133 430
Nenue@133 431 end
Nenue@133 432
Nenue@133 433 end
Nenue@133 434 end
Nenue@133 435
Nenue@133 436
Nenue@133 437 end
Nenue@133 438
Nenue@133 439 GameTooltip:Show()
Nenue@133 440 end
Nenue@133 441 else
Nenue@133 442 if GameTooltip:IsOwned(self) then
Nenue@133 443 hasShownHeaderTip = nil
Nenue@133 444 GameTooltip:Hide()
Nenue@133 445 end
Nenue@133 446
Nenue@133 447 end
Nenue@133 448
Nenue@133 449
Nenue@101 450 end
Nenue@101 451
Nenue@119 452 function Module:OnMouseDown(button)
Nenue@97 453 self.enabled = nil
Nenue@119 454 if button == 'RightButton' then
Nenue@119 455 self:Hide()
Nenue@119 456 end
Nenue@119 457
Nenue@97 458 end
Nenue@97 459
Nenue@116 460 function Module:Update()
Nenue@97 461 if not self:IsShown() then
Nenue@99 462 print('|cFFFF4400Update()|r')
Nenue@97 463 return
Nenue@97 464 end
Nenue@122 465 print('|cFFFFFF00pdate()|r')
Nenue@122 466
Nenue@122 467 local numButtons = 0
Nenue@122 468 local contentsHeight = 16
Nenue@122 469 local contentsWidth = 400
Nenue@122 470 if self.profile.knowledgeMultiplier then
Nenue@122 471 local artifactsWidth = self:UpdateArtifactButtons()
Nenue@122 472
Nenue@122 473 if artifactsWidth ~= 0 then
Nenue@122 474 contentsHeight = contentsHeight + 64
Nenue@122 475 end
Nenue@122 476
Nenue@122 477 contentsWidth = max(contentsWidth, min(artifactsWidth, 400))
Nenue@122 478
Nenue@122 479 local itemsWidth, itemsHeight = self:UpdateItemButtons()
Nenue@122 480 contentsHeight = contentsHeight + itemsHeight
Nenue@122 481 contentsWidth = max(contentsWidth, itemsWidth)
Nenue@122 482 end
Nenue@122 483
Nenue@122 484
Nenue@97 485
Nenue@97 486 local bankText, bagText
Nenue@101 487 if not self.profile.knowledgeMultiplier then
Nenue@101 488 bankText = '|cFF00FF00Shift-Right-Click an artifact weapon to start building data.'
Nenue@101 489 elseif not (self.bankAP and self.bagAP) then
Nenue@97 490 bankText = '|cFFFF0000Open bank frame to count all AP|r '
Nenue@97 491 else
Nick@111 492
Nick@111 493 if self.bagAP and (self.bagAP > 0) then
Nick@111 494 bankText = 'Inventory: |cFFFFFFFF' .. ShortNumberString(self.bagAP) .. '|r'
Nick@111 495 end
Nick@111 496 if self.bankAP and (self.bankAP > 0) then
Nick@111 497 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFFFFFF00'..ShortNumberString(self.bankAP)..' banked|r'
Nick@111 498 end
Nick@111 499 if self.fishingAP and self.fishingAP > 0 then
Nick@111 500 bankText = (bankText and (bankText .. ' | ') or '') .. '|cFF0088FF' .. ShortNumberString(self.fishingAP) .. ' fishing|r'
Nick@111 501 end
Nick@111 502 end
Nick@111 503
Nenue@119 504 if self.worldQuestAP then
Nenue@119 505 bankText = (bankText and (bankText .. '\n') or '') .. '|cFFFFBB00World Quests:|r |cFFFFFFFF' .. ShortNumberString(self.worldQuestAP) .. ''
Nenue@119 506 end
Nick@111 507
Nenue@129 508 if self.argusAP then
Nenue@129 509 bankText = (bankText and (bankText .. '\n') or '') .. '|cFF88FF00Argus WQ:|r |cFFFFFFFF' .. ShortNumberString(self.argusAP) .. ''
Nenue@129 510 end
Nenue@129 511
Nenue@129 512
Nenue@99 513
Nenue@97 514 self.SummaryHeader:SetText(bankText)
Nenue@122 515 if not self.lastButton then
Nenue@122 516 contentsHeight = contentsHeight + self.SummaryHeader:GetHeight()
Nenue@101 517 end
Nenue@101 518
Nenue@101 519
Nick@111 520 if not self.hasArtifacts then
Nick@111 521 self:SetShown(false)
Nick@111 522 end
Nick@111 523
Nenue@101 524
Nick@108 525 self:SetWidth(contentsWidth)
Nick@108 526 self:SetHeight(contentsHeight)
Nenue@101 527 self:Reanchor()
Nenue@101 528 end
Nenue@101 529
Nenue@133 530 Module.apQuests = {}
Nenue@129 531 function Module:GetContinentAP(mapAreaID)
Nenue@119 532
Nenue@129 533 for zoneIndex = 1, C_MapCanvas.GetNumZones(mapAreaID) do
Nenue@129 534 local zoneMapID, zoneName, zoneDepth, left, right, top, bottom = C_MapCanvas.GetZoneInfo(mapAreaID, zoneIndex);
Nenue@119 535 --print(zoneMapID, zoneName)
Nenue@119 536 if zoneDepth <= 1 then -- Exclude subzones
Nenue@129 537 local taskInfo = C_TaskQuest.GetQuestsForPlayerByMapID(zoneMapID, mapAreaID, (mapAreaID == 1184) and 1 or nil);
Nenue@119 538
Nenue@133 539 self.apQuests[zoneName] = self.apQuests[zoneName] or {}
Nenue@133 540 wipe(self.apQuests[zoneName])
Nenue@133 541
Nenue@119 542 if taskInfo then
Nenue@119 543 for i, info in ipairs(taskInfo) do
Nenue@119 544 local questID = info.questId
Nenue@119 545
Nenue@119 546 local questTitle, factionID, capped = C_TaskQuest.GetQuestInfoByQuestID(questID)
Nenue@133 547 if HaveQuestRewardData(questID) then
Nenue@119 548
Nenue@119 549
Nenue@131 550 for i = 1, GetNumQuestLogRewards(questID) or 0 do
Nenue@119 551 local name, texture, numItems, quality, isUsable, itemID = GetQuestLogRewardInfo(i, questID)
Nenue@119 552 if IsArtifactPowerItem(itemID) then
Nenue@133 553
Nenue@133 554 print(questTitle, HaveQuestRewardData(questID))
Nenue@119 555 local _, link = GetItemInfo(itemID)
Nenue@119 556 if link then
Nenue@119 557 local ap = self:GetItemAP(itemID, link)
Nenue@119 558 --print('ap =', ap)
Nenue@119 559 if ap then
Nenue@133 560
Nenue@133 561 if not IsQuestComplete(questID) then
Nenue@133 562 self.worldQuestAP = self.worldQuestAP + ap
Nenue@133 563 if mapAreaID == ZONE_ID_ARGUS then
Nenue@133 564 self.argusAP = self.argusAP + ap
Nenue@133 565 end
Nenue@129 566 end
Nenue@119 567
Nenue@133 568
Nenue@133 569 tinsert(self.apQuests[zoneName], {questID, questTitle, ap})
Nenue@133 570
Nenue@133 571
Nenue@119 572 end
Nenue@119 573
Nenue@119 574 self.worldQuestItems[itemID] = (self.worldQuestItems[itemID] or 0) + 1
Nenue@119 575 end
Nenue@119 576
Nenue@119 577 --print(self.worldQuestAP)
Nenue@119 578 end
Nenue@119 579
Nenue@119 580 end
Nenue@119 581
Nenue@119 582
Nenue@119 583 else
Nenue@119 584 C_TaskQuest.RequestPreloadRewardData(questID);
Nenue@119 585 self.waitingForQuestRewardData = true
Nenue@119 586 end
Nenue@119 587 end
Nenue@119 588 end
Nenue@119 589 end
Nenue@119 590 end
Nenue@129 591
Nenue@129 592 end
Nenue@129 593
Nenue@129 594 function Module:UpdateWorldQuestsAP()
Nenue@129 595 self.waitingForQuestRewardData = false
Nenue@129 596 self.worldQuestAP = 0
Nenue@129 597 self.argusAP = 0
Nenue@129 598 wipe(self.worldQuestItems)
Nenue@133 599 wipe(self.apQuests)
Nenue@129 600 self:GetContinentAP(ZONE_ID_BROKEN_ISLE)
Nenue@129 601 self:GetContinentAP(ZONE_ID_ARGUS)
Nenue@129 602
Nenue@119 603 end
Nenue@119 604
Nenue@116 605 function Module:UpdateArtifactButtons()
Nenue@101 606
Nenue@97 607 -- Artifact icons, in no particular order
Nenue@99 608 self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo()
Nenue@122 609 self.lastButton = nil
Nick@111 610 self.canAddAP = nil
Nick@111 611 self.canAddFishingAP = nil
Nick@111 612 local hasArtifacts
Nenue@97 613 local numButtons = 0
Nenue@99 614 local lastFrame = self
Nenue@99 615 local fishingID, fishingData
Nenue@98 616 local index, button
Nenue@116 617 local equipped =self.profile.artifacts[self.equippedID]
Nenue@116 618 local buttonsWidth = 0
Nenue@116 619 if equipped then
Nenue@116 620 numButtons = numButtons + 1
Nenue@116 621 button = self.Artifact[numButtons]
Nenue@116 622 button.relativeFrame = self
Nenue@125 623 button:SetItem(self.equippedID, equipped, numButtons, true, nil)
Nenue@125 624
Nenue@122 625 if self.equippedID ~= button.itemID then
Nenue@125 626
Nenue@122 627 hasArtifacts = true
Nenue@122 628 end
Nenue@122 629 lastFrame = button
Nenue@116 630 buttonsWidth = EQUIPPED_SIZE + (FRAME_PADDING * 2)
Nenue@116 631 end
Nenue@97 632 for itemID, artifact in pairs(self.profile.artifacts) do
Nenue@116 633 if (itemID == UNDERLIGHT_ANGLER_ID) then
Nenue@116 634 -- only add if we have fishing AP items and it's not being shown in the equipped slot
Nenue@116 635 if VeneerData.ArtifactPower.EnableFishing and (itemID ~= self.equippedID) then
Nenue@98 636 fishingID = itemID
Nenue@98 637 fishingData = artifact
Nenue@98 638 end
Nenue@97 639
Nick@111 640 if artifact.level < FISHING_MAX_TRAITS then
Nick@111 641 if itemID == self.equippedID then
Nick@111 642 self.canAddFishingAP = true
Nick@111 643 end
Nick@111 644 end
Nenue@98 645 else
Nick@111 646 if artifact.level < WEAPON_MAX_TRAITS then
Nick@111 647 if itemID == self.equippedID then
Nick@111 648 self.canAddAP = true
Nenue@116 649 else
Nenue@116 650
Nenue@116 651 hasArtifacts = true
Nenue@116 652 numButtons = numButtons + 1
Nenue@116 653 button = self.Artifact[numButtons]
Nenue@116 654 button.relativeFrame = lastFrame
Nenue@125 655 button:SetItem(itemID, artifact, numButtons, (self.equippedID == itemID), nil)
Nenue@122 656 lastFrame = button
Nenue@116 657 buttonsWidth = buttonsWidth + lastFrame:GetWidth() + FRAME_PADDING
Nick@111 658 end
Nick@108 659 end
Nenue@97 660 end
Nick@111 661 end
Nenue@97 662
Nenue@122 663 self.lastButton = lastFrame
Nenue@122 664
Nenue@97 665
Nick@108 666 if fishingData and (self.fishingAP and self.fishingAP > 0) then
Nenue@98 667 numButtons = numButtons + 1
Nick@111 668 hasArtifacts = true
Nenue@99 669 local button = self.Artifact[numButtons]
Nenue@99 670 button.relativeFrame = lastFrame
Nick@111 671 button.isFishing = true
Nenue@122 672 button:SetItem(fishingID, fishingData, numButtons, self.equippedID == fishingID)
Nenue@122 673 self.lastButton = button
Nenue@98 674 end
Nenue@97 675
Nick@111 676 self.hasArtifacts = hasArtifacts
Nenue@99 677 for i = numButtons+ 1, #self.Artifact do
Nenue@97 678 print('hide', i)
Nenue@97 679 self.Artifact[i]:Hide()
Nenue@97 680 end
Nenue@97 681
Nenue@122 682 self.SummaryHeader:ClearAllPoints()
Nenue@122 683 if self.lastButton then
Nenue@122 684 self.SummaryHeader:SetPoint('TOPLEFT', self.lastButton, 'TOPRIGHT', 4, -2)
Nenue@122 685 else
Nenue@122 686 self.SummaryHeader:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', 4, 4)
Nenue@122 687 end
Nenue@122 688
Nenue@122 689
Nick@111 690
Nenue@116 691 return buttonsWidth
Nenue@97 692 end
Nenue@97 693
Nenue@99 694
Nenue@116 695 function Module:UpdateItemButtons()
Nenue@99 696 print('|cFF00FFFFUpdateItemButtons()|r')
Nick@111 697
Nick@111 698 local apType
Nick@111 699 if self.canAddFishingAP then
Nick@111 700 apType = true
Nick@111 701 elseif not self.canAddAP then
Nick@111 702 for index, button in ipairs(self.Tokens) do
Nick@111 703 button:Hide()
Nick@111 704 end
Nick@111 705 return 0, 0
Nick@111 706 end
Nick@111 707
Nick@111 708
Nenue@99 709 local lastFrame, upFrame
Nenue@99 710 local numButtons = 0
Nenue@101 711 local buttonsHeight = 0
Nick@108 712 local buttonsWidth = 0
Nick@111 713
Nenue@99 714 for index, button in ipairs(self.Tokens) do
Nick@111 715 if (button.numItems >= 1) and (button.isFishingAP == apType) then
Nenue@99 716 if button.itemName then
Nenue@99 717 self:SetItemAction(button)
Nenue@99 718 end
Nenue@99 719
Nenue@99 720 button:ClearAllPoints()
Nenue@99 721 numButtons = numButtons + 1
Nick@111 722 local col = mod(numButtons,8)
Nenue@99 723 print(index, button:GetID(), button.Icon:GetTexture())
Nenue@99 724 if numButtons == 1 then
Nenue@101 725 button:SetPoint('TOPLEFT', self, 'TOPLEFT', 4, -76)
Nenue@99 726 upFrame = button
Nenue@101 727 buttonsHeight = 52
Nenue@99 728 else
Nick@108 729 if col == 1 then
Nick@108 730 button:SetPoint('TOPLEFT', upFrame, 'BOTTOMLEFT', 0, -2)
Nick@108 731 upFrame = button
Nick@108 732 buttonsHeight = buttonsHeight + 52
Nick@108 733
Nick@108 734 else
Nick@108 735 button:SetPoint('TOPLEFT', lastFrame, 'TOPRIGHT', 2, 0)
Nick@108 736
Nick@108 737 end
Nenue@99 738 end
Nick@111 739
Nenue@99 740 button.Count:SetText(button.numItems)
Nenue@99 741 lastFrame = button
Nenue@99 742 button:Show()
Nenue@99 743 else
Nenue@99 744 button:Hide()
Nenue@99 745 end
Nick@111 746 buttonsWidth = min(numButtons, 8) * (BUTTON_SIZE)
Nick@111 747 end
Nick@111 748
Nick@111 749
Nick@111 750
Nick@111 751 if buttonsWidth ~= 0 then
Nick@111 752 buttonsWidth = buttonsWidth + 8+ ((min(numButtons, 8)-1)*2)
Nenue@99 753 end
Nenue@99 754
Nenue@101 755
Nenue@101 756
Nick@108 757 return buttonsWidth, buttonsHeight
Nenue@99 758 end
Nenue@99 759
Nenue@116 760 function Module:SetItemAction(button, name)
Nenue@99 761 name = name or self.itemName
Nenue@99 762 if InCombatLockdown() then
Nenue@99 763 self.itemName = name
Nenue@99 764 return
Nenue@99 765 else
Nenue@99 766 button:SetAttribute('*type*','item')
Nenue@99 767 button:SetAttribute('*item*', name)
Nenue@99 768 end
Nenue@99 769 end
Nenue@99 770
Nenue@116 771 function Module:GetItemButton(itemID, texture, itemAP, fishing)
Nenue@99 772 print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP)
Nenue@99 773 local button = self.ItemButtons[itemID]
Nenue@101 774
Nenue@99 775 if not button then
Nenue@99 776 button = CreateFrame('Button', 'VeneerAPToken'..itemID, self, 'VeneerItemButton')
Nenue@101 777 button.baseAP = itemAP
Nenue@101 778
Nenue@99 779 button:SetPushedTexture([[Interface\Buttons\UI-Quickslot-Depress]])
Nenue@99 780 button:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]],"ADD")
Nenue@99 781 button:SetID(itemID)
Nenue@99 782 button.numItems = 0
Nenue@99 783 button.Icon:SetTexture(texture)
Nenue@99 784 button:RegisterForClicks("AnyUp")
Nick@111 785 button.isFishingAP = fishing
Nenue@99 786 self:SetItemAction(button, GetItemInfo(itemID))
Nenue@99 787
Nenue@99 788 print(' created')
Nenue@99 789 self.ItemButtons[itemID] = button
Nenue@99 790 self.numItems = self.numItems + 1
Nenue@99 791 end
Nenue@99 792
Nenue@116 793 button.Label:SetText(ShortNumberString(itemAP))
Nenue@101 794
Nenue@99 795 button.numItems = button.numItems + 1
Nenue@99 796 return button
Nenue@99 797 end
Nenue@99 798
Nenue@116 799 function Module:GetItemAP(itemID, itemLink, bagData)
Nick@108 800 if not self.cache.items[itemID] then
Nenue@101 801
Nick@111 802 print('doing tooltip scan', itemLink, itemID)
Nenue@101 803 self.tooltip:SetOwner(self, 'ANCHOR_NONE')
Nenue@101 804 self.tooltip:SetHyperlink(itemLink)
Nenue@101 805 self.tooltip:Show()
Nenue@101 806 local numLines = self.tooltip:NumLines()
Nenue@101 807 if numLines >= 3 then
Nenue@101 808 for i = 3, numLines do
Nenue@101 809 local text = _G[TOOLTIP_NAME .. 'TextLeft'.. i]:GetText()
Nick@111 810 if text then
Nick@111 811
Nick@111 812 text = text:lower():gsub(',', '')
Nenue@116 813
Nick@111 814 if text:match('equipped artifact') then
Nick@111 815 print(itemLink, '-', tonumber(text))
Nenue@116 816
Nenue@116 817 local itemAP = text:match('[%d%.]+')
Nick@111 818 if itemAP then
Nenue@116 819 -- tokens > 1M are described as '%f million'
Nenue@116 820 if text:match("million") then
Nenue@116 821 itemAP = tonumber(itemAP) * 1000000
Nenue@129 822 elseif text:match("billion") then
Nenue@129 823 itemAP = tonumber(itemAP) * 1000000000
Nenue@116 824 end
Nenue@116 825
Nick@111 826 itemAP = itemAP
Nick@111 827 self.cache.items[itemID] = tonumber(itemAP)
Nick@111 828 end
Nick@111 829 end
Nick@111 830 if text:match('fishing artifact') then
Nick@111 831 local fishingAP = text:match("%d+")
Nick@111 832 fishingAP = fishingAP
Nick@111 833 print(itemLink, 'fishing', tonumber(text))
Nick@111 834 if fishingAP then
Nick@111 835 self.cache.items[itemID] = tonumber(fishingAP)
Nick@111 836 self.cache.fishing[itemID] = true
Nick@111 837 end
Nenue@101 838 end
Nenue@101 839 end
Nenue@101 840 end
Nenue@101 841 else
Nenue@101 842
Nick@108 843 self.cache.items[itemID] = 0
Nenue@101 844 end
Nenue@101 845 end
Nick@108 846 return self.cache.items[itemID], self.cache.fishing[itemID]
Nenue@101 847 end
Nenue@101 848
Nenue@122 849 function Module:UpdateArtifact(itemID, name, texture, currentXP, pointsSpent)
Nenue@122 850 print('|cFF00FF00UpdateArtifact()|r')
Nenue@103 851 if not self.profile then
Nenue@103 852 return
Nenue@103 853 end
Nenue@103 854 local artifacts = self.profile.artifacts
Nenue@103 855
Nenue@103 856 if itemID then
Nenue@103 857
Nenue@103 858 artifacts[itemID] = artifacts[itemID] or {}
Nenue@103 859 table.wipe(artifacts[itemID])
Nenue@103 860 local artifact = artifacts[itemID]
Nenue@103 861
Nenue@103 862 artifact.name = name
Nenue@103 863 artifact.texture = texture
Nenue@103 864 artifact.currentXP = currentXP
Nenue@103 865 artifact.level = pointsSpent
Nenue@116 866 artifact.tier = C_ArtifactUI.GetArtifactTier() or ((pointsSpent >= 36) and 2 or 1)
Nenue@122 867 artifact.itemID = itemID
Nenue@116 868
Nenue@116 869 print('tier', artifact.tier)
Nenue@116 870 local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent, artifact.tier)
Nick@108 871 artifact.currentCost = cost
Nenue@125 872 end
Nenue@103 873
Nenue@125 874 local equippedID = C_ArtifactUI:GetEquippedArtifactInfo()
Nenue@125 875 self.currentEquipped = equippedID
Nenue@103 876 end
Nenue@103 877
Nenue@116 878 function Module:ScanBag(id)
Nenue@97 879 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id))
Nenue@97 880 local numSlots = GetContainerNumSlots(id)
Nenue@97 881 local requiresUpdate
Nenue@97 882 if numSlots == 0 then
Nenue@97 883 return nil
Nenue@97 884 end
Nenue@97 885
Nenue@97 886
Nenue@97 887 self.profile.bagslots[id] = self.profile.bagslots[id] or {}
Nenue@97 888 table.wipe(self.profile.bagslots[id])
Nenue@97 889 local bagData = self.profile.bagslots[id]
Nenue@97 890 bagData.totalAP = 0
Nenue@99 891 bagData.fishingAP = 0
Nenue@99 892 bagData.items = bagData.items or {}
Nenue@99 893 table.wipe(bagData.items)
Nick@111 894 local c = self.cache
Nenue@99 895
Nick@111 896 c.bagItems[id] = c.bagItems[id] or {}
Nick@111 897 c.bags[id] = c.bags[id] or {}
Nick@111 898 c.fishing[id] = c.fishing[id] or {}
Nick@108 899
Nenue@97 900 for slotID = 1, numSlots do
Nenue@97 901 local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(id, slotID)
Nenue@101 902 if link then
Nenue@101 903 local itemID = GetContainerItemID(id, slotID)
Nenue@101 904 local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link)
Nenue@97 905
Nick@111 906 if class == 'Consumable' or subclass == 'Cooking' then
Nenue@102 907 --print(GetItemInfo(link))
Nick@108 908 local itemAP, isFishingAP
Nick@111 909 if c.bags[id][slotID] and (c.bagItems[id][slotID] == itemID) then
Nick@111 910 --print('cached slot', id, slotID, name)
Nick@111 911 itemAP = c.bags[id][slotID]
Nick@111 912 isFishingAP = c.fishing[id] and c.fishing[id][slotID]
Nick@108 913 else
Nick@108 914 itemAP, isFishingAP = self:GetItemAP(itemID, link)
Nick@111 915 c.bagItems[id][slotID] = itemID
Nick@111 916 c.bags[id][slotID] = itemAP
Nick@111 917 c.fishing[id][slotID] = isFishingAP
Nick@108 918 end
Nick@108 919
Nick@108 920
Nenue@102 921 --print(itemAP, isFishingAP)
Nenue@102 922 if itemAP and (itemAP > 0) then
Nick@111 923 local itemButton = self:GetItemButton(itemID, texture, itemAP, isFishingAP)
Nenue@102 924
Nenue@101 925 if isFishingAP then
Nenue@101 926 bagData.fishingItems = (bagData.fishingItems or 0) + 1
Nenue@101 927 bagData.fishingAP = (bagData.fishingAP or 0) + itemAP
Nenue@101 928 else
Nick@108 929 itemAP = itemAP
Nenue@101 930 bagData.numItems = (bagData.numItems or 0) + 1
Nenue@101 931 bagData.totalAP = (bagData.totalAP or 0) + itemAP
Nenue@101 932 end
Nenue@101 933 bagData.items[itemID] = (bagData.items[itemID] or 0) + 1
Nenue@101 934 end
Nenue@101 935 elseif self.profile.artifacts[itemID] then
Nick@111 936 --print('artifact weapon', itemID, link, id, slotID)
Nenue@101 937 self.profile.artifacts[itemID].containerID = id
Nenue@101 938 self.profile.artifacts[itemID].slotID = slotID
Nick@111 939 else
Nick@111 940 --print('skipping', class, subclass, link)
Nenue@101 941 end
Nenue@99 942
Nenue@97 943 end
Nenue@97 944
Nenue@97 945 end
Nenue@97 946
Nenue@97 947 end
Nenue@97 948
Nenue@98 949 local BAG_SLOTS = {0, 1, 2, 3, 4 }
Nenue@98 950 local BANK_SLOTS = {-1, 5, 6,7, 8, 9, 10, 11, 12}
Nenue@99 951 local ItemCounts = {}
Nenue@116 952 function Module:ScanAllBags()
Nenue@99 953 if InCombatLockdown() then
Nenue@99 954 self.queuedScan = true
Nenue@99 955 return
Nenue@99 956 end
Nenue@101 957 if not self.profile.knowledgeMultiplier then
Nenue@101 958 print('need to get knowledge level')
Nenue@101 959 return
Nenue@101 960 end
Nenue@101 961
Nenue@99 962 self.queuedScan = nil
Nenue@98 963
Nenue@101 964 print('|cFFFF0088ScanAllBags()|r', self.profile.knowledgeMultiplier)
Nenue@97 965
Nenue@99 966 for _, button in ipairs(self.Tokens) do
Nenue@99 967 button.numItems = 0
Nenue@99 968 end
Nenue@99 969
Nenue@99 970
Nenue@98 971 for _, bagID in ipairs(BAG_SLOTS) do
Nenue@98 972 self:ScanBag(bagID)
Nenue@97 973 end
Nenue@97 974
Nenue@99 975 if self.bankAccess then
Nenue@98 976 for _, bagID in ipairs(BANK_SLOTS) do
Nenue@98 977 self:ScanBag(bagID)
Nenue@98 978 end
Nenue@98 979 end
Nenue@98 980
Nenue@125 981
Nenue@125 982
Nenue@98 983 self.bankAP = 0
Nenue@98 984 self.bagAP = 0
Nenue@99 985 self.fishingAP = 0
Nenue@99 986
Nenue@99 987 table.wipe(ItemCounts)
Nenue@98 988 for id, bagData in pairs(self.profile.bagslots) do
Nick@111 989 print(id, GetBagName(id), bagData.totalAP, bagData.fishingAP)
Nenue@98 990 id = tonumber(id)
Nenue@98 991 if bagData.totalAP then
Nenue@98 992 if (id == BANK_CONTAINER) or (id >= 5) then
Nenue@98 993 self.bankAP = self.bankAP + bagData.totalAP
Nenue@98 994 else
Nenue@98 995 self.bagAP = self.bagAP + bagData.totalAP
Nenue@97 996 end
Nenue@98 997 end
Nenue@99 998 if bagData.fishingAP then
Nenue@99 999 self.fishingAP = self.fishingAP + bagData.fishingAP
Nenue@99 1000 end
Nenue@97 1001
Nenue@97 1002 end
Nenue@98 1003 self.lastUpdate = GetTime()
Nenue@103 1004 self.queuedScan = nil
Nenue@99 1005 self:TryToShow()
Nenue@97 1006 end
Nenue@97 1007
Nenue@98 1008
Nenue@122 1009 function Artifact:SetItem(itemID, artifact, index, equipped, fishing)
Nenue@122 1010 print('|cFF00FFFFSetItem()|r', itemID, index)
Nenue@98 1011 print(artifact.name, artifact.texture, artifact.currentXP)
Nenue@122 1012
Nick@108 1013 if not artifact.currentCost then
Nick@108 1014 artifact.currentCost = artifact.cost
Nick@108 1015 end
Nick@108 1016
Nenue@98 1017 for k,v in pairs(artifact) do
Nenue@98 1018 --print('::',k,v)
Nenue@98 1019 self[k] = v
Nenue@98 1020 end
Nenue@98 1021
Nick@111 1022 self.isFishing = fishing
Nenue@98 1023 -- this can change between artifact parses
Nenue@117 1024 local unusedXP = (itemID ~= UNDERLIGHT_ANGLER_ID) and ((self:GetParent().bankAP or 0) + (self:GetParent().bagAP or 0)) or (self:GetParent().fishingAP or 0)
Nenue@117 1025 print('unspent:', unusedXP)
Nenue@99 1026
Nenue@117 1027 -- current standing artifact XP (what appears in the artifact ui)
Nenue@117 1028 -- actual artifact XP after any unlocked points are spent
Nenue@117 1029 -- total total of invested and inventory XP
Nenue@117 1030 -- totalCost total of costs between current and actual level
Nenue@117 1031 local actualXP = artifact.currentXP
Nenue@116 1032 local actualLevel = artifact.level
Nenue@116 1033 local actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
Nenue@116 1034
Nenue@117 1035 print('tier:', artifact.tier)
Nenue@117 1036 print('current:', self.level, self.currentXP, '/', self.currentCost)
Nenue@131 1037 while (actualXP >= actualCost) and (actualCost > 0) do
Nenue@116 1038 actualXP = actualXP - actualCost
Nenue@116 1039 actualLevel = actualLevel + 1
Nenue@116 1040 actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
Nenue@117 1041
Nenue@117 1042 print('* ', actualLevel, actualXP, actualCost, totalCost)
Nenue@98 1043 end
Nenue@117 1044 print('actual:', actualLevel, actualXP, '/', actualCost)
Nenue@117 1045
Nenue@117 1046
Nenue@123 1047 local totalXP = actualXP + unusedXP
Nenue@123 1048 local totalCost = actualCost
Nenue@123 1049 local totalLevel = actualLevel
Nenue@123 1050
Nenue@123 1051 local remaining = totalXP
Nenue@120 1052 local nextCost = artifact.currentCost
Nenue@123 1053 print(totalXP, totalCost)
Nenue@120 1054 if remaining > nextCost then
Nenue@131 1055 while (remaining >= nextCost) and (nextCost > 0) do
Nenue@117 1056 totalLevel = totalLevel + 1
Nenue@119 1057 remaining = remaining - nextCost
Nenue@117 1058 nextCost = C_ArtifactUI.GetCostForPointAtRank(totalLevel, artifact.tier)
Nenue@119 1059 print('|cFFFFFF00+ ', totalLevel, remaining, '/', totalCost)
Nenue@117 1060 end
Nenue@119 1061 totalXP = remaining
Nenue@119 1062 totalCost = nextCost
Nenue@117 1063 end
Nenue@117 1064 print('total:', totalLevel, totalXP, '/', totalCost)
Nenue@117 1065
Nenue@117 1066 self.currentLevel = self.level
Nenue@117 1067
Nenue@117 1068
Nenue@116 1069 self.actualCost = actualCost
Nenue@116 1070 self.actualLevel = actualLevel
Nenue@116 1071 self.actualXP = actualXP
Nenue@117 1072
Nenue@117 1073 self.totalXP = totalXP
Nenue@117 1074 self.totalCost = totalCost
Nenue@117 1075 self.totalLevel = totalLevel
Nenue@117 1076
Nenue@98 1077
Nenue@98 1078
Nenue@99 1079 if index ~= 1 then
Nenue@99 1080 self:ClearAllPoints()
Nenue@99 1081 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPRIGHT', 4, 0)
Nenue@99 1082 else
Nenue@99 1083 self:ClearAllPoints()
Nenue@99 1084 self:SetPoint('TOPLEFT', self.relativeFrame, 'TOPLEFT', 4, -4)
Nenue@99 1085 end
Nenue@98 1086
Nenue@122 1087 self.itemID = itemID
Nenue@99 1088 self.isEquipped = equipped
Nenue@98 1089 self:Update()
Nenue@125 1090 self:SetShown(true)
Nenue@122 1091
Nenue@98 1092 return self
Nenue@98 1093 end
Nenue@98 1094
Nenue@122 1095 function Artifact:UpdateXPBar()
Nenue@122 1096 local r3, g3, b3 = 1, .5, 0 -- main xp bar
Nenue@122 1097 -- current: amount shown in blizz ui
Nenue@122 1098 -- actual: amount contributing the next level, will be same until current point cap is reached
Nenue@122 1099 -- potential: total of ap on hand
Nenue@122 1100 print(self.currentXP, self.actualXP, self.potentialXP)
Nenue@122 1101
Nenue@123 1102 local maxHeight = self:GetHeight() - (XP_INSET*2)
Nenue@122 1103 local currentHeight = self.CurrentProgress:GetHeight() or 1
Nenue@122 1104 local offHeight = self.AdjustedProgress:GetHeight() or 1
Nenue@122 1105
Nenue@122 1106
Nenue@129 1107 self.CurrentProgress:SetPoint('BOTTOM', self.XPBackground, 'BOTTOM', 0, 0)
Nenue@122 1108 local currentProgress = (self.currentXP < self.currentCost) and (self.currentXP / self.currentCost) or 1
Nenue@122 1109 local projectedProgress = (self.totalXP < self.totalCost) and (self.totalXP / self.totalCost) or 1
Nenue@122 1110 if self.actualLevel ~= self.level then
Nenue@122 1111 r3, g3, b3 = 0, 1, 1
Nenue@122 1112 end
Nenue@122 1113
Nenue@123 1114 print('|cFFFF4400', currentProgress, projectedProgress, self.currentLevel, self.totalLevel)
Nenue@122 1115 if self.level <= WEAPON_MAX_TRAITS then
Nenue@122 1116 self.CurrentProgress.animateFrom = currentHeight or 1
Nenue@122 1117 self.CurrentProgress.animateTo = currentProgress * maxHeight
Nenue@122 1118 self.CurrentProgress:Show()
Nenue@122 1119 else
Nenue@122 1120 self.CurrentProgress:Hide()
Nenue@122 1121 end
Nenue@122 1122
Nenue@123 1123 local nextLevel = (self.totalLevel ~= self.currentLevel)
Nenue@123 1124
Nenue@123 1125 if self.totalXP ~= self.currentXP or nextLevel then
Nenue@123 1126 print('project', 'xp test=', (self.totalXP ~= self.currentXP), 'lvl test=', (self.totalLevel ~= self.currentLevel))
Nenue@123 1127
Nenue@123 1128 local projectedPos = projectedProgress
Nenue@123 1129
Nenue@123 1130 if projectedProgress > currentProgress and (not nextLevel) then
Nenue@123 1131 projectedPos = (projectedProgress - currentProgress)
Nenue@123 1132 self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP', 0, 0)
Nenue@123 1133 print(' set above', projectedPos, self.CurrentProgress:GetPoint(3))
Nenue@122 1134 else
Nenue@123 1135 self.AdjustedProgress:SetPoint('BOTTOM', self, 'BOTTOM', 0 , XP_INSET)
Nenue@123 1136 print(' set under', projectedPos)
Nenue@122 1137 end
Nenue@122 1138 self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1
Nenue@123 1139 self.AdjustedProgress.animateTo = projectedPos * maxHeight
Nenue@122 1140 self.AdjustedProgress:Show()
Nenue@122 1141 else
Nenue@123 1142 print('nothing to project')
Nenue@122 1143 self.AdjustedProgress:Hide()
Nenue@122 1144 end
Nenue@123 1145
Nenue@123 1146
Nenue@122 1147 --print(self.CurrentProgress:GetPoint(3))
Nenue@122 1148 --print(self.CurrentProgress:GetSize())
Nenue@122 1149
Nenue@123 1150 self.XPBackground:SetPoint('BOTTOMLEFT', self, 'BOTTOMLEFT', XP_INSET, XP_INSET)
Nenue@123 1151 self.XPBackground:SetPoint('TOPRIGHT', self, 'TOPLEFT', XP_INSET + XP_WIDTH, -XP_INSET)
Nenue@122 1152 self.CurrentProgress:SetColorTexture(r3,g3,b3,1)
Nenue@122 1153
Nenue@122 1154 end
Nenue@122 1155
Nenue@122 1156 function Artifact:OnLoad()
Nenue@122 1157 print('|cFFFF4400OnLoad()|r', self:GetName(), self:GetID())
Nenue@122 1158 end
Nenue@122 1159
Nenue@116 1160 function Artifact:Update()
Nenue@122 1161 if not self.itemID then
Nenue@122 1162 return
Nenue@122 1163 end
Nenue@122 1164
Nenue@125 1165 print(self:GetName(), '|cff00FFFFUpdate()|r')
Nenue@122 1166 local r1, g1, b1 = 1, 1, 1 -- top text
Nenue@122 1167 local r2, g2, b2 = 1, 1, 0 -- bottom text
Nenue@99 1168 local levelText = self.level
Nenue@116 1169 local xpText = ShortNumberString(self.currentXP)
Nenue@116 1170 local costText = ShortNumberString(self.currentCost)
Nenue@116 1171 local remainingText = ShortNumberString(self.currentCost - self.currentXP)
Nenue@122 1172
Nenue@122 1173 local maxHeight = self:GetHeight() - 4
Nenue@122 1174 local currentHeight = self.CurrentProgress:GetHeight() or 1
Nenue@122 1175 local offHeight = self.AdjustedProgress:GetHeight() or 1
Nenue@122 1176
Nenue@97 1177 if self.actualLevel ~= self.level then
Nenue@116 1178 levelText = self.actualLevel
Nenue@116 1179 r1, g1, b1 = 0, 1, 0
Nenue@116 1180 xpText = ShortNumberString(self.actualXP)
Nenue@116 1181 costText = ShortNumberString(self.actualCost)
Nenue@116 1182 remainingText = ShortNumberString(self.actualCost-self.actualXP)
Nenue@116 1183 --[[elseif self.potentialLevel ~= self.level then
Nenue@116 1184 r1, g1, b1 = 0, 1, 1
Nenue@116 1185 r2, g2, b2 = 0, 1, 1
Nenue@116 1186 costText = ShortNumberString(self.potentialCost)
Nenue@116 1187 remainingText = ShortNumberString(self.potentialCost-self.potentialXP)
Nenue@116 1188 --]]
Nenue@97 1189 end
Nenue@97 1190
Nenue@99 1191 self.Level:SetText(levelText)
Nenue@116 1192 self.CurrentXP:SetText( xpText )
Nenue@116 1193 self.RemainingCost:SetText(remainingText)
Nenue@116 1194 self.Level:SetTextColor(r1, g1, b1)
Nenue@116 1195 self.CurrentXP:SetTextColor(r1, g1, b1)
Nenue@99 1196
Nenue@97 1197 if self.isEquipped then
Nenue@116 1198 self:SetSize(64,64)
Nenue@97 1199 self:SetNormalTexture([[Interface\Buttons\ButtonHilight-Square]])
Nenue@97 1200 self:GetNormalTexture():SetBlendMode('ADD')
Nenue@97 1201 self:GetNormalTexture():SetVertexColor(0,1,0)
Nenue@97 1202 else
Nenue@116 1203 self:SetSize(48,48)
Nenue@97 1204 self:SetNormalTexture(nil, 'ADD')
Nenue@97 1205 end
Nenue@97 1206
Nenue@122 1207 self:UpdateXPBar()
Nenue@116 1208
Nenue@117 1209 if self.actualLevel ~= self.currentLevel then
Nenue@117 1210 self:SetNormalTexture([[Interface\Buttons\UI-Quickslot-Depress]], 'ADD')
Nenue@117 1211 self:GetNormalTexture():SetBlendMode('BLEND')
Nenue@117 1212 self:GetNormalTexture():SetVertexColor(1,1,1)
Nenue@117 1213 else
Nenue@117 1214 self:SetNormalTexture(nil, 'ADD')
Nenue@117 1215 end
Nenue@97 1216 self.Icon:SetTexture(self.texture)
Nenue@97 1217 end
Nenue@97 1218
Nenue@119 1219 local XP_SCALING_DURATION = .5
Nenue@116 1220 function Artifact:AnimateProgress(region)
Nenue@98 1221 local cTime = GetTime()
Nenue@98 1222 if not region.animateStart then
Nenue@98 1223 region.animateStart = cTime
Nenue@98 1224 end
Nenue@98 1225 local progressTo, progressFrom = region.animateTo, region.animateFrom
Nenue@98 1226 local elapsed = cTime - region.animateStart
Nenue@119 1227 if elapsed >= XP_SCALING_DURATION then
Nenue@98 1228 region:SetHeight(progressTo)
Nenue@98 1229 region.animateTo = nil
Nenue@98 1230 region.animateStart = nil
Nenue@98 1231 region.animateFrom = nil
Nenue@98 1232 else
Nenue@119 1233 local progress = elapsed / XP_SCALING_DURATION
Nenue@98 1234 local height = (progressFrom + (progressTo - progressFrom) * progress)
Nenue@98 1235 --print(self:GetName(), progressTo, progressFrom, (progressTo - progressFrom), ceil(progress*10)/10, ceil(height))
Nenue@98 1236 region:SetHeight(height)
Nenue@98 1237 end
Nenue@98 1238 end
Nenue@98 1239
Nenue@116 1240 function Artifact:OnUpdate(sinceLast)
Nenue@98 1241 if self.CurrentProgress.animateTo then
Nenue@98 1242 self:AnimateProgress(self.CurrentProgress)
Nenue@98 1243 end
Nenue@98 1244
Nenue@98 1245 if self.AdjustedProgress.animateTo then
Nenue@98 1246 self:AnimateProgress(self.AdjustedProgress)
Nenue@98 1247 end
Nenue@98 1248 end
Nenue@98 1249
Nenue@116 1250 function Artifact:OnEnter()
Nenue@97 1251 GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
Nenue@97 1252 GameTooltip:SetText(self.name)
Nenue@119 1253 GameTooltip:AddLine(ShortNumberString(self.currentXP) .. ' / '..ShortNumberString(self.currentCost), 1, 1, 1)
Nenue@99 1254 if self.actualLevel ~= self.level then
Nenue@119 1255 GameTooltip:AddLine(ShortNumberString(self.actualLevel - self.level) .. ' points unlocked', 1, 1, 0)
Nick@108 1256 end
Nick@108 1257 if self.currentXP < self.currentCost then
Nenue@117 1258 GameTooltip:AddLine(ShortNumberString(self.currentCost - self.currentXP) .. ' for level ' .. (self.currentLevel+1), 1, 1, 0)
Nenue@117 1259 else
Nenue@117 1260 GameTooltip:AddLine(ShortNumberString(self.actualCost - self.actualXP) .. ' for level ' .. (self.actualLevel+1), 0, 1, 0)
Nenue@117 1261 end
Nenue@117 1262 if self.totalLevel ~= self.actualLevel then
Nenue@117 1263 GameTooltip:AddLine('Level ' .. self.totalLevel .. ' with unspent tokens', 0, 1, 1)
Nenue@99 1264 end
Nenue@99 1265
Nenue@97 1266 GameTooltip:Show()
Nenue@97 1267 end
Nenue@116 1268 function Artifact:OnLeave()
Nenue@97 1269 if GameTooltip:IsOwned(self) then
Nenue@97 1270 GameTooltip:Hide()
Nenue@97 1271 end
Nenue@97 1272 end
Nenue@116 1273 function Artifact:OnHide()
Nick@108 1274
Nick@108 1275 if GameTooltip:IsOwned(self) then
Nick@108 1276 GameTooltip:Hide()
Nick@108 1277 end
Nick@108 1278 end
Nenue@97 1279
Nenue@116 1280 function Artifact:OnClick(button, down)
Nenue@97 1281 if self.isEquipped then
Nenue@97 1282 SocketInventoryItem(16)
Nenue@97 1283 else
Nick@108 1284 if IsShiftKeyDown() then
Nenue@119 1285 SocketContainerItem(self.containerID, self.slotID)
Nick@108 1286 else
Nick@108 1287
Nick@108 1288 end
Nenue@97 1289 end
Nenue@122 1290 end