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)
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;
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!");
return;

View file

@ -920,7 +920,7 @@ namespace Server.Mobiles
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[]

View file

@ -61,7 +61,7 @@ namespace Server.Mobiles
m_Mobile.Say( Utility.RandomList( 1005305, 501603 ) );
Action = ActionType.Flee;
return true;
}
@ -88,7 +88,7 @@ namespace Server.Mobiles
m_Mobile.FocusMob = null;
Action = ActionType.Wander;
Action = ActionType.Wander;
}
}
@ -109,28 +109,28 @@ namespace Server.Mobiles
return base.HandlesOnSpeech( from );
}
// Temporary
// Temporary
public override void OnSpeech( SpeechEventArgs e )
{
base.OnSpeech( e );
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*
{
e.Handled = true;
((BaseVendor)m_Mobile).VendorSell( from );
m_Mobile.FocusMob = from;
vendor.VendorSell( from );
vendor.FocusMob = from;
}
else if ( e.HasKeyword( 0x3C ) ) // *vendor buy*
{
e.Handled = true;
((BaseVendor)m_Mobile).VendorBuy( from );
m_Mobile.FocusMob = from;
vendor.VendorBuy( from );
vendor.FocusMob = from;
}
else if ( WasNamed( e.Speech ) )
{
@ -138,18 +138,18 @@ namespace Server.Mobiles
{
e.Handled = true;
((BaseVendor)m_Mobile).VendorSell( from );
vendor.VendorSell( from );
}
else if ( e.HasKeyword( 0x171 ) ) // *buy*
{
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()
{
if ( m_InternalItem != null )
m_InternalItem.Delete();
m_InternalItem?.Delete();
m_InternalItem = null;
base.OnAfterDelete();
@ -196,10 +194,7 @@ namespace Server.Mobiles
{
get
{
if ( m_InternalItem != null )
return m_InternalItem.ItemID;
else
return 0;
return m_InternalItem?.ItemID ?? 0;
}
set
{
@ -242,8 +237,7 @@ namespace Server.Mobiles
Location = loc;
Map = map;
if ( m_InternalItem != null )
m_InternalItem.Internalize();
m_InternalItem?.Internalize();
}
else
{
@ -280,10 +274,9 @@ namespace Server.Mobiles
{
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;
}
@ -333,9 +326,7 @@ namespace Server.Mobiles
public override void OnAfterDelete()
{
if ( m_Mount != null )
m_Mount.Delete();
m_Mount?.Delete();
m_Mount = null;
base.OnAfterDelete();

View file

@ -345,8 +345,7 @@ namespace Server.Mobiles
public static void StopMounting( Mobile mob )
{
if ( mob.Spell is EtherealSpell )
( (EtherealSpell)mob.Spell ).Stop();
(mob.Spell as EtherealSpell)?.Stop();
}
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 )
return;
if ( !World.OnDelete( this ) )
return;
@ -3630,11 +3631,8 @@ namespace Server
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_FacialHair = null;
@ -3652,11 +3650,8 @@ namespace Server
/// </summary>
public virtual void OnDelete()
{
if ( m_Spawner != null )
{
m_Spawner.Remove( this );
m_Spawner = null;
}
m_Spawner?.Remove( this );
m_Spawner = null;
}
/// <summary>