|
|
@ -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) |
|
|
|