Implement Core.TickCount

Convert movement, actions (lift/use), combat, and spells to use Core.TickCount and avoid DateTime caveats (performance, system time dependency, etc)
Refactor DateTime.Now to DateTime.UtcNow
Add LOS check for Iron Maiden addon
This commit is contained in:
Mark Sturgill 2013-10-06 03:21:18 -07:00
parent f99eefb288
commit d2c670f5c3
241 changed files with 842 additions and 831 deletions

View file

@ -43,7 +43,7 @@ namespace Server.Items
m_Entries = new ArrayList();
m_Created = DateTime.Now;
m_Created = DateTime.UtcNow;
m_Timer = Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), TimeSpan.FromSeconds( 1.0 ), new TimerCallback( OnTick ) );
}
@ -102,7 +102,7 @@ namespace Server.Items
private void OnTick()
{
DateTime now = DateTime.Now;
DateTime now = DateTime.UtcNow;
TimeSpan age = now - this.Created;
if ( age >= TimeSpan.FromSeconds( 100.0 ) )
@ -210,7 +210,7 @@ namespace Server.Items
{
m_Player = player;
m_Fire = fire;
m_Start = DateTime.Now;
m_Start = DateTime.UtcNow;
m_Safe = false;
}
}

View file

@ -124,8 +124,8 @@ namespace Server.Items
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null && timer.Next > DateTime.Now )
return (int) (timer.Next - DateTime.Now).TotalSeconds;
if ( timer != null && timer.Next > DateTime.UtcNow )
return (int) (timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
}
@ -211,7 +211,7 @@ namespace Server.Items
MoveToWorld( loc, map );
m_From = from;
m_End = DateTime.Now + TimeSpan.FromSeconds( 10 );
m_End = DateTime.UtcNow + TimeSpan.FromSeconds( 10 );
SetDamage( min, max );
@ -310,7 +310,7 @@ namespace Server.Items
if ( m_Item.Deleted )
return;
if ( DateTime.Now > m_End )
if ( DateTime.UtcNow > m_End )
{
m_Item.Delete();
Stop();

View file

@ -109,7 +109,7 @@ namespace Server.Items
if ( mon.Controlled || mon.Summoned )
continue;
mon.Pacify( from, DateTime.Now + TimeSpan.FromSeconds( 5.0 ) ); // TODO check
mon.Pacify( from, DateTime.UtcNow + TimeSpan.FromSeconds( 5.0 ) ); // TODO check
}
}
}
@ -146,8 +146,8 @@ namespace Server.Items
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null && timer.Next > DateTime.Now )
return (int) (timer.Next - DateTime.Now).TotalSeconds;
if ( timer != null && timer.Next > DateTime.UtcNow )
return (int) (timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
}

View file

@ -337,7 +337,7 @@ namespace Server.Items
return;
}
if ( DateTime.Now < m_NextUse )
if ( DateTime.UtcNow < m_NextUse )
{
from.SendLocalizedMessage( 502406 ); // This book needs time to recharge.
return;
@ -353,7 +353,7 @@ namespace Server.Items
public virtual void OnTravel()
{
if ( !Core.SA )
m_NextUse = DateTime.Now + UseDelay;
m_NextUse = DateTime.UtcNow + UseDelay;
}
public override void OnAfterDuped( Item newItem )

View file

@ -96,7 +96,7 @@ namespace Server.Items
set
{
if( value != m_ReplenishesCharges && value )
m_LastReplenished = DateTime.Now;
m_LastReplenished = DateTime.UtcNow;
m_ReplenishesCharges = value;
}
@ -112,12 +112,12 @@ namespace Server.Items
if( !m_ReplenishesCharges || m_UsesRemaining >= InitMaxUses )
return;
if( m_LastReplenished + ChargeReplenishRate < DateTime.Now )
if( m_LastReplenished + ChargeReplenishRate < DateTime.UtcNow )
{
TimeSpan timeDifference = DateTime.Now - m_LastReplenished;
TimeSpan timeDifference = DateTime.UtcNow - m_LastReplenished;
m_UsesRemaining = Math.Min( m_UsesRemaining + (int)( timeDifference.Ticks / ChargeReplenishRate.Ticks), InitMaxUses ); //How rude of TimeSpan to not allow timespan division.
m_LastReplenished = DateTime.Now;
m_LastReplenished = DateTime.UtcNow;
if( invalidate )
InvalidateProperties();

View file

@ -34,7 +34,7 @@ namespace Server.Items
// You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
from.SendLocalizedMessage( 1063013, "50\tNinjitsu" );
}
else if ( from.NextSkillTime > DateTime.Now )
else if (Core.TickCount - from.NextSkillTime < 0)
{
// You must wait a few seconds before you can use that item.
from.SendLocalizedMessage( 1070772 );

View file

@ -28,7 +28,7 @@ namespace Server.Items
// You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
from.SendLocalizedMessage( 1063013, "50\tNinjitsu" );
}
else if ( from.NextSkillTime > DateTime.Now )
else if (Core.TickCount - from.NextSkillTime < 0)
{
// You must wait a few seconds before you can use that item.
from.SendLocalizedMessage( 1070772 );

View file

@ -67,7 +67,7 @@ namespace Server.Items
{
from.SendLocalizedMessage( 1062845 + Utility.Random( 3 ) ); //"That doesn't seem like the smartest thing to do." / "That was an encounter you don't wish to repeat." / "Ha! You missed!"
}
else if( Core.SE && Utility.RandomDouble() > .20 && (from.Direction & Direction.Running) != 0 && ( DateTime.Now - from.LastMoveTime ) < from.ComputeMovementSpeed( from.Direction ) )
else if (Core.SE && Utility.RandomDouble() > .20 && (from.Direction & Direction.Running) != 0 && (Core.TickCount - from.LastMoveTime) < from.ComputeMovementSpeed(from.Direction))
{
from.SendLocalizedMessage( 1063305 ); // Didn't your parents ever tell you not to run with scissors in your hand?!
}

View file

@ -330,7 +330,7 @@ namespace Server.Items
if ( t != null )
{
t.Delay = t.Next - DateTime.Now;
t.Delay = t.Next - DateTime.UtcNow;
t.Stop();
}
@ -356,7 +356,7 @@ namespace Server.Items
if ( t != null )
{
return t.Next - DateTime.Now;
return t.Next - DateTime.UtcNow;
}
return TimeSpan.Zero;

View file

@ -47,7 +47,7 @@ namespace Server.Items
Mobile m = (Mobile)entry.Key;
writer.Write( m );
writer.Write( ((Timer)entry.Value).Next - DateTime.Now );
writer.Write( ((Timer)entry.Value).Next - DateTime.UtcNow );
writer.Write( m.NameMod );
}
}

View file

@ -27,7 +27,7 @@ namespace Server.Items
public static void Initialize()
{
m_ServerStart = DateTime.Now;
m_ServerStart = DateTime.UtcNow;
}
[Constructable]
@ -71,7 +71,7 @@ namespace Server.Items
public static void GetTime( Map map, int x, int y, out int hours, out int minutes, out int totalMinutes )
{
TimeSpan timeSpan = DateTime.Now - WorldStart;
TimeSpan timeSpan = DateTime.UtcNow - WorldStart;
totalMinutes = (int)(timeSpan.TotalSeconds / SecondsPerUOMinute);