From 4cec209e4d74acdbb2a355e297fd6c149272546a Mon Sep 17 00:00:00 2001 From: shagu Date: Mon, 4 Nov 2024 15:19:40 +0100 Subject: [PATCH] libpredict: calculate timeleft in GetHotDuration --- api/unitframes.lua | 23 +++++++---------------- libs/libpredict.lua | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/api/unitframes.lua b/api/unitframes.lua index d2bf7726..dca423d8 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -1739,28 +1739,19 @@ function pfUI.uf:RefreshUnit(unit, component) -- match filter for _, filter in pairs(unit.indicators) do if filter == string.lower(texture) then - if string.lower(texture) == "interface\\icons\\spell_nature_rejuvenation" then --I'd like to do all 3 hots in one if statement later. TODO: check TBC compatibility - local start, duration = libpredict:getHoTTime(unitstr, "Reju") --get rejuv start and runtime - if start and duration then --show the buff even if time is unknown, important as pfUI seems to see the buff before healcomm/libpredict processing is done - timeleft = (start + duration) - GetTime() - end - pfUI.uf:AddIcon(unit, pos, texture, timeleft, count) + if string.lower(texture) == "interface\\icons\\spell_nature_rejuvenation" then + local start, duration, prediction = libpredict:GetHotDuration(unitstr, "Reju") + pfUI.uf:AddIcon(unit, pos, texture, timeleft or prediction, count) pos = pos + 1 break elseif string.lower(texture) == "interface\\icons\\spell_holy_renew" then - local start, duration = libpredict:getHoTTime(unitstr, "Renew") - if start and duration then - timeleft = (start + duration) - GetTime() - end - pfUI.uf:AddIcon(unit, pos, texture, timeleft, count) + local start, duration, prediction = libpredict:GetHotDuration(unitstr, "Renew") + pfUI.uf:AddIcon(unit, pos, texture, timeleft or prediction, count) pos = pos + 1 break elseif string.lower(texture) == "interface\\icons\\spell_nature_resistnature" then - local start, duration = libpredict:getHoTTime(unitstr, "Regr") - if start and duration then - timeleft = (start + duration) - GetTime() - end - pfUI.uf:AddIcon(unit, pos, texture, timeleft, count) + local start, duration, prediction = libpredict:GetHotDuration(unitstr, "Regr") + pfUI.uf:AddIcon(unit, pos, texture, timeleft or prediction, count) pos = pos + 1 break else diff --git a/libs/libpredict.lua b/libs/libpredict.lua index 0744fc22..4c9d91a1 100644 --- a/libs/libpredict.lua +++ b/libs/libpredict.lua @@ -541,16 +541,19 @@ libpredict.sender:SetScript("OnEvent", function() end end) -function libpredict:getHoTTime(unit, spell) - if unit == UNKNOWNOBJECT or unit == UNKOWNBEING then - return - end - local dbUnit = hots[UnitName(unit)] - if dbUnit and dbUnit[spell] and (dbUnit[spell].start + dbUnit[spell].duration) > GetTime() then - return dbUnit[spell].start, dbUnit[spell].duration - else - return +function libpredict:GetHotDuration(unit, spell) + if unit == UNKNOWNOBJECT or unit == UNKOWNBEING then return end + + local start, duration, timeleft + + local unitdata = hots[UnitName(unit)] + if unitdata and unitdata[spell] and (unitdata[spell].start + unitdata[spell].duration) > GetTime() - 1 then + start = unitdata[spell].start + duration = unitdata[spell].duration + timeleft = (start + duration) - GetTime() end + + return start, duration, timeleft end pfUI.api.libpredict = libpredict