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] local unitTable = units[unitGUID]
-- Check if we have seen one time this unit, if we don't then initialize it. -- 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. -- 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 = { unitTable = {
history = { history = {},
{ time = currentTime, percentage = healthPercentage } time = currentTime
},
time =
currentTime
} }
units[unitGUID] = unitTable units[unitGUID] = unitTable
end end
local history = unitTable.history local history = unitTable.history
local time = currentTime - unitTable.time local time = currentTime - unitTable.time
-- Check if the % HP changed since the last check (or if there were none) -- 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 val
local lastIndex = #ttdCache local lastIndex = #ttdCache
-- Check if we can re-use a table from the cache -- Check if we can re-use a table from the cache
if lastIndex == 0 then if lastIndex == 0 then
val = { time = currentTime, percentage = healthPercentage } val = { time = time, percentage = healthPercentage }
else else
val = ttdCache[lastIndex] val = ttdCache[lastIndex]
ttdCache[lastIndex] = nil ttdCache[lastIndex] = nil
val.time = currentTime val.time = time
val.percentage = healthPercentage val.percentage = healthPercentage
end end
table.insert(history, 1, val) table.insert(history, 1, val)

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

Loading…
Cancel
Save