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

@ -31,7 +31,7 @@ namespace Server.Mobiles
double scalar = caster.Skills[SkillName.SpiritSpeak].Value * 0.01;
m_Target = target;
m_ExpireTime = DateTime.Now + duration;
m_ExpireTime = DateTime.UtcNow + duration;
SetStr( 200 );
SetDex( 150 );
@ -86,7 +86,7 @@ namespace Server.Mobiles
public override void OnThink()
{
if ( !m_Target.Alive || DateTime.Now > m_ExpireTime )
if ( !m_Target.Alive || DateTime.UtcNow > m_ExpireTime )
{
Kill();
return;
@ -134,7 +134,7 @@ namespace Server.Mobiles
PlaySound( 0x37D );
}
if ( m_Target.Hidden && InRange( m_Target, 3 ) && DateTime.Now >= this.NextSkillTime && UseSkill( SkillName.DetectHidden ) )
if (m_Target.Hidden && InRange(m_Target, 3) && Core.TickCount - this.NextSkillTime >= 0 && UseSkill(SkillName.DetectHidden))
{
Target targ = this.Target;

View file

@ -53,7 +53,7 @@ namespace Server.Mobiles
if ( 0.02 > Utility.RandomDouble() )
PackItem( new BlackthornWelcomeBook() );
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 30 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 30 ) );
}
public override void OnDeath( Container c )
@ -146,10 +146,10 @@ namespace Server.Mobiles
{
Mobile combatant = Combatant;
if ( DateTime.Now < m_NextAbilityTime || combatant == null || combatant.Deleted || combatant.Map != Map || !InRange( combatant, 3 ) || !CanBeHarmful( combatant ) || !InLOS( combatant ) )
if ( DateTime.UtcNow < m_NextAbilityTime || combatant == null || combatant.Deleted || combatant.Map != Map || !InRange( combatant, 3 ) || !CanBeHarmful( combatant ) || !InLOS( combatant ) )
return;
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 30 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 5, 30 ) );
if ( Utility.RandomBool() )
{

View file

@ -129,7 +129,7 @@ namespace Server.Mobiles
Animate( 111, 5, 1, true, false, 0 ); // Do a little dance...
if ( AIObject != null )
AIObject.NextMove = DateTime.Now + TimeSpan.FromSeconds( 1.0 );
AIObject.NextMove = DateTime.UtcNow + TimeSpan.FromSeconds( 1.0 );
if ( list.Count >= 3 )
{
@ -140,7 +140,7 @@ namespace Server.Mobiles
dancer.Animate( 111, 5, 1, true, false, 0 ); // Get down tonight...
if ( dancer.AIObject != null )
dancer.AIObject.NextMove = DateTime.Now + TimeSpan.FromSeconds( 1.0 );
dancer.AIObject.NextMove = DateTime.UtcNow + TimeSpan.FromSeconds( 1.0 );
}
Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( EndSavageDance ) );

View file

@ -72,7 +72,7 @@ namespace Server.Mobiles
Hue = 0x41CE;
m_Target = target;
m_ExpireTime = DateTime.Now + TimeSpan.FromMinutes( 10.0 );
m_ExpireTime = DateTime.UtcNow + TimeSpan.FromMinutes( 10.0 );
SetStr( 401, 500 );
SetDex( 296, 315 );
@ -129,7 +129,7 @@ namespace Server.Mobiles
public override void OnThink()
{
if ( !m_Target.Alive || DateTime.Now > m_ExpireTime )
if ( !m_Target.Alive || DateTime.UtcNow > m_ExpireTime )
{
Delete();
return;

View file

@ -102,16 +102,16 @@ namespace Server.Mobiles
if ( combatant == null || combatant.Deleted || combatant.Map != Map || !InRange( combatant, 12 ) || !CanBeHarmful( combatant ) || !InLOS( combatant ) )
return;
if ( DateTime.Now >= m_NextBomb )
if ( DateTime.UtcNow >= m_NextBomb )
{
ThrowBomb( combatant );
m_Thrown++;
if ( 0.75 >= Utility.RandomDouble() && (m_Thrown % 2) == 1 ) // 75% chance to quickly throw another bomb
m_NextBomb = DateTime.Now + TimeSpan.FromSeconds( 3.0 );
m_NextBomb = DateTime.UtcNow + TimeSpan.FromSeconds( 3.0 );
else
m_NextBomb = DateTime.Now + TimeSpan.FromSeconds( 5.0 + (10.0 * Utility.RandomDouble()) ); // 5-15 seconds
m_NextBomb = DateTime.UtcNow + TimeSpan.FromSeconds( 5.0 + (10.0 * Utility.RandomDouble()) ); // 5-15 seconds
}
}

View file

@ -67,7 +67,7 @@ namespace Server.Mobiles
if ( Core.ML && Utility.RandomDouble() < .33 )
PackItem( Engines.Plants.Seed.RandomPeculiarSeed(4) );
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
}
public override void GenerateLoot()
@ -104,7 +104,7 @@ namespace Server.Mobiles
public override void OnThink()
{
if ( DateTime.Now >= m_NextAbilityTime )
if ( DateTime.UtcNow >= m_NextAbilityTime )
{
JukaLord toBuff = null;
@ -121,7 +121,7 @@ namespace Server.Mobiles
{
if ( CanBeBeneficial( toBuff ) && toBuff.BeginAction( typeof( JukaMage ) ) )
{
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 30, 60 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 30, 60 ) );
toBuff.Say( true, "Give me the power to destroy my enemies!" );
this.Say( true, "Fight well my lord!" );
@ -164,7 +164,7 @@ namespace Server.Mobiles
}
else
{
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
}
}

