diff Modules/ArtifactPower.lua @ 116:ddfe19d70a34

ArtifactPower: - Further 7.2 accommodations, relating to tokens that grant millions of AP. Currency: - Ancient Mana zones list expanded - Legionfall War Supplies, Nethershards, and Blood of Sargeras are tracked globally PaperDoll: - Should update more effectively when delayed artifact data loads in. WorldState: - Fixed hanging panels after OrderHallCommandBar is hidden.
author Nenue
date Wed, 26 Apr 2017 20:06:38 -0400
parents 8c94bee4fdfc
children 589045559484
line wrap: on
line diff
--- a/Modules/ArtifactPower.lua	Tue Mar 28 07:02:26 2017 -0400
+++ b/Modules/ArtifactPower.lua	Wed Apr 26 20:06:38 2017 -0400
@@ -13,7 +13,7 @@
   scanQueue = {},
   ItemButtons = {},
   anchorPoint = 'TOP',
-  anchorPriority = 2,
+  anchorPriority = 3,
   anchorFrom = 'TOP',
   moduleName = 'Artifactor',
   HideCombat = true
@@ -22,7 +22,7 @@
   firstUse = true,
   autoHide = true,
 }
-local ap = VeneerArtifactPowerMixin
+local Module = VeneerArtifactPowerMixin
 local BAGS_TO_SCAN = {BACKPACK_CONTAINER }
 local TOOLTIP_NAME = 'VeneerAPScanner'
 local POINT_COSTS = {
@@ -39,13 +39,15 @@
   3975000, 4175000, 4385000, 4605000
 }
 local FISHING_MAX_TRAITS = 24
-local WEAPON_MAX_TRAITS = 54
+local WEAPON_MAX_TRAITS = 92
+local FRAME_PADDING = 4
+local EQUIPPED_SIZE = 64
 local BUTTON_SIZE = 48
 local FRAME_LIST = {'ContainerFrame1', 'BankFrame'}
 local BAG_FRAMES = {'ContainerFrame1'}
 local BANK_FRAMES = {'BankFrame'}
 
-function ap:OnLoad()
+function Module:OnLoad()
   self:RegisterEvent('BAG_UPDATE') -- use to obtain bag IDs to scan
   self:RegisterEvent('BAG_UPDATE_DELAYED') -- use to trigger actual scan activity
   self:RegisterEvent('BANKFRAME_OPENED')  -- determine when bank info is available
@@ -85,7 +87,9 @@
 
 end
 local ShortNumberString = function (value)
-  if value >= 100000 then
+  if value >= 1000000 then
+    return tostring(floor(value/100000)/10) .. 'M'
+  elseif value >= 100000 then
     return tostring(floor(value/1000)) .. 'k'
   elseif value >= 1000 then
     return tostring(floor(value/100)/10) .. 'k'
@@ -163,7 +167,7 @@
   end
 end
 
-function ap:Setup()
+function Module:Setup()
   print(self:GetName()..':Setup()')
   local guid = UnitGUID('player')
   VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings
@@ -243,7 +247,7 @@
 
 local UNDERLIGHT_ANGLER_ID = 133755
 
-function ap:ResetCache()
+function Module:ResetCache()
   table.wipe(self.cache.items)
   table.wipe(self.cache.fishing)
   table.wipe(self.cache.bags)
@@ -251,7 +255,7 @@
   self:ScanAllBags()
 end
 
-function ap:QueueBag(containerID)
+function Module:QueueBag(containerID)
   containerID = tonumber(containerID)
   if not containerID then
     return
@@ -263,13 +267,13 @@
   end
 end
 
-function ap:Reanchor()
+function Module:Reanchor()
   if Veneer then
     Veneer:DynamicReanchor()
   end
 end
 
-function ap:OnShow()
+function Module:OnShow()
   print('|cFFFFFF00OnShow()|r')
 
   for name, args in pairs(PENDING_HOOKS) do
@@ -284,11 +288,11 @@
   self:ScanAllBags()
   self:Reanchor()
 end
-function ap:OnHide()
+function Module:OnHide()
   print('|cFF88FF00OnHide()|r', debugstack())
   self:Reanchor()
 end
-function ap:OnEnter()
+function Module:OnEnter()
 
   GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
 
@@ -298,7 +302,7 @@
 
 end
 
-function ap:TryToShow()
+function Module:TryToShow()
 
   print('|cFFFFFF00TryToShow()')
 
@@ -321,7 +325,7 @@
 end
 
 
