More cast conversion fixes

This commit is contained in:
Kamron Batman 2018-09-06 18:07:42 -07:00
parent 3f45bd57b9
commit aba9452161
46 changed files with 359 additions and 506 deletions

View file

@ -81,13 +81,9 @@ namespace Server.Items
if ( handTwo is BaseWeapon )
handOne = handTwo;
if ( handTwo is BaseRanged )
{
BaseRanged ranged = (BaseRanged) handTwo;
if ( ranged.Balanced )
return true;
}
if ( handTwo is BaseRanged ranged && ranged.Balanced )
return true;
return ( handOne == null || handTwo == null );
}
@ -223,10 +219,8 @@ namespace Server.Items
public override bool StackWith( Mobile from, Item dropped, bool playSound )
{
if ( dropped is BasePotion && ((BasePotion)dropped).m_PotionEffect == m_PotionEffect )
return base.StackWith( from, dropped, playSound );
return false;
return dropped is BasePotion potion && potion.m_PotionEffect == m_PotionEffect &&
base.StackWith(from, potion, playSound);
}
#region ICraftable Members

View file

@ -40,9 +40,7 @@ namespace Server.Items
return;
}
ThrowTarget targ = from.Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( from.Target is ThrowTarget targ && targ.Potion == this )
return;
from.RevealingAction();
@ -86,9 +84,7 @@ namespace Server.Items
// Check if any other players are using this potion
for ( int i = 0; i < m_Users.Count; i ++ )
{
ThrowTarget targ = m_Users[ i ].Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( m_Users[ i ].Target is ThrowTarget targ && targ.Potion == this )
Target.Cancel( from );
}
@ -112,9 +108,7 @@ namespace Server.Items
public static void AddDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
timer.Stop();
m_Delay[ m ] = Timer.DelayCall( TimeSpan.FromSeconds( 30 ), new TimerStateCallback( EndDelay_Callback ), m );
@ -122,9 +116,7 @@ namespace Server.Items
public static int GetDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null && timer.Next > DateTime.UtcNow )
if ( m_Delay[ m ] is Timer timer && timer.Next > DateTime.UtcNow )
return (int) (timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
@ -132,15 +124,13 @@ namespace Server.Items
private static void EndDelay_Callback( object obj )
{
if ( obj is Mobile )
EndDelay( (Mobile) obj );
if ( obj is Mobile mobile )
EndDelay( mobile );
}
public static void EndDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
{
timer.Stop();
m_Delay.Remove( m );
@ -167,13 +157,11 @@ namespace Server.Items
if ( m_Potion.Deleted || m_Potion.Map == Map.Internal )
return;
IPoint3D p = targeted as IPoint3D;
if ( p == null || from.Map == null )
if ( !(targeted is IPoint3D p) || from.Map == null )
return;
// Add delay
BaseConflagrationPotion.AddDelay( from );
AddDelay( from );
SpellHelper.GetSurfaceTop( ref p );
@ -181,8 +169,8 @@ namespace Server.Items
IEntity to;
if ( p is Mobile )
to = (Mobile)p;
if ( p is Mobile mobile )
to = mobile;
else
to = new Entity( Serial.Zero, new Point3D( p ), from.Map );

View file

@ -41,9 +41,7 @@ namespace Server.Items
return;
}
ThrowTarget targ = from.Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( from.Target is ThrowTarget targ && targ.Potion == this )
return;
from.RevealingAction();
@ -87,9 +85,7 @@ namespace Server.Items
// Check if any other players are using this potion
for ( int i = 0; i < m_Users.Count; i ++ )
{
ThrowTarget targ = m_Users[ i ].Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( m_Users[ i ].Target is ThrowTarget targ && targ.Potion == this )
Target.Cancel( from );
}
@ -102,10 +98,8 @@ namespace Server.Items
foreach ( Mobile mobile in map.GetMobilesInRange( loc, Radius ) )
{
if ( mobile is BaseCreature )
if ( mobile is BaseCreature mon )
{
BaseCreature mon = (BaseCreature) mobile;
if ( mon.Controlled || mon.Summoned )
continue;
@ -134,9 +128,7 @@ namespace Server.Items
public static void AddDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
timer.Stop();
m_Delay[ m ] = Timer.DelayCall( TimeSpan.FromSeconds( 60 ), new TimerStateCallback( EndDelay_Callback ), m );
@ -144,9 +136,7 @@ namespace Server.Items
public static int GetDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null && timer.Next > DateTime.UtcNow )
if ( m_Delay[ m ] is Timer timer && timer.Next > DateTime.UtcNow )
return (int) (timer.Next - DateTime.UtcNow).TotalSeconds;
return 0;
@ -154,15 +144,13 @@ namespace Server.Items
private static void EndDelay_Callback( object obj )
{
if ( obj is Mobile )
EndDelay( (Mobile) obj );
if ( obj is Mobile mobile )
EndDelay( mobile );
}
public static void EndDelay( Mobile m )
{
Timer timer = m_Delay[ m ] as Timer;
if ( timer != null )
if ( m_Delay[ m ] is Timer timer )
{
timer.Stop();
m_Delay.Remove( m );
@ -189,13 +177,11 @@ namespace Server.Items
if ( m_Potion.Deleted || m_Potion.Map == Map.Internal )
return;
IPoint3D p = targeted as IPoint3D;
if ( p == null || from.Map == null )
if ( !(targeted is IPoint3D p) || from.Map == null )
return;
// Add delay
BaseConfusionBlastPotion.AddDelay( from );
AddDelay( from );
SpellHelper.GetSurfaceTop( ref p );
@ -203,8 +189,8 @@ namespace Server.Items
IEntity to;
if ( p is Mobile )
to = (Mobile)p;
if ( p is Mobile mobile )
to = mobile;
else
to = new Entity( Serial.Zero, new Point3D( p ), from.Map );

View file

@ -117,17 +117,13 @@ namespace Server.Items
Point3D loc;
Map map;
if ( parent is Item )
if ( parent is Item item )
{
Item item = (Item)parent;
loc = item.GetWorldLocation();
map = item.Map;
}
else if ( parent is Mobile )
else if ( parent is Mobile m )
{
Mobile m = (Mobile)parent;
loc = m.Location;
map = m.Map;
}
@ -141,10 +137,10 @@ namespace Server.Items
}
else
{
if ( parent is Item )
((Item)parent).PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
else if ( parent is Mobile )
((Mobile)parent).PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
if ( parent is Item item )
item.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
else if ( parent is Mobile mobile )
mobile.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() );
states[1] = timer - 1;
}
@ -187,9 +183,7 @@ namespace Server.Items
if ( m_Potion.Deleted || m_Potion.Map == Map.Internal )
return;
IPoint3D p = targeted as IPoint3D;
if ( p == null )
if ( !(targeted is IPoint3D p) )
return;
Map map = from.Map;
@ -201,16 +195,14 @@ namespace Server.Items
from.RevealingAction();
IEntity to;
IEntity to = new Entity( Serial.Zero, new Point3D( p ), map );
to = new Entity( Serial.Zero, new Point3D( p ), map );
if ( p is Mobile )
if ( p is Mobile m )
{
if ( !RelativeLocation ) // explosion location = current mob location.
p = ((Mobile)p).Location;
p = m.Location;
else
to = (Mobile)p;
to = m;
}
Effects.SendMovingEffect( from, to, m_Potion.ItemID, 7, 0, false, false, m_Potion.Hue, 0 );
@ -235,9 +227,8 @@ namespace Server.Items
for ( int i = 0; m_Users != null && i < m_Users.Count; ++i )
{
Mobile m = m_Users[i];
ThrowTarget targ = m.Target as ThrowTarget;
if ( targ != null && targ.Potion == this )
if ( m.Target is ThrowTarget targ && targ.Potion == this )
Target.Cancel( m );
}
@ -259,9 +250,9 @@ namespace Server.Items
foreach ( IEntity o in eable )
{
if ( o is Mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, (Mobile)o ) && from.CanBeHarmful( (Mobile)o, false ))))
if ( o is Mobile mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, mobile ) && from.CanBeHarmful( mobile, false ))))
{
toExplode.Add( o );
toExplode.Add( mobile );
++toDamage;
}
else if ( o is BaseExplosionPotion && o != this )
@ -279,12 +270,9 @@ namespace Server.Items
{
object o = toExplode[i];
if ( o is Mobile )
if ( o is Mobile m )
{
Mobile m = (Mobile)o;
if ( from != null )
from.DoHarmful( m );
from?.DoHarmful( m );
int damage = Utility.RandomMinMax( min, max );
@ -297,10 +285,8 @@ namespace Server.Items
AOS.Damage( m, from, damage, 0, 100, 0, 0, 0 );
}
else if ( o is BaseExplosionPotion )
else if ( o is BaseExplosionPotion pot )
{
BaseExplosionPotion pot = (BaseExplosionPotion)o;
pot.Explode( from, false, pot.GetWorldLocation(), pot.Map );
}
}

View file

@ -39,8 +39,8 @@ namespace Server.Items
private static void Hide_Callback( object obj )
{
if ( obj is Mobile )
Hide( (Mobile) obj );
if ( obj is Mobile mobile )
Hide( mobile );
}
public static void Hide( Mobile m )
@ -60,8 +60,8 @@ namespace Server.Items
private static void EndHide_Callback( object obj )
{
if ( obj is Mobile )
EndHide( (Mobile) obj );
if ( obj is Mobile mobile )
EndHide( mobile );
}
public static void EndHide( Mobile m )