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

@ -328,12 +328,10 @@ namespace Server.Commands
sb.AppendFormat( "0x{0:X}; ", built.Serial.Value );
if ( built is Item ) {
Container pack = packs[i];
pack.DropItem( (Item)built );
if ( built is Item item ) {
packs[i].DropItem( item );
}
else if ( built is Mobile ) {
Mobile m = (Mobile)built;
else if ( built is Mobile m ) {
m.MoveToWorld( new Point3D( start.X, start.Y, start.Z ), map );
}
}
@ -356,12 +354,10 @@ namespace Server.Commands
sb.AppendFormat( "0x{0:X}; ", built.Serial.Value );
if ( built is Item ) {
Item item = (Item)built;
if ( built is Item item ) {
item.MoveToWorld( new Point3D( x, y, z ), map );
}
else if ( built is Mobile ) {
Mobile m = (Mobile)built;
else if ( built is Mobile m ) {
m.MoveToWorld( new Point3D( x, y, z ), map );
}
}
@ -438,14 +434,12 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object o )
{
IPoint3D p = o as IPoint3D;
if ( p != null )
if ( o is IPoint3D p )
{
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;
Point3D point = new Point3D( p );
Add.Invoke( from, point, point, m_Args );

View file

@ -37,12 +37,11 @@ namespace Server
protected override void OnTarget( Mobile from, object targeted )
{
IPoint3D p = targeted as IPoint3D;
if ( p == null )
if ( !(targeted is IPoint3D p) )
return;
else if ( p is Item )
p = ((Item)p).GetWorldTop();
if ( p is Item item )
p = item.GetWorldTop();
if ( m_First )
{
@ -65,4 +64,4 @@ namespace Server
}
}
}
}
}

View file