-function ap:OnEvent(event, ...)
+function Module:OnEvent(event, ...)
   print('|cFF00FF88OnEvent()', event, ...)
   if event == 'PLAYER_ENTERING_WORLD' then
     self:TryToShow()
@@ -380,7 +384,7 @@
   end
 end
 
-function ap:OnUpdate()
+function Module:OnUpdate()
   if #self.scanQueue >= 1 then
     local scanInfo = tremove(self.scanQueue, 1)
   end
@@ -392,12 +396,12 @@
 
 end
 
-function ap:OnMouseDown()
+function Module:OnMouseDown()
   self.enabled = nil
   self:Hide()
 end
 
-function ap:Update()
+function Module:Update()
   if not self:IsShown() then
     print('|cFFFF4400Update()|r')
     return
@@ -427,8 +431,10 @@
 
     if not self.worldPlanHooked then
       WorldPlan:RegisterDataCallback(function()
+        print('data udpate callback')
         self:Update()
       end)
+      self.worldPlanHooked = true
     end
 
 
@@ -436,7 +442,7 @@
     print('world plan is loaded')
     local worldQuests = WorldPlan:GetQuestPins()
     for index, pin in ipairs(worldQuests) do
-      if pin.dataLoaded and (pin.rewardType == WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER) and (pin.isActive) then
+      if (pin.rewardType == WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER) and (pin.isActive) and (pin.dataLoaded) then
         showWQ = true
         print(pin.itemNumber)
         self.worldQuestAP = self.worldQuestAP + pin.itemNumber
@@ -455,13 +461,13 @@
   local contentsHeight = 16 + self.SummaryHeader:GetHeight()
   local contentsWidth = self.SummaryHeader:GetWidth() + 16
   if self.profile.knowledgeMultiplier then
-    numButtons = self:UpdateArtifactButtons()
+    local artifactsWidth = self:UpdateArtifactButtons()
 
-    if numButtons ~= 0 then
+    if artifactsWidth ~= 0 then
       contentsHeight = contentsHeight + 64
     end
 
-    contentsWidth = max(contentsWidth, 64*numButtons + 4 * (numButtons+1))
+    contentsWidth = max(contentsWidth, artifactsWidth)
 
     local itemsWidth, itemsHeight = self:UpdateItemButtons()
     contentsHeight = contentsHeight + itemsHeight
@@ -479,7 +485,7 @@
   self:Reanchor()
 end
 
-function ap:UpdateArtifactButtons()
+function Module:UpdateArtifactButtons()
 
   -- Artifact icons, in no particular order
   self.equippedID = C_ArtifactUI.GetEquippedArtifactInfo()
@@ -490,9 +496,23 @@
   local lastFrame = self
   local fishingID, fishingData
   local index, button
+  local equipped =self.profile.artifacts[self.equippedID]
+  local buttonsWidth = 0
+  if equipped then
+    numButtons = numButtons + 1
+    button = self.Artifact[numButtons]
+    button.relativeFrame = self
+    lastFrame = button:SetButton(self.equippedID, equipped, numButtons, true, nil)
+    hasArtifacts = true
+
+    buttonsWidth = EQUIPPED_SIZE + (FRAME_PADDING * 2)
+  end
+
+
   for itemID, artifact in pairs(self.profile.artifacts) do
-    if (itemID == UNDERLIGHT_ANGLER_ID)  then
-      if VeneerData.ArtifactPower.EnableFishing then
+    if (itemID == UNDERLIGHT_ANGLER_ID) then
+      -- only add if we have fishing AP items and it's not being shown in the equipped slot
+      if VeneerData.ArtifactPower.EnableFishing and (itemID ~= self.equippedID) then
         fishingID = itemID
         fishingData = artifact
       end
@@ -502,19 +522,19 @@
           self.canAddFishingAP = true
         end
       end
-
-
     else
       if artifact.level < WEAPON_MAX_TRAITS then
-
         if itemID == self.equippedID then
           self.canAddAP = true
+        else
+
+          hasArtifacts = true
+          numButtons = numButtons + 1
+          button = self.Artifact[numButtons]
+          button.relativeFrame = lastFrame
+          lastFrame = button:SetButton(itemID, artifact, numButtons, (self.equippedID == itemID), nil)
+          buttonsWidth = buttonsWidth + lastFrame:GetWidth() + FRAME_PADDING
         end
-        hasArtifacts = true
-        numButtons = numButtons + 1
-        button = self.Artifact[numButtons]
-        button.relativeFrame = lastFrame
-        lastFrame = button:SetButton(itemID, artifact, numButtons, (self.equippedID == itemID), nil)
       end
     end
   end
@@ -536,11 +556,11 @@
   end
 
 
