From e852e8ed69e60e1dd27d2e9130aab9f7aaf93aab Mon Sep 17 00:00:00 2001 From: ck Date: Fri, 16 Feb 2024 02:02:26 -0600 Subject: [PATCH] Updates to TimeToDie2 --- src/TimeToDie/TimeToDie.lua | 15 ++++++--------- src/Unit/Unit.lua | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/TimeToDie/TimeToDie.lua b/src/TimeToDie/TimeToDie.lua index e4144b0..3859da6 100644 --- a/src/TimeToDie/TimeToDie.lua +++ b/src/TimeToDie/TimeToDie.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) diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index 661321a..cdf2016 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -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