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

@ -26,7 +26,7 @@ namespace Server.Factions
public List<Candidate> Candidates { get { return m_Candidates; } }
public ElectionState State{ get{ return m_State; } set{ m_State = value; m_LastStateTime = DateTime.Now; } }
public ElectionState State{ get{ return m_State; } set{ m_State = value; m_LastStateTime = DateTime.UtcNow; } }
public DateTime LastStateTime{ get{ return m_LastStateTime; } }
[CommandProperty( AccessLevel.GameMaster )]
@ -47,7 +47,7 @@ namespace Server.Factions
case ElectionState.Campaign: period = CampaignPeriod; break;
}
TimeSpan until = (m_LastStateTime + period) - DateTime.Now;
TimeSpan until = (m_LastStateTime + period) - DateTime.UtcNow;
if ( until < TimeSpan.Zero )
until = TimeSpan.Zero;
@ -66,7 +66,7 @@ namespace Server.Factions
case ElectionState.Campaign: period = CampaignPeriod; break;
}
m_LastStateTime = DateTime.Now - period + value;
m_LastStateTime = DateTime.UtcNow - period + value;
}
}
@ -280,7 +280,7 @@ namespace Server.Factions
{
case ElectionState.Pending:
{
if ( (m_LastStateTime + PendingPeriod) > DateTime.Now )
if ( (m_LastStateTime + PendingPeriod) > DateTime.UtcNow )
break;
m_Faction.Broadcast( 1038023 ); // Campaigning for the Faction Commander election has begun.
@ -292,7 +292,7 @@ namespace Server.Factions
}
case ElectionState.Campaign:
{
if ( (m_LastStateTime + CampaignPeriod) > DateTime.Now )
if ( (m_LastStateTime + CampaignPeriod) > DateTime.UtcNow )
break;
if ( m_Candidates.Count == 0 )
@ -332,7 +332,7 @@ namespace Server.Factions
}
case ElectionState.Election:
{
if ( (m_LastStateTime + VotingPeriod) > DateTime.Now )
if ( (m_LastStateTime + VotingPeriod) > DateTime.UtcNow )
break;
m_Faction.Broadcast( 1038024 ); // The results for the Faction Commander election are in
@ -445,7 +445,7 @@ namespace Server.Factions
else
m_Address = IPAddress.None;
m_Time = DateTime.Now;
m_Time = DateTime.UtcNow;
}
public Voter( GenericReader reader, Mobile candidate )

View file

@ -218,7 +218,7 @@ namespace Server.Factions
}
else
{
recvState.LastHonorTime = DateTime.Now;
recvState.LastHonorTime = DateTime.UtcNow;
giveState.KillPoints -= 5;
recvState.KillPoints += 4;
@ -552,7 +552,7 @@ namespace Server.Factions
if ( pl == null || !pl.IsLeaving )
return false;
if ( (pl.Leaving + LeavePeriod) >= DateTime.Now )
if ( (pl.Leaving + LeavePeriod) >= DateTime.UtcNow )
return false;
mob.SendLocalizedMessage( 1005163 ); // You have now quit your faction
@ -833,12 +833,12 @@ namespace Server.Factions
{
Sigil sigil = sigils[i];
if ( !sigil.IsBeingCorrupted && sigil.GraceStart != DateTime.MinValue && (sigil.GraceStart + Sigil.CorruptionGrace) < DateTime.Now )
if ( !sigil.IsBeingCorrupted && sigil.GraceStart != DateTime.MinValue && (sigil.GraceStart + Sigil.CorruptionGrace) < DateTime.UtcNow )
{
if ( sigil.LastMonolith is StrongholdMonolith && ( sigil.Corrupted == null || sigil.LastMonolith.Faction != sigil.Corrupted ))
{
sigil.Corrupting = sigil.LastMonolith.Faction;
sigil.CorruptionStart = DateTime.Now;
sigil.CorruptionStart = DateTime.UtcNow;
}
else
{
@ -851,19 +851,19 @@ namespace Server.Factions
if ( sigil.LastMonolith == null || sigil.LastMonolith.Sigil == null )
{
if ( (sigil.LastStolen + Sigil.ReturnPeriod) < DateTime.Now )
if ( (sigil.LastStolen + Sigil.ReturnPeriod) < DateTime.UtcNow )
sigil.ReturnHome();
}
else
{
if ( sigil.IsBeingCorrupted && (sigil.CorruptionStart + Sigil.CorruptionPeriod) < DateTime.Now )
if ( sigil.IsBeingCorrupted && (sigil.CorruptionStart + Sigil.CorruptionPeriod) < DateTime.UtcNow )
{
sigil.Corrupted = sigil.Corrupting;
sigil.Corrupting = null;
sigil.CorruptionStart = DateTime.MinValue;
sigil.GraceStart = DateTime.MinValue;
}
else if ( sigil.IsPurifying && (sigil.PurificationStart + Sigil.PurificationPeriod) < DateTime.Now )
else if ( sigil.IsPurifying && (sigil.PurificationStart + Sigil.PurificationPeriod) < DateTime.UtcNow )
{
sigil.PurificationStart = DateTime.MinValue;
sigil.Corrupted = null;

View file

@ -26,13 +26,13 @@ namespace Server.Factions
if ( m_Item == null || m_Item.Deleted )
return true;
return ( m_Expiration != DateTime.MinValue && DateTime.Now >= m_Expiration );
return ( m_Expiration != DateTime.MinValue && DateTime.UtcNow >= m_Expiration );
}
}
public void StartExpiration()
{
m_Expiration = DateTime.Now + ExpirationPeriod;
m_Expiration = DateTime.UtcNow + ExpirationPeriod;
}
public void CheckAttach()

View file

@ -28,7 +28,7 @@ namespace Server.Factions
{
for ( int i = 0; i < m_LastBroadcasts.Length; ++i )
{
if ( DateTime.Now >= (m_LastBroadcasts[i] + BroadcastPeriod) )
if ( DateTime.UtcNow >= (m_LastBroadcasts[i] + BroadcastPeriod) )
return true;
}
@ -36,15 +36,15 @@ namespace Server.Factions
}
}
public bool IsAtrophyReady{ get{ return DateTime.Now >= (m_LastAtrophy + TimeSpan.FromHours( 47.0 )); } }
public bool IsAtrophyReady{ get{ return DateTime.UtcNow >= (m_LastAtrophy + TimeSpan.FromHours( 47.0 )); } }
public int CheckAtrophy()
{
if ( DateTime.Now < (m_LastAtrophy + TimeSpan.FromHours( 47.0 )) )
if ( DateTime.UtcNow < (m_LastAtrophy + TimeSpan.FromHours( 47.0 )) )
return 0;
int distrib = 0;
m_LastAtrophy = DateTime.Now;
m_LastAtrophy = DateTime.UtcNow;
List<PlayerState> members = new List<PlayerState>( m_Members );
@ -72,9 +72,9 @@ namespace Server.Factions
{
for ( int i = 0; i < m_LastBroadcasts.Length; ++i )
{
if ( DateTime.Now >= (m_LastBroadcasts[i] + BroadcastPeriod) )
if ( DateTime.UtcNow >= (m_LastBroadcasts[i] + BroadcastPeriod) )
{
m_LastBroadcasts[i] = DateTime.Now;
m_LastBroadcasts[i] = DateTime.UtcNow;
break;
}
}
@ -193,7 +193,7 @@ namespace Server.Factions
m_Commander = reader.ReadMobile();
if ( version < 5 )
m_LastAtrophy = DateTime.Now;
m_LastAtrophy = DateTime.UtcNow;
if ( version < 4 )
{

View file

@ -104,7 +104,7 @@ namespace Server.Factions
if ( Faction.CheckLeaveTimer( from ) )
break;
TimeSpan remaining = ( pl.Leaving + Faction.LeavePeriod ) - DateTime.Now;
TimeSpan remaining = ( pl.Leaving + Faction.LeavePeriod ) - DateTime.UtcNow;
if( remaining.TotalDays >= 1 )
from.SendLocalizedMessage( 1042743, remaining.TotalDays.ToString( "N0" ) ) ;// Your term of service will come to an end in ~1_DAYS~ days.

View file

@ -12,12 +12,12 @@ namespace Server.Factions
public Mobile GivenTo{ get{ return m_GivenTo; } }
public DateTime TimeOfGift{ get{ return m_TimeOfGift; } }
public bool IsExpired{ get{ return ( m_TimeOfGift + ExpirePeriod ) < DateTime.Now; } }
public bool IsExpired{ get{ return ( m_TimeOfGift + ExpirePeriod ) < DateTime.UtcNow; } }
public SilverGivenEntry( Mobile givenTo )
{
m_GivenTo = givenTo;
m_TimeOfGift = DateTime.Now;
m_TimeOfGift = DateTime.UtcNow;
}
}
}

View file

@ -67,7 +67,7 @@ namespace Server.Factions
public bool TaxChangeReady
{
get{ return ( m_State.LastTaxChange + TaxChangePeriod ) < DateTime.Now; }
get{ return ( m_State.LastTaxChange + TaxChangePeriod ) < DateTime.UtcNow; }
}
public static Town FromRegion( Region reg )
@ -224,7 +224,7 @@ namespace Server.Factions
public void CheckIncome()
{
if ( (LastIncome + IncomePeriod) > DateTime.Now || Owner == null )
if ( (LastIncome + IncomePeriod) > DateTime.UtcNow || Owner == null )
return;
ProcessIncome();
@ -232,7 +232,7 @@ namespace Server.Factions
public void ProcessIncome()
{
LastIncome = DateTime.Now;
LastIncome = DateTime.UtcNow;
int flow = NetCashFlow;
@ -447,7 +447,7 @@ namespace Server.Factions
if ( m_State.Owner == null ) // going from unowned to owned
{
LastIncome = DateTime.Now;
LastIncome = DateTime.UtcNow;
f.Silver += SilverCaptureBonus;
}
else if ( f == null ) // going from owned to unowned

View file

@ -55,7 +55,7 @@ namespace Server.Factions
{
case ElectionState.Pending:
{
TimeSpan toGo = ( election.LastStateTime + Election.PendingPeriod ) - DateTime.Now;
TimeSpan toGo = ( election.LastStateTime + Election.PendingPeriod ) - DateTime.UtcNow;
int days = (int) (toGo.TotalDays + 0.5);
AddHtmlLocalized( 20, 40, 380, 20, 1038034, false, false ); // A new election campaign is pending
@ -74,7 +74,7 @@ namespace Server.Factions
}
case ElectionState.Campaign:
{
TimeSpan toGo = ( election.LastStateTime + Election.CampaignPeriod ) - DateTime.Now;
TimeSpan toGo = ( election.LastStateTime + Election.CampaignPeriod ) - DateTime.UtcNow;
int days = (int) (toGo.TotalDays + 0.5);
AddHtmlLocalized( 20, 40, 380, 20, 1018058, false, false ); // There is an election campaign in progress.
@ -106,7 +106,7 @@ namespace Server.Factions
}
case ElectionState.Election:
{
TimeSpan toGo = ( election.LastStateTime + Election.VotingPeriod ) - DateTime.Now;
TimeSpan toGo = ( election.LastStateTime + Election.VotingPeriod ) - DateTime.UtcNow;
int days = (int) Math.Ceiling( toGo.TotalDays );
AddHtmlLocalized( 20, 40, 380, 20, 1018060, false, false ); // There is an election vote in progress.

View file

@ -211,7 +211,7 @@ namespace Server.Factions
if ( m_From.AccessLevel == AccessLevel.Player && !m_Town.TaxChangeReady )
{
TimeSpan remaining = DateTime.Now - ( m_Town.LastTaxChange + Town.TaxChangePeriod );
TimeSpan remaining = DateTime.UtcNow - ( m_Town.LastTaxChange + Town.TaxChangePeriod );
if ( remaining.TotalMinutes < 4 )
m_From.SendLocalizedMessage( 1042165 ); // You must wait a short while before changing prices again.
@ -229,7 +229,7 @@ namespace Server.Factions
m_Town.Tax = newTax;
if ( m_From.AccessLevel == AccessLevel.Player )
m_Town.LastTaxChange = DateTime.Now;
m_Town.LastTaxChange = DateTime.UtcNow;
}
break;

View file

@ -46,7 +46,7 @@ namespace Server.Factions
if ( pl != null )
{
pl.Leaving = DateTime.Now;
pl.Leaving = DateTime.UtcNow;
if ( Faction.LeavePeriod == TimeSpan.FromDays( 3.0 ) )
m_From.SendLocalizedMessage( 1005065 ); // You will be removed from the faction in 3 days
@ -69,7 +69,7 @@ namespace Server.Factions
if ( pl != null )
{
pl.Leaving = DateTime.Now;
pl.Leaving = DateTime.UtcNow;
if ( Faction.LeavePeriod == TimeSpan.FromDays( 3.0 ) )
mob.SendLocalizedMessage( 1005060 ); // Your guild will quit the faction in 3 days

View file

@ -233,7 +233,7 @@ namespace Server.Factions
private void BeginCorrupting( Faction faction )
{
m_Corrupting = faction;
m_CorruptionStart = DateTime.Now;
m_CorruptionStart = DateTime.UtcNow;
}
private void ClearCorrupting()
@ -250,7 +250,7 @@ namespace Server.Factions
if ( !IsBeingCorrupted )
return TimeSpan.Zero;
TimeSpan ts = ( m_CorruptionStart + CorruptionPeriod ) - DateTime.Now;
TimeSpan ts = ( m_CorruptionStart + CorruptionPeriod ) - DateTime.UtcNow;
if ( ts < TimeSpan.Zero )
ts = TimeSpan.Zero;
@ -319,7 +319,7 @@ namespace Server.Factions
if ( m_Corrupted != newController )
BeginCorrupting( newController );
}
else if ( m_GraceStart > DateTime.MinValue && (m_GraceStart + CorruptionGrace) < DateTime.Now )
else if ( m_GraceStart > DateTime.MinValue && (m_GraceStart + CorruptionGrace) < DateTime.UtcNow )
{
if ( m_Corrupted != newController )
BeginCorrupting( newController ); // grace time over, reset period
@ -334,7 +334,7 @@ namespace Server.Factions
}
else if ( m_GraceStart == DateTime.MinValue )
{
m_GraceStart = DateTime.Now;
m_GraceStart = DateTime.UtcNow;
}
m_PurificationStart = DateTime.MinValue;
@ -356,7 +356,7 @@ namespace Server.Factions
m.Sigil = this;
m_Corrupting = null;
m_PurificationStart = DateTime.Now;
m_PurificationStart = DateTime.UtcNow;
m_CorruptionStart = DateTime.MinValue;
m_Town.Capture( m_Corrupted );

View file

@ -191,7 +191,7 @@ namespace Server.Factions
Visible = false;
m_Faction = f;
m_TimeOfPlacement = DateTime.Now;
m_TimeOfPlacement = DateTime.UtcNow;
m_Placer = m;
}
@ -206,7 +206,7 @@ namespace Server.Factions
if ( decayPeriod == TimeSpan.MaxValue )
return false;
if ( (m_TimeOfPlacement + decayPeriod) < DateTime.Now )
if ( (m_TimeOfPlacement + decayPeriod) < DateTime.UtcNow )
{
Timer.DelayCall( TimeSpan.Zero, new TimerCallback( Delete ) );
return true;

View file

@ -185,14 +185,14 @@ namespace Server.Factions
else if ( Town.FromRegion( this.Region ) == m_Town )
{
this.Say( 1042180 ); // Your orders, sire?
m_OrdersEnd = DateTime.Now + TimeSpan.FromSeconds( 10.0 );
m_OrdersEnd = DateTime.UtcNow + TimeSpan.FromSeconds( 10.0 );
}
}
else if ( DateTime.Now < m_OrdersEnd )
else if ( DateTime.UtcNow < m_OrdersEnd )
{
if ( m_Town != null && m_Town.IsSheriff( from ) && Town.FromRegion( this.Region ) == m_Town )
{
m_OrdersEnd = DateTime.Now + TimeSpan.FromSeconds( 10.0 );
m_OrdersEnd = DateTime.UtcNow + TimeSpan.FromSeconds( 10.0 );
bool understood = true;
ReactionType newType = 0;

View file

@ -94,7 +94,7 @@ namespace Server.Factions
if ( entry.Chance > Utility.Random( 100 ) )
{
releaseTime = DateTime.Now + entry.Hold;
releaseTime = DateTime.UtcNow + entry.Hold;
return (Spell) Activator.CreateInstance( entry.Spell, new object[]{ mob, null } );
}
}
@ -143,7 +143,7 @@ namespace Server.Factions
if ( m_Bandage == null )
return TimeSpan.MaxValue;
TimeSpan ts = ( m_BandageStart + m_Bandage.Timer.Delay ) - DateTime.Now;
TimeSpan ts = ( m_BandageStart + m_Bandage.Timer.Delay ) - DateTime.UtcNow;
if ( ts < TimeSpan.FromSeconds( -1.0 ) )
{
@ -206,7 +206,7 @@ namespace Server.Factions
return false;
m_Bandage = BandageContext.BeginHeal( m_Guard, m_Guard );
m_BandageStart = DateTime.Now;
m_BandageStart = DateTime.UtcNow;
return ( m_Bandage != null );
}
@ -486,9 +486,9 @@ namespace Server.Factions
Mobile dispelTarget = FindDispelTarget( true );
if ( m_Guard.Target != null && m_ReleaseTarget == DateTime.MinValue )
m_ReleaseTarget = DateTime.Now + TimeSpan.FromSeconds( 10.0 );
m_ReleaseTarget = DateTime.UtcNow + TimeSpan.FromSeconds( 10.0 );
if ( m_Guard.Target != null && DateTime.Now > m_ReleaseTarget )
if ( m_Guard.Target != null && DateTime.UtcNow > m_ReleaseTarget )
{
Target targ = m_Guard.Target;
@ -584,7 +584,7 @@ namespace Server.Factions
StartBandage();
}
if ( m_Mobile.Spell == null && DateTime.Now >= m_Mobile.NextSpellTime )
if ( m_Mobile.Spell == null && Core.TickCount - m_Mobile.NextSpellTime >= 0 )
{
Spell spell = null;
@ -614,7 +614,7 @@ namespace Server.Factions
{
if ( m_Guard.Mana >= 11 && (m_Guard.Hits + 30) < m_Guard.HitsMax )
spell = new GreaterHealSpell( m_Guard, null );
else if ( (m_Guard.Hits + 10) < m_Guard.HitsMax && (m_Guard.Mana < 11 || (m_Guard.NextCombatTime - DateTime.Now) > TimeSpan.FromSeconds( 2.0 )) )
else if ( (m_Guard.Hits + 10) < m_Guard.HitsMax && (m_Guard.Mana < 11 || (m_Guard.NextCombatTime - Core.TickCount) > 2000) )
spell = new HealSpell( m_Guard, null );
}
else if ( m_Guard.CanBeginAction( typeof( BaseHealPotion ) ) )