-  return numButtons
+  return buttonsWidth
 end
 
 
-function ap:UpdateItemButtons()
+function Module:UpdateItemButtons()
   print('|cFF00FFFFUpdateItemButtons()|r')
 
   local apType
@@ -605,7 +625,7 @@
   return buttonsWidth, buttonsHeight
 end
 
-function ap:SetItemAction(button, name)
+function Module:SetItemAction(button, name)
   name = name or self.itemName
   if InCombatLockdown() then
     self.itemName = name
@@ -616,7 +636,7 @@
   end
 end
 
-function ap:GetItemButton(itemID, texture, itemAP, fishing)
+function Module:GetItemButton(itemID, texture, itemAP, fishing)
   print('|cFF00FFFFGetItemButton()|r', itemID, texture, itemAP)
   local button = self.ItemButtons[itemID]
 
@@ -638,19 +658,13 @@
     self.numItems = self.numItems +  1
   end
 
-  local itemAPtext = itemAP
-  if itemAPtext >= 100000 then
-    itemAPtext = floor(itemAPtext/1000) .. 'k'
-  elseif itemAPtext >= 1000 then
-    itemAPtext = (floor(itemAPtext/100)/10 ) .. 'k'
-  end
-  button.Label:SetText(itemAPtext)
+  button.Label:SetText(ShortNumberString(itemAP))
 
   button.numItems = button.numItems + 1
   return button
 end
 
-function ap:GetItemAP(itemID, itemLink, bagData)
+function Module:GetItemAP(itemID, itemLink, bagData)
   if not self.cache.items[itemID] then
 
     print('doing tooltip scan', itemLink, itemID)
@@ -664,10 +678,17 @@
           if text then
 
             text = text:lower():gsub(',', '')
+
             if text:match('equipped artifact') then
               print(itemLink, '-', tonumber(text))
-              local itemAP = text:match('%d+')
+
+              local itemAP = text:match('[%d%.]+')
               if itemAP then
+                -- tokens > 1M are described as '%f million'
+                if text:match("million") then
+                  itemAP = tonumber(itemAP) * 1000000
+                end
+
                 itemAP = itemAP
                 self.cache.items[itemID] = tonumber(itemAP)
               end
@@ -691,7 +712,7 @@
   return self.cache.items[itemID], self.cache.fishing[itemID]
 end
 
-function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent)
+function Module:SetArtifact(itemID, name, texture, currentXP, pointsSpent)
   print('|cFF00FF00SetArtifact()|r')
   if not self.profile then
     return
@@ -719,27 +740,18 @@
     artifact.texture = texture
     artifact.currentXP = currentXP
     artifact.level = pointsSpent
-    local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent)
+    artifact.tier = C_ArtifactUI.GetArtifactTier() or ((pointsSpent >= 36) and 2 or 1)
+
+    print('tier', artifact.tier)
+    local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent, artifact.tier)
     artifact.currentCost = cost
 
-    local pointsAvailable = pointsSpent
-    local actualCost = cost
-    local actualXP = currentXP
-    while actualXP >= actualCost do
-      pointsAvailable = pointsAvailable + 1
-      actualXP = actualXP - actualCost
-      print(pointsAvailable, '-', actualCost, '=', actualXP)
-      actualCost = C_ArtifactUI.GetCostForPointAtRank(pointsAvailable)
-    end
-    print('updating', itemID, name,  currentXP, pointsSpent, pointsAvailable, actualXP)
-    artifact.actualXP = actualXP
-    artifact.actualLevel = pointsAvailable
-    artifact.actualCost = actualCost
+
 
   end
 end
 
-function ap:ScanBag(id)
+function Module:ScanBag(id)
   print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id))
   local numSlots = GetContainerNumSlots(id)
   local requiresUpdate
@@ -813,7 +825,7 @@
 local BAG_SLOTS = {0, 1, 2, 3, 4 }
 local BANK_SLOTS = {-1, 5, 6,7, 8, 9, 10, 11, 12}
 local ItemCounts = {}
-function ap:ScanAllBags()
+function Module:ScanAllBags()
   if InCombatLockdown() then
     self.queuedScan = true
     return
@@ -868,8 +880,9 @@
 end
 
 VeneerArtifactButtonMixin = {}
+local Artifact = VeneerArtifactButtonMixin
 
-function VeneerArtifactButtonMixin:SetButton(itemID, artifact, index, equipped, fishing)
+function Artifact:SetButton(itemID, artifact, index, equipped, fishing)
   print(itemID, index)
   print(artifact.name, artifact.texture, artifact.currentXP)
   self:SetID(itemID)
