From 8eb4a620e5af7cc1253275db7daa5c41d3b0ad73 Mon Sep 17 00:00:00 2001 From: mrmoo Date: Thu, 28 Dec 2023 17:06:04 +0000 Subject: [PATCH] Fixed function Unit:PredictHealth(time) Added the future prediction point, we need to add the function input to the current time to get it. --- src/Unit/Unit.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index d9cd4ef..5477cdb 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -784,7 +784,8 @@ function Unit:PredictHealth(time) table.remove(self.regression_history, 1) end - table.insert(self.regression_history, { time = GetTime(), percent = self:GetHP() }) + local currentTime = GetTime() + table.insert(self.regression_history, { time = currentTime, percent = self:GetHP() }) for i = 1, #self.regression_history do local entry = self.regression_history[i] @@ -793,9 +794,12 @@ function Unit:PredictHealth(time) end local slope, intercept = self:LinearRegression(x, y) - return slope * time + intercept + + return slope * (currentTime + time) + intercept end + + -- Use linear regression to guess the time until a given health percent ---@param percent number ---@return number