View file

@ -78,7 +78,7 @@ namespace Server.Mobiles
AddItem( new Crossbow() );
PackItem( pack );
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
}
public override void GenerateLoot()
@ -117,9 +117,9 @@ namespace Server.Mobiles
this.PlaySound( 0x1E9 );
}
if ( DateTime.Now >= m_NextAbilityTime )
if ( DateTime.UtcNow >= m_NextAbilityTime )
{
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 10, 15 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 10, 15 ) );
ArrayList list = new ArrayList();

View file

@ -44,7 +44,7 @@ namespace Server.Mobiles
VirtualArmor = 34;
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
}
public override void GenerateLoot()
@ -174,13 +174,13 @@ namespace Server.Mobiles
public override void OnThink()
{
if ( DateTime.Now >= m_NextAbilityTime )
if ( DateTime.UtcNow >= m_NextAbilityTime )
{
Mobile combatant = this.Combatant;
if ( combatant != null && combatant.Map == this.Map && combatant.InRange( this, 12 ) )
{
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 10, 15 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 10, 15 ) );
int ability = Utility.Random( 4 );

View file

@ -44,7 +44,7 @@ namespace Server.Mobiles
VirtualArmor = 16;
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 2, 5 ) );
}
public override void GenerateLoot()
@ -80,13 +80,13 @@ namespace Server.Mobiles
public override void OnThink()
{
if ( DateTime.Now >= m_NextAbilityTime )
if ( DateTime.UtcNow >= m_NextAbilityTime )
{
Mobile combatant = this.Combatant;
if ( combatant != null && combatant.Map == this.Map && combatant.InRange( this, 12 ) && IsEnemy( combatant ) && !UnderEffect( combatant ) )
{
m_NextAbilityTime = DateTime.Now + TimeSpan.FromSeconds( Utility.RandomMinMax( 20, 30 ) );
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 20, 30 ) );
if( combatant is BaseCreature )
{

View file

@ -75,7 +75,7 @@ namespace Server.Mobiles
public void AreaPeace()
{
if ( Combatant == null || Deleted || !Alive || m_NextPeace > DateTime.Now || 0.1 < Utility.RandomDouble() )
if ( Combatant == null || Deleted || !Alive || m_NextPeace > DateTime.UtcNow || 0.1 < Utility.RandomDouble() )
return;
TimeSpan duration = TimeSpan.FromSeconds( Utility.RandomMinMax( 20, 80 ) );
@ -86,20 +86,20 @@ namespace Server.Mobiles
if ( IsValidTarget( p ) )
{
p.PeacedUntil = DateTime.Now + duration;
p.PeacedUntil = DateTime.UtcNow + duration;
p.SendLocalizedMessage( 1072065 ); // You gaze upon the dryad's beauty, and forget to continue battling!
p.FixedParticles( 0x376A, 1, 20, 0x7F5, EffectLayer.Waist );
p.Combatant = null;
}
}
m_NextPeace = DateTime.Now + TimeSpan.FromSeconds( 10 );
m_NextPeace = DateTime.UtcNow + TimeSpan.FromSeconds( 10 );
PlaySound( 0x1D3 );
}
public bool IsValidTarget( PlayerMobile m )
{
if ( m != null && m.PeacedUntil < DateTime.Now && !m.Hidden && m.AccessLevel == AccessLevel.Player && CanBeHarmful( m ) )
if ( m != null && m.PeacedUntil < DateTime.UtcNow && !m.Hidden && m.AccessLevel == AccessLevel.Player && CanBeHarmful( m ) )
return true;
return false;
@ -111,7 +111,7 @@ namespace Server.Mobiles
public void AreaUndress()
{
if ( Combatant == null || Deleted || !Alive || m_NextUndress > DateTime.Now || 0.005 < Utility.RandomDouble() )
if ( Combatant == null || Deleted || !Alive || m_NextUndress > DateTime.UtcNow || 0.005 < Utility.RandomDouble() )
return;
foreach ( Mobile m in GetMobilesInRange( RangePerception ) )
@ -128,7 +128,7 @@ namespace Server.Mobiles
}
}
m_NextUndress = DateTime.Now + TimeSpan.FromMinutes( 1 );
m_NextUndress = DateTime.UtcNow + TimeSpan.FromMinutes( 1 );
}
public void UndressItem( Mobile m, Layer layer )

