From 90d74e412b15f7934636e12c5983c83e6211352d Mon Sep 17 00:00:00 2001 From: xavier Date: Sat, 6 Aug 2011 00:02:52 +0000 Subject: [PATCH] sanity checks, to address a null ref issue. --- .../Evil Home Decor Collection/BedOfNails.cs | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs b/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs index a2c47cc1c..f4b3e9a53 100644 --- a/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs +++ b/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs @@ -6,11 +6,13 @@ namespace Server.Items { public override int LabelNumber { get { return 1074801; } } // Bed of Nails - public BedOfNailsComponent( int itemID ) : base( itemID ) + public BedOfNailsComponent( int itemID ) + : base( itemID ) { } - public BedOfNailsComponent( Serial serial ) : base( serial ) + public BedOfNailsComponent( Serial serial ) + : base( serial ) { } @@ -18,8 +20,8 @@ namespace Server.Items { bool allow = base.OnMoveOver( m ); - if ( allow && Addon is BedOfNailsAddon ) - ( (BedOfNailsAddon) Addon ).OnMoveOver( m ); + if( allow && Addon is BedOfNailsAddon ) + ( (BedOfNailsAddon)Addon ).OnMoveOver( m ); return allow; } @@ -47,7 +49,8 @@ namespace Server.Items private InternalTimer m_Timer; [Constructable] - public BedOfNailsAddon() : base() + public BedOfNailsAddon() + : base() { Direction = Direction.South; @@ -55,23 +58,24 @@ namespace Server.Items AddComponent( new BedOfNailsComponent( 0x2A82 ), 0, -1, 0 ); } - public BedOfNailsAddon( Serial serial ) : base( serial ) + public BedOfNailsAddon( Serial serial ) + : base( serial ) { } public override bool OnMoveOver( Mobile m ) { - if ( m.Alive && ( m.AccessLevel == AccessLevel.Player || !m.Hidden ) ) + if( m.Alive && ( m.AccessLevel == AccessLevel.Player || !m.Hidden ) ) { - if ( m.Player ) + if( m.Player ) { - if ( m.Female ) + if( m.Female ) Effects.PlaySound( Location, Map, Utility.RandomMinMax( 0x53B, 0x53D ) ); else Effects.PlaySound( Location, Map, Utility.RandomMinMax( 0x53E, 0x540 ) ); } - if ( m_Timer == null || !m_Timer.Running ) + if( m_Timer == null || !m_Timer.Running ) ( m_Timer = new InternalTimer( m ) ).Start(); } @@ -94,7 +98,7 @@ namespace Server.Items public virtual void Flip( Mobile from, Direction direction ) { - switch ( direction ) + switch( direction ) { case Direction.East: AddComponent( new BedOfNailsComponent( 0x2A89 ), 0, 0, 0 ); @@ -112,7 +116,8 @@ namespace Server.Items private Mobile m_Mobile; private Point3D m_Location; - public InternalTimer( Mobile m ) : base( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), 5 ) + public InternalTimer( Mobile m ) + : base( TimeSpan.Zero, TimeSpan.FromSeconds( 1 ), 5 ) { m_Mobile = m; m_Location = Point3D.Zero; @@ -120,29 +125,37 @@ namespace Server.Items protected override void OnTick() { - if ( m_Location != m_Mobile.Location ) + if( m_Mobile == null || m_Mobile.Map == null || m_Mobile.Deleted || !m_Mobile.Alive || m_Mobile.Map == Map.Internal ) { - int amount = Utility.RandomMinMax( 0, 7 ); - - for ( int i = 0; i < amount; i++ ) + Stop(); + } + else + { + if( m_Location != m_Mobile.Location ) { - int x = m_Mobile.X + Utility.RandomMinMax( -1, 1 ); - int y = m_Mobile.Y + Utility.RandomMinMax( -1, 1 ); - int z = m_Mobile.Z; + int amount = Utility.RandomMinMax( 0, 7 ); - if ( !m_Mobile.Map.CanFit( x, y, z, 1, false, false, true ) ) + for( int i = 0; i < amount; i++ ) { - z = m_Mobile.Map.GetAverageZ( x, y ); + int x = m_Mobile.X + Utility.RandomMinMax( -1, 1 ); + int y = m_Mobile.Y + Utility.RandomMinMax( -1, 1 ); + int z = m_Mobile.Z; - if ( !m_Mobile.Map.CanFit( x, y, z, 1, false, false, true ) ) - continue; + if( !m_Mobile.Map.CanFit( x, y, z, 1, false, false, true ) ) + { + z = m_Mobile.Map.GetAverageZ( x, y ); + + if( !m_Mobile.Map.CanFit( x, y, z, 1, false, false, true ) ) + { + continue; + } + } + + Blood blood = new Blood( Utility.RandomMinMax( 0x122C, 0x122F ) ); + blood.MoveToWorld( new Point3D( x, y, z ), m_Mobile.Map ); } - - Blood blood = new Blood( Utility.RandomMinMax( 0x122C, 0x122F ) ); - blood.MoveToWorld( new Point3D( x, y, z ), m_Mobile.Map ); + m_Location = m_Mobile.Location; } - - m_Location = m_Mobile.Location; } } } @@ -154,12 +167,14 @@ namespace Server.Items public override int LabelNumber { get { return 1074801; } } // Bed of Nails [Constructable] - public BedOfNailsDeed() : base() + public BedOfNailsDeed() + : base() { LootType = LootType.Blessed; } - public BedOfNailsDeed( Serial serial ) : base( serial ) + public BedOfNailsDeed( Serial serial ) + : base( serial ) { } @@ -177,4 +192,4 @@ namespace Server.Items int version = reader.ReadEncodedInt(); } } -} +} \ No newline at end of file