Updates to TimeToDie2

main
ck 11 months ago
parent f43b18f311
commit e852e8ed69
  1. 15
      src/TimeToDie/TimeToDie.lua
  2. 2
      src/Unit/Unit.lua

@ -83,29 +83,26 @@ function TimeToDie:Refresh()
local unitTable = units[unitGUID]
-- Check if we have seen one time this unit, if we don't then initialize it.
-- Also check to see if the unit's health percentage is higher than the last one we saw. If so, we recreate the table.
if not unitTable or #unitTable.history > 0 and healthPercentage > unitTable.history[1].percentage then
if not unitTable or healthPercentage > unitTable.history[1].percentage then
unitTable = {
history = {
{ time = currentTime, percentage = healthPercentage }
},
time =
currentTime
history = {},
time = currentTime
}
units[unitGUID] = unitTable
end
local history = unitTable.history
local time = currentTime - unitTable.time
-- Check if the % HP changed since the last check (or if there were none)
if not history or healthPercentage ~= history[1].percentage then
if not history or not history[1] or healthPercentage ~= history[1].percentage then
local val
local lastIndex = #ttdCache
-- Check if we can re-use a table from the cache
if lastIndex == 0 then
val = { time = currentTime, percentage = healthPercentage }
val = { time = time, percentage = healthPercentage }
else
val = ttdCache[lastIndex]
ttdCache[lastIndex] = nil
val.time = currentTime
val.time = time
val.percentage = healthPercentage
end
table.insert(history, 1, val)

@ -994,7 +994,7 @@ end
---@param upper? number
---@return boolean
function Unit:TTD(lower, upper)
upper = type(upper) == "nil" and lower or upper
upper = not upper and lower or upper
local ttd = self:TimeToDie()
return ttd >= lower and ttd <= upper
end

Loading…
Cancel
Save