@@ -884,27 +897,27 @@
 
   self.isFishing = fishing
   -- this can change between artifact parses
-  local potentialPoints = self.actualLevel
   local totalAP = (itemID ~= UNDERLIGHT_ANGLER_ID) and ((self:GetParent().bankAP or 0) + (self:GetParent().bagAP or 0)) or (self:GetParent().fishingAP or 0)
   print(totalAP)
-  local potentialXP = self.actualXP + totalAP
 
-  self.potentialXP = potentialXP
-  local potentialCost = C_ArtifactUI.GetCostForPointAtRank(potentialPoints)
-  while potentialXP >= potentialCost do
-    potentialXP = potentialXP - potentialCost
-    potentialPoints = potentialPoints + 1
-    print('inc estimate', potentialXP, potentialPoints)
-    potentialCost = C_ArtifactUI.GetCostForPointAtRank(potentialPoints)
+  -- currentXP  what has been spent on the artifact
+  -- actualXP   amount
+  -- totalXP
+  local actualXP = artifact.currentXP + totalAP
+  local actualLevel = artifact.level
+  local actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
+
+  while actualXP >= actualCost do
+    actualXP = actualXP - actualCost
+    actualLevel = actualLevel + 1
+    actualCost = C_ArtifactUI.GetCostForPointAtRank(actualLevel, artifact.tier)
+    print('* ', actualLevel, actualXP, actualCost)
   end
-  self.potentialCost = potentialCost
-  self.potentialLevel = potentialPoints
-  self.potentialAdjustedXP = potentialXP
+  self.actualCost = actualCost
+  self.actualLevel = actualLevel
+  self.actualXP = actualXP
+  self.totalXP = artifact.currentXP + totalAP
 
-  self.maxCost = self.currentCost
-  for i = self.level + 1, #POINT_COSTS do
-    self.maxCost = self.maxCost + POINT_COSTS[i]
-  end
 
   if index ~= 1 then
     self:ClearAllPoints()
@@ -920,32 +933,46 @@
   return self
 end
 
-function VeneerArtifactButtonMixin:Update()
-  local r, g, b = 1, 1, 1
-  local lR, lG, lB = 1, 1, 0
+function Artifact:Update()
+  local r1, g1, b1 = 1, 1, 1
+  local r2, g2, b2 = 1, 1, 0
   local levelText = self.level
-  local xpValue = ShortNumberString(self.currentXP)
-  local costValue = self.currentCost
+  local xpText = ShortNumberString(self.currentXP)
+  local costText = ShortNumberString(self.currentCost)
+  local remainingText  = ShortNumberString(self.currentCost - self.currentXP)
+  -- current:   amount shown in blizz ui
+  -- actual:    amount contributing the next level, will be same until current point cap is reached
+  -- potential: total of ap on hand
+  print(self.currentXP, self.actualXP, self.potentialXP)
   if self.actualLevel ~= self.level then
-    levelText, r,g,b = self.actualLevel, 0,1,0
-    xpValue, costValue, lR, lG, lB = ShortNumberString(self.potentialXP) .. '\n' .. ShortNumberString(self.potentialCost-self.potentialXP), self.actualCost, 0, 1, 0
-  elseif self.potentialLevel ~= self.level then
-    levelText, r, g, b = self.potentialLevel, 0,1,1
-    xpValue, costValue, lR, lG, lB = ShortNumberString(self.potentialXP) .. '\n' .. ShortNumberString(self.potentialCost-self.potentialXP), self.potentialCost, 0,1,1
-  else
-    xpValue, lR, lG, lB = ShortNumberString(self.actualXP) .. '\n|cFFFFFF00' .. ShortNumberString(self.actualCost-self.actualXP)..'|r', 1, 1, 1
+
+    levelText = self.actualLevel
+    r1, g1, b1 = 0, 1, 0
+    r2, g2, b2 = 0, 1, 0
+    xpText = ShortNumberString(self.actualXP)
+    costText = ShortNumberString(self.actualCost)
+    remainingText = ShortNumberString(self.actualCost-self.actualXP)
+  --[[elseif self.potentialLevel ~= self.level then
+    r1, g1, b1 = 0, 1, 1
+    r2, g2, b2 = 0, 1, 1
+    costText = ShortNumberString(self.potentialCost)
+    remainingText = ShortNumberString(self.potentialCost-self.potentialXP)
+    --]]
   end
 
   self.Level:SetText(levelText)