@ -6,6 +6,7 @@ using Server;
using Server.Items;
using Server.Engines.Quests.Haven;
using Server.Engines.Quests.Necro;
using Server.Mobiles;
namespace Server.Commands
{
@ -388,12 +389,10 @@ namespace Server.Commands
throw new Exception( String.Format( "Bad type: {0}", m_Type ), e );
}
if ( item is BaseAddon )
if ( item is BaseAddon addon )
{
if ( item is MaabusCoffin )
if ( addon is MaabusCoffin coffin )
{
MaabusCoffin coffin = (MaabusCoffin)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "SpawnLocation" ) )
@ -407,18 +406,18 @@ namespace Server.Commands
}
else if ( m_ItemID > 0 )
{
List<AddonComponent> comps = ((BaseAddon)item).Components;
List<AddonComponent> comps = addon.Components;
for ( int i = 0; i < comps.Count; ++i )
{
AddonComponent comp = (AddonComponent)comps[i];
AddonComponent comp = comps[i];
if ( comp.Offset == Point3D.Zero )
comp.ItemID = m_ItemID;
}
}
}
else if ( item is BaseLight )
else if ( item is BaseLight light )
{
bool unlit = false, unprotected = false;
@ -428,23 +427,21 @@ namespace Server.Commands
unlit = true;
else if ( !unprotected && m_Params[i] == "Unprotected" )
unprotected = true;
if ( unlit && unprotected )
break;
}
if ( !unlit )
((BaseLight)item).Ignite();
light.Ignite();
if ( !unprotected )
((BaseLight)item).Protected = true;
light.Protected = true;
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
light.ItemID = m_ItemID;
}
else if ( item is Server.Mobiles.Spawner )
else if ( item is Spawner sp )
{
Server.Mobiles.Spawner sp = (Server.Mobiles.Spawner)item;
sp.NextSpawn = TimeSpan.Zero;
for ( int i = 0; i < m_Params.Length; ++i )
@ -518,10 +515,8 @@ namespace Server.Commands
}
}
}
else if ( item is RecallRune )
else if ( item is RecallRune rune )
{
RecallRune rune = (RecallRune)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "Description" ) )
@ -554,10 +549,8 @@ namespace Server.Commands
}
}
}
else if ( item is SkillTeleporter )
else if ( item is SkillTeleporter st )
{
SkillTeleporter tp = (SkillTeleporter)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "Skill" ) )
@ -565,94 +558,92 @@ namespace Server.Commands
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Skill = (SkillName)Enum.Parse( typeof( SkillName ), m_Params[i].Substring( ++indexOf ), true );
st.Skill = (SkillName)Enum.Parse( typeof( SkillName ), m_Params[i].Substring( ++indexOf ), true );
}
else if ( m_Params[i].StartsWith( "RequiredFixedPoint" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Required = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) ) * 0.1;
st.Required = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) ) * 0.1;
}
else if ( m_Params[i].StartsWith( "Required" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Required = Utility.ToDouble( m_Params[i].Substring( ++indexOf ) );
st.Required = Utility.ToDouble( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "MessageString" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MessageString = m_Params[i].Substring( ++indexOf );
st.MessageString = m_Params[i].Substring( ++indexOf );
}
else if ( m_Params[i].StartsWith( "MessageNumber" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MessageNumber = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
st.MessageNumber = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "PointDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
st.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "MapDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
st.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Creatures" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
st.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SourceEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
st.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "DestEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
st.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SoundID" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
st.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Delay" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
st.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
}
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
st.ItemID = m_ItemID;
}
else if ( item is KeywordTeleporter )
else if ( item is KeywordTeleporter kt )
{
KeywordTeleporter tp = (KeywordTeleporter)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "Substring" ) )
@ -660,80 +651,78 @@ namespace Server.Commands
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Substring = m_Params[i].Substring( ++indexOf );
kt.Substring = m_Params[i].Substring( ++indexOf );
}
else if ( m_Params[i].StartsWith( "Keyword" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Keyword = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
kt.Keyword = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Range" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Range = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
kt.Range = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "PointDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
kt.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "MapDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
kt.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Creatures" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
kt.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SourceEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
kt.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "DestEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
kt.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SoundID" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
kt.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Delay" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
kt.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
}
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
kt.ItemID = m_ItemID;
}
else if ( item is Teleporter )
else if ( item is Teleporter tp )
{
Teleporter tp = (Teleporter)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "PointDest" ) )
@ -788,12 +777,10 @@ namespace Server.Commands
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
tp.ItemID = m_ItemID;
}
else if ( item is FillableContainer )
else if ( item is FillableContainer cont )
{
FillableContainer cont = (FillableContainer) item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "ContentType" ) )
@ -806,7 +793,7 @@ namespace Server.Commands
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
cont.ItemID = m_ItemID;
}
else if ( m_ItemID > 0 )
{
@ -832,8 +819,8 @@ namespace Server.Commands
{
int hue = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
if ( item is DyeTub )
((DyeTub)item).DyedHue = hue;
if ( item is DyeTub tub )
tub.DyedHue = hue;
else
item.Hue = hue;
}
@ -1000,27 +987,30 @@ namespace Server.Commands
item.MoveToWorld( loc, maps[j] );
++count;
if ( item is BaseDoor )
if ( item is BaseDoor door )
{
IPooledEnumerable<BaseDoor> eable = maps[j].GetItemsInRange<BaseDoor>( loc, 1 );
Type itemType = item.GetType();
Type itemType = door.GetType();
foreach ( BaseDoor link in eable )
{
if ( link != item && link.Z == item.Z && link.GetType() == itemType )
if ( link != item && link.Z == door.Z && link.GetType() == itemType )
{
((BaseDoor)item).Link = link;
link.Link = (BaseDoor)item;
door.Link = link;
link.Link = door;
break;
}
}
eable.Free();
}
else if ( item is MarkContainer )
else if ( item is MarkContainer markCont )
{
try{ ((MarkContainer)item).Target = Point3D.Parse( extra ); }
try
{
markCont.Target = Point3D.Parse( extra );
}
catch{}
}

View file

@ -6,6 +6,7 @@ using Server;
using Server.Items;
using Server.Engines.Quests.Haven;
using Server.Engines.Quests.Necro;
using Server.Mobiles;
namespace Server.Commands
{
@ -385,12 +386,10 @@ namespace Server.Commands
throw new Exception( String.Format( "Bad type: {0}", m_Type ), e );
}
if ( item is BaseAddon )
if ( item is BaseAddon addon )
{
if ( item is MaabusCoffin )
if ( addon is MaabusCoffin coffin )
{
MaabusCoffin coffin = (MaabusCoffin)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "SpawnLocation" ) )
@ -404,7 +403,7 @@ namespace Server.Commands
}
else if ( m_ItemID > 0 )
{
List<AddonComponent> comps = ((BaseAddon)item).Components;
List<AddonComponent> comps = addon.Components;
for ( int i = 0; i < comps.Count; ++i )
{
@ -415,7 +414,7 @@ namespace Server.Commands
}
}
}
else if ( item is BaseLight )
else if ( item is BaseLight light )
{
bool unlit = false, unprotected = false;
@ -425,23 +424,21 @@ namespace Server.Commands
unlit = true;
else if ( !unprotected && m_Params[i] == "Unprotected" )
unprotected = true;
if ( unlit && unprotected )
break;
}
if ( !unlit )
((BaseLight)item).Ignite();
light.Ignite();
if ( !unprotected )
((BaseLight)item).Protected = true;
light.Protected = true;
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
light.ItemID = m_ItemID;
}
else if ( item is Server.Mobiles.Spawner )
else if ( item is Spawner sp )
{
Server.Mobiles.Spawner sp = (Server.Mobiles.Spawner)item;
sp.NextSpawn = TimeSpan.Zero;
for ( int i = 0; i < m_Params.Length; ++i )
@ -515,10 +512,8 @@ namespace Server.Commands
}
}
}
else if ( item is RecallRune )
else if ( item is RecallRune rune )
{
RecallRune rune = (RecallRune)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "Description" ) )
@ -551,10 +546,8 @@ namespace Server.Commands
}
}
}
else if ( item is SkillTeleporter )
else if ( item is SkillTeleporter st )
{
SkillTeleporter tp = (SkillTeleporter)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "Skill" ) )
@ -562,94 +555,92 @@ namespace Server.Commands
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Skill = (SkillName)Enum.Parse( typeof( SkillName ), m_Params[i].Substring( ++indexOf ), true );
st.Skill = (SkillName)Enum.Parse( typeof( SkillName ), m_Params[i].Substring( ++indexOf ), true );
}
else if ( m_Params[i].StartsWith( "RequiredFixedPoint" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Required = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) ) * 0.1;
st.Required = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) ) * 0.1;
}
else if ( m_Params[i].StartsWith( "Required" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Required = Utility.ToDouble( m_Params[i].Substring( ++indexOf ) );
st.Required = Utility.ToDouble( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "MessageString" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MessageString = m_Params[i].Substring( ++indexOf );
st.MessageString = m_Params[i].Substring( ++indexOf );
}
else if ( m_Params[i].StartsWith( "MessageNumber" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MessageNumber = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
st.MessageNumber = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "PointDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
st.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "MapDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
st.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Creatures" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
st.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SourceEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
st.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "DestEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
st.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SoundID" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
st.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Delay" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
st.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
}
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
st.ItemID = m_ItemID;
}
else if ( item is KeywordTeleporter )
else if ( item is KeywordTeleporter kt )
{
KeywordTeleporter tp = (KeywordTeleporter)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "Substring" ) )
@ -657,80 +648,78 @@ namespace Server.Commands
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Substring = m_Params[i].Substring( ++indexOf );
kt.Substring = m_Params[i].Substring( ++indexOf );
}
else if ( m_Params[i].StartsWith( "Keyword" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Keyword = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
kt.Keyword = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Range" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Range = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
kt.Range = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "PointDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
kt.PointDest = Point3D.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "MapDest" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
kt.MapDest = Map.Parse( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Creatures" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
kt.Creatures = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SourceEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
kt.SourceEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "DestEffect" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
kt.DestEffect = Utility.ToBoolean( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "SoundID" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
kt.SoundID = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
}
else if ( m_Params[i].StartsWith( "Delay" ) )
{
int indexOf = m_Params[i].IndexOf( '=' );
if ( indexOf >= 0 )
tp.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
kt.Delay = TimeSpan.Parse( m_Params[i].Substring( ++indexOf ) );
}
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
kt.ItemID = m_ItemID;
}
else if ( item is Teleporter )
else if ( item is Teleporter tp )
{
Teleporter tp = (Teleporter)item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "PointDest" ) )
@ -785,12 +774,10 @@ namespace Server.Commands
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
tp.ItemID = m_ItemID;
}
else if ( item is FillableContainer )
else if ( item is FillableContainer cont )
{
FillableContainer cont = (FillableContainer) item;
for ( int i = 0; i < m_Params.Length; ++i )
{
if ( m_Params[i].StartsWith( "ContentType" ) )
@ -803,7 +790,7 @@ namespace Server.Commands
}
if ( m_ItemID > 0 )
item.ItemID = m_ItemID;
cont.ItemID = m_ItemID;
}
else if ( m_ItemID > 0 )
{
@ -829,8 +816,8 @@ namespace Server.Commands
{
int hue = Utility.ToInt32( m_Params[i].Substring( ++indexOf ) );
if ( item is DyeTub )
((DyeTub)item).DyedHue = hue;
if ( item is DyeTub tub )
tub.DyedHue = hue;
else
item.Hue = hue;
}
@ -997,27 +984,30 @@ namespace Server.Commands
item.MoveToWorld( loc, maps[j] );
++count;
if ( item is BaseDoor )
if ( item is BaseDoor door )
{
IPooledEnumerable<BaseDoor> eable = maps[j].GetItemsInRange<BaseDoor>( loc, 1 );
Type itemType = item.GetType();
Type itemType = door.GetType();
foreach ( BaseDoor link in eable )
{
if ( link != item && link.Z == item.Z && link.GetType() == itemType )
if ( link != item && link.Z == door.Z && link.GetType() == itemType )
{
((BaseDoor)item).Link = link;
link.Link = (BaseDoor)item;
door.Link = link;
link.Link = door;
break;
}
}
eable.Free();
}
else if ( item is MarkContainer )
else if ( item is MarkContainer markCont )
{
try{ ((MarkContainer)item).Target = Point3D.Parse( extra ); }
try
{
markCont.Target = Point3D.Parse( extra );
}
catch{}
}

File diff suppressed because it is too large Load diff

View file

@ -60,16 +60,14 @@ namespace Server.Commands
CommandLogging.WriteLine( from, "{0} {1} duping {2} (inBag={3}; amount={4})", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targ ), m_InBag, m_Amount );
Item copy = (Item)targ;
Container pack;
Container pack = null;
if ( m_InBag )
{
if ( copy.Parent is Container )
pack = (Container)copy.Parent;
else if ( copy.Parent is Mobile )
pack = ( (Mobile)copy.Parent ).Backpack;
else
pack = null;
if ( copy.Parent is Container cont )
pack = cont;
else if ( copy.Parent is Mobile m )
pack = m.Backpack;
}
else
pack = from.Backpack;
@ -87,11 +85,8 @@ namespace Server.Commands
from.SendMessage( "Duping {0}...", m_Amount );
for ( int i = 0; i < m_Amount; i++ )
{
object o = c.Invoke( null );
if ( o != null && o is Item )
if ( c.Invoke( null ) is Item newItem )
{
Item newItem = (Item)o;
CopyProperties( newItem, copy );//copy.Dupe( item, copy.Amount );
copy.OnAfterDuped( newItem );
newItem.Parent = null;

View file

@ -97,16 +97,12 @@ namespace Server.Commands
xml.WriteAttributeString( "type", cte.Type.ToString() );
object obj = cte.Object;
if ( obj is Item )
if ( cte.Object is Item item )
{
Item item = (Item)obj;
int itemID = item.ItemID;
if ( item is BaseAddon && ((BaseAddon)item).Components.Count == 1 )
itemID = ((AddonComponent)(((BaseAddon)item).Components[0])).ItemID;
if ( item is BaseAddon addon && addon.Components.Count == 1 )
itemID = addon.Components[0].ItemID;
if ( itemID > TileData.MaxItemValue )
itemID = 1;
@ -123,10 +119,8 @@ namespace Server.Commands
item.Delete();
}
else if ( obj is Mobile )
else if ( cte.Object is Mobile mob )
{
Mobile mob = (Mobile)obj;
int itemID = ShrinkTable.Lookup( mob, 1 );
xml.WriteAttributeString( "gfx", XmlConvert.ToString( itemID ) );
@ -251,15 +245,15 @@ namespace Server.Commands
{
string a = null, b = null;
if ( x is CategoryEntry )
a = ((CategoryEntry)x).Title;
else if ( x is CategoryTypeEntry )
a = ((CategoryTypeEntry)x).Type.Name;
if ( x is CategoryEntry entry )
a = entry.Title;
else if ( x is CategoryTypeEntry typeEntry )
a = typeEntry.Type.Name;
if ( y is CategoryEntry )
b = ((CategoryEntry)y).Title;
else if ( y is CategoryTypeEntry )
b = ((CategoryTypeEntry)y).Type.Name;
if ( y is CategoryEntry categoryEntry )
b = categoryEntry.Title;
else if ( y is CategoryTypeEntry typeEntry )
b = typeEntry.Type.Name;
if ( a == null && b == null )
return 0;
@ -423,4 +417,4 @@ namespace Server.Commands
return (CategoryLine[])list.ToArray( typeof( CategoryLine ) );
}
}
}
}

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
}
}
}
}
}

