fix: Fixes timer index offset (#1907)

### Summary

- Fixes timer intervals not continuing
- Fixes `Timer.Index` being off by 1. Should start at 0 for the first OnTick
- Simplifies Gift of Renewal end check
- Fixes force of nature not applying at the proper time and simplifies the timer logic.
This commit is contained in:
Kamron Batman 2024-08-06 15:46:40 -07:00 committed by GitHub
parent 2c9b3ef112
commit 28860b7f53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 47 deletions

View file

@ -134,13 +134,11 @@ public partial class Timer
private static void Execute(Timer timer)
{
var finished = timer.Count != 0 && ++timer.Index >= timer.Count;
var finished = timer.Count != 0 && timer.Index + 1 >= timer.Count;
var prof = timer.GetProfile();
prof?.Start();
var version = timer.Version;
// Stop the timer from running so that way if Start() is called in OnTick, the timer will be started.
if (finished)
{
@ -148,25 +146,30 @@ public partial class Timer
timer.Version++;
}
var version = timer.Version;
timer.OnTick();
prof?.Finish();
// If the timer has been altered (restarted, returned etc) then bail
if (timer.Version != version)
// Starting doesn't change the timer version, so we need to check if it's finished and if it's still running.
if (timer.Version != version || finished && timer.Running)
{
return;
}
if (finished)
if (!finished)
{
timer.Delay = timer.Interval;
timer.Next = DateTime.UtcNow + timer.Interval;
AddTimer(timer, (long)timer.Delay.TotalMilliseconds);
}
else
{
// Already stopped and detached, now run OnDetach
timer.OnDetach();
return;
}
timer.Delay = timer.Interval;
timer.Next = DateTime.UtcNow + timer.Interval;
AddTimer(timer, (long)timer.Delay.TotalMilliseconds);
timer.Index++;
}
private static void AddTimer(Timer timer, long delay)