Skip to content

Commit

Permalink
fix: Use quantityString instead of estimating forces count (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
happenslol authored Sep 21, 2024
1 parent a629387 commit 52de974
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 144 deletions.
10 changes: 4 additions & 6 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ WarpDeplete.defaultForcesState = {

completed = false,
completedTime = 0,

hasMDTTotalCount = false,
}

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

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

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

-- Expects direct forces value
-- 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
function WarpDeplete:SetForcesTotal(totalCount)
self.forcesState.totalCount = totalCount
self.forcesState.pullPercent = totalCount > 0 and self.forcesState.pullCount / totalCount or 0

-- Expects direct forces value
-- 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
)
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)
-- Check if we just completed the dungeon
if self.forcesState.currentPercent < 1.0 and scaledPercent >= 1.0 then
if self.forcesState.currentCount < self.forcesState.totalCount and
currentCount >= self.forcesState.totalCount
then
self.forcesState.completed = true
self.forcesState.completedTime = self.timerState.current
end
Expand All @@ -591,23 +553,15 @@ function WarpDeplete:SetForcesPercent(currentPercent)
-- 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 scaledPercent >= self.forcesState.currentPercent then
self.forcesState.currentPercent = scaledPercent
if currentCount >= self.forcesState.currentCount then
self.forcesState.currentCount = currentCount
end

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
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
Expand Down
72 changes: 22 additions & 50 deletions Events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,28 +187,23 @@ end
function WarpDeplete:GetObjectivesInfo()
self:PrintDebug("Getting objectives info")

-- The last step is forces, all previous steps are bosses
local stepCount = select(3, C_Scenario.GetStepInfo())
if stepCount <= 0 then
self:PrintDebug("No steps received, can't update objective info")
return false
end

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 .. "%")
local currentCount, totalCount = self:GetEnemyForcesCount()
self:PrintDebug("Got forces info: " .. tonumber(currentCount) .. "/" .. tonumber(totalCount))

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

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

local objectives = {}
for i = 1, stepCount - 1 do
Expand All @@ -219,8 +214,8 @@ function WarpDeplete:GetObjectivesInfo()
local completed = CriteriaInfo.completed
if not name then break end

name = gsub(name, " defeated", "")
name = gsub(name, " Defeated", "")
name = name:gsub(" defeated", "")
name = name:gsub(" Defeated", "")
self:PrintDebug("Got boss name for index " .. i .. ": " .. tostring(name))
objectives[i] = { name = name, time = completed and 0 or nil }
end
Expand All @@ -234,60 +229,37 @@ function WarpDeplete:GetObjectivesInfo()
return true
end

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()
function WarpDeplete:GetEnemyForcesCount()
local stepCount = select(3, C_Scenario.GetStepInfo())

local CriteriaInfo = C_ScenarioInfo.GetCriteriaInfo(stepCount)
if not CriteriaInfo then return nil end
if not CriteriaInfo then return nil, 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 totalCount = CriteriaInfo.totalQuantity
local currentCountStr = CriteriaInfo.quantityString
if not currentCountStr or not totalCount then return nil, nil end

local mobPercentStr = CriteriaInfo.quantity
if not mobPercentStr then return nil end
-- NOTE(happens): The current count contains a percentage sign
-- even though it's an absolute value.
local currentCount = tonumber(currentCountStr:match("%d+"))

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

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

local currentPercent = self:GetEnemyForcesPercent()
local currentCount, totalCount = self:GetEnemyForcesCount()
-- This mostly happens when we have already completed the dungeon
if not currentPercent then return end
self:PrintDebug("currentPercent: " .. currentPercent)
if not currentCount or not totalCount then return end
self:PrintDebug("Count: " .. tostring(currentCount) .. "/" .. tostring(totalCount))

if currentPercent >= 100 and not self.forcesState.completed then
if currentCount >= totalCount 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:SetForcesPercent(currentPercent)
self:SetForcesCurrent(currentCount)
end

function WarpDeplete:UpdateObjectives()
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 52de974

Please sign in to comment.