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

@ -28,7 +28,7 @@ namespace Server.Factions
{
case ElectionState.Pending:
{
var toGo = election.LastStateTime + Election.PendingPeriod - DateTime.UtcNow;
var toGo = election.LastStateTime + Election.PendingPeriod - Core.Now;
var days = (int)(toGo.TotalDays + 0.5);
AddHtmlLocalized(20, 40, 380, 20, 1038034); // A new election campaign is pending
@ -47,7 +47,7 @@ namespace Server.Factions
}
case ElectionState.Campaign:
{
var toGo = election.LastStateTime + Election.CampaignPeriod - DateTime.UtcNow;
var toGo = election.LastStateTime + Election.CampaignPeriod - Core.Now;
var days = (int)(toGo.TotalDays + 0.5);
AddHtmlLocalized(20, 40, 380, 20, 1018058); // There is an election campaign in progress.
@ -81,7 +81,7 @@ namespace Server.Factions
}
case ElectionState.Election:
{
var toGo = election.LastStateTime + Election.VotingPeriod - DateTime.UtcNow;
var toGo = election.LastStateTime + Election.VotingPeriod - Core.Now;
var days = (int)Math.Ceiling(toGo.TotalDays);
AddHtmlLocalized(20, 40, 380, 20, 1018060); // There is an election vote in progress.

View file

@ -209,7 +209,7 @@ namespace Server.Factions
if (m_From.AccessLevel == AccessLevel.Player && !m_Town.TaxChangeReady)
{
var remaining = DateTime.UtcNow - (m_Town.LastTaxChange + Town.TaxChangePeriod);
var remaining = Core.Now - (m_Town.LastTaxChange + Town.TaxChangePeriod);
if (remaining.TotalMinutes < 4)
{
@ -243,7 +243,7 @@ namespace Server.Factions
if (m_From.AccessLevel == AccessLevel.Player)
{
m_Town.LastTaxChange = DateTime.UtcNow;
m_Town.LastTaxChange = Core.Now;
}
}

View file

@ -56,7 +56,7 @@ namespace Server.Factions
if (pl != null)
{
pl.Leaving = DateTime.UtcNow;
pl.Leaving = Core.Now;
if (TimeSpan.FromDays(3.0) == Faction.LeavePeriod)
{
@ -87,7 +87,7 @@ namespace Server.Factions
if (pl != null)
{
pl.Leaving = DateTime.UtcNow;
pl.Leaving = Core.Now;
if (TimeSpan.FromDays(3.0) == Faction.LeavePeriod)
{