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:
parent
5de6edbeb8
commit
6c4308bce6
208 changed files with 660 additions and 793 deletions
|
|
@ -67,7 +67,7 @@ namespace Server.Factions
|
|||
set
|
||||
{
|
||||
CurrentState = value;
|
||||
LastStateTime = DateTime.UtcNow;
|
||||
LastStateTime = Core.Now;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,12 +89,7 @@ namespace Server.Factions
|
|||
_ => PendingPeriod
|
||||
};
|
||||
|
||||
var until = LastStateTime + period - DateTime.UtcNow;
|
||||
|
||||
if (until < TimeSpan.Zero)
|
||||
{
|
||||
until = TimeSpan.Zero;
|
||||
}
|
||||
var until = Utility.Max(LastStateTime + period - Core.Now, TimeSpan.Zero);
|
||||
|
||||
return until;
|
||||
}
|
||||
|
|
@ -108,7 +103,7 @@ namespace Server.Factions
|
|||
_ => PendingPeriod
|
||||
};
|
||||
|
||||
LastStateTime = DateTime.UtcNow - period + value;
|
||||
LastStateTime = Core.Now - period + value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -290,7 +285,7 @@ namespace Server.Factions
|
|||
{
|
||||
case ElectionState.Pending:
|
||||
{
|
||||
if (LastStateTime + PendingPeriod > DateTime.UtcNow)
|
||||
if (LastStateTime + PendingPeriod > Core.Now)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -304,7 +299,7 @@ namespace Server.Factions
|
|||
}
|
||||
case ElectionState.Campaign:
|
||||
{
|
||||
if (LastStateTime + CampaignPeriod > DateTime.UtcNow)
|
||||
if (LastStateTime + CampaignPeriod > Core.Now)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -346,7 +341,7 @@ namespace Server.Factions
|
|||
}
|
||||
case ElectionState.Election:
|
||||
{
|
||||
if (LastStateTime + VotingPeriod > DateTime.UtcNow)
|
||||
if (LastStateTime + VotingPeriod > Core.Now)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
@ -413,7 +408,7 @@ namespace Server.Factions
|
|||
Address = IPAddress.None;
|
||||
}
|
||||
|
||||
Time = DateTime.UtcNow;
|
||||
Time = Core.Now;
|
||||
}
|
||||
|
||||
public Voter(IGenericReader reader, Mobile candidate)
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ namespace Server.Factions
|
|||
}
|
||||
else
|
||||
{
|
||||
recvState.LastHonorTime = DateTime.UtcNow;
|
||||
recvState.LastHonorTime = Core.Now;
|
||||
giveState.KillPoints -= 5;
|
||||
recvState.KillPoints += 4;
|
||||
|
||||
|
|
@ -604,7 +604,7 @@ namespace Server.Factions
|
|||
return false;
|
||||
}
|
||||
|
||||
if (pl.Leaving + LeavePeriod >= DateTime.UtcNow)
|
||||
if (pl.Leaving + LeavePeriod >= Core.Now)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -911,13 +911,13 @@ namespace Server.Factions
|
|||
var sigil = sigils[i];
|
||||
|
||||
if (!sigil.IsBeingCorrupted && sigil.GraceStart != DateTime.MinValue &&
|
||||
sigil.GraceStart + Sigil.CorruptionGrace < DateTime.UtcNow)
|
||||
sigil.GraceStart + Sigil.CorruptionGrace < Core.Now)
|
||||
{
|
||||
if (sigil.LastMonolith is StrongholdMonolith &&
|
||||
(sigil.Corrupted == null || sigil.LastMonolith.Faction != sigil.Corrupted))
|
||||
{
|
||||
sigil.Corrupting = sigil.LastMonolith.Faction;
|
||||
sigil.CorruptionStart = DateTime.UtcNow;
|
||||
sigil.CorruptionStart = Core.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -930,21 +930,21 @@ namespace Server.Factions
|
|||
|
||||
if (sigil.LastMonolith?.Sigil == null)
|
||||
{
|
||||
if (sigil.LastStolen + Sigil.ReturnPeriod < DateTime.UtcNow)
|
||||
if (sigil.LastStolen + Sigil.ReturnPeriod < Core.Now)
|
||||
{
|
||||
sigil.ReturnHome();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sigil.IsBeingCorrupted && sigil.CorruptionStart + Sigil.CorruptionPeriod < DateTime.UtcNow)
|
||||
if (sigil.IsBeingCorrupted && sigil.CorruptionStart + Sigil.CorruptionPeriod < Core.Now)
|
||||
{
|
||||
sigil.Corrupted = sigil.Corrupting;
|
||||
sigil.Corrupting = null;
|
||||
sigil.CorruptionStart = DateTime.MinValue;
|
||||
sigil.GraceStart = DateTime.MinValue;
|
||||
}
|
||||
else if (sigil.IsPurifying && sigil.PurificationStart + Sigil.PurificationPeriod < DateTime.UtcNow)
|
||||
else if (sigil.IsPurifying && sigil.PurificationStart + Sigil.PurificationPeriod < Core.Now)
|
||||
{
|
||||
sigil.PurificationStart = DateTime.MinValue;
|
||||
sigil.Corrupted = null;
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ namespace Server.Factions
|
|||
return true;
|
||||
}
|
||||
|
||||
return Expiration != DateTime.MinValue && DateTime.UtcNow >= Expiration;
|
||||
return Expiration != DateTime.MinValue && Core.Now >= Expiration;
|
||||
}
|
||||
}
|
||||
|
||||
public void StartExpiration()
|
||||
{
|
||||
Expiration = DateTime.UtcNow + ExpirationPeriod;
|
||||
Expiration = Core.Now + ExpirationPeriod;
|
||||
}
|
||||
|
||||
public void CheckAttach()
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Server.Factions
|
|||
|
||||
if (version < 5)
|
||||
{
|
||||
LastAtrophy = DateTime.UtcNow;
|
||||
LastAtrophy = Core.Now;
|
||||
}
|
||||
|
||||
if (version < 4)
|
||||
|
|
@ -161,7 +161,7 @@ namespace Server.Factions
|
|||
{
|
||||
for (var i = 0; i < m_LastBroadcasts.Length; ++i)
|
||||
{
|
||||
if (DateTime.UtcNow >= m_LastBroadcasts[i] + BroadcastPeriod)
|
||||
if (Core.Now >= m_LastBroadcasts[i] + BroadcastPeriod)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ namespace Server.Factions
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsAtrophyReady => DateTime.UtcNow >= LastAtrophy + TimeSpan.FromHours(47.0);
|
||||
public bool IsAtrophyReady => Core.Now >= LastAtrophy + TimeSpan.FromHours(47.0);
|
||||
|
||||
public List<FactionItem> FactionItems { get; set; }
|
||||
|
||||
|
|
@ -217,13 +217,13 @@ namespace Server.Factions
|
|||
|
||||
public int CheckAtrophy()
|
||||
{
|
||||
if (DateTime.UtcNow < LastAtrophy + TimeSpan.FromHours(47.0))
|
||||
if (Core.Now < LastAtrophy + TimeSpan.FromHours(47.0))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var distrib = 0;
|
||||
LastAtrophy = DateTime.UtcNow;
|
||||
LastAtrophy = Core.Now;
|
||||
|
||||
var members = new List<PlayerState>(Members);
|
||||
|
||||
|
|
@ -252,9 +252,9 @@ namespace Server.Factions
|
|||
{
|
||||
for (var i = 0; i < m_LastBroadcasts.Length; ++i)
|
||||
{
|
||||
if (DateTime.UtcNow >= m_LastBroadcasts[i] + BroadcastPeriod)
|
||||
if (Core.Now >= m_LastBroadcasts[i] + BroadcastPeriod)
|
||||
{
|
||||
m_LastBroadcasts[i] = DateTime.UtcNow;
|
||||
m_LastBroadcasts[i] = Core.Now;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ namespace Server.Factions
|
|||
break;
|
||||
}
|
||||
|
||||
var remaining = pl.Leaving + Faction.LeavePeriod - DateTime.UtcNow;
|
||||
var remaining = pl.Leaving + Faction.LeavePeriod - Core.Now;
|
||||
|
||||
if (remaining.TotalDays >= 1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ namespace Server.Factions
|
|||
public SilverGivenEntry(Mobile givenTo)
|
||||
{
|
||||
GivenTo = givenTo;
|
||||
TimeOfGift = DateTime.UtcNow;
|
||||
TimeOfGift = Core.Now;
|
||||
}
|
||||
|
||||
public Mobile GivenTo { get; }
|
||||
|
||||
public DateTime TimeOfGift { get; }
|
||||
|
||||
public bool IsExpired => TimeOfGift + ExpirePeriod < DateTime.UtcNow;
|
||||
public bool IsExpired => TimeOfGift + ExpirePeriod < Core.Now;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ namespace Server.Factions
|
|||
set => m_State.LastTaxChange = value;
|
||||
}
|
||||
|
||||
public bool TaxChangeReady => m_State.LastTaxChange + TaxChangePeriod < DateTime.UtcNow;
|
||||
public bool TaxChangeReady => m_State.LastTaxChange + TaxChangePeriod < Core.Now;
|
||||
|
||||
public int FinanceUpkeep
|
||||
{
|
||||
|
|
@ -236,7 +236,7 @@ namespace Server.Factions
|
|||
|
||||
public void CheckIncome()
|
||||
{
|
||||
if (LastIncome + IncomePeriod > DateTime.UtcNow || Owner == null)
|
||||
if (LastIncome + IncomePeriod > Core.Now || Owner == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ namespace Server.Factions
|
|||
|
||||
public void ProcessIncome()
|
||||
{
|
||||
LastIncome = DateTime.UtcNow;
|
||||
LastIncome = Core.Now;
|
||||
|
||||
var flow = NetCashFlow;
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ namespace Server.Factions
|
|||
|
||||
if (m_State.Owner == null) // going from unowned to owned
|
||||
{
|
||||
LastIncome = DateTime.UtcNow;
|
||||
LastIncome = Core.Now;
|
||||
f.Silver += SilverCaptureBonus;
|
||||
}
|
||||
else if (f == null) // going from owned to unowned
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue