From f4067140472e8651cd7cd7380d7d0d3c1a4e77b1 Mon Sep 17 00:00:00 2001 From: Buds Date: Sat, 26 Aug 2023 19:41:00 +0200 Subject: [PATCH 1/3] Bossmod Timer triggers: improve remainingTime precision and fix timer not shown when remainingTime + extendTimer would start a bar after non modified timer has expired --- WeakAuras/BossMods.lua | 73 +++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/WeakAuras/BossMods.lua b/WeakAuras/BossMods.lua index 9998f3f572..bef989af9e 100644 --- a/WeakAuras/BossMods.lua +++ b/WeakAuras/BossMods.lua @@ -127,7 +127,9 @@ Private.ExecEnv.BossMods.DBM = { for timerId, bar in pairs(self.bars) do if not bar.paused then if bar.expirationTime < now then - self.bars[timerId] = nil + if bar.scheduledScanExpireAt == nil or bar.scheduledScanExpireAt <= GetTime() then + self.bars[timerId] = nil + end WeakAuras.ScanEvents("DBM_TimerStop", timerId) if self.isGeneric then WeakAuras.ScanEvents("BossMod_TimerStop", timerId) @@ -212,10 +214,15 @@ Private.ExecEnv.BossMods.DBM = { end elseif event == "DBM_TimerStop" then local timerId = ... - self.bars[timerId] = nil - WeakAuras.ScanEvents("DBM_TimerStop", timerId) - if self.isGeneric then - WeakAuras.ScanEvents("BossMod_TimerStop", timerId) + local bar = self.bars[timerId] + if bar then + if bar.scheduledScanExpireAt == nil or bar.scheduledScanExpireAt <= GetTime() then + self.bars[timerId] = nil + end + WeakAuras.ScanEvents("DBM_TimerStop", timerId) + if self.isGeneric then + WeakAuras.ScanEvents("BossMod_TimerStop", timerId) + end end elseif event == "DBM_TimerPause" then local timerId = ... @@ -321,7 +328,7 @@ Private.ExecEnv.BossMods.DBM = { ScheduleCheck = function(self, fireTime) if not self.scheduled_scans[fireTime] then - self.scheduled_scans[fireTime] = timer:ScheduleTimerFixed(self.DoScan, fireTime - GetTime() + 0.1, self, fireTime) + self.scheduled_scans[fireTime] = timer:ScheduleTimerFixed(self.DoScan, fireTime - GetTime(), self, fireTime) end end } @@ -471,6 +478,9 @@ Private.event_prototypes["DBM Timer"] = { end end if remainingTime >= triggerRemaining and not bar.paused then + if extendTimer >= triggerRemaining then + bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) + end Private.ExecEnv.BossMods.DBM:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) end else @@ -491,8 +501,8 @@ Private.event_prototypes["DBM Timer"] = { end end elseif event == "DBM_TimerStop" and state then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true return true @@ -506,8 +516,8 @@ Private.event_prototypes["DBM Timer"] = { else local state = states[timerId] if state then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true changed = true @@ -551,8 +561,8 @@ Private.event_prototypes["DBM Timer"] = { end else if state and state.show then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true return true @@ -751,7 +761,9 @@ Private.ExecEnv.BossMods.BigWigs = { for timerId, bar in pairs(self.bars) do if not bar.paused then if bar.expirationTime < now then - self.bars[timerId] = nil + if bar.scheduledScanExpireAt == nil or bar.scheduledScanExpireAt <= GetTime() then + self.bars[timerId] = nil + end WeakAuras.ScanEvents("BigWigs_StopBar", timerId) if self.isGeneric then WeakAuras.ScanEvents("BossMod_TimerStop", timerId) @@ -812,8 +824,11 @@ Private.ExecEnv.BossMods.BigWigs = { end elseif event == "BigWigs_StopBar" then local addon, text = ... - if self.bars[text] then - self.bars[text] = nil + local bar = self.bars[text] + if bar then + if bar.scheduledScanExpireAt == nil or bar.scheduledScanExpireAt <= GetTime() then + self.bars[text] = nil + end WeakAuras.ScanEvents("BigWigs_StopBar", text) if self.isGeneric then WeakAuras.ScanEvents("BossMod_TimerStop", text) @@ -936,7 +951,7 @@ Private.ExecEnv.BossMods.BigWigs = { ScheduleCheck = function(self, fireTime) if not self.scheduled_scans[fireTime] then - self.scheduled_scans[fireTime] = timer:ScheduleTimerFixed(self.DoScan, fireTime - GetTime() + 0.1, self, fireTime) + self.scheduled_scans[fireTime] = timer:ScheduleTimerFixed(self.DoScan, fireTime - GetTime(), self, fireTime) end end } @@ -1084,6 +1099,9 @@ Private.event_prototypes["BigWigs Timer"] = { end end if remainingTime >= triggerRemaining and not bar.paused then + if extendTimer >= triggerRemaining then + bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) + end Private.ExecEnv.BossMods.BigWigs:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) end else @@ -1104,8 +1122,8 @@ Private.event_prototypes["BigWigs Timer"] = { end end elseif event == "BigWigs_StopBar" and state then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true return true @@ -1154,8 +1172,8 @@ Private.event_prototypes["BigWigs Timer"] = { end else if state and state.show then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true return true @@ -1451,6 +1469,9 @@ Private.event_prototypes["Boss Mod Timer"] = { end end if remainingTime >= triggerRemaining and not bar.paused then + if extendTimer >= triggerRemaining then + bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) + end Private.ExecEnv.BossMods.Generic:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) end else @@ -1471,8 +1492,8 @@ Private.event_prototypes["Boss Mod Timer"] = { end end elseif event == "BossMod_TimerStop" and state then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true return true @@ -1486,8 +1507,8 @@ Private.event_prototypes["Boss Mod Timer"] = { else local state = states[timerId] if state then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true changed = true @@ -1531,8 +1552,8 @@ Private.event_prototypes["Boss Mod Timer"] = { end else if state and state.show then - local bar_remainingTime = GetTime() - state.expirationTime + (state.extend or 0) - if state.extend == 0 or bar_remainingTime > 0.2 then + local bar_remainingTime = state.expirationTime - GetTime() + (state.extend or 0) + if state.extend == 0 or bar_remainingTime <= 0 then state.show = false state.changed = true return true From 656368531d674e15ffce3e203de579d832134dbb Mon Sep 17 00:00:00 2001 From: Infus Date: Sun, 3 Sep 2023 20:45:05 +0200 Subject: [PATCH 2/3] FixFixFix --- WeakAuras/BossMods.lua | 172 +++++++++++++++++++++++++---------------- 1 file changed, 107 insertions(+), 65 deletions(-) diff --git a/WeakAuras/BossMods.lua b/WeakAuras/BossMods.lua index bef989af9e..a2ce9a3b11 100644 --- a/WeakAuras/BossMods.lua +++ b/WeakAuras/BossMods.lua @@ -16,7 +16,6 @@ Private.ExecEnv.BossMods.DBM = { CopyBarToState = function(self, bar, states, timerId, extendTimer) extendTimer = extendTimer or 0 - if extendTimer + bar.duration < 0 then return end states[timerId] = states[timerId] or {} local state = states[timerId] state.show = true @@ -129,10 +128,19 @@ Private.ExecEnv.BossMods.DBM = { if bar.expirationTime < now then if bar.scheduledScanExpireAt == nil or bar.scheduledScanExpireAt <= GetTime() then self.bars[timerId] = nil + else + if self.nextExpire == nil then + self.nextExpire = bar.scheduledScanExpireAt + elseif bar.scheduledScanExpireAt < self.nextExpire then + self.nextExpire = bar.scheduledScanExpireAt + end end - WeakAuras.ScanEvents("DBM_TimerStop", timerId) - if self.isGeneric then - WeakAuras.ScanEvents("BossMod_TimerStop", timerId) + if not bar.expired then + bar.expired = true + WeakAuras.ScanEvents("DBM_TimerStop", timerId) + if self.isGeneric then + WeakAuras.ScanEvents("BossMod_TimerStop", timerId) + end end elseif self.nextExpire == nil then self.nextExpire = bar.expirationTime @@ -168,6 +176,7 @@ Private.ExecEnv.BossMods.DBM = { bar.spellId = tostring(spellId) bar.count = timerCount and tostring(timerCount) or "0" bar.dbmType = dbmType + bar.expired = nil local r, g, b = 0, 0, 0 if DBT.GetColorForType then @@ -461,31 +470,43 @@ Private.event_prototypes["DBM Timer"] = { local counter = counter function copyOrSchedule(bar, cloneId) + local remainingTime + local changed + if bar.paused then + remainingTime = bar.remaining + extendTimer + else + remainingTime = bar.expirationTime - GetTime() + extendTimer + end if triggerUseRemaining then - local remainingTime - if bar.paused then - remainingTime = bar.remaining + extendTimer - else - remainingTime = bar.expirationTime - GetTime() + extendTimer - end - if remainingTime %s triggerRemaining then + if remainingTime > 0 and remainingTime %s triggerRemaining then Private.ExecEnv.BossMods.DBM:CopyBarToState(bar, states, cloneId, extendTimer) + changed = true else local state = states[cloneId] if state and state.show then state.show = false state.changed = true + changed = true end end - if remainingTime >= triggerRemaining and not bar.paused then - if extendTimer >= triggerRemaining then + if not bar.paused then + if extendTimer > 0 then bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) end - Private.ExecEnv.BossMods.DBM:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) + if remainingTime >= triggerRemaining then + Private.ExecEnv.BossMods.DBM:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) + end end else - Private.ExecEnv.BossMods.DBM:CopyBarToState(bar, states, cloneId, extendTimer) + if not bar.paused and extendTimer > 0 then + bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) + end + if remainingTime > 0 then + Private.ExecEnv.BossMods.DBM:CopyBarToState(bar, states, cloneId, extendTimer) + changed = true + end end + return changed end if useClone then @@ -496,8 +517,7 @@ Private.event_prototypes["DBM Timer"] = { if Private.ExecEnv.BossMods.DBM:TimerMatches(timerId, triggerText, triggerTextOperator, triggerSpellId, counter, triggerId, triggerDbmType) then local bar = Private.ExecEnv.BossMods.DBM:GetTimerById(timerId) if bar then - copyOrSchedule(bar, cloneId) - return true + return copyOrSchedule(bar, cloneId) end end elseif event == "DBM_TimerStop" and state then @@ -511,8 +531,7 @@ Private.event_prototypes["DBM Timer"] = { local changed for timerId, bar in pairs(Private.ExecEnv.BossMods.DBM:GetAllTimers()) do if Private.ExecEnv.BossMods.DBM:TimerMatches(timerId, triggerText, triggerTextOperator, triggerSpellId, counter, triggerId, triggerDbmType) then - copyOrSchedule(bar, timerId) - changed = true + changed = copyOrSchedule(bar, timerId) or changed else local state = states[timerId] if state then @@ -535,8 +554,7 @@ Private.event_prototypes["DBM Timer"] = { end for timerId, bar in pairs(Private.ExecEnv.BossMods.DBM:GetAllTimers()) do if Private.ExecEnv.BossMods.DBM:TimerMatches(timerId, triggerText, triggerTextOperator, triggerSpellId, counter, triggerId, triggerDbmType) then - copyOrSchedule(bar, timerId) - changed = true + changed = copyOrSchedule(bar, timerId) or changed end end return changed @@ -556,8 +574,7 @@ Private.event_prototypes["DBM Timer"] = { or not (state and state.show) or (state and state.show and state.expirationTime > (bar.expirationTime + extendTimer)) then - copyOrSchedule(bar, cloneId) - return true + return copyOrSchedule(bar, cloneId) end else if state and state.show then @@ -656,7 +673,6 @@ Private.ExecEnv.BossMods.BigWigs = { CopyBarToState = function(self, bar, states, timerId, extendTimer) extendTimer = extendTimer or 0 - if extendTimer + bar.duration < 0 then return end states[timerId] = states[timerId] or {} local state = states[timerId] state.show = true @@ -763,10 +779,19 @@ Private.ExecEnv.BossMods.BigWigs = { if bar.expirationTime < now then if bar.scheduledScanExpireAt == nil or bar.scheduledScanExpireAt <= GetTime() then self.bars[timerId] = nil + else + if self.nextExpire == nil then + self.nextExpire = bar.scheduledScanExpireAt + elseif bar.scheduledScanExpireAt < self.nextExpire then + self.nextExpire = bar.scheduledScanExpireAt + end end - WeakAuras.ScanEvents("BigWigs_StopBar", timerId) - if self.isGeneric then - WeakAuras.ScanEvents("BossMod_TimerStop", timerId) + if not bar.expired then + bar.expired = true + WeakAuras.ScanEvents("BigWigs_StopBar", timerId) + if self.isGeneric then + WeakAuras.ScanEvents("BossMod_TimerStop", timerId) + end end elseif self.nextExpire == nil then self.nextExpire = bar.expirationTime @@ -803,6 +828,7 @@ Private.ExecEnv.BossMods.BigWigs = { bar.expirationTime = expirationTime bar.icon = icon bar.isCooldown = isCD or false + bar.expired = nil local BWColorModule = BigWigs:GetPlugin("Colors") bar.bwBarColor = BWColorModule:GetColorTable("barColor", addon, spellId) bar.bwTextColor = BWColorModule:GetColorTable("barText", addon, spellId) @@ -1082,31 +1108,43 @@ Private.event_prototypes["BigWigs Timer"] = { local counter = counter function copyOrSchedule(bar, cloneId) + local remainingTime + local changed + if bar.paused then + remainingTime = bar.remaining + extendTimer + else + remainingTime = bar.expirationTime - GetTime() + extendTimer + end if triggerUseRemaining then - local remainingTime - if bar.paused then - remainingTime = bar.remaining + extendTimer - else - remainingTime = bar.expirationTime - GetTime() + extendTimer - end - if remainingTime %s triggerRemaining then + if remainingTime > 0 and remainingTime %s triggerRemaining then Private.ExecEnv.BossMods.BigWigs:CopyBarToState(bar, states, cloneId, extendTimer) + changed = true else local state = states[cloneId] if state and state.show then state.show = false state.changed = true + changed = true end end - if remainingTime >= triggerRemaining and not bar.paused then - if extendTimer >= triggerRemaining then + if not bar.paused then + if extendTimer > 0 then bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) end - Private.ExecEnv.BossMods.BigWigs:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) + if remainingTime >= triggerRemaining then + Private.ExecEnv.BossMods.BigWigs:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) + end end else - Private.ExecEnv.BossMods.BigWigs:CopyBarToState(bar, states, cloneId, extendTimer) + if not bar.paused and extendTimer > 0 then + bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) + end + if remainingTime > 0 then + Private.ExecEnv.BossMods.BigWigs:CopyBarToState(bar, states, cloneId, extendTimer) + changed = true + end end + return changed end if useClone then @@ -1117,8 +1155,7 @@ Private.event_prototypes["BigWigs Timer"] = { if Private.ExecEnv.BossMods.BigWigs:TimerMatches(timerId, triggerText, triggerTextOperator, triggerSpellId, counter, triggerCast, triggerIsCooldown) then local bar = Private.ExecEnv.BossMods.BigWigs:GetTimerById(timerId) if bar then - copyOrSchedule(bar, cloneId) - return true + return copyOrSchedule(bar, cloneId) end end elseif event == "BigWigs_StopBar" and state then @@ -1132,8 +1169,7 @@ Private.event_prototypes["BigWigs Timer"] = { local changed for timerId, bar in pairs(Private.ExecEnv.BossMods.BigWigs:GetAllTimers()) do if Private.ExecEnv.BossMods.BigWigs:TimerMatches(timerId, triggerText, triggerTextOperator, triggerSpellId, counter, triggerCast, triggerIsCooldown) then - copyOrSchedule(bar, timerId) - changed = true + changed = copyOrSchedule(bar, timerId) or changed end end return changed @@ -1146,8 +1182,7 @@ Private.event_prototypes["BigWigs Timer"] = { end for timerId, bar in pairs(Private.ExecEnv.BossMods.BigWigs:GetAllTimers()) do if Private.ExecEnv.BossMods.BigWigs:TimerMatches(timerId, triggerText, triggerTextOperator, triggerSpellId, counter, triggerCast, triggerIsCooldown) then - copyOrSchedule(bar, timerId) - changed = true + changed = copyOrSchedule(bar, timerId) or changed end end return changed @@ -1167,8 +1202,7 @@ Private.event_prototypes["BigWigs Timer"] = { or not (state and state.show) or (state and state.show and state.expirationTime > (bar.expirationTime + extendTimer)) then - copyOrSchedule(bar, cloneId) - return true + return copyOrSchedule(bar, cloneId) end else if state and state.show then @@ -1452,31 +1486,43 @@ Private.event_prototypes["Boss Mod Timer"] = { local counter = counter function copyOrSchedule(bar, cloneId) + local remainingTime + local changed + if bar.paused then + remainingTime = bar.remaining + extendTimer + else + remainingTime = bar.expirationTime - GetTime() + extendTimer + end if triggerUseRemaining then - local remainingTime - if bar.paused then - remainingTime = bar.remaining + extendTimer - else - remainingTime = bar.expirationTime - GetTime() + extendTimer - end - if remainingTime %s triggerRemaining then + if remainingTime > 0 and remainingTime %s triggerRemaining then Private.ExecEnv.BossMods.Generic:CopyBarToState(bar, states, cloneId, extendTimer) + changed = true else local state = states[cloneId] if state and state.show then state.show = false state.changed = true + changed = true end end - if remainingTime >= triggerRemaining and not bar.paused then - if extendTimer >= triggerRemaining then + if not bar.paused then + if extendTimer > 0 then bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) end - Private.ExecEnv.BossMods.Generic:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) + if remainingTime >= triggerRemaining then + Private.ExecEnv.BossMods.Generic:ScheduleCheck(bar.expirationTime - triggerRemaining + extendTimer) + end end else - Private.ExecEnv.BossMods.Generic:CopyBarToState(bar, states, cloneId, extendTimer) + if not bar.paused and extendTimer > 0 then + bar.scheduledScanExpireAt = math.max(bar.scheduledScanExpireAt or 0, bar.expirationTime + extendTimer) + end + if remainingTime > 0 then + Private.ExecEnv.BossMods.Generic:CopyBarToState(bar, states, cloneId, extendTimer) + changed = true + end end + return changed end if useClone then @@ -1487,8 +1533,7 @@ Private.event_prototypes["Boss Mod Timer"] = { if Private.ExecEnv.BossMods.Generic:TimerMatchesGeneric(timerId, triggerText, triggerTextOperator, triggerSpellId, counter) then local bar = Private.ExecEnv.BossMods.Generic:GetTimerById(timerId) if bar then - copyOrSchedule(bar, cloneId) - return true + return copyOrSchedule(bar, cloneId) end end elseif event == "BossMod_TimerStop" and state then @@ -1502,8 +1547,7 @@ Private.event_prototypes["Boss Mod Timer"] = { local changed for timerId, bar in pairs(Private.ExecEnv.BossMods.Generic:GetAllTimers()) do if Private.ExecEnv.BossMods.Generic:TimerMatchesGeneric(timerId, triggerText, triggerTextOperator, triggerSpellId, counter) then - copyOrSchedule(bar, timerId) - changed = true + changed = copyOrSchedule(bar, timerId) or changed else local state = states[timerId] if state then @@ -1526,8 +1570,7 @@ Private.event_prototypes["Boss Mod Timer"] = { end for timerId, bar in pairs(Private.ExecEnv.BossMods.Generic:GetAllTimers()) do if Private.ExecEnv.BossMods.Generic:TimerMatchesGeneric(timerId, triggerText, triggerTextOperator, triggerSpellId, counter) then - copyOrSchedule(bar, timerId) - changed = true + changed = copyOrSchedule(bar, timerId) or changed end end return changed @@ -1547,8 +1590,7 @@ Private.event_prototypes["Boss Mod Timer"] = { or not (state and state.show) or (state and state.show and state.expirationTime > (bar.expirationTime + extendTimer)) then - copyOrSchedule(bar, cloneId) - return true + return copyOrSchedule(bar, cloneId) end else if state and state.show then From 124b61d466849c91e0da2bb4008b786c7363b677 Mon Sep 17 00:00:00 2001 From: Infus Date: Sun, 3 Sep 2023 20:58:38 +0200 Subject: [PATCH 3/3] More fixfixfix --- WeakAuras/BossMods.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/WeakAuras/BossMods.lua b/WeakAuras/BossMods.lua index a2ce9a3b11..6ab6436308 100644 --- a/WeakAuras/BossMods.lua +++ b/WeakAuras/BossMods.lua @@ -228,6 +228,7 @@ Private.ExecEnv.BossMods.DBM = { if bar.scheduledScanExpireAt == nil or bar.scheduledScanExpireAt <= GetTime() then self.bars[timerId] = nil end + bar.expired = true WeakAuras.ScanEvents("DBM_TimerStop", timerId) if self.isGeneric then WeakAuras.ScanEvents("BossMod_TimerStop", timerId)