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
|
|
@ -483,7 +483,7 @@ namespace Server.Spells
|
|||
{
|
||||
Caster.SendLocalizedMessage(502644); // You have not yet recovered from casting a spell.
|
||||
}
|
||||
else if (Caster is PlayerMobile mobile && mobile.PeacedUntil > DateTime.UtcNow)
|
||||
else if (Caster is PlayerMobile mobile && mobile.PeacedUntil > Core.Now)
|
||||
{
|
||||
mobile.SendLocalizedMessage(1072060); // You cannot cast a spell while calmed.
|
||||
}
|
||||
|
|
@ -691,7 +691,7 @@ namespace Server.Spells
|
|||
|
||||
var fcDelay = TimeSpan.FromSeconds(-(CastDelayFastScalar * fc * CastDelaySecondsPerTick));
|
||||
|
||||
return (CastDelayBase + fcDelay).Max(CastDelayMinimum);
|
||||
return Utility.Max(CastDelayBase + fcDelay, CastDelayMinimum);
|
||||
}
|
||||
|
||||
public virtual int ComputeKarmaAward() => 0;
|
||||
|
|
@ -723,7 +723,7 @@ namespace Server.Spells
|
|||
Caster.SendLocalizedMessage(502646); // You cannot cast a spell while frozen.
|
||||
DoFizzle();
|
||||
}
|
||||
else if (Caster is PlayerMobile mobile && mobile.PeacedUntil > DateTime.UtcNow)
|
||||
else if (Caster is PlayerMobile mobile && mobile.PeacedUntil > Core.Now)
|
||||
{
|
||||
mobile.SendLocalizedMessage(1072060); // You cannot cast a spell while calmed.
|
||||
DoFizzle();
|
||||
|
|
@ -924,7 +924,7 @@ namespace Server.Spells
|
|||
|
||||
if (m_Spell.Caster.Player && m_Spell.Caster.Target != originalTarget)
|
||||
{
|
||||
m_Spell.Caster.Target?.BeginTimeout(m_Spell.Caster, TimeSpan.FromSeconds(30.0));
|
||||
m_Spell.Caster.Target?.BeginTimeout(m_Spell.Caster, 30000); // 30 seconds
|
||||
}
|
||||
|
||||
m_Spell.m_CastTimer = null;
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ namespace Server.Spells
|
|||
{
|
||||
var info = m.Aggressed[i];
|
||||
|
||||
if (info.Defender.Player && DateTime.UtcNow - info.LastCombatTime < CombatHeatDelay)
|
||||
if (info.Defender.Player && Core.Now - info.LastCombatTime < CombatHeatDelay)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -228,7 +228,7 @@ namespace Server.Spells
|
|||
{
|
||||
var info = m.Aggressors[i];
|
||||
|
||||
if (info.Attacker.Player && DateTime.UtcNow - info.LastCombatTime < CombatHeatDelay)
|
||||
if (info.Attacker.Player && Core.Now - info.LastCombatTime < CombatHeatDelay)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ namespace Server.Spells.Fifth
|
|||
|
||||
m_Caster = caster;
|
||||
|
||||
m_End = DateTime.UtcNow + duration;
|
||||
m_End = Core.Now + duration;
|
||||
|
||||
m_Timer = new InternalTimer(this, TimeSpan.FromSeconds(Math.Abs(val) * 0.2), caster.InLOS(this), canFit);
|
||||
m_Timer.Start();
|
||||
|
|
@ -267,7 +267,7 @@ namespace Server.Spells.Fifth
|
|||
);
|
||||
}
|
||||
}
|
||||
else if (DateTime.UtcNow > m_Item.m_End)
|
||||
else if (Core.Now > m_Item.m_End)
|
||||
{
|
||||
m_Item.Delete();
|
||||
Stop();
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace Server.Spells.Fourth
|
|||
|
||||
m_Damage = damage;
|
||||
|
||||
m_End = DateTime.UtcNow + duration;
|
||||
m_End = Core.Now + duration;
|
||||
|
||||
m_Timer = new InternalTimer(this, TimeSpan.FromSeconds(Math.Abs(val) * 0.2), caster.InLOS(this), canFit);
|
||||
m_Timer.Start();
|
||||
|
|
@ -263,7 +263,7 @@ namespace Server.Spells.Fourth
|
|||
);
|
||||
}
|
||||
}
|
||||
else if (DateTime.UtcNow > m_Item.m_End)
|
||||
else if (Core.Now > m_Item.m_End)
|
||||
{
|
||||
m_Item.Delete();
|
||||
Stop();
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ namespace Server.Spells.Necromancy
|
|||
{
|
||||
m_Caster = caster;
|
||||
m_Target = target;
|
||||
m_End = DateTime.UtcNow + delay;
|
||||
m_End = Core.Now + delay;
|
||||
|
||||
Priority = TimerPriority.TwoFiftyMS;
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ namespace Server.Spells.Necromancy
|
|||
protected override void OnTick()
|
||||
{
|
||||
if (m_Caster.Deleted || m_Target.Deleted || !m_Caster.Alive || !m_Target.Alive ||
|
||||
DateTime.UtcNow >= m_End)
|
||||
Core.Now >= m_End)
|
||||
{
|
||||
DoExpire();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,13 +119,13 @@ namespace Server.Spells.Necromancy
|
|||
)
|
||||
{
|
||||
m_Target = target;
|
||||
m_End = DateTime.UtcNow + delay;
|
||||
m_End = Core.Now + delay;
|
||||
Priority = TimerPriority.TwoFiftyMS;
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (m_Target.Deleted || !m_Target.Alive || DateTime.UtcNow >= m_End)
|
||||
if (m_Target.Deleted || !m_Target.Alive || Core.Now >= m_End)
|
||||
{
|
||||
MindRotSpell.ClearMindRotScalar(m_Target);
|
||||
Stop();
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Server.Spells.Necromancy
|
|||
{
|
||||
damage = Utility.RandomMinMax(3, 7);
|
||||
timer.Delay += TimeSpan.FromSeconds(2.0);
|
||||
buffTime = timer.Next - DateTime.UtcNow;
|
||||
buffTime = timer.Next - Core.Now;
|
||||
}
|
||||
|
||||
BuffInfo.AddBuff(m, new BuffInfo(BuffIcon.PainSpike, 1075667, buffTime, m, Convert.ToString((int)damage)));
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ namespace Server.Spells.Necromancy
|
|||
m_MaxBaseDamage = spiritLevel + 1;
|
||||
|
||||
m_HitDelay = 5;
|
||||
m_NextHit = DateTime.UtcNow + TimeSpan.FromSeconds(m_HitDelay);
|
||||
m_NextHit = Core.Now + TimeSpan.FromSeconds(m_HitDelay);
|
||||
|
||||
m_Count = (int)spiritLevel;
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ namespace Server.Spells.Necromancy
|
|||
Stop();
|
||||
}
|
||||
|
||||
if (!m_Target.Alive || DateTime.UtcNow < m_NextHit)
|
||||
if (!m_Target.Alive || Core.Now < m_NextHit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ namespace Server.Spells.Necromancy
|
|||
}
|
||||
else
|
||||
{
|
||||
m_NextHit = DateTime.UtcNow + TimeSpan.FromSeconds(m_HitDelay);
|
||||
m_NextHit = Core.Now + TimeSpan.FromSeconds(m_HitDelay);
|
||||
|
||||
var damage = m_MinBaseDamage + Utility.RandomDouble() * (m_MaxBaseDamage - m_MinBaseDamage);
|
||||
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ namespace Server.Mobiles
|
|||
var duration = TimeSpan.FromSeconds(30 + caster.Skills.Ninjitsu.Fixed / 40);
|
||||
|
||||
new UnsummonTimer(caster, this, duration).Start();
|
||||
SummonEnd = DateTime.UtcNow + duration;
|
||||
SummonEnd = Core.Now + duration;
|
||||
|
||||
MirrorImage.AddClone(m_Caster);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ namespace Server.Spells.Sixth
|
|||
m_Timer = new InternalTimer(this, duration);
|
||||
m_Timer.Start();
|
||||
|
||||
m_End = DateTime.UtcNow + duration;
|
||||
m_End = Core.Now + duration;
|
||||
}
|
||||
|
||||
public InternalItem(Serial serial) : base(serial)
|
||||
|
|
@ -170,7 +170,7 @@ namespace Server.Spells.Sixth
|
|||
m_Caster = reader.ReadEntity<Mobile>();
|
||||
m_End = reader.ReadDeltaTime();
|
||||
|
||||
m_Timer = new InternalTimer(this, m_End - DateTime.UtcNow);
|
||||
m_Timer = new InternalTimer(this, m_End - Core.Now);
|
||||
m_Timer.Start();
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ namespace Server.Spells.Spellweaving
|
|||
{
|
||||
to.SendLocalizedMessage(1072828); // Your arcane focus is renewed.
|
||||
focus.LifeSpan = duration;
|
||||
focus.CreationTime = DateTime.UtcNow;
|
||||
focus.CreationTime = Core.Now;
|
||||
focus.StrengthBonus = strengthBonus;
|
||||
focus.InvalidateProperties();
|
||||
focus.SendTimeRemainingMessage(to);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Server.Items
|
|||
public TransientItem(int itemID, TimeSpan lifeSpan)
|
||||
: base(itemID)
|
||||
{
|
||||
CreationTime = DateTime.UtcNow;
|
||||
CreationTime = Core.Now;
|
||||
LifeSpan = lifeSpan;
|
||||
|
||||
m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), CheckExpiry);
|
||||
|
|
@ -67,7 +67,7 @@ namespace Server.Items
|
|||
|
||||
public virtual void CheckExpiry()
|
||||
{
|
||||
if (CreationTime + LifeSpan < DateTime.UtcNow)
|
||||
if (CreationTime + LifeSpan < Core.Now)
|
||||
{
|
||||
Expire(RootParent as Mobile);
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ namespace Server.Items
|
|||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
var remaining = CreationTime + LifeSpan - DateTime.UtcNow;
|
||||
var remaining = CreationTime + LifeSpan - Core.Now;
|
||||
|
||||
list.Add(1072517, ((int)remaining.TotalSeconds).ToString()); // Lifespan: ~1_val~ seconds
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace Server.Spells
|
|||
|
||||
from.SendLocalizedMessage(501943); // Target cannot be seen. Try again.
|
||||
from.Target = new SpellTargetPoint3D(m_Spell);
|
||||
from.Target.BeginTimeout(from, TimeoutTime - DateTime.UtcNow);
|
||||
from.Target.BeginTimeout(from, TimeoutTime - Core.TickCount);
|
||||
m_Spell = null; // Needed?
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ namespace Server.Spells.Third
|
|||
m_Timer = new InternalTimer(this, TimeSpan.FromSeconds(10.0));
|
||||
m_Timer.Start();
|
||||
|
||||
m_End = DateTime.UtcNow + TimeSpan.FromSeconds(10.0);
|
||||
m_End = Core.Now + TimeSpan.FromSeconds(10.0);
|
||||
}
|
||||
|
||||
public InternalItem(Serial serial) : base(serial)
|
||||
|
|
@ -152,7 +152,7 @@ namespace Server.Spells.Third
|
|||
{
|
||||
m_End = reader.ReadDeltaTime();
|
||||
|
||||
m_Timer = new InternalTimer(this, m_End - DateTime.UtcNow);
|
||||
m_Timer = new InternalTimer(this, m_End - Core.Now);
|
||||
m_Timer.Start();
|
||||
|
||||
break;
|
||||
|
|
@ -164,7 +164,7 @@ namespace Server.Spells.Third
|
|||
m_Timer = new InternalTimer(this, duration);
|
||||
m_Timer.Start();
|
||||
|
||||
m_End = DateTime.UtcNow + duration;
|
||||
m_End = Core.Now + duration;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue