Skip to content

Commit

Permalink
fix: Fix count display and use MDT total count when available (#76)
Browse files Browse the repository at this point in the history
Use percentages returned from GetScenarioInfo for count calculation

Fetch total count from MDT

Use MDT total count to calculate current count

Fixed the ObjectiveTrackerFrame not staying hidden, again

Add logging for SetForcesPercent

Ceil and log estimated count

Fix current count for MDT total count

Use floor again for count calculations

Fix another forcesState typo
  • Loading branch information
happenslol committed Jul 29, 2024
1 parent 69f04a8 commit e128a7b
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 77 deletions.
12 changes: 7 additions & 5 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ WarpDeplete.defaultForcesState = {
currentPull = {},

completed = false,
completedTime = 0
completedTime = 0,

hasMDTTotalCount = false,
}

WarpDeplete.defaultTimerState = {
Expand Down Expand Up @@ -108,7 +110,7 @@ function WarpDeplete:ShowMDTAlert()
Util.showAlert(
"MDT_NOT_FOUND",
L["Mythic Dungeon Tools (MDT) is not installed."].."\n\n" ..
L["WarpDeplete will not display the count for you current pull."]
L["WarpDeplete will not display mob counts or count for the current pull."]
.. " \n\n" .. L["Install MDT to enable this functionality."])
end

Expand All @@ -119,13 +121,13 @@ function WarpDeplete:UpdateDemoModeForces()
if not self.challengeState.demoModeActive then return end

if self.db.profile.showForcesGlow and self.db.profile.demoForcesGlow then
self:SetForcesCurrent(92)
self:SetForcesPercent(92)
self:SetForcesPull(8)
elseif self.db.profile.unclampForcesPercent then
self:SetForcesCurrent(101)
self:SetForcesPercent(101)
self:SetForcesPull(3.4)
else
self:SetForcesCurrent(34)
self:SetForcesPercent(34)
self:SetForcesPull(7)
end
end
Expand Down
110 changes: 79 additions & 31 deletions Display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -522,34 +522,65 @@ function WarpDeplete:UpdateTimerDisplay()
end
end

function WarpDeplete:SetForcesTotal(totalCount)
self.forcesState.totalCount = totalCount
self.forcesState.pullPercent = totalCount > 0 and self.forcesState.pullCount / totalCount or 0

local currentPercent = totalCount > 0 and self.forcesState.currentCount / totalCount or 0
if currentPercent > 1.0 then currentPercent = 1.0 end
self.forcesState.currentPercent = currentPercent

self.forcesState.completed = false
self.forcesState.completedTime = 0

self:UpdateForcesDisplay()
end

-- Expects direct forces value
function WarpDeplete:SetForcesPull(pullCount)
self.forcesState.pullCount = pullCount
self.forcesState.pullPercent = self.forcesState.totalCount > 0
and pullCount / self.forcesState.totalCount or 0

self:UpdateForcesDisplay()
end
-- NOTE(happens): This is currently unused as Blizzard does not offer
-- direct forces values anymore, only percentages.
-- function WarpDeplete:SetForcesTotal(totalCount)
-- self.forcesState.totalCount = totalCount
-- self.forcesState.pullPercent = totalCount > 0 and self.forcesState.pullCount / totalCount or 0
--
-- local currentPercent = totalCount > 0 and self.forcesState.currentCount / totalCount or 0
-- if currentPercent > 1.0 then currentPercent = 1.0 end
-- self.forcesState.currentPercent = currentPercent
--
-- self.forcesState.completed = false
-- self.forcesState.completedTime = 0
--
-- self:UpdateForcesDisplay()
-- end

-- Expects direct forces value
function WarpDeplete:SetForcesCurrent(currentCount)
if self.forcesState.currentCount < self.forcesState.totalCount and
currentCount >= self.forcesState.totalCount
then
-- NOTE(happens): This is currently unused as Blizzard does not offer
-- direct forces values anymore, only percentages.
-- function WarpDeplete:SetForcesCurrent(currentCount)
-- if self.forcesState.currentCount < self.forcesState.totalCount and
-- currentCount >= self.forcesState.totalCount
-- then
-- self.forcesState.completed = true
-- self.forcesState.completedTime = self.timerState.current
-- end
--
-- -- The current count can only ever go up. The only place where it should
-- -- ever decrease is when it's reset in ResetState.
-- -- It seems that the API reports a current count of 0 when the dungeon is
-- -- finished, but possibly right before the challengeCompleted flag is triggered.
-- -- So, to make sure we don't reset the bar to 0 in that case, we only allow
-- -- the count to go up here.
-- if currentCount >= self.forcesState.currentCount then
-- self.forcesState.currentCount = currentCount
-- end
--
-- local currentPercent = self.forcesState.totalCount > 0
-- and self.forcesState.currentCount / self.forcesState.totalCount or 0
--
-- if currentPercent > 1.0 then currentPercent = 1.0 end
-- self.forcesState.currentPercent = currentPercent
--
-- self:UpdateForcesDisplay()
-- end

-- Expects a number between 0 and 100
function WarpDeplete:SetForcesPercent(currentPercent)
-- We want the percentage in a scale from 0.0 to 1.0
local scaledPercent = currentPercent / 100

self:PrintDebug("Setting forces percent to " ..
currentPercent .. " (" .. scaledPercent .. ") " ..
"current: " .. self.forcesState.currentPercent
)

-- Check if we just completed the dungeon
if self.forcesState.currentPercent < 1.0 and scaledPercent >= 1.0 then
self.forcesState.completed = true
self.forcesState.completedTime = self.timerState.current
end
Expand All @@ -560,15 +591,32 @@ function WarpDeplete:SetForcesCurrent(currentCount)
-- finished, but possibly right before the challengeCompleted flag is triggered.
-- So, to make sure we don't reset the bar to 0 in that case, we only allow
-- the count to go up here.
if currentCount >= self.forcesState.currentCount then
self.forcesState.currentCount = currentCount
if scaledPercent >= self.forcesState.currentPercent then
self.forcesState.currentPercent = scaledPercent
end

local currentPercent = self.forcesState.totalCount > 0
and self.forcesState.currentCount / self.forcesState.totalCount or 0
if self.forcesState.hasMDTTotalCount then
-- If we have count information from MDT, we use that to calculate the
-- current count.
local estimatedCount = self.forcesState.totalCount * scaledPercent
self.forcesState.currentCount = math.floor(estimatedCount)
if self.forcesState.currentCount >= self.forcesState.totalCount then
self.forcesState.currentCount = self.forcesState.totalCount
end
else
-- If we don't have any count information, we just use the percentage as
-- the count, as 100 as the max count is set as default from the start.
self.forcesState.currentCount = currentPercent
end

if currentPercent > 1.0 then currentPercent = 1.0 end
self.forcesState.currentPercent = currentPercent
self:UpdateForcesDisplay()
end

-- Expects direct forces value
function WarpDeplete:SetForcesPull(pullCount)
self.forcesState.pullCount = pullCount
self.forcesState.pullPercent = self.forcesState.totalCount > 0
and pullCount / self.forcesState.totalCount or 0

self:UpdateForcesDisplay()
end
Expand Down
82 changes: 59 additions & 23 deletions Events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,28 @@ function WarpDeplete:GetObjectivesInfo()
return false
end

local currentCount, totalCount = self:GetEnemyForcesCount()
-- The last step will forces, all previous steps are bosses
self:PrintDebug("Got forces info: " .. currentCount .. "/" .. totalCount)
local mdtTotalCount = self:GetMDTTotalCountInfo()
if mdtTotalCount then
self.forcesState.hasMDTTotalCount = true
self.forcesState.totalCount = mdtTotalCount
end

local currentPercent = self:GetEnemyForcesPercent()
-- The last step is forces, all previous steps are bosses
self:PrintDebug("Got forces info: " .. currentPercent .. "%")

if totalCount <= 0 then
if currentPercent == nil then
self:PrintDebug("No mob count received")
return false
end

self:SetForcesTotal(totalCount)
self:SetForcesCurrent(currentCount)
self:SetForcesPercent(currentPercent)

local objectives = {}
for i = 1, stepCount - 1 do
local CriteriaInfo = C_ScenarioInfo.GetCriteriaInfo(i)
if CriteriaInfo == nil then return false end

local name = CriteriaInfo.description
local completed = CriteriaInfo.completed
if not name then break end
Expand All @@ -191,34 +198,60 @@ function WarpDeplete:GetObjectivesInfo()
return true
end

function WarpDeplete:GetEnemyForcesCount()
function WarpDeplete:GetMDTTotalCountInfo()
if not MDT then return nil end
local zoneId = C_Map.GetBestMapForUnit("player")
local mdtDungeonIdx = MDT.zoneIdToDungeonIdx[zoneId]

if not mdtDungeonIdx then
self:PrintDebug("No MDT dungeon index found for zoneId " .. zoneId)
return nil
end

local mdtDungeonCountInfo = MDT.dungeonTotalCount[mdtDungeonIdx]
if not mdtDungeonCountInfo then
self:PrintDebug("No MDT dungeon count found for dungeon index " .. mdtDungeonIdx)
return nil
end

self:PrintDebug("Got MDT total count: " .. mdtDungeonCountInfo.normal)
return mdtDungeonCountInfo.normal or nil
end

function WarpDeplete:GetEnemyForcesPercent()
local stepCount = select(3, C_Scenario.GetStepInfo())

local CriteriaInfo = C_ScenarioInfo.GetCriteriaInfo(stepCount)
local totalCount = CriteriaInfo.totalQuantity
local mobPointsStr = CriteriaInfo.quantity
if not totalCount or not mobPointsStr then return nil, nil end
if not CriteriaInfo then return nil end

-- NOTE(happens): Blizzard decided in 11.0 to not return count
-- anymore, but instead a percentage. This means the totalQuantity
-- is useless to us now.
-- local totalCount = CriteriaInfo.totalQuantity

local currentCountStr = gsub(mobPointsStr, "%%", "")
local currentCount = tonumber(currentCountStr)
return currentCount, totalCount
local mobPercentStr = CriteriaInfo.quantity
if not mobPercentStr then return nil end

local currentPercentStr = gsub(mobPercentStr, "%%", "")
local currentPercent = tonumber(currentPercentStr)
return currentPercent
end

function WarpDeplete:UpdateForces()
if not self.challengeState.inChallenge then return end

local stepCount = select(3, C_Scenario.GetStepInfo())
local currentCount = self:GetEnemyForcesCount()
local currentPercent = self:GetEnemyForcesPercent()
-- This mostly happens when we have already completed the dungeon
if not currentCount then return end
self:PrintDebug("currentCount: " .. currentCount)
if not currentPercent then return end
self:PrintDebug("currentPercent: " .. currentPercent)

if currentCount >= self.forcesState.totalCount and not self.forcesState.completed then
if currentPercent >= 100 and not self.forcesState.completed then
-- If we just went above the total count (or matched it), we completed it just now
self.forcesState.completed = true
self.forcesState.completedTime = self.timerState.current
end

self:SetForcesCurrent(currentCount)
self:SetForcesPercent(currentPercent)
end

function WarpDeplete:UpdateObjectives()
Expand All @@ -233,10 +266,12 @@ function WarpDeplete:UpdateObjectives()
-- If it wasn't completed before and it is now, we've just completed
-- it and can set the completion time
local CriteriaInfo = C_ScenarioInfo.GetCriteriaInfo(i)
local completed = CriteriaInfo.completed
if completed then
objectives[i].time = self.timerState.current
changed = true
if CriteriaInfo ~= nil then
local completed = CriteriaInfo.completed
if completed then
objectives[i].time = self.timerState.current
changed = true
end
end
end
end
Expand Down Expand Up @@ -517,6 +552,7 @@ end
function WarpDeplete:OnResetCurrentPull(ev)
self:PrintDebugEvent(ev)
self:ResetCurrentPull()
self:HideBlizzardObjectiveTracker()
end

function WarpDeplete:OnThreatListUpdate(ev, unit)
Expand Down
36 changes: 18 additions & 18 deletions Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,15 @@ function WarpDeplete:InitOptions()
set = function(info, value) WarpDeplete:SetTimerRemaining(value * 60) end
},

{
type = "range",
name = L["Forces total"],
min = 1,
max = 500,
step = 1,
get = function(info) return WarpDeplete.forcesState.totalCount end,
set = function(info, value) WarpDeplete:SetForcesTotal(value) end
},
-- {
-- type = "range",
-- name = L["Forces total"],
-- min = 1,
-- max = 500,
-- step = 1,
-- get = function(info) return WarpDeplete.forcesState.totalCount end,
-- set = function(info, value) WarpDeplete:SetForcesTotal(value) end
-- },

{
type = "range",
Expand All @@ -701,15 +701,15 @@ function WarpDeplete:InitOptions()
set = function(info, value) WarpDeplete:SetForcesPull(value) end
},

{
type = "range",
name = L["Forces current"],
min = 1,
max = 500,
step = 1,
get = function(info) return WarpDeplete.forcesState.currentCount end,
set = function(info, value) WarpDeplete:SetForcesCurrent(value) end
}
-- {
-- type = "range",
-- name = L["Forces current"],
-- min = 1,
-- max = 500,
-- step = 1,
-- get = function(info) return WarpDeplete.forcesState.currentCount end,
-- set = function(info, value) WarpDeplete:SetForcesCurrent(value) end
-- }
})

options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
Expand Down

0 comments on commit e128a7b

Please sign in to comment.