-  self.Level:SetTextColor(r, g, b)
-  self.CurrentXP:SetText( xpValue)
-  self.CurrentXP:SetTextColor(lR, lG, lB)
+  self.CurrentXP:SetText( xpText )
+  self.RemainingCost:SetText(remainingText)
+  self.Level:SetTextColor(r1, g1, b1)
+  self.CurrentXP:SetTextColor(r1, g1, b1)
 
   if self.isEquipped then
+    self:SetSize(64,64)
     self:SetNormalTexture([[Interface\Buttons\ButtonHilight-Square]])
     self:GetNormalTexture():SetBlendMode('ADD')
     self:GetNormalTexture():SetVertexColor(0,1,0)
   else
+    self:SetSize(48,48)
     self:SetNormalTexture(nil, 'ADD')
   end
 
@@ -960,15 +987,17 @@
     self.ProgressLine:Hide()
   end
 
-  if self.potentialXP > self.currentXP then
-    local projectedProgress = (self.potentialAdjustedXP < self.potentialCost) and (self.potentialXP / self.potentialCost) or 1
+  if self.actualXP ~= self.currentXP then
+    local projectedProgress = (self.actualXP ~= self.actualCost) and (self.actualXP / self.actualCost) or 1
     if (projectedProgress > currentProgress) then
       self.AdjustedProgress:SetPoint('BOTTOM', self.CurrentProgress, 'TOP')
       projectedProgress = projectedProgress - currentProgress
     else
+      self.CurrentProgress:Hide()
+      self.ProgressLine:Hide()
       self.AdjustedProgress:SetPoint('BOTTOM', self, 'BOTTOM')
     end
-    print('show potential', currentProgress, projectedProgress)
+    print('show actual', currentProgress, projectedProgress)
     self.AdjustedProgress.animateFrom = self.AdjustedProgress:GetHeight() or 1
     self.AdjustedProgress.animateTo = projectedProgress * self:GetHeight()
     self.AdjustedLine:Show()
@@ -977,12 +1006,14 @@
     self.AdjustedProgress:Hide()
     self.AdjustedLine:Hide()
   end
+
+
+
   self.Icon:SetTexture(self.texture)
-  self:SetSize(64,64)
 end
 
 
-function VeneerArtifactButtonMixin:AnimateProgress(region)
+function Artifact:AnimateProgress(region)
   local cTime = GetTime()
   if not region.animateStart then
     region.animateStart = cTime
@@ -1002,7 +1033,7 @@
   end
 end
 
-function VeneerArtifactButtonMixin:OnUpdate(sinceLast)
+function Artifact:OnUpdate(sinceLast)
   if self.CurrentProgress.animateTo then
     self:AnimateProgress(self.CurrentProgress)
   end
@@ -1012,14 +1043,14 @@
   end
 end
 
-function VeneerArtifactButtonMixin:OnEnter()
+function Artifact:OnEnter()
   GameTooltip:SetOwner(self, 'ANCHOR_CURSOR')
   GameTooltip:SetText(self.name)
   GameTooltip:AddLine(ShortNumberString(self.currentXP) .. ' / '..ShortNumberString(self.currentCost), 1, 1, 0)
-  if self.potentialXP > self.currentXP then
-    GameTooltip:AddLine(ShortNumberString(self.potentialXP) .. ' potential XP', 0, 1, 1)
-    if self.potentialAdjustedXP ~= self.potentialXP then
-      GameTooltip:AddLine(ShortNumberString(self.potentialAdjustedXP) .. ' / ' .. ShortNumberString(self.potentialCost).. ' after', 0, 1, 0)
+  if self.totalXP ~= self.currentXP then
+    GameTooltip:AddLine(ShortNumberString(self.totalXP) .. ' total XP', 0, 1, 1)
+    if self.actualXP ~= self.potentialXP then
+      GameTooltip:AddLine(ShortNumberString(self.actualXP) .. ' / ' .. ShortNumberString(self.actualCost).. ' after', 0, 1, 0)
     end
   end
   if self.actualLevel ~= self.level then
@@ -1031,19 +1062,19 @@
 
   GameTooltip:Show()
 end
-function VeneerArtifactButtonMixin:OnLeave()
+function Artifact:OnLeave()
   if GameTooltip:IsOwned(self) then
     GameTooltip:Hide()
   end
 end
-function VeneerArtifactButtonMixin:OnHide()
+function Artifact:OnHide()
 
   if GameTooltip:IsOwned(self) then
     GameTooltip:Hide()
   end
 end
 
-function VeneerArtifactButtonMixin:OnClick(button, down)
+function Artifact:OnClick(button, down)
   if self.isEquipped then
     SocketInventoryItem(16)
   else