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

@ -14,7 +14,7 @@ namespace Server.Items
{
Movable = false;
Light = LightType.Circle225;
NextSpawn = DateTime.UtcNow;
NextSpawn = Core.Now;
NextSpawnDelay = TimeSpan.FromMinutes(15.0);
SpawnRange = 5;
}
@ -87,7 +87,7 @@ namespace Server.Items
NextSpawnDelay = reader.ReadTimeSpan();
}
NextSpawn = DateTime.UtcNow;
NextSpawn = Core.Now;
}
public virtual void HeedWarning()
@ -101,7 +101,7 @@ namespace Server.Items
public override void OnMovement(Mobile m, Point3D oldLocation)
{
if (NextSpawn < DateTime.UtcNow) // means we haven't spawned anything if the next spawn is below
if (NextSpawn < Core.Now) // means we haven't spawned anything if the next spawn is below
{
if (Utility.InRange(m.Location, Location, 1) && !Utility.InRange(oldLocation, Location, 1) && m.Player &&
!(m.AccessLevel > AccessLevel.Player || m.Hidden))
@ -171,7 +171,7 @@ namespace Server.Items
{
try
{
if (NextSpawn < DateTime.UtcNow)
if (NextSpawn < Core.Now)
{
var map = Map;
var bc = Creatures.RandomElement().CreateInstance<BaseCreature>();
@ -182,7 +182,7 @@ namespace Server.Items
Timer.DelayCall(TimeSpan.FromSeconds(1), SummonCreatureToWorld, bc, spawnLoc, map);
NextSpawn = DateTime.UtcNow + NextSpawnDelay;
NextSpawn = Core.Now + NextSpawnDelay;
}
else
{