Fixes more casting and null propogation

This commit is contained in:
Kamron Batman 2018-09-11 16:20:57 -07:00
parent 403e2a8b9d
commit f211efc3bd
7 changed files with 242 additions and 412 deletions

View file

@ -250,12 +250,12 @@ namespace Server.Mobiles
if (!isOwner && !isFriend) if (!isOwner && !isFriend)
return; return;
else if (isFriend && order != OrderType.Follow && order != OrderType.Stay && order != OrderType.Stop) if (isFriend && order != OrderType.Follow && order != OrderType.Stay && order != OrderType.Stop)
return; return;
if (order == OrderType.Attack) if (order == OrderType.Attack)
{ {
if (target is BaseCreature && ((BaseCreature)target).IsScaryToPets && m_Mobile.IsScaredOfScaryThings) if (target is BaseCreature creature && creature.IsScaryToPets && m_Mobile.IsScaredOfScaryThings)
{ {
m_Mobile.SayTo(from, "Your pet refuses to attack this creature!"); m_Mobile.SayTo(from, "Your pet refuses to attack this creature!");
return; return;

View file

@ -920,7 +920,7 @@ namespace Server.Mobiles
public bool CanDispel( Mobile m ) public bool CanDispel( Mobile m )
{ {
return ( m is BaseCreature && ( (BaseCreature)m ).Summoned && m_Mobile.CanBeHarmful( m, false ) && !( (BaseCreature)m ).IsAnimatedDead ); return ( m is BaseCreature creature && creature.Summoned && m_Mobile.CanBeHarmful( creature, false ) && !creature.IsAnimatedDead );
} }
private static int[] m_Offsets = new int[] private static int[] m_Offsets = new int[]

View file

@ -61,7 +61,7 @@ namespace Server.Mobiles
m_Mobile.Say( Utility.RandomList( 1005305, 501603 ) ); m_Mobile.Say( Utility.RandomList( 1005305, 501603 ) );
Action = ActionType.Flee; Action = ActionType.Flee;
return true; return true;
} }
@ -88,7 +88,7 @@ namespace Server.Mobiles
m_Mobile.FocusMob = null; m_Mobile.FocusMob = null;
Action = ActionType.Wander; Action = ActionType.Wander;
} }
} }
@ -109,28 +109,28 @@ namespace Server.Mobiles
return base.HandlesOnSpeech( from ); return base.HandlesOnSpeech( from );
} }
// Temporary // Temporary
public override void OnSpeech( SpeechEventArgs e ) public override void OnSpeech( SpeechEventArgs e )
{ {
base.OnSpeech( e ); base.OnSpeech( e );
Mobile from = e.Mobile; Mobile from = e.Mobile;
if ( m_Mobile is BaseVendor && from.InRange( m_Mobile, Core.AOS ? 1 : 4 ) && !e.Handled ) if ( m_Mobile is BaseVendor vendor && from.InRange( m_Mobile, Core.AOS ? 1 : 4 ) && !e.Handled )
{ {
if ( e.HasKeyword( 0x14D ) ) // *vendor sell* if ( e.HasKeyword( 0x14D ) ) // *vendor sell*
{ {
e.Handled = true; e.Handled = true;
((BaseVendor)m_Mobile).VendorSell( from ); vendor.VendorSell( from );
m_Mobile.FocusMob = from; vendor.FocusMob = from;
} }
else if ( e.HasKeyword( 0x3C ) ) // *vendor buy* else if ( e.HasKeyword( 0x3C ) ) // *vendor buy*
{ {
e.Handled = true; e.Handled = true;
((BaseVendor)m_Mobile).VendorBuy( from ); vendor.VendorBuy( from );
m_Mobile.FocusMob = from; vendor.FocusMob = from;
} }
else if ( WasNamed( e.Speech ) ) else if ( WasNamed( e.Speech ) )
{ {
@ -138,18 +138,18 @@ namespace Server.Mobiles
{ {
e.Handled = true; e.Handled = true;
((BaseVendor)m_Mobile).VendorSell( from ); vendor.VendorSell( from );
} }
else if ( e.HasKeyword( 0x171 ) ) // *buy* else if ( e.HasKeyword( 0x171 ) ) // *buy*
{ {
e.Handled = true; e.Handled = true;
((BaseVendor)m_Mobile).VendorBuy( from ); vendor.VendorBuy( from );
} }
m_Mobile.FocusMob = from; vendor.FocusMob = from;
} }
} }
} }
} }
} }

View file

@ -59,9 +59,7 @@ namespace Server.Mobiles
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
if ( m_InternalItem != null ) m_InternalItem?.Delete();
m_InternalItem.Delete();
m_InternalItem = null; m_InternalItem = null;
base.OnAfterDelete(); base.OnAfterDelete();
@ -196,10 +194,7 @@ namespace Server.Mobiles
{ {
get get
{ {
if ( m_InternalItem != null ) return m_InternalItem?.ItemID ?? 0;
return m_InternalItem.ItemID;
else
return 0;
} }
set set
{ {
@ -242,8 +237,7 @@ namespace Server.Mobiles
Location = loc; Location = loc;
Map = map; Map = map;
if ( m_InternalItem != null ) m_InternalItem?.Internalize();
m_InternalItem.Internalize();
} }
else else
{ {
@ -280,10 +274,9 @@ namespace Server.Mobiles
{ {
bool result = true; bool result = true;
if ((mob is PlayerMobile) && (mob as PlayerMobile).MountBlockReason != BlockMountType.None) if ((mob is PlayerMobile mobile) && mobile.MountBlockReason != BlockMountType.None)
{ {
mob.SendLocalizedMessage((int)(mob as PlayerMobile).MountBlockReason); mobile.SendLocalizedMessage((int)mobile.MountBlockReason);
result = false; result = false;
} }
@ -333,9 +326,7 @@ namespace Server.Mobiles
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
if ( m_Mount != null ) m_Mount?.Delete();
m_Mount.Delete();
m_Mount = null; m_Mount = null;
base.OnAfterDelete(); base.OnAfterDelete();

View file

@ -345,8 +345,7 @@ namespace Server.Mobiles
public static void StopMounting( Mobile mob ) public static void StopMounting( Mobile mob )
{ {
if ( mob.Spell is EtherealSpell ) (mob.Spell as EtherealSpell)?.Stop();
( (EtherealSpell)mob.Spell ).Stop();
} }
public void OnRiderDamaged( int amount, Mobile from, bool willKill ) public void OnRiderDamaged( int amount, Mobile from, bool willKill )

File diff suppressed because it is too large Load diff

View file

@ -3597,6 +3597,7 @@ namespace Server
{ {
if ( m_Deleted ) if ( m_Deleted )
return; return;
if ( !World.OnDelete( this ) ) if ( !World.OnDelete( this ) )
return; return;
@ -3630,11 +3631,8 @@ namespace Server
m_Deleted = true; m_Deleted = true;
if ( m_Map != null ) m_Map?.OnLeave( this );
{ m_Map = null;
m_Map.OnLeave( this );
m_Map = null;
}
m_Hair = null; m_Hair = null;
m_FacialHair = null; m_FacialHair = null;
@ -3652,11 +3650,8 @@ namespace Server
/// </summary> /// </summary>
public virtual void OnDelete() public virtual void OnDelete()
{ {
if ( m_Spawner != null ) m_Spawner?.Remove( this );
{ m_Spawner = null;
m_Spawner.Remove( this );
m_Spawner = null;
}
} }
/// <summary> /// <summary>