Fixes casting checks

This commit is contained in:
Kamron Batman 2018-08-19 01:38:55 +08:00
parent 7ea00fbf4f
commit 03dd5f1926
431 changed files with 5616 additions and 6250 deletions

View file

@ -76,19 +76,14 @@ namespace Server.Commands.Generic
if ( from.AccessLevel >= AccessLevel.Administrator || obj == null )
return true;
Mobile mob;
Mobile mob = null;
if ( obj is Mobile )
mob = (Mobile)obj;
else if ( obj is Item )
mob = ((Item)obj).RootParent as Mobile;
else
mob = null;
if ( obj is Mobile m )
mob = m;
else if ( obj is Item item )
mob = item.RootParent as Mobile;
if ( mob == null || mob == from || from.AccessLevel > mob.AccessLevel )
return true;
return false;
return mob == null || mob == from || from.AccessLevel > mob.AccessLevel;
}
public virtual void ExecuteList( CommandEventArgs e, ArrayList list )
@ -179,16 +174,16 @@ namespace Server.Commands.Generic
{
object obj = m_Responses[i];
if ( obj is MessageEntry )
if ( obj is MessageEntry entry )
{
from.SendMessage( ((MessageEntry)obj).ToString() );
from.SendMessage( entry.ToString() );
if ( flushToLog )
CommandLogging.WriteLine( from, ((MessageEntry)obj).ToString() );
CommandLogging.WriteLine( from, entry.ToString() );
}
else if ( obj is Gump )
else if ( obj is Gump gump )
{
from.SendGump( (Gump) obj );
from.SendGump( gump );
}
}
}
@ -202,4 +197,4 @@ namespace Server.Commands.Generic
m_Failures.Clear();
}
}
}
}

View file

