From f8316228d7d21d1855399fd2e68e95d799495336 Mon Sep 17 00:00:00 2001 From: shagu Date: Sat, 2 Jul 2022 21:38:32 +0200 Subject: [PATCH] cooldown: a weird fix for weird cooldown issues Some items with huge cooldowns (like Salt Shaker) send remaining cooldown times that are way higher than they should be. You often see a cooldown of 52d and alike. This seems to have "reasons" and is fixed by this commit. All credits to the guys at: https://github.com/Stanzilla/WoWUIBugs/issues/47 --- modules/cooldown.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/cooldown.lua b/modules/cooldown.lua index 1c5fd7bc..a4ca7b6b 100644 --- a/modules/cooldown.lua +++ b/modules/cooldown.lua @@ -25,11 +25,30 @@ pfUI:RegisterModule("cooldown", "vanilla:tbc", function () -- fix own alpha value (should be inherited, but somehow isn't always) this:SetAlpha(parent:GetAlpha()) - local remaining = this.duration - (GetTime() - this.start) - if remaining >= 0 then - this.text:SetText(GetColoredTimeString(remaining)) + if this.start < GetTime() then + -- calculating remaining time as it should be + local remaining = this.duration - (GetTime() - this.start) + if remaining >= 0 then + this.text:SetText(GetColoredTimeString(remaining)) + else + this:Hide() + end else - this:Hide() + -- I have absolutely no idea, but it works: + -- https://github.com/Stanzilla/WoWUIBugs/issues/47 + local time = time() + local startupTime = time - GetTime() + -- just a simplification of: ((2^32) - (start * 1000)) / 1000 + local cdTime = (2 ^ 32) / 1000 - this.start + local cdStartTime = startupTime - cdTime + local cdEndTime = cdStartTime + this.duration + local remaining = cdEndTime - time + + if remaining >= 0 then + this.text:SetText(GetColoredTimeString(remaining)) + else + this:Hide() + end end end