fix(core): Caches DateTime.NowUtc (#548)

- [X] Caches DateTime.NowUtc on the game loop (not other threads)
- [X] Replaces all locations where it makes sense
- [X] Adds Min/Max for `IComparable` (TimeSpan, DateTimes, etc)

Closes #261
This commit is contained in:
Kamron Batman 2021-03-13 01:32:04 -08:00 • committed by GitHub
parent 5de6edbeb8
commit 6c4308bce6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
208 changed files with 660 additions and 793 deletions

View file

@ -65,7 +65,7 @@ namespace Server.Gumps
{
m_Mobile.SendLocalizedMessage(1010405); // You cannot change guild types while in a Faction!
}
else if (m_Guild.TypeLastChange.AddDays(7) > DateTime.UtcNow)
else if (m_Guild.TypeLastChange.AddDays(7) > Core.Now)
{
m_Mobile.SendLocalizedMessage(1011142); // You have already changed your guild type recently.
// TODO: Clilocs 1011142-1011145 suggest a timer for pending changes

View file

@ -70,9 +70,9 @@ namespace Server.Guilds
var timeRemaining = TimeSpan.Zero;
if (activeWar.WarLength != TimeSpan.Zero && activeWar.WarBeginning + activeWar.WarLength > DateTime.UtcNow)
if (activeWar.WarLength != TimeSpan.Zero && activeWar.WarBeginning + activeWar.WarLength > Core.Now)
{
timeRemaining = activeWar.WarBeginning + activeWar.WarLength - DateTime.UtcNow;
timeRemaining = activeWar.WarBeginning + activeWar.WarLength - Core.Now;
}
time = $"{timeRemaining.Hours:D2}:{DateTime.MinValue + timeRemaining:mm}";
@ -234,7 +234,7 @@ namespace Server.Guilds
{
// Accept the war
guild.PendingWars.Remove(war);
war.WarBeginning = DateTime.UtcNow;
war.WarBeginning = Core.Now;
guild.AcceptedWars.Add(war);
if (alliance?.IsMember(guild) == true)
@ -260,7 +260,7 @@ namespace Server.Guilds
// Technically SHOULD say Your guild is now at war w/out any info, intentional diff.
otherGuild.PendingWars.Remove(otherWar);
otherWar.WarBeginning = DateTime.UtcNow;
otherWar.WarBeginning = Core.Now;
otherGuild.AcceptedWars.Add(otherWar);
if (otherAlliance != null && m_Other.Alliance.IsMember(m_Other))