View file

@ -148,9 +148,8 @@ namespace Server.Commands
public static void DropHolding_OnTarget( Mobile from, object obj )
{
if ( obj is Mobile && ((Mobile)obj).Player )
if ( obj is Mobile targ && targ.Player )
{
Mobile targ = (Mobile)obj;
Item held = targ.Holding;
if ( held == null )
@ -163,15 +162,12 @@ namespace Server.Commands
{
Engines.Help.PageEntry pe = Engines.Help.PageQueue.GetEntry( targ );
if ( pe == null || pe.Handler != from )
{
if ( pe == null )
from.SendMessage( "You may only use this command on someone who has paged you." );
else
from.SendMessage( "You may only use this command if you are handling their help page." );
if ( pe?.Handler == from )
from.SendMessage( "You may only use this command if you are handling their help page." );
else
from.SendMessage( "You may only use this command on someone who has paged you." );
return;
}
return;
}
if ( targ.AddToBackpack( held ) )
@ -262,23 +258,22 @@ namespace Server.Commands
public static void GetFollowers_OnTarget( Mobile from, object obj )
{
if ( obj is PlayerMobile )
if ( obj is PlayerMobile pm )
{
PlayerMobile master = (PlayerMobile)obj;
List<Mobile> pets = master.AllFollowers;
List<Mobile> pets = pm.AllFollowers;
if ( pets.Count > 0 )
{
CommandLogging.WriteLine( from, "{0} {1} getting all followers of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( master ) );
CommandLogging.WriteLine( from, "{0} {1} getting all followers of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( pm ) );
from.SendMessage( "That player has {0} pet{1}.", pets.Count, pets.Count != 1 ? "s" : "" );
for ( int i = 0; i < pets.Count; ++i )
{
Mobile pet = (Mobile)pets[i];
Mobile pet = pets[i];
if ( pet is IMount )
((IMount)pet).Rider = null; // make sure it's dismounted
if ( pet is IMount mount )
mount.Rider = null; // make sure it's dismounted
pet.MoveToWorld( from.Location, from.Map );
}
@ -288,17 +283,14 @@ namespace Server.Commands
from.SendMessage( "There were no pets found for that player." );
}
}
else if ( obj is Mobile && ((Mobile)obj).Player )
else if ( obj is Mobile master && master.Player )
{
Mobile master = (Mobile)obj;
ArrayList pets = new ArrayList();
foreach ( Mobile m in World.Mobiles.Values )
{
if ( m is BaseCreature )
if ( m is BaseCreature bc )
{
BaseCreature bc = (BaseCreature)m;
if ( (bc.Controlled && bc.ControlMaster == master) || (bc.Summoned && bc.SummonMaster == master) )
pets.Add( bc );
}
@ -314,8 +306,8 @@ namespace Server.Commands
{
Mobile pet = (Mobile)pets[i];
if ( pet is IMount )
((IMount)pet).Rider = null; // make sure it's dismounted
if ( pet is IMount mount )
mount.Rider = null; // make sure it's dismounted
pet.MoveToWorld( from.Location, from.Map );
}
@ -346,8 +338,8 @@ namespace Server.Commands
return;
}
if ( targeted is Mobile )
from.SendMenu( new EquipMenu( from, (Mobile)targeted, GetEquip( (Mobile)targeted ) ) );
if ( targeted is Mobile mobile )
from.SendMenu( new EquipMenu( from, mobile, GetEquip( mobile ) ) );
}
private static ItemListEntry[] GetEquip( Mobile m )
@ -472,17 +464,15 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
if ( targeted is Mobile m )
{
Mobile m = (Mobile)targeted;
BankBox box = ( m.Player ? m.BankBox : m.FindBankNoCreate() );
if ( box != null )
{
CommandLogging.WriteLine( from, "{0} {1} opening bank box of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targeted ) );
CommandLogging.WriteLine( from, "{0} {1} opening bank box of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( m ) );
if ( from == targeted )
if ( from == m )
box.Open();
else
box.DisplayTo( from );
@ -522,19 +512,17 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
if ( targeted is Mobile targ )
{
CommandLogging.WriteLine( from, "{0} {1} dismounting {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targeted ) );
Mobile targ = (Mobile)targeted;
CommandLogging.WriteLine( from, "{0} {1} dismounting {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targ ) );
for ( int i = 0; i < targ.Items.Count; ++i )
{
Item item = targ.Items[i];
if ( item is IMountItem )
if ( item is IMountItem mountItem )
{
IMount mount = ((IMountItem)item).Mount;
IMount mount = mountItem.Mount;
if ( mount != null )
mount.Rider = null;
@ -566,15 +554,10 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
if ( targeted is Mobile targ && targ.NetState != null )
{
Mobile targ = (Mobile)targeted;
if ( targ.NetState != null )
{
CommandLogging.WriteLine( from, "{0} {1} opening client menu of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targeted ) );
from.SendGump( new ClientGump( from, targ.NetState ) );
}
CommandLogging.WriteLine( from, "{0} {1} opening client menu of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targ ) );
from.SendGump( new ClientGump( from, targ.NetState ) );
}
}
}
@ -610,14 +593,7 @@ namespace Server.Commands
private static bool FixMap( ref Map map, ref Point3D loc, Item item )
{
if ( map == null || map == Map.Internal )
{
Mobile m = item.RootParent as Mobile;
return ( m != null && FixMap( ref map, ref loc, m ) );
}
return true;
return map == null || map == Map.Internal && item.RootParent is Mobile m && FixMap( ref map, ref loc, m );
}
private static bool FixMap( ref Map map, ref Point3D loc, Mobile m )
@ -651,26 +627,24 @@ namespace Server.Commands
IEntity ent = World.FindEntity( ser );
if ( ent is Item )
if ( ent is Item item )
{
Item item = (Item)ent;
Map map = item.Map;
Point3D loc = item.GetWorldLocation();
Mobile owner = item.RootParent as Mobile;
if( owner != null && (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible( from, owner ) /* !from.CanSee( owner )*/ )
if ( owner != null && (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible( from, owner ) /* !from.CanSee( owner )*/ )
{
from.SendMessage( "You can not go to what you can not see." );
return;
}
else if ( owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel )
if ( owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel )
{
from.SendMessage( "You can not go to what you can not see." );
return;
}
else if ( !FixMap( ref map, ref loc, item ) )
if ( !FixMap( ref map, ref loc, item ) )
{
from.SendMessage( "That is an internal item and you cannot go to it." );
return;
@ -680,26 +654,24 @@ namespace Server.Commands
return;
}
else if ( ent is Mobile )
if ( ent is Mobile m )
{
Mobile m = (Mobile)ent;
Map map = m.Map;
Point3D loc = m.Location;
Mobile owner = m;
if ( owner != null && (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible( from, owner ) /* !from.CanSee( owner )*/ )
if ( (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible( from, owner ) /* !from.CanSee( owner )*/ )
{
from.SendMessage( "You can not go to what you can not see." );
return;
}
else if ( owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel )
if ( (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel )
{
from.SendMessage( "You can not go to what you can not see." );
return;
}
else if ( !FixMap( ref map, ref loc, m ) )
if ( !FixMap( ref map, ref loc, m ) )
{
from.SendMessage( "That is an internal mobile and you cannot go to it." );
return;
@ -743,16 +715,16 @@ namespace Server.Commands
for( int i = 0; i < Map.AllMaps.Count; ++i )
{
Map m = Map.AllMaps[i];
map = Map.AllMaps[i];
if( m.MapIndex == 0x7F || m.MapIndex == 0xFF || from.Map == m )
if ( map.MapIndex == 0x7F || map.MapIndex == 0xFF || from.Map == map )
continue;
foreach( Region r in m.Regions.Values )
foreach( Region r in map.Regions.Values )
{
if( Insensitive.Equals( r.Name, name ) )
if ( Insensitive.Equals( r.Name, name ) )
{
from.MoveToWorld( r.GoLocation, m );
from.MoveToWorld( r.GoLocation, map );
return;
}
}
@ -873,8 +845,8 @@ namespace Server.Commands
BroadcastMessage( AccessLevel.Player, 0x482, e.ArgString );
}
public static void BroadcastMessage ( AccessLevel ac, int hue, string message )
{
public static void BroadcastMessage ( AccessLevel ac, int hue, string message )
{
foreach ( NetState state in NetState.Instances )
{
Mobile m = state.Mobile;
@ -940,12 +912,12 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
if ( targeted is Mobile mobile )
{
if( ((Mobile)targeted).AccessLevel >= from.AccessLevel && targeted != from )
if ( mobile.AccessLevel >= from.AccessLevel && mobile != from )
from.SendMessage( "You can't do that to someone with higher Accesslevel than you!" );
else
from.SendGump( new StuckMenu( from, (Mobile) targeted, false ) );
from.SendGump( new StuckMenu( from, mobile, false ) );
}
}
}

View file

@ -34,14 +34,14 @@ namespace Server.Commands
[Description( "Gives information on a specified command, or when no argument specified, displays a gump containing all commands" )]
private static void HelpInfo_OnCommand( CommandEventArgs e )
{
if( e.Length > 0 )
if ( e.Length > 0 )
{
string arg = e.GetString( 0 ).ToLower();
if (m_HelpInfos.TryGetValue( arg, out CommandInfo c ))
{
Mobile m = e.Mobile;
if( m.AccessLevel >= c.AccessLevel )
if ( m.AccessLevel >= c.AccessLevel )
m.SendGump( new CommandInfoGump( c ) );
else
m.SendMessage( "You don't have access to that command." );
@ -73,19 +73,17 @@ namespace Server.Commands
object[] attrs = mi.GetCustomAttributes( typeof( UsageAttribute ), false );
if( attrs.Length == 0 )
if ( attrs.Length == 0 )
continue;
UsageAttribute usage = attrs[0] as UsageAttribute;
attrs = mi.GetCustomAttributes( typeof( DescriptionAttribute ), false );
if( attrs.Length == 0 )
if ( attrs.Length == 0 )
continue;
DescriptionAttribute desc = attrs[0] as DescriptionAttribute;
if( usage == null || desc == null )
if ( usage == null || !(attrs[0] is DescriptionAttribute desc) )
continue;
attrs = mi.GetCustomAttributes( typeof( AliasesAttribute ), false );
@ -94,7 +92,7 @@ namespace Server.Commands
string descString = desc.Description.Replace( "<", "(" ).Replace( ">", ")" );
if( aliases == null )
if ( aliases == null )
list.Add( new CommandInfo( e.AccessLevel, e.Command, null, usage.Usage, descString ) );
else
{
@ -121,7 +119,7 @@ namespace Server.Commands
string usage = command.Usage;
string desc = command.Description;
if( usage == null || desc == null )
if ( usage == null || desc == null )
continue;
string[] cmds = command.Commands;
@ -133,31 +131,31 @@ namespace Server.Commands
desc = desc.Replace( "<", "(" ).Replace( ">", ")" );
if( command.Supports != CommandSupport.Single )
if ( command.Supports != CommandSupport.Single )
{
StringBuilder sb = new StringBuilder( 50 + desc.Length );
sb.Append( "Modifiers: " );
if( (command.Supports & CommandSupport.Global) != 0 )
if ( (command.Supports & CommandSupport.Global) != 0 )
sb.Append( "<i>Global</i>, " );
if( (command.Supports & CommandSupport.Online) != 0 )
if ( (command.Supports & CommandSupport.Online) != 0 )
sb.Append( "<i>Online</i>, " );
if( (command.Supports & CommandSupport.Region) != 0 )
if ( (command.Supports & CommandSupport.Region) != 0 )
sb.Append( "<i>Region</i>, " );
if( (command.Supports & CommandSupport.Contained) != 0 )
if ( (command.Supports & CommandSupport.Contained) != 0 )
sb.Append( "<i>Contained</i>, " );
if( (command.Supports & CommandSupport.Multi) != 0 )
if ( (command.Supports & CommandSupport.Multi) != 0 )
sb.Append( "<i>Multi</i>, " );
if( (command.Supports & CommandSupport.Area) != 0 )
if ( (command.Supports & CommandSupport.Area) != 0 )
sb.Append( "<i>Area</i>, " );
if( (command.Supports & CommandSupport.Self) != 0 )
if ( (command.Supports & CommandSupport.Self) != 0 )
sb.Append( "<i>Self</i>, " );
sb.Remove( sb.Length - 2, 2 );
@ -190,7 +188,7 @@ namespace Server.Commands
string usage = command.Usage;
string desc = command.Description;
if( usage == null || desc == null )
if ( usage == null || desc == null )
continue;
string[] cmds = command.Accessors;
@ -222,7 +220,7 @@ namespace Server.Commands
foreach( CommandInfo c in m_SortedHelpInfo )
{
if( !m_HelpInfos.ContainsKey( c.Name.ToLower() ) )
if ( !m_HelpInfos.ContainsKey( c.Name.ToLower() ) )
m_HelpInfos.Add( c.Name.ToLower(), c );
}
}
@ -239,13 +237,13 @@ namespace Server.Commands
{
m_Page = page;
if( list == null )
if ( list == null )
{
m_List = new List<CommandInfo>();
foreach( CommandInfo c in m_SortedHelpInfo )
{
if( from.AccessLevel >= c.AccessLevel )
if ( from.AccessLevel >= c.AccessLevel )
m_List.Add( c );
}
}
@ -255,14 +253,14 @@ namespace Server.Commands
AddNewPage();
if( m_Page > 0 )
if ( m_Page > 0 )
AddEntryButton( 20, ArrowLeftID1, ArrowLeftID2, 1, ArrowLeftWidth, ArrowLeftHeight );
else
AddEntryHeader( 20 );
AddEntryHtml( 160, Center( String.Format( "Page {0} of {1}", m_Page+1, (m_List.Count + EntriesPerPage - 1) / EntriesPerPage ) ) );
if( (m_Page + 1) * EntriesPerPage < m_List.Count )
if ( (m_Page + 1) * EntriesPerPage < m_List.Count )
AddEntryButton( 20, ArrowRightID1, ArrowRightID2, 2, ArrowRightWidth, ArrowRightHeight );
else
AddEntryHeader( 20 );
@ -272,9 +270,9 @@ namespace Server.Commands
for( int i = m_Page * EntriesPerPage, line = 0; line < EntriesPerPage && i < m_List.Count; ++i, ++line )
{
CommandInfo c = m_List[i];
if( from.AccessLevel >= c.AccessLevel )
if ( from.AccessLevel >= c.AccessLevel )
{
if( (int)c.AccessLevel != last )
if ( (int)c.AccessLevel != last )
{
AddNewLine();
@ -308,14 +306,14 @@ namespace Server.Commands
}
case 1:
{
if( m_Page > 0 )
if ( m_Page > 0 )
m.SendGump( new CommandListGump( m_Page - 1, m, m_List ) );
break;
}
case 2:
{
if( (m_Page + 1) * EntriesPerPage < m_SortedHelpInfo.Count )
if ( (m_Page + 1) * EntriesPerPage < m_SortedHelpInfo.Count )
m.SendGump( new CommandListGump( m_Page + 1, m, m_List ) );
break;
@ -325,11 +323,11 @@ namespace Server.Commands
int v = info.ButtonID - 3;
if( v >= 0 && v < m_List.Count )
if ( v >= 0 && v < m_List.Count )
{
CommandInfo c = m_List[v];
if( m.AccessLevel >= c.AccessLevel )
if ( m.AccessLevel >= c.AccessLevel )
{
m.SendGump( new CommandInfoGump( c ) );
m.SendGump( new CommandListGump( m_Page, m, m_List ) );
@ -387,13 +385,13 @@ namespace Server.Commands
string[] aliases = info.Aliases;
if( aliases != null && aliases.Length != 0 )
if ( aliases != null && aliases.Length != 0 )
{
sb.Append( String.Format( "Alias{0}: ", aliases.Length == 1 ? "" : "es" ) );
for( int i = 0; i < aliases.Length; ++i )
{
if( i != 0 )
if ( i != 0 )
sb.Append( ", " );
sb.Append( aliases[i] );

View file

@ -43,19 +43,15 @@ namespace Server.Commands
public static object Format( object o )
{
if ( o is Mobile )
if ( o is Mobile m )
{
Mobile m = (Mobile)o;
if ( m.Account == null )
return String.Format( "{0} (no account)", m );
else
return String.Format( "{0} ('{1}')", m, m.Account.Username );
}
else if ( o is Item )
{
Item item = (Item)o;
return String.Format( "{0} ('{1}')", m, m.Account.Username );
}
if ( o is Item item )
{
return String.Format( "0x{0:X} ({1})", item.Serial.Value, item.GetType().Name );
}
@ -81,9 +77,7 @@ namespace Server.Commands
string path = Core.BaseDirectory;
Account acct = from.Account as Account;
string name = ( acct == null ? from.Name : acct.Username );
string name = ( !(from.Account is Account acct) ? from.Name : acct.Username );
AppendPath( ref path, "Logs" );
AppendPath( ref path, "Commands" );
@ -144,4 +138,4 @@ namespace Server.Commands
WriteLine( from, "{0} {1} set property '{2}' of {3} to '{4}'", from.AccessLevel, Format( from ), name, Format( o ), value );
}
}
}
}

View file

@ -109,13 +109,11 @@ namespace Server.Commands
private int GetCount( object obj )
{
if ( obj is int )
return (int) obj;
if ( obj is int intObj )
return intObj;
if ( obj is int[] )
if ( obj is int[] list )
{
int[] list = (int[]) obj;
int total = 0;
for ( int i = 0; i < list.Length; ++i )
@ -207,9 +205,7 @@ namespace Server.Commands
do
{
int[] countTable = typeTable[itemType] as int[];
if ( countTable == null )
if ( !(typeTable[itemType] is int[] countTable) )
typeTable[itemType] = countTable = new int[9];
if ( ( flags & ExpandFlag.Name ) != 0 )
@ -401,4 +397,4 @@ namespace Server.Commands
}
}
}
}
}

View file

@ -263,7 +263,7 @@ namespace Server.Commands
{
object obj = realProps[i].GetValue( realObjs[i], null );
if( !( obj is IConvertible ) )
if ( !( obj is IConvertible ) )
return "Property is not IConvertable.";
try
@ -509,9 +509,8 @@ namespace Server.Commands
{
try
{
if ( toSet is AccessLevel )
if ( toSet is AccessLevel newLevel )
{
AccessLevel newLevel = (AccessLevel) toSet;
AccessLevel reqLevel = AccessLevel.Administrator;
if ( newLevel == AccessLevel.Administrator )
@ -843,4 +842,4 @@ namespace Server
return prop;
}
}
}
}

View file

@ -25,7 +25,7 @@ namespace Server.Commands
else
{
SkillName skill;
if( Enum.TryParse( arg.GetString( 0 ), true, out skill ) )
if ( Enum.TryParse( arg.GetString( 0 ), true, out skill ) )
{
arg.Mobile.Target = new SkillTarget( skill, arg.GetDouble( 1 ) );
}
@ -61,7 +61,7 @@ namespace Server.Commands
else
{
SkillName skill;
if( Enum.TryParse( arg.GetString( 0 ), true, out skill ) )
if ( Enum.TryParse( arg.GetString( 0 ), true, out skill ) )
{
arg.Mobile.Target = new SkillTarget( skill );
}
@ -83,9 +83,8 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
if ( targeted is Mobile targ )
{
Mobile targ = (Mobile)targeted;
Server.Skills skills = targ.Skills;
for ( int i = 0; i < skills.Length; ++i )
@ -121,9 +120,8 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object targeted )
{
if ( targeted is Mobile )
if ( targeted is Mobile targ )
{
Mobile targ = (Mobile)targeted;
Skill skill = targ.Skills[m_Skill];
if ( skill == null )
@ -144,4 +142,4 @@ namespace Server.Commands
}
}
}
}
}

View file

@ -25,8 +25,8 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object o )
{
if ( o is Mobile )
from.SendGump( new SkillsGump( from, (Mobile)o ) );
if ( o is Mobile mobile )
from.SendGump( new SkillsGump( from, mobile ) );
}
}
@ -37,4 +37,4 @@ namespace Server.Commands
e.Mobile.Target = new SkillsTarget();
}
}
}
}

View file

@ -21,10 +21,8 @@ namespace Server.Commands
public static void OnLogin( LoginEventArgs e )
{
if ( e.Mobile is PlayerMobile )
if ( e.Mobile is PlayerMobile pm )
{
PlayerMobile pm = (PlayerMobile)e.Mobile;
pm.VisibilityList.Clear();
}
}
@ -44,9 +42,8 @@ namespace Server.Commands
[Description( "Shows the names of everyone in your visibility list." )]
public static void VisList_OnCommand( CommandEventArgs e )
{
if ( e.Mobile is PlayerMobile )
if ( e.Mobile is PlayerMobile pm )
{
PlayerMobile pm = (PlayerMobile)e.Mobile;
List<Mobile> list = pm.VisibilityList;
if ( list.Count > 0 )
@ -67,11 +64,10 @@ namespace Server.Commands
[Description( "Removes everyone from your visibility list." )]
public static void VisClear_OnCommand( CommandEventArgs e )
{
if ( e.Mobile is PlayerMobile )
if ( e.Mobile is PlayerMobile pm )
{
PlayerMobile pm = (PlayerMobile)e.Mobile;
List<Mobile> list = new List<Mobile>( pm.VisibilityList );
pm.VisibilityList.Clear();
pm.SendMessage( "Your visibility list has been cleared." );
@ -93,24 +89,21 @@ namespace Server.Commands
protected override void OnTarget( Mobile from, object targeted )
{
if ( from is PlayerMobile && targeted is Mobile )
if ( from is PlayerMobile pm && targeted is Mobile targ )
{
PlayerMobile pm = (PlayerMobile)from;
Mobile targ = (Mobile)targeted;
if ( targ.AccessLevel <= from.AccessLevel )
if ( targ.AccessLevel <= pm.AccessLevel )
{
List<Mobile> list = pm.VisibilityList;
if ( list.Contains( targ ) )
{
list.Remove( targ );
from.SendMessage( "{0} has been removed from your visibility list.", targ.Name );
pm.SendMessage( "{0} has been removed from your visibility list.", targ.Name );
}
else
{
list.Add( targ );
from.SendMessage( "{0} has been added to your visibility list.", targ.Name );
pm.SendMessage( "{0} has been added to your visibility list.", targ.Name );
}
if ( Utility.InUpdateRange( targ, from ) )
@ -118,28 +111,28 @@ namespace Server.Commands
NetState ns = targ.NetState;
if ( ns != null ) {
if ( targ.CanSee( from ) )
if ( targ.CanSee( pm ) )
{
ns.Send(MobileIncoming.Create(ns, targ, from));
ns.Send(MobileIncoming.Create(ns, targ, pm));
if ( ObjectPropertyList.Enabled )
{
ns.Send( from.OPLPacket );
ns.Send( pm.OPLPacket );
foreach ( Item item in from.Items )
foreach ( Item item in pm.Items )
ns.Send( item.OPLPacket );
}
}
else
{
ns.Send( from.RemovePacket );
ns.Send( pm.RemovePacket );
}
}
}
}
else
{
from.SendMessage( "They can already see you!" );
pm.SendMessage( "They can already see you!" );
}
}
else

View file

@ -89,8 +89,8 @@ namespace Server.Commands
toDelete.Add( obj );
else if ( multis && (obj is BaseMulti) )
toDelete.Add( obj );
else if ( mobiles && (obj is Mobile) && !((Mobile)obj).Player )
toDelete.Add( obj );
else if ( mobiles && (obj is Mobile mobile) && !mobile.Player )
toDelete.Add( mobile );
}
eable.Free();