View file

@ -66,14 +66,14 @@ namespace Server.Mobiles
public void Peace( Mobile target )
{
if ( target == null || Deleted || !Alive || m_NextPeace > DateTime.Now || 0.1 < Utility.RandomDouble() )
if ( target == null || Deleted || !Alive || m_NextPeace > DateTime.UtcNow || 0.1 < Utility.RandomDouble() )
return;
PlayerMobile p = target as PlayerMobile;
if ( p != null && p.PeacedUntil < DateTime.Now && !p.Hidden && CanBeHarmful( p ) )
if ( p != null && p.PeacedUntil < DateTime.UtcNow && !p.Hidden && CanBeHarmful( p ) )
{
p.PeacedUntil = DateTime.Now + TimeSpan.FromMinutes( 1 );
p.PeacedUntil = DateTime.UtcNow + TimeSpan.FromMinutes( 1 );
p.SendLocalizedMessage( 500616 ); // You hear lovely music, and forget to continue battling!
p.FixedParticles( 0x376A, 1, 32, 0x15BD, EffectLayer.Waist );
p.Combatant = null;
@ -81,7 +81,7 @@ namespace Server.Mobiles
PlaySound( 0x58D );
}
m_NextPeace = DateTime.Now + TimeSpan.FromSeconds( 10 );
m_NextPeace = DateTime.UtcNow + TimeSpan.FromSeconds( 10 );
}
#endregion
@ -91,7 +91,7 @@ namespace Server.Mobiles
public void Suppress( Mobile target )
{
if ( target == null || m_Suppressed.ContainsKey( target ) || Deleted || !Alive || m_NextSuppress > DateTime.Now || 0.1 < Utility.RandomDouble() )
if ( target == null || m_Suppressed.ContainsKey( target ) || Deleted || !Alive || m_NextSuppress > DateTime.UtcNow || 0.1 < Utility.RandomDouble() )
return;
TimeSpan delay = TimeSpan.FromSeconds( Utility.RandomMinMax( 20, 80 ) );
@ -115,7 +115,7 @@ namespace Server.Mobiles
PlaySound( 0x58C );
}
m_NextSuppress = DateTime.Now + TimeSpan.FromSeconds( 10 );
m_NextSuppress = DateTime.UtcNow + TimeSpan.FromSeconds( 10 );
}
public static void SuppressRemove( Mobile target )
@ -159,7 +159,7 @@ namespace Server.Mobiles
public void Undress( Mobile target )
{
if ( target == null || Deleted || !Alive || m_NextUndress > DateTime.Now || 0.005 < Utility.RandomDouble() )
if ( target == null || Deleted || !Alive || m_NextUndress > DateTime.UtcNow || 0.005 < Utility.RandomDouble() )
return;
if ( target.Player && target.Female && !target.Hidden && CanBeHarmful( target ) )
@ -173,7 +173,7 @@ namespace Server.Mobiles
target.SendLocalizedMessage( 1072196 ); // The satyr's music makes your blood race. Your clothing is too confining.
}
m_NextUndress = DateTime.Now + TimeSpan.FromMinutes( 1 );
m_NextUndress = DateTime.UtcNow + TimeSpan.FromMinutes( 1 );
}
public void UndressItem( Mobile m, Layer layer )
@ -190,7 +190,7 @@ namespace Server.Mobiles
public void Provoke( Mobile target )
{
if ( target == null || Deleted || !Alive || m_NextProvoke > DateTime.Now || 0.05 < Utility.RandomDouble() )
if ( target == null || Deleted || !Alive || m_NextProvoke > DateTime.UtcNow || 0.05 < Utility.RandomDouble() )
return;
foreach ( Mobile m in GetMobilesInRange( RangePerception ) )
@ -212,7 +212,7 @@ namespace Server.Mobiles
}
}
m_NextProvoke = DateTime.Now + TimeSpan.FromSeconds( 10 );
m_NextProvoke = DateTime.UtcNow + TimeSpan.FromSeconds( 10 );
}
#endregion

View file

@ -256,7 +256,7 @@ namespace Server.Mobiles
return m_Table[ from ] != null;
}
private DateTime m_NextDrop = DateTime.Now;
private DateTime m_NextDrop = DateTime.UtcNow;
public virtual void DropOoze()
{

View file

@ -95,7 +95,7 @@ namespace Server.Mobiles
if ( value != null )
{
Morph( value );
m_LastMorph = DateTime.Now;
m_LastMorph = DateTime.UtcNow;
}
m_MorphedInto = value;
@ -110,10 +110,10 @@ namespace Server.Mobiles
if ( Combatant != null )
{
if ( m_NextFireRing <= DateTime.Now && Utility.RandomDouble() < 0.02 )
if ( m_NextFireRing <= DateTime.UtcNow && Utility.RandomDouble() < 0.02 )
{
FireRing();
m_NextFireRing = DateTime.Now + TimeSpan.FromMinutes( 2 );
m_NextFireRing = DateTime.UtcNow + TimeSpan.FromMinutes( 2 );
}
if ( Combatant.Player && m_MorphedInto != Combatant && Utility.RandomDouble() < 0.05 )
@ -125,7 +125,7 @@ namespace Server.Mobiles
{
bool idle = base.CheckIdle();
if ( idle && m_MorphedInto != null && DateTime.Now - m_LastMorph > TimeSpan.FromSeconds( 30 ) )
if ( idle && m_MorphedInto != null && DateTime.UtcNow - m_LastMorph > TimeSpan.FromSeconds( 30 ) )
MorphedInto = null;
return idle;

View file

@ -61,9 +61,9 @@ namespace Server.Mobiles
{
if (!from.Alive && (from is PlayerMobile))
{
if (!from.Frozen && (DateTime.Now >= m_NextResurrect) && InRange(from, 4) && !InRange(oldLocation, 4) && InLOS(from))
if (!from.Frozen && (DateTime.UtcNow >= m_NextResurrect) && InRange(from, 4) && !InRange(oldLocation, 4) && InLOS(from))
{
m_NextResurrect = DateTime.Now + ResurrectDelay;
m_NextResurrect = DateTime.UtcNow + ResurrectDelay;
if (!from.Criminal && (from.Kills < 5) && (from.Karma > 0))
{
if (from.Map != null && from.Map.CanFit(from.Location, 16, false, false))

View file

@ -51,7 +51,7 @@ namespace Server.Mobiles
public override void OnThink()
{
if ( m_Owner != null && ( DateTime.Now >= m_ExpireTime || m_Owner.Deleted || Map != m_Owner.Map || !InRange( m_Owner, 16 ) ) )
if ( m_Owner != null && ( DateTime.UtcNow >= m_ExpireTime || m_Owner.Deleted || Map != m_Owner.Map || !InRange( m_Owner, 16 ) ) )
{
PlaySound( GetIdleSound() );
Delete();
@ -65,7 +65,7 @@ namespace Server.Mobiles
public PlagueSpawn( Mobile owner ) : base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4 )
{
m_Owner = owner;
m_ExpireTime = DateTime.Now + TimeSpan.FromMinutes( 1.0 );
m_ExpireTime = DateTime.UtcNow + TimeSpan.FromMinutes( 1.0 );
Name = "a plague spawn";
Hue = Utility.Random( 0x11, 15 );

View file

@ -56,10 +56,10 @@ namespace Server.Mobiles
if ( combatant == null || combatant.Deleted || combatant.Map != Map || !InRange( combatant, 12 ) || !CanBeHarmful( combatant ) || !InLOS( combatant ) )
return;
if ( DateTime.Now >= m_NextAttack )
if ( DateTime.UtcNow >= m_NextAttack )
{
SandAttack( combatant );
m_NextAttack = DateTime.Now + TimeSpan.FromSeconds( 10.0 + (10.0 * Utility.RandomDouble()) );
m_NextAttack = DateTime.UtcNow + TimeSpan.FromSeconds( 10.0 + (10.0 * Utility.RandomDouble()) );
}
}