@ -130,9 +130,7 @@ namespace Server.Commands.Generic
public override void Execute( CommandEventArgs e, object obj )
{
Item item = obj as Item;
if ( item != null )
if ( obj is Item item )
{
if ( e.Mobile.PlaceInBackpack( item ) )
AddResponse( "The item has been placed in your backpack." );
@ -156,9 +154,9 @@ namespace Server.Commands.Generic
public override void Execute( CommandEventArgs e, object obj )
{
if ( obj is HouseSign )
if ( obj is HouseSign sign )
{
BaseHouse house = ((HouseSign)obj).Owner;
BaseHouse house = sign.Owner;
if ( house == null )
{
@ -416,10 +414,10 @@ namespace Server.Commands.Generic
object obj = list[i];
Container cont = null;
if ( obj is Mobile )
cont = ((Mobile)obj).Backpack;
else if ( obj is Container )
cont = (Container)obj;
if ( obj is Mobile mobile )
cont = mobile.Backpack;
else if ( obj is Container container )
cont = container;
if ( cont != null )
packs.Add( cont );
@ -480,15 +478,13 @@ namespace Server.Commands.Generic
public override void Execute( CommandEventArgs e, object obj )
{
IPoint3D p = obj as IPoint3D;
if ( p == null )
if ( !(obj is IPoint3D p) )
return;
if ( p is Item )
p = ((Item)p).GetWorldTop();
else if ( p is Mobile )
p = ((Mobile)p).Location;
if ( p is Item item )
p = item.GetWorldTop();
else if ( p is Mobile m )
p = m.Location;
Add.Invoke( e.Mobile, new Point3D( p ), new Point3D( p ), e.Arguments );
}
@ -508,9 +504,7 @@ namespace Server.Commands.Generic
public override void Execute( CommandEventArgs e, object obj )
{
IPoint3D p = obj as IPoint3D;
if ( p == null )
if ( !(obj is IPoint3D p) )
return;
Mobile from = e.Mobile;
@ -560,9 +554,9 @@ namespace Server.Commands.Generic
{
Item item = mob.Items[i];
if ( item is IMountItem )
if ( item is IMountItem mountItem )
{
IMount mount = ((IMountItem)item).Mount;
IMount mount = mountItem.Mount;
if ( mount != null )
{
@ -608,11 +602,11 @@ namespace Server.Commands.Generic
public override void Execute( CommandEventArgs e, object obj )
{
if ( obj is BaseVendor )
if ( obj is BaseVendor vendor )
{
CommandLogging.WriteLine( e.Mobile, "{0} {1} restocking {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( obj ) );
CommandLogging.WriteLine( e.Mobile, "{0} {1} restocking {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( vendor ) );
((BaseVendor)obj).Restock();
vendor.Restock();
AddResponse( "The vendor has been restocked." );
}
else
@ -816,16 +810,16 @@ namespace Server.Commands.Generic
public override void Execute( CommandEventArgs e, object obj )
{
if ( obj is Item )
if ( obj is Item item )
{
CommandLogging.WriteLine( e.Mobile, "{0} {1} deleting {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( obj ) );
((Item)obj).Delete();
CommandLogging.WriteLine( e.Mobile, "{0} {1} deleting {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( item ) );
item.Delete();
AddResponse( "The item has been deleted." );
}
else if ( obj is Mobile && !((Mobile)obj).Player )
else if ( obj is Mobile mobile && !mobile.Player )
{
CommandLogging.WriteLine( e.Mobile, "{0} {1} deleting {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( obj ) );
((Mobile)obj).Delete();
CommandLogging.WriteLine( e.Mobile, "{0} {1} deleting {2}", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), CommandLogging.Format( mobile ) );
mobile.Delete();
AddResponse( "The mobile has been deleted." );
}
else
@ -887,9 +881,7 @@ namespace Server.Commands.Generic
{
if ( mob.IsDeadBondedPet )
{
BaseCreature bc = mob as BaseCreature;
if ( bc != null )
if ( mob is BaseCreature bc )
{
CommandLogging.WriteLine( from, "{0} {1} resurrecting {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( mob ) );
@ -1048,10 +1040,7 @@ namespace Server.Commands.Generic
if ( fromState != null && targState != null )
{
Account fromAccount = fromState.Account as Account;
Account targAccount = targState.Account as Account;
if ( fromAccount != null && targAccount != null )
if ( fromState.Account is Account && targState.Account is Account targAccount )
{
CommandLogging.WriteLine( from, "{0} {1} {2} {3}", from.AccessLevel, CommandLogging.Format( from ), m_Ban ? "banning" : "kicking", CommandLogging.Format( targ ) );
@ -1095,9 +1084,7 @@ namespace Server.Commands.Generic
public override void Execute( CommandEventArgs e, object obj )
{
Item item = obj as Item;
if ( item == null )
if ( !(obj is Item item) )
return;
if ( !item.IsLockedDown && !item.IsSecure )

View file

@ -137,17 +137,13 @@ namespace Server.Commands.Generic
object obj = m_List[i];
bool isDeleted = false;
if ( obj is Item )
if ( obj is Item item )
{
Item item = (Item)obj;
if ( !(isDeleted = item.Deleted) )
AddEntryHtml( 40 + 130, item.GetType().Name );
}
else if ( obj is Mobile )
else if ( obj is Mobile mob )
{
Mobile mob = (Mobile)obj;
if ( !(isDeleted = mob.Deleted) )
AddEntryHtml( 40 + 130, mob.Name );
}
@ -231,10 +227,10 @@ namespace Server.Commands.Generic
break;
}
if ( obj is Item && !((Item)obj).Deleted )
m_From.SendGump( new InterfaceItemGump( m_From, m_Columns, m_List, m_Page, (Item) obj ) );
else if ( obj is Mobile && !((Mobile)obj).Deleted )
m_From.SendGump( new InterfaceMobileGump( m_From, m_Columns, m_List, m_Page, (Mobile) obj ) );
if ( obj is Item item && !item.Deleted )
m_From.SendGump( new InterfaceItemGump( m_From, m_Columns, m_List, m_Page, item ) );
else if ( obj is Mobile mobile && !mobile.Deleted )
m_From.SendGump( new InterfaceMobileGump( m_From, m_Columns, m_List, m_Page, mobile ) );
else
m_From.SendGump( new InterfaceGump( m_From, m_Columns, m_List, m_Page, m_Select ) );
}
@ -567,4 +563,4 @@ namespace Server.Commands.Generic
}
}
}
}
}

View file

@ -107,8 +107,8 @@ namespace Server.Commands.Generic
ext.Parse( from, args, i + 1, size - i - 1 );
if ( ext is WhereExtension )
baseType = ( ext as WhereExtension ).Conditional.Type;
if ( ext is WhereExtension extension )
baseType = extension.Conditional.Type;
parsed.Add( ext );

View file

@ -87,22 +87,22 @@ namespace Server.Commands.Generic
}
else
{
if ( m_Value is int )
method.Load( (int) m_Value );
else if ( m_Value is long )
method.Load( (long) m_Value );
else if ( m_Value is float )
method.Load( (float) m_Value );
else if ( m_Value is double )
method.Load( (double) m_Value );
else if ( m_Value is char )
method.Load( (char) m_Value );
else if ( m_Value is bool )
method.Load( (bool) m_Value );
else if ( m_Value is string )
method.Load( (string) m_Value );
else if ( m_Value is Enum )
method.Load( (Enum) m_Value );
if ( m_Value is int i )
method.Load( i );
else if ( m_Value is long l )
method.Load( l );
else if ( m_Value is float f )
method.Load( f );
else if ( m_Value is double d )
method.Load( d );
else if ( m_Value is char c )
method.Load( c );
else if ( m_Value is bool b )
method.Load( b );
else if ( m_Value is string s )
method.Load( s );
else if ( m_Value is Enum e )
method.Load( e );
else
throw new InvalidOperationException( "Unrecognized comparison value." );
}
@ -110,10 +110,8 @@ namespace Server.Commands.Generic
public void Acquire( TypeBuilder typeBuilder, ILGenerator il, string fieldName )
{
if ( m_Value is string )
if ( m_Value is string toParse )
{
string toParse = (string) m_Value;
if ( !m_Type.IsValueType && toParse == "null" )
{
m_Value = null;
@ -391,7 +389,7 @@ namespace Server.Commands.Generic
bool inverse = false;
bool couldCompare =
emitter.CompareTo( 1, delegate()
emitter.CompareTo( 1, delegate
{
m_Value.Load( emitter );
} );

View file

@ -84,7 +84,7 @@ namespace Server.Commands.Generic
emitter.Chain( prop );
bool couldCompare =
emitter.CompareTo( 1, delegate()
emitter.CompareTo( 1, delegate
{
emitter.LoadLocal( b );
emitter.Chain( prop );

View file

@ -130,7 +130,7 @@ namespace Server.Commands.Generic
emitter.Chain( prop );
bool couldCompare =
emitter.CompareTo( sign, delegate()
emitter.CompareTo( sign, delegate
{
emitter.LoadLocal( b );
emitter.Chain( prop );

View file

@ -8,7 +8,7 @@ namespace Server.Commands.Generic
{
public sealed class DistinctExtension : BaseExtension
{
public static ExtensionInfo ExtInfo = new ExtensionInfo( 30, "Distinct", -1, delegate() { return new DistinctExtension(); } );
public static ExtensionInfo ExtInfo = new ExtensionInfo( 30, "Distinct", -1, delegate { return new DistinctExtension(); } );
public static void Initialize()
{

View file

@ -6,7 +6,7 @@ namespace Server.Commands.Generic
{
public sealed class LimitExtension : BaseExtension
{
public static ExtensionInfo ExtInfo = new ExtensionInfo( 80, "Limit", 1, delegate() { return new LimitExtension(); } );
public static ExtensionInfo ExtInfo = new ExtensionInfo( 80, "Limit", 1, delegate { return new LimitExtension(); } );
public static void Initialize()
{

View file

@ -8,7 +8,7 @@ namespace Server.Commands.Generic
{
public sealed class SortExtension : BaseExtension
{
public static ExtensionInfo ExtInfo = new ExtensionInfo( 40, "Order", -1, delegate() { return new SortExtension(); } );
public static ExtensionInfo ExtInfo = new ExtensionInfo( 40, "Order", -1, delegate { return new SortExtension(); } );
public static void Initialize()
{

View file

@ -8,7 +8,7 @@ namespace Server.Commands.Generic
{
public sealed class WhereExtension : BaseExtension
{
public static ExtensionInfo ExtInfo = new ExtensionInfo( 20, "Where", -1, delegate() { return new WhereExtension(); } );
public static ExtensionInfo ExtInfo = new ExtensionInfo( 20, "Where", -1, delegate { return new WhereExtension(); } );
public static void Initialize()
{

View file

@ -121,9 +121,9 @@ namespace Server.Commands.Generic
foreach ( BaseExtension check in ext )
{
if ( check is WhereExtension )
if ( check is WhereExtension extension )
{
cond = ( check as WhereExtension ).Conditional;
cond = extension.Conditional;
break;
}
@ -234,10 +234,8 @@ namespace Server.Commands.Generic
bool flushToLog = false;
if ( obj is ArrayList )
if ( obj is ArrayList list )
{
ArrayList list = (ArrayList)obj;
if ( list.Count > 20 )
CommandLogging.Enabled = false;
else if ( list.Count == 0 )
@ -255,9 +253,7 @@ namespace Server.Commands.Generic
{
if ( command.ListOptimized )
{
ArrayList list = new ArrayList();
list.Add( obj );
command.ExecuteList( e, list );
command.ExecuteList( e, new ArrayList{ obj } );
}
else
{

View file

@ -47,7 +47,7 @@ namespace Server.Commands.Generic
if ( mob == null )
continue;
if( !BaseCommand.IsAccessible( from, mob ) )
if ( !BaseCommand.IsAccessible( from, mob ) )
continue;
if ( ext.IsValid( mob ) )
@ -64,4 +64,4 @@ namespace Server.Commands.Generic
}
}
}
}
}

View file

@ -35,7 +35,7 @@ namespace Server.Commands.Generic
{
foreach ( Mobile mob in reg.GetMobiles() )
{
if( !BaseCommand.IsAccessible( from, mob ) )
if ( !BaseCommand.IsAccessible( from, mob ) )
continue;
if ( ext.IsValid( mob ) )
@ -58,4 +58,4 @@ namespace Server.Commands.Generic
}
}
}
}
}