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

@ -99,7 +99,7 @@ namespace Server.Mobiles
public int Count
{
get { return m_Count; }
set { m_Count = value; m_Stamp = DateTime.Now; }
set { m_Count = value; m_Stamp = DateTime.UtcNow; }
}
}
@ -261,7 +261,7 @@ namespace Server.Mobiles
}
[CommandProperty( AccessLevel.GameMaster )]
public DateTime LastMoved
public int LastMoved
{
get{ return LastMoveTime; }
}
@ -1132,13 +1132,13 @@ namespace Server.Mobiles
if ( pm != null )
{
pm.m_SessionStart = DateTime.Now;
pm.m_SessionStart = DateTime.UtcNow;
if ( pm.m_Quest != null )
pm.m_Quest.StartTimer();
pm.BedrollLogout = false;
pm.LastOnline = DateTime.Now;
pm.LastOnline = DateTime.UtcNow;
}
DisguiseTimers.StartTimer( e.Mobile );
@ -1186,13 +1186,13 @@ namespace Server.Mobiles
if ( pm != null )
{
pm.m_GameTime += (DateTime.Now - pm.m_SessionStart);
pm.m_GameTime += (DateTime.UtcNow - pm.m_SessionStart);
if ( pm.m_Quest != null )
pm.m_Quest.StopTimer();
pm.m_SpeechLog = null;
pm.LastOnline = DateTime.Now;
pm.LastOnline = DateTime.UtcNow;
}
DisguiseTimers.StopTimer( from );
@ -1447,7 +1447,7 @@ namespace Server.Mobiles
}
}
TimeSpan speed = ComputeMovementSpeed( d );
int speed = ComputeMovementSpeed( d );
bool res;
@ -2778,7 +2778,7 @@ namespace Server.Mobiles
Criminal = true;
}
if ( this.Kills >= 5 && DateTime.Now >= m_NextJustAward )
if ( this.Kills >= 5 && DateTime.UtcNow >= m_NextJustAward )
{
Mobile m = FindMostRecentDamager( false );
@ -2805,7 +2805,7 @@ namespace Server.Mobiles
m.FixedParticles( 0x375A, 9, 20, 5027, EffectLayer.Waist );
m.PlaySound( 0x1F7 );
m_NextJustAward = DateTime.Now + TimeSpan.FromMinutes( pointsToGain / 3 );
m_NextJustAward = DateTime.UtcNow + TimeSpan.FromMinutes( pointsToGain / 3 );
}
}
}
@ -2891,7 +2891,7 @@ namespace Server.Mobiles
{
get
{
TimeSpan ts = m_SavagePaintExpiration - DateTime.Now;
TimeSpan ts = m_SavagePaintExpiration - DateTime.UtcNow;
if ( ts < TimeSpan.Zero )
ts = TimeSpan.Zero;
@ -2900,7 +2900,7 @@ namespace Server.Mobiles
}
set
{
m_SavagePaintExpiration = DateTime.Now + value;
m_SavagePaintExpiration = DateTime.UtcNow + value;
}
}
@ -2909,7 +2909,7 @@ namespace Server.Mobiles
{
get
{
TimeSpan ts = m_NextSmithBulkOrder - DateTime.Now;
TimeSpan ts = m_NextSmithBulkOrder - DateTime.UtcNow;
if ( ts < TimeSpan.Zero )
ts = TimeSpan.Zero;
@ -2918,7 +2918,7 @@ namespace Server.Mobiles
}
set
{
try{ m_NextSmithBulkOrder = DateTime.Now + value; }
try{ m_NextSmithBulkOrder = DateTime.UtcNow + value; }
catch{}
}
}
@ -2928,7 +2928,7 @@ namespace Server.Mobiles
{
get
{
TimeSpan ts = m_NextTailorBulkOrder - DateTime.Now;
TimeSpan ts = m_NextTailorBulkOrder - DateTime.UtcNow;
if ( ts < TimeSpan.Zero )
ts = TimeSpan.Zero;
@ -2937,7 +2937,7 @@ namespace Server.Mobiles
}
set
{
try{ m_NextTailorBulkOrder = DateTime.Now + value; }
try{ m_NextTailorBulkOrder = DateTime.UtcNow + value; }
catch{}
}
}
@ -3198,7 +3198,7 @@ namespace Server.Mobiles
CountAndTimeStamp count = (CountAndTimeStamp)tbl[obj];
if ( count != null )
{
if ( count.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.Now )
if ( count.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow )
{
count.Count = 1;
return true;
@ -3517,7 +3517,7 @@ namespace Server.Mobiles
ArrayList remove = new ArrayList();
foreach ( CountAndTimeStamp time in t.Values )
{
if ( time.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.Now )
if ( time.TimeStamp + SkillCheck.AntiMacroExpire <= DateTime.UtcNow )
remove.Add( time );
}
@ -3682,7 +3682,7 @@ namespace Server.Mobiles
get
{
if ( NetState != null )
return m_GameTime + (DateTime.Now - m_SessionStart);
return m_GameTime + (DateTime.UtcNow - m_SessionStart);
else
return m_GameTime;
}
@ -4071,13 +4071,14 @@ namespace Server.Mobiles
#region Fastwalk Prevention
private static bool FastwalkPrevention = true; // Is fastwalk prevention enabled?
private static TimeSpan FastwalkThreshold = TimeSpan.FromSeconds( 0.4 ); // Fastwalk prevention will become active after 0.4 seconds
private static int FastwalkThreshold = 400; // Fastwalk prevention will become active after 0.4 seconds
private DateTime m_NextMovementTime;
private int m_NextMovementTime;
private bool m_HasMoved;
public virtual bool UsesFastwalkPrevention{ get{ return ( AccessLevel < AccessLevel.Counselor ); } }
public override TimeSpan ComputeMovementSpeed( Direction dir, bool checkTurning )
public override int ComputeMovementSpeed( Direction dir, bool checkTurning )
{
if ( checkTurning && (dir & Direction.Mask) != (this.Direction & Direction.Mask) )
return Mobile.RunMount; // We are NOT actually moving (just a direction change)
@ -4106,19 +4107,20 @@ namespace Server.Mobiles
if ( pm == null || !pm.UsesFastwalkPrevention )
return true;
if ( pm.m_NextMovementTime == DateTime.MinValue )
if ( !pm.m_HasMoved )
{
// has not yet moved
pm.m_NextMovementTime = DateTime.Now;
pm.m_NextMovementTime = Core.TickCount;
pm.m_HasMoved = true;
return true;
}
TimeSpan ts = pm.m_NextMovementTime - DateTime.Now;
int ts = pm.m_NextMovementTime - Core.TickCount;
if ( ts < TimeSpan.Zero )
if ( ts < 0 )
{
// been a while since we've last moved
pm.m_NextMovementTime = DateTime.Now;
pm.m_NextMovementTime = Core.TickCount;
return true;
}
@ -4352,9 +4354,9 @@ namespace Server.Mobiles
if ( this.Quest != null && this.Quest.IgnoreYoungProtection( from ) )
return false;
if ( DateTime.Now - m_LastYoungMessage > TimeSpan.FromMinutes( 1.0 ) )
if ( DateTime.UtcNow - m_LastYoungMessage > TimeSpan.FromMinutes( 1.0 ) )
{
m_LastYoungMessage = DateTime.Now;
m_LastYoungMessage = DateTime.UtcNow;
SendLocalizedMessage( 1019067 ); // A monster looks at you menacingly but does not attack. You would be under attack now if not for your status as a new citizen of Britannia.
}
@ -4365,9 +4367,9 @@ namespace Server.Mobiles
public bool CheckYoungHealTime()
{
if ( DateTime.Now - m_LastYoungHeal > TimeSpan.FromMinutes( 5.0 ) )
if ( DateTime.UtcNow - m_LastYoungHeal > TimeSpan.FromMinutes( 5.0 ) )
{
m_LastYoungHeal = DateTime.Now;
m_LastYoungHeal = DateTime.UtcNow;
return true;
}
@ -4661,7 +4663,7 @@ namespace Server.Mobiles
m_Values[index].Value -= value;
if( before != m_Values[index].Value )
m_Values[index].LastDecay = DateTime.Now;
m_Values[index].LastDecay = DateTime.UtcNow;
}
public override string ToString()
@ -4762,7 +4764,7 @@ namespace Server.Mobiles
for( int i = 0; i < t.m_Values.Length; i++ )
{
if( (t.GetLastDecay( i ) + LossDelay) < DateTime.Now )
if( (t.GetLastDecay( i ) + LossDelay) < DateTime.UtcNow )
{
t.Atrophy( i, LossAmount );
}