Fixes more casting

This commit is contained in:
Kamron Batman 2018-09-09 08:03:01 -07:00
parent aba9452161
commit 74f498c1c8
17 changed files with 581 additions and 805 deletions

View file

@ -76,13 +76,13 @@ namespace Server.ContextMenus
List<ContextMenuEntry> list = new List<ContextMenuEntry>();
if ( target is Mobile )
if ( target is Mobile mobile )
{
((Mobile)target).GetContextMenuEntries( from, list );
mobile.GetContextMenuEntries( from, list );
}
else if ( target is Item )
else if ( target is Item item )
{
((Item)target).GetContextMenuEntries( from, list );
item.GetContextMenuEntries( from, list );
}
//m_Entries = (ContextMenuEntry[])list.ToArray( typeof( ContextMenuEntry ) );
@ -112,4 +112,4 @@ namespace Server.ContextMenus
}
}
}
}
}

View file

@ -509,10 +509,8 @@ namespace Server
return new BounceInfo( map, loc, worldLoc, parent );
}
else
{
return null;
}
return null;
}
public static void Serialize( BounceInfo info, GenericWriter writer )
@ -529,10 +527,10 @@ namespace Server
writer.Write( info.m_Location );
writer.Write( info.m_WorldLoc );
if ( info.m_Parent is Mobile )
writer.Write( (Mobile) info.m_Parent );
else if ( info.m_Parent is Item )
writer.Write( (Item) info.m_Parent );
if ( info.m_Parent is Mobile mobile )
writer.Write( mobile );
else if ( info.m_Parent is Item item )
writer.Write( item );
else
writer.Write( (Serial) 0 );
}
@ -797,23 +795,18 @@ namespace Server
public List<Item> LookupItems()
{
if ( this is Container )
return ( this as Container ).m_Items;
if ( this is Container container )
return container.m_Items;
CompactInfo info = LookupCompactInfo();
if ( info != null )
return info.m_Items;
return null;
return info?.m_Items;
}
public List<Item> AcquireItems()
{
if ( this is Container )
if ( this is Container cont )
{
Container cont = this as Container;
if ( cont.m_Items == null )
cont.m_Items = new List<Item>();
@ -845,10 +838,7 @@ namespace Server
{
CompactInfo info = LookupCompactInfo();
if ( info != null )
return info.m_Bounce;
return null;
return info?.m_Bounce;
}
public void RecordBounce()
@ -862,31 +852,24 @@ namespace Server
{
CompactInfo info = LookupCompactInfo();
if ( info != null )
BounceInfo bounce = info?.m_Bounce;
if ( bounce != null )
{
BounceInfo bounce = info.m_Bounce;
info.m_Bounce = null;
if ( bounce != null )
if ( bounce.m_Parent is Item parentItem )
{
info.m_Bounce = null;
if ( bounce.m_Parent is Item )
{
Item parent = (Item) bounce.m_Parent;
if ( !parent.Deleted )
parent.OnItemBounceCleared( this );
}
else if ( bounce.m_Parent is Mobile )
{
Mobile parent = (Mobile) bounce.m_Parent;
if ( !parent.Deleted )
parent.OnItemBounceCleared( this );
}
VerifyCompactInfo();
if ( !parentItem.Deleted )
parentItem.OnItemBounceCleared( this );
}
else if ( bounce.m_Parent is Mobile parentMobile )
{
if ( !parentMobile.Deleted )
parentMobile.OnItemBounceCleared( this );
}
VerifyCompactInfo();
}
}
@ -1114,10 +1097,10 @@ namespace Server
/// </summary>
public virtual void GetChildProperties( ObjectPropertyList list, Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).GetChildProperties( list, item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).GetChildProperties( list, item );
if ( m_Parent is Item parentItem )
parentItem.GetChildProperties( list, item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.GetChildProperties( list, item );
}
/// <summary>
@ -1125,10 +1108,10 @@ namespace Server
/// </summary>
public virtual void GetChildNameProperties( ObjectPropertyList list, Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).GetChildNameProperties( list, item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).GetChildNameProperties( list, item );
if ( m_Parent is Item parentItem )
parentItem.GetChildNameProperties( list, item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.GetChildNameProperties( list, item );
}
public virtual bool IsChildVisibleTo( Mobile m, Item child )
@ -1138,10 +1121,10 @@ namespace Server
public void Bounce( Mobile from )
{
if ( m_Parent is Item )
((Item)m_Parent).RemoveItem( this );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).RemoveItem( this );
if ( m_Parent is Item item )
item.RemoveItem( this );
else if ( m_Parent is Mobile mobile )
mobile.RemoveItem( this );
m_Parent = null;
@ -1155,11 +1138,11 @@ namespace Server
{
MoveToWorld(bounce.m_WorldLoc, bounce.m_Map);
}
else if ( parent is Item )
else if ( parent is Item p )
{
Item p = (Item)parent;
IEntity root = p.RootParent;
if ( p.IsAccessibleTo( from ) && ( !(root is Mobile) || ((Mobile)root).CheckNonlocalDrop( from, this, p ) ) )
if ( p.IsAccessibleTo( from ) && ( !(root is Mobile mobileRoot) || mobileRoot.CheckNonlocalDrop( from, this, p ) ) )
{
Location = bounce.m_Location;
p.AddItem( this );
@ -1169,9 +1152,9 @@ namespace Server
MoveToWorld( from.Location, from.Map );
}
}
else if ( parent is Mobile )
else if ( parent is Mobile parentMobile )
{
if ( !((Mobile)parent).EquipItem( this ) )
if (!parentMobile.EquipItem( this ))
MoveToWorld( bounce.m_WorldLoc, bounce.m_Map );
}
else
@ -1220,18 +1203,18 @@ namespace Server
public virtual void GetChildContextMenuEntries( Mobile from, List<ContextMenuEntry> list, Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).GetChildContextMenuEntries( from, list, item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).GetChildContextMenuEntries( from, list, item );
if ( m_Parent is Item parentItem )
parentItem.GetChildContextMenuEntries( from, list, item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.GetChildContextMenuEntries( from, list, item );
}
public virtual void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
{
if ( m_Parent is Item )
((Item)m_Parent).GetChildContextMenuEntries( from, list, this );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).GetChildContextMenuEntries( from, list, this );
if ( m_Parent is Item item )
item.GetChildContextMenuEntries( from, list, this );
else if ( m_Parent is Mobile mobile )
mobile.GetChildContextMenuEntries( from, list, this );
}
public virtual bool VerifyMove( Mobile from )
@ -1243,32 +1226,32 @@ namespace Server
{
if ( !Movable )
return DeathMoveResult.RemainEquipped;
else if ( parent.KeepsItemsOnDeath )
if ( parent.KeepsItemsOnDeath )
return DeathMoveResult.MoveToBackpack;
else if ( CheckBlessed( parent ) )
if ( CheckBlessed( parent ) )
return DeathMoveResult.MoveToBackpack;
else if ( CheckNewbied() && parent.Kills < 5 )
if ( CheckNewbied() && parent.Kills < 5 )
return DeathMoveResult.MoveToBackpack;
else if ( parent.Player && Nontransferable )
if ( parent.Player && Nontransferable )
return DeathMoveResult.MoveToBackpack;
else
return DeathMoveResult.MoveToCorpse;
return DeathMoveResult.MoveToCorpse;
}
public virtual DeathMoveResult OnInventoryDeath( Mobile parent )
{
if ( !Movable )
return DeathMoveResult.MoveToBackpack;
else if ( parent.KeepsItemsOnDeath )
if ( parent.KeepsItemsOnDeath )
return DeathMoveResult.MoveToBackpack;
else if ( CheckBlessed( parent ) )
if ( CheckBlessed( parent ) )
return DeathMoveResult.MoveToBackpack;
else if ( CheckNewbied() && parent.Kills < 5 )
if ( CheckNewbied() && parent.Kills < 5 )
return DeathMoveResult.MoveToBackpack;
else if ( parent.Player && Nontransferable )
if ( parent.Player && Nontransferable )
return DeathMoveResult.MoveToBackpack;
else
return DeathMoveResult.MoveToCorpse;
return DeathMoveResult.MoveToCorpse;
}
/// <summary>
@ -1340,10 +1323,10 @@ namespace Server
SetLastMoved();
if ( Parent is Mobile )
((Mobile)Parent).RemoveItem( this );
else if ( Parent is Item )
((Item)Parent).RemoveItem( this );
if ( Parent is Mobile mobile )
mobile.RemoveItem( this );
else if ( Parent is Item item )
item.RemoveItem( this );
if ( m_Map != map )
{
@ -1383,9 +1366,7 @@ namespace Server
}
m_Map = map;
if ( m_Map != null )
m_Map.OnEnter( this );
m_Map?.OnEnter( this );
OnMapChange();
@ -1690,18 +1671,18 @@ namespace Server
public virtual void AppendChildProperties( ObjectPropertyList list )
{
if ( m_Parent is Item )
((Item)m_Parent).GetChildProperties( list, this );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).GetChildProperties( list, this );
if ( m_Parent is Item item )
item.GetChildProperties( list, this );
else if ( m_Parent is Mobile mobile )
mobile.GetChildProperties( list, this );
}
public virtual void AppendChildNameProperties( ObjectPropertyList list )
{
if ( m_Parent is Item )
((Item)m_Parent).GetChildNameProperties( list, this );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).GetChildNameProperties( list, this );
if ( m_Parent is Item item )
item.GetChildNameProperties( list, this );
else if ( m_Parent is Mobile mobile )
mobile.GetChildNameProperties( list, this );
}
public void ClearProperties()
@ -2052,7 +2033,7 @@ namespace Server
if ( m_Direction != Direction.North )
flags |= SaveFlag.Direction;
if ( info != null && info.m_Bounce != null )
if ( info?.m_Bounce != null )
flags |= SaveFlag.Bounce;
if ( m_LootType != LootType.Regular )
flags |= SaveFlag.LootType;
@ -2064,7 +2045,7 @@ namespace Server
flags |= SaveFlag.Amount;
if ( m_Layer != Layer.Invalid )
flags |= SaveFlag.Layer;
if ( info != null && info.m_Name != null )
if ( info?.m_Name != null )
flags |= SaveFlag.Name;
if ( m_Parent != null )
flags |= SaveFlag.Parent;
@ -2074,12 +2055,16 @@ namespace Server
flags |= SaveFlag.Map;
//if ( m_InsuredFor != null && !m_InsuredFor.Deleted )
//flags |= SaveFlag.InsuredFor;
if ( info != null && info.m_BlessedFor != null && !info.m_BlessedFor.Deleted )
flags |= SaveFlag.BlessedFor;
if ( info != null && info.m_HeldBy != null && !info.m_HeldBy.Deleted )
flags |= SaveFlag.HeldBy;
if ( info != null && info.m_SavedFlags != 0 )
flags |= SaveFlag.SavedFlags;
if (info != null)
{
if ( info.m_BlessedFor != null && !info.m_BlessedFor.Deleted )
flags |= SaveFlag.BlessedFor;
if ( info.m_HeldBy != null && !info.m_HeldBy.Deleted )
flags |= SaveFlag.HeldBy;
if ( info.m_SavedFlags != 0 )
flags |= SaveFlag.SavedFlags;
}
if ( info == null || info.m_Weight == -1 )
{
@ -2761,12 +2746,14 @@ namespace Server
{
if ( !IsVirtualItem )
{
if ( m_Parent is Item )
( m_Parent as Item ).UpdateTotal( sender, type, delta );
else if ( m_Parent is Mobile )
( m_Parent as Mobile ).UpdateTotal( sender, type, delta );
else if ( this.HeldBy != null )
( this.HeldBy as Mobile ).UpdateTotal( sender, type, delta );
if ( m_Parent is Item item )
item.UpdateTotal( sender, type, delta );
else if ( m_Parent is Mobile mobile )
mobile.UpdateTotal( sender, type, delta );
else
{
HeldBy?.UpdateTotal( sender, type, delta );
}
}
}
@ -2780,8 +2767,8 @@ namespace Server
{
if ( m_ItemID < 0x4000 )
return 1020000 + m_ItemID;
else
return 1078872 + m_ItemID;
return 1078872 + m_ItemID;
}
}
@ -2974,10 +2961,8 @@ namespace Server
{
break;
}
else
{
p = item.m_Parent;
}
p = item.m_Parent;
}
return false;
@ -2989,25 +2974,28 @@ namespace Server
{
return;
}
else if ( item == this )
if ( item == this )
{
Console.WriteLine( "Warning: Adding item to itself: [0x{0:X} {1}].AddItem( [0x{2:X} {3}] )", this.Serial.Value, this.GetType().Name, item.Serial.Value, item.GetType().Name );
Console.WriteLine( new System.Diagnostics.StackTrace() );
return;
}
else if ( IsChildOf( item ) )
if ( IsChildOf( item ) )
{
Console.WriteLine( "Warning: Adding parent item to child: [0x{0:X} {1}].AddItem( [0x{2:X} {3}] )", this.Serial.Value, this.GetType().Name, item.Serial.Value, item.GetType().Name );
Console.WriteLine( new System.Diagnostics.StackTrace() );
return;
}
else if ( item.m_Parent is Mobile )
if ( item.m_Parent is Mobile parentMobile )
{
((Mobile)item.m_Parent).RemoveItem( item );
parentMobile.RemoveItem( item );
}
else if ( item.m_Parent is Item )
else if ( item.m_Parent is Item parentItem )
{
((Item)item.m_Parent).RemoveItem( item );
parentItem.RemoveItem( item );
}
else
{
@ -3106,9 +3094,7 @@ namespace Server
{
bool sendOPLUpdate = ObjectPropertyList.Enabled && (flags & ItemDelta.Properties) != 0;
Container contParent = m_Parent as Container;
if ( contParent != null && !contParent.IsPublicContainer )
if ( m_Parent is Container contParent && !contParent.IsPublicContainer )
{
if ( (flags & ItemDelta.Update) != 0 )
{
@ -3138,39 +3124,33 @@ namespace Server
SecureTradeContainer stc = this.GetSecureTradeCont();
if ( stc != null )
SecureTrade st = stc?.Trade;
if ( st != null )
{
SecureTrade st = stc.Trade;
Mobile test = st.From.Mobile;
if ( st != null )
if ( test != null && test != rootParent )
tradeRecip = test;
test = st.To.Mobile;
if ( test != null && test != rootParent )
tradeRecip = test;
NetState ns = tradeRecip?.NetState;
if ( ns != null )
{
Mobile test = st.From.Mobile;
if ( test != null && test != rootParent )
tradeRecip = test;
test = st.To.Mobile;
if ( test != null && test != rootParent )
tradeRecip = test;
if ( tradeRecip != null )
if ( tradeRecip.CanSee( this ) && tradeRecip.InRange( worldLoc, GetUpdateRange( tradeRecip ) ) )
{
NetState ns = tradeRecip.NetState;
if ( ns.ContainerGridLines )
ns.Send( new ContainerContentUpdate6017( this ) );
else
ns.Send( new ContainerContentUpdate( this ) );
if ( ns != null )
{
if ( tradeRecip.CanSee( this ) && tradeRecip.InRange( worldLoc, GetUpdateRange( tradeRecip ) ) )
{
if ( ns.ContainerGridLines )
ns.Send( new ContainerContentUpdate6017( this ) );
else
ns.Send( new ContainerContentUpdate( this ) );
if ( ObjectPropertyList.Enabled )
ns.Send( OPLPacket );
}
}
if ( ObjectPropertyList.Enabled )
ns.Send( OPLPacket );
}
}
}
@ -3359,7 +3339,8 @@ namespace Server
{
if ( Deleted )
return;
else if ( !World.OnDelete( this ) )
if ( !World.OnDelete( this ) )
return;
OnDelete();
@ -3379,10 +3360,10 @@ namespace Server
SetFlag( ImplFlag.Deleted, true );
if ( Parent is Mobile )
((Mobile)Parent).RemoveItem( this );
else if ( Parent is Item )
((Item)Parent).RemoveItem( this );
if ( Parent is Mobile mobile )
mobile.RemoveItem( this );
else if ( Parent is Item item )
item.RemoveItem( this );
ClearBounce();
@ -3516,11 +3497,7 @@ namespace Server
{
CompactInfo info = LookupCompactInfo();
if (info != null)
return info.m_Spawner;
return null;
return info?.m_Spawner;
}
set
{
@ -3702,7 +3679,7 @@ namespace Server
{
CompactInfo info = LookupCompactInfo();
if ( info != null && info.m_Name != null )
if ( info?.m_Name != null )
return info.m_Name;
return this.DefaultName;
@ -3847,18 +3824,18 @@ namespace Server
{
if ( Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || target.Map == null )
return false;
else if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.Location, 2 ) )
if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.Location, 2 ) )
return false;
else if ( !from.CanSee( target ) || !from.InLOS( target ) )
if ( !from.CanSee( target ) || !from.InLOS( target ) )
return false;
else if ( !from.OnDroppedItemToMobile( this, target ) )
if ( !from.OnDroppedItemToMobile( this, target ) )
return false;
else if ( !OnDroppedToMobile( from, target ) )
if ( !OnDroppedToMobile( from, target ) )
return false;
else if ( !target.OnDragDrop( from, this ) )
if ( !target.OnDragDrop( from, this ) )
return false;
else
return true;
return true;
}
public virtual bool OnDroppedInto( Mobile from, Container target, Point3D p )
@ -3867,7 +3844,8 @@ namespace Server
{
return false;
}
else if ( Nontransferable && from.Player && target != from.Backpack )
if ( Nontransferable && from.Player && target != from.Backpack )
{
HandleInvalidTransfer( from );
return false;
@ -3880,21 +3858,21 @@ namespace Server
{
if ( Deleted || from.Deleted || target.Deleted || from.Map != target.Map || from.Map == null || target.Map == null )
return false;
else if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.GetWorldLocation(), 2 ) )
if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.GetWorldLocation(), 2 ) )
return false;
else if ( !from.CanSee( target ) || !from.InLOS( target ) )
if ( !from.CanSee( target ) || !from.InLOS( target ) )
return false;
else if ( !target.IsAccessibleTo( from ) )
if ( !target.IsAccessibleTo( from ) )
return false;
else if ( !from.OnDroppedItemOnto( this, target ) )
if ( !from.OnDroppedItemOnto( this, target ) )
return false;
else if ( Nontransferable && from.Player && target != from.Backpack )
if ( Nontransferable && from.Player && target != from.Backpack )
{
HandleInvalidTransfer( from );
return false;
}
else
return target.OnDragDrop( from, this );
return target.OnDragDrop( from, this );
}
public virtual bool DropToItem( Mobile from, Item target, Point3D p )
@ -3906,18 +3884,18 @@ namespace Server
if ( from.AccessLevel < AccessLevel.GameMaster && !from.InRange( target.GetWorldLocation(), 2 ) )
return false;
else if ( !from.CanSee( target ) || !from.InLOS( target ) )
if ( !from.CanSee( target ) || !from.InLOS( target ) )
return false;
else if ( !target.IsAccessibleTo( from ) )
if ( !target.IsAccessibleTo( from ) )
return false;
else if ( root is Mobile && !((Mobile)root).CheckNonlocalDrop( from, this, target ) )
if ( root is Mobile mobile && !mobile.CheckNonlocalDrop( from, this, target ) )
return false;
else if ( !from.OnDroppedItemToItem( this, target, p ) )
if ( !from.OnDroppedItemToItem( this, target, p ) )
return false;
else if ( target is Container && p.m_X != -1 && p.m_Y != -1 )
return OnDroppedInto( from, (Container)target, p );
else
return OnDroppedOnto( from, target );
if ( target is Container container && p.m_X != -1 && p.m_Y != -1 )
return OnDroppedInto( from, container, p );
return OnDroppedOnto( from, target );
}
public virtual bool OnDroppedToWorld( Mobile from, Point3D p )
@ -3942,7 +3920,8 @@ namespace Server
{
if ( Deleted || from.Deleted || from.Map == null )
return false;
else if ( !from.InRange( p, 2 ) )
if ( !from.InRange( p, 2 ) )
return false;
Map map = from.Map;
@ -4112,7 +4091,8 @@ namespace Server
if ( landAvg > z && (z + height) > landZ )
return false;
else if ( (landFlags & TileFlag.Impassable) != 0 && landAvg > surfaceZ && (z + height) > landZ )
if ( (landFlags & TileFlag.Impassable) != 0 && landAvg > surfaceZ && (z + height) > landZ )
return false;
for ( int i = 0; i < tiles.Length; ++i )
@ -4125,7 +4105,8 @@ namespace Server
if ( checkTop > z && (z + height) > checkZ )
return false;
else if ( (id.Surface || id.Impassable) && checkTop > surfaceZ && (z + height) > checkZ )
if ( (id.Surface || id.Impassable) && checkTop > surfaceZ && (z + height) > checkZ )
return false;
}
@ -4145,9 +4126,9 @@ namespace Server
if ( !from.InLOS( new Point3D( x, y, z + 1 ) ) )
return false;
else if ( !from.OnDroppedItemToWorld( this, p ) )
if ( !from.OnDroppedItemToWorld( this, p ) )
return false;
else if ( !OnDroppedToWorld( from, p ) )
if ( !OnDroppedToWorld( from, p ) )
return false;
int soundID = GetDropSound();
@ -4204,8 +4185,8 @@ namespace Server
if ( root == null )
return new Point3D( m_Location.m_X, m_Location.m_Y, m_Location.m_Z + (ItemData.Surface ? ItemData.CalcHeight : 0) );
else
return root.Location;
return root.Location;
}
public Point3D GetWorldTop()
@ -4214,8 +4195,8 @@ namespace Server
if ( root == null )
return new Point3D( m_Location.m_X, m_Location.m_Y, m_Location.m_Z + ItemData.CalcHeight );
else
return root.Location;
return root.Location;
}
public void SendLocalizedMessageTo( Mobile to, int number )
@ -4290,8 +4271,8 @@ namespace Server
while ( p is Item )
{
if ( p is SecureTradeContainer )
return (SecureTradeContainer)p;
if ( p is SecureTradeContainer container )
return container;
p = ((Item)p).m_Parent;
}
@ -4301,66 +4282,66 @@ namespace Server
public virtual void OnItemAdded( Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnSubItemAdded( item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnSubItemAdded( item );
if ( m_Parent is Item parentItem )
parentItem.OnSubItemAdded( item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnSubItemAdded( item );
}
public virtual void OnItemRemoved( Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnSubItemRemoved( item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnSubItemRemoved( item );
if ( m_Parent is Item parentItem )
parentItem.OnSubItemRemoved( item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnSubItemRemoved( item );
}
public virtual void OnSubItemAdded( Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnSubItemAdded( item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnSubItemAdded( item );
if ( m_Parent is Item parentItem )
parentItem.OnSubItemAdded( item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnSubItemAdded( item );
}
public virtual void OnSubItemRemoved( Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnSubItemRemoved( item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnSubItemRemoved( item );
if ( m_Parent is Item parentItem )
parentItem.OnSubItemRemoved( item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnSubItemRemoved( item );
}
public virtual void OnItemBounceCleared( Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnSubItemBounceCleared( item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnSubItemBounceCleared( item );
if ( m_Parent is Item parentItem )
parentItem.OnSubItemBounceCleared( item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnSubItemBounceCleared( item );
}
public virtual void OnSubItemBounceCleared( Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnSubItemBounceCleared( item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnSubItemBounceCleared( item );
if ( m_Parent is Item parentItem )
parentItem.OnSubItemBounceCleared( item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnSubItemBounceCleared( item );
}
public virtual bool CheckTarget( Mobile from, Server.Targeting.Target targ, object targeted )
{
if ( m_Parent is Item )
return ((Item)m_Parent).CheckTarget( from, targ, targeted );
else if ( m_Parent is Mobile )
return ((Mobile)m_Parent).CheckTarget( from, targ, targeted );
if ( m_Parent is Item item )
return item.CheckTarget( from, targ, targeted );
if ( m_Parent is Mobile mobile )
return mobile.CheckTarget( from, targ, targeted );
return true;
}
public virtual bool IsAccessibleTo( Mobile check )
{
if ( m_Parent is Item )
return ((Item)m_Parent).IsAccessibleTo( check );
if ( m_Parent is Item item )
return item.IsAccessibleTo( check );
Region reg = Region.Find( GetWorldLocation(), m_Map );
@ -4394,16 +4375,12 @@ namespace Server
Item item = (Item)p;
if ( item.m_Parent == null )
{
break;
}
else
{
p = item.m_Parent;
if ( p == o )
return true;
}
p = item.m_Parent;
if ( p == o )
return true;
}
return false;
@ -4419,10 +4396,10 @@ namespace Server
public virtual void OnItemUsed( Mobile from, Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnItemUsed( from, item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnItemUsed( from, item );
if ( m_Parent is Item parentItem )
parentItem.OnItemUsed( from, item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnItemUsed( from, item );
}
public bool CheckItemUse( Mobile from )
@ -4432,20 +4409,19 @@ namespace Server
public virtual bool CheckItemUse( Mobile from, Item item )
{
if ( m_Parent is Item )
return ((Item)m_Parent).CheckItemUse( from, item );
else if ( m_Parent is Mobile )
return ((Mobile)m_Parent).CheckItemUse( from, item );
else
return true;
if ( m_Parent is Item parentItem )
return parentItem.CheckItemUse( from, item );
if ( m_Parent is Mobile parentMobile )
return parentMobile.CheckItemUse( from, item );
return true;
}
public virtual void OnItemLifted( Mobile from, Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnItemLifted( from, item );
else if ( m_Parent is Mobile )
((Mobile)m_Parent).OnItemLifted( from, item );
if ( m_Parent is Item parentItem )
parentItem.OnItemLifted( from, item );
else if ( m_Parent is Mobile parentMobile )
parentMobile.OnItemLifted( from, item );
}
public bool CheckLift( Mobile from )
@ -4457,12 +4433,13 @@ namespace Server
public virtual bool CheckLift( Mobile from, Item item, ref LRReason reject )
{
if ( m_Parent is Item )
return ((Item)m_Parent).CheckLift( from, item, ref reject );
else if ( m_Parent is Mobile )
return ((Mobile)m_Parent).CheckLift( from, item, ref reject );
else
return true;
if ( m_Parent is Item parentItem )
return parentItem.CheckLift( from, item, ref reject );
if ( m_Parent is Mobile parentMobile )
return parentMobile.CheckLift( from, item, ref reject );
return true;
}
public virtual bool CanTarget{ get{ return true; } }
@ -4470,8 +4447,8 @@ namespace Server
public virtual void OnSingleClickContained( Mobile from, Item item )
{
if ( m_Parent is Item )
((Item)m_Parent).OnSingleClickContained( from, item );
if ( m_Parent is Item item1 )
item1.OnSingleClickContained( from, item );
}
public virtual void OnAosSingleClick( Mobile from )
@ -4566,9 +4543,9 @@ namespace Server
public virtual void ReplaceWith( Item newItem )
{
if ( m_Parent is Container )
if ( m_Parent is Container container )
{
((Container)m_Parent).AddItem( newItem );
container.AddItem( newItem );
newItem.Location = m_Location;
}
else

View file

@ -108,14 +108,12 @@ namespace Server.Items
{
get
{
if ( Parent is Container && ((Container)Parent).MaxWeight == 0 )
if ( Parent is Container container && container.MaxWeight == 0 )
{
return 0;
}
else
{
return DefaultMaxWeight;
}
return DefaultMaxWeight;
}
}
@ -225,12 +223,13 @@ namespace Server.Items
while ( parent != null )
{
if ( parent is Container )
return ((Container)parent).CheckHold( m, item, message, checkItems, plusItems, plusWeight );
else if ( parent is Item )
parent = ((Item)parent).Parent;
else
if ( parent is Container container )
return container.CheckHold( m, item, message, checkItems, plusItems, plusWeight );
if ( !(parent is Item parentItem) )
break;
parent = parentItem.Parent;
}
return true;

View file

@ -999,13 +999,12 @@ namespace Server
GetSector( item ).OnEnter( item );
if ( item is BaseMulti )
if ( item is BaseMulti m )
{
BaseMulti m = (BaseMulti)item;
MultiComponentList mcl = m.Components;
Sector start = GetMultiMinSector( item.Location, mcl );
Sector end = GetMultiMaxSector( item.Location, mcl );
Sector start = GetMultiMinSector( m.Location, mcl );
Sector end = GetMultiMaxSector( m.Location, mcl );
AddMulti( m, start, end );
}
@ -1024,13 +1023,12 @@ namespace Server
GetSector( item ).OnLeave( item );
if ( item is BaseMulti )
if ( item is BaseMulti m )
{
BaseMulti m = (BaseMulti)item;
MultiComponentList mcl = m.Components;
Sector start = GetMultiMinSector( item.Location, mcl );
Sector end = GetMultiMaxSector( item.Location, mcl );
Sector start = GetMultiMinSector( m.Location, mcl );
Sector end = GetMultiMaxSector( m.Location, mcl );
RemoveMulti( m, start, end );
}
@ -1095,13 +1093,12 @@ namespace Server
newSector.OnEnter( item );
}
if ( item is BaseMulti )
if ( item is BaseMulti m )
{
BaseMulti m = (BaseMulti)item;
MultiComponentList mcl = m.Components;
Sector start = GetMultiMinSector( item.Location, mcl );
Sector end = GetMultiMaxSector( item.Location, mcl );
Sector start = GetMultiMinSector( m.Location, mcl );
Sector end = GetMultiMaxSector( m.Location, mcl );
Sector oldStart = GetMultiMinSector( oldLocation, mcl );
Sector oldEnd = GetMultiMaxSector( oldLocation, mcl );
@ -1310,39 +1307,38 @@ namespace Server
{
Point3D p;
if ( o is Mobile )
if ( o is Mobile mobile )
{
p = ((Mobile)o).Location;
p = mobile.Location;
p.Z += 14; //eye ? 15 : 10;
}
else if ( o is Item )
else if ( o is Item item )
{
p = ((Item)o).GetWorldLocation();
p.Z += (((Item)o).ItemData.Height / 2) + 1;
p = item.GetWorldLocation();
p.Z += (item.ItemData.Height / 2) + 1;
}
else if ( o is Point3D )
else if ( o is Point3D point3D )
{
p = (Point3D)o;
p = point3D;
}
else if ( o is LandTarget )
else if ( o is LandTarget target )
{
p = ((LandTarget)o).Location;
p = target.Location;
int low = 0, avg = 0, top = 0;
GetAverageZ( p.X, p.Y, ref low, ref avg, ref top );
p.Z = top + 1;
}
else if ( o is StaticTarget )
else if ( o is StaticTarget st )
{
StaticTarget st = (StaticTarget)o;
ItemData id = TileData.ItemTable[st.ItemID & TileData.MaxItemValue];
p = new Point3D( st.X, st.Y, st.Z - id.CalcHeight + id.Height / 2 + 1 );
}
else if ( o is IPoint3D )
else if ( o is IPoint3D d )
{
p = new Point3D( (IPoint3D)o );
p = new Point3D( d );
}
else
{

File diff suppressed because it is too large Load diff

View file

@ -94,11 +94,9 @@ namespace Server.Network
}
catch ( Exception e )
{
if ( e is SocketException ) {
SocketException se = (SocketException)e;
if ( e is SocketException se ) {
if ( se.ErrorCode == 10048 ) { // WSAEADDRINUSE
Console.WriteLine( "Listener Failed: {0}:{1} (In Use)", ipep.Address, ipep.Port );
Console.WriteLine( "Listener Failed: {0}:{1} (In Use)", ipep.Address, ipep.Port );
}
else if ( se.ErrorCode == 10049 ) { // WSAEADDRNOTAVAIL
Console.WriteLine( "Listener Failed: {0}:{1} (Unavailable)", ipep.Address, ipep.Port );
@ -115,16 +113,14 @@ namespace Server.Network
private void DisplayListener()
{
IPEndPoint ipep = m_Listener.LocalEndPoint as IPEndPoint;
if ( ipep == null )
if ( !(m_Listener.LocalEndPoint is IPEndPoint ipep) )
return;
if ( ipep.Address.Equals( IPAddress.Any ) || ipep.Address.Equals( IPAddress.IPv6Any ) ) {
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach ( NetworkInterface adapter in adapters ) {
IPInterfaceProperties properties = adapter.GetIPProperties();
foreach ( IPAddressInformation unicast in properties.UnicastAddresses ) {
foreach ( UnicastIPAddressInformation unicast in properties.UnicastAddresses ) {
if ( ipep.AddressFamily == unicast.Address.AddressFamily )
Console.WriteLine( "Listening: {0}:{1}", unicast.Address, ipep.Port );
}
@ -285,4 +281,4 @@ namespace Server.Network
GC.SuppressFinalize(this);
}
}
}
}

View file

@ -343,9 +343,7 @@ namespace Server.Network
{
Serial serial = pvSrc.ReadInt32();
SecureTradeContainer cont = World.FindItem( serial ) as SecureTradeContainer;
if ( cont != null && cont.Trade != null && (cont.Trade.From.Mobile == state.Mobile || cont.Trade.To.Mobile == state.Mobile) )
if ( World.FindItem( serial ) is SecureTradeContainer cont && cont.Trade != null && (cont.Trade.From.Mobile == state.Mobile || cont.Trade.To.Mobile == state.Mobile) )
cont.Trade.Cancel();
break;
@ -354,9 +352,7 @@ namespace Server.Network
{
Serial serial = pvSrc.ReadInt32();
SecureTradeContainer cont = World.FindItem( serial ) as SecureTradeContainer;
if ( cont != null )
if ( World.FindItem( serial ) is SecureTradeContainer cont )
{
SecureTrade trade = cont.Trade;
@ -380,9 +376,7 @@ namespace Server.Network
{
Serial serial = pvSrc.ReadInt32();
SecureTradeContainer cont = World.FindItem(serial) as SecureTradeContainer;
if (cont != null)
if (World.FindItem(serial) is SecureTradeContainer cont)
{
int gold = pvSrc.ReadInt32();
int plat = pvSrc.ReadInt32();
@ -445,13 +439,8 @@ namespace Server.Network
buyList.Add( new BuyItemResponse( serial, amount ) );
}
if ( buyList.Count > 0 )
{
IVendor v = vendor as IVendor;
if ( v != null && v.OnBuyItems( state.Mobile, buyList ) )
state.Send( new EndVendorBuy( vendor ) );
}
if ( buyList.Count > 0 && vendor is IVendor v && v.OnBuyItems( state.Mobile, buyList ) )
state.Send( new EndVendorBuy( vendor ) );
}
else
{
@ -488,13 +477,8 @@ namespace Server.Network
sellList.Add( new SellItemResponse( item, Amount ) );
}
if ( sellList.Count > 0 )
{
IVendor v = vendor as IVendor;
if ( v != null && v.OnSellItems( state.Mobile, sellList ) )
state.Send( new EndVendorSell( vendor ) );
}
if ( sellList.Count > 0 && vendor is IVendor v && v.OnSellItems( state.Mobile, sellList ) )
state.Send( new EndVendorSell( vendor ) );
}
}
@ -1052,10 +1036,10 @@ namespace Server.Network
{
Item item = World.FindItem( dest );
if ( item is BaseMulti && ((BaseMulti)item).AllowsRelativeDrop )
if ( item is BaseMulti multi && multi.AllowsRelativeDrop )
{
loc.m_X += item.X;
loc.m_Y += item.Y;
loc.m_X += multi.X;
loc.m_Y += multi.Y;
from.Drop( loc );
}
else
@ -1090,10 +1074,10 @@ namespace Server.Network
{
Item item = World.FindItem( dest );
if ( item is BaseMulti && ((BaseMulti)item).AllowsRelativeDrop )
if ( item is BaseMulti multi && multi.AllowsRelativeDrop )
{
loc.m_X += item.X;
loc.m_Y += item.Y;
loc.m_X += multi.X;
loc.m_Y += multi.Y;
from.Drop( loc );
}
else
@ -1251,13 +1235,13 @@ namespace Server.Network
{
foreach (var e in gump.Entries)
{
if (e is GumpButton && ((GumpButton)e).ButtonID == buttonID)
if (e is GumpButton button && button.ButtonID == buttonID)
{
buttonExists = true;
break;
}
if (e is GumpImageTileButton && ((GumpImageTileButton)e).ButtonID == buttonID)
if (e is GumpImageTileButton tileButton && tileButton.ButtonID == buttonID)
{
buttonExists = true;
break;
@ -1546,8 +1530,8 @@ namespace Server.Network
}
else if ( from.Region.OnSingleClick( from, item ) )
{
if ( item.Parent is Item )
((Item)item.Parent).OnSingleClickContained( from, item );
if ( item.Parent is Item item1 )
item1.OnSingleClickContained( from, item );
item.OnSingleClick( from );
}
@ -1888,8 +1872,8 @@ namespace Server.Network
if ( entity is Mobile )
p = entity.Location;
else if ( entity is Item )
p = ((Item)entity).GetWorldLocation();
else if ( entity is Item item )
p = item.GetWorldLocation();
else
return;
@ -1921,7 +1905,10 @@ namespace Server.Network
{
if ( target is Mobile && !Utility.InUpdateRange( from.Location, target.Location ) )
return;
else if ( target is Item && !Utility.InUpdateRange( from.Location, ((Item)target).GetWorldLocation() ) )
Item item = target as Item;
if ( item != null && !Utility.InUpdateRange( from.Location, item.GetWorldLocation() ) )
return;
if ( !from.CheckContextMenuDisplay( target ) )
@ -1931,17 +1918,12 @@ namespace Server.Network
if ( c.Entries.Length > 0 )
{
if ( target is Item )
if ( item?.RootParent is Mobile mobile && mobile != from && mobile.AccessLevel >= from.AccessLevel )
{
object root = ((Item)target).RootParent;
if ( root is Mobile && root != from && ((Mobile)root).AccessLevel >= from.AccessLevel )
for ( int i = 0; i < c.Entries.Length; ++i )
{
for ( int i = 0; i < c.Entries.Length; ++i )
{
if ( !c.Entries[i].NonLocalUse )
c.Entries[i].Enabled = false;
}
if ( !c.Entries[i].NonLocalUse )
c.Entries[i].Enabled = false;
}
}

View file

@ -371,8 +371,7 @@ namespace Server.Network
{
this.EnsureCapacity( 256 );
Container BuyPack = vendor.FindItemOnLayer( Layer.ShopBuy ) as Container;
m_Stream.Write( (int)(BuyPack == null ? Serial.MinusOne : BuyPack.Serial) );
m_Stream.Write( (int)(!(vendor.FindItemOnLayer( Layer.ShopBuy ) is Container BuyPack) ? Serial.MinusOne : BuyPack.Serial) );
m_Stream.Write( (byte)list.Count );
@ -949,8 +948,8 @@ namespace Server.Network
if ( target is Mobile )
p = target.Location;
else if ( target is Item )
p = ((Item)target).GetWorldLocation();
else if ( target is Item item )
p = item.GetWorldLocation();
else
p = Point3D.Zero;
@ -998,8 +997,8 @@ namespace Server.Network
if ( target is Mobile )
p = target.Location;
else if ( target is Item )
p = ((Item)target).GetWorldLocation();
else if ( target is Item item )
p = item.GetWorldLocation();
else
p = Point3D.Zero;
@ -1072,9 +1071,11 @@ namespace Server.Network
{
Serial parentSerial;
if ( item.Parent is Mobile )
Mobile parent = item.Parent as Mobile;
if ( parent != null )
{
parentSerial = ((Mobile)item.Parent).Serial;
parentSerial = parent.Serial;
}
else
{
@ -1084,12 +1085,10 @@ namespace Server.Network
int hue = item.Hue;
if ( item.Parent is Mobile )
if ( parent != null )
{
Mobile mob = (Mobile)item.Parent;
if ( mob.SolidHueOverride >= 0 )
hue = mob.SolidHueOverride;
if ( parent.SolidHueOverride >= 0 )
hue = parent.SolidHueOverride;
}
m_Stream.Write( (int) item.Serial );
@ -1890,9 +1889,9 @@ namespace Server.Network
{
Serial parentSerial;
if ( item.Parent is Item )
if ( item.Parent is Item parentItem )
{
parentSerial = ((Item)item.Parent).Serial;
parentSerial = parentItem.Serial;
}
else
{
@ -1917,9 +1916,9 @@ namespace Server.Network
{
Serial parentSerial;
if ( item.Parent is Item )
if ( item.Parent is Item parentItem )
{
parentSerial = ((Item)item.Parent).Serial;
parentSerial = parentItem.Serial;
}
else
{
@ -2845,9 +2844,7 @@ namespace Server.Network
flags |= m_AdditionalFlags;
IAccount acct = ns.Account as IAccount;
if ( acct != null && acct.Limit >= 6 )
if ( ns.Account is IAccount acct && acct.Limit >= 6 )
{
flags |= FeatureFlags.LiveAccount;
flags &= ~FeatureFlags.UOTD;

View file

@ -170,23 +170,12 @@ namespace Server {
ISerializable value = entry.value;
BinaryMemoryWriter writer = entry.writer;
Item item = value as Item;
if ( item != null ) {
if ( value is Item item )
Save( item, writer );
} else {
Mobile mob = value as Mobile;
if ( mob != null ) {
else if ( value is Mobile mob )
Save( mob, writer );
} else {
BaseGuild guild = value as BaseGuild;
if ( guild != null ) {
Save( guild, writer );
}
}
}
else if ( value is BaseGuild guild )
Save( guild, writer );
}
private void Save( Item item, BinaryMemoryWriter writer ) {

View file

@ -31,10 +31,8 @@ namespace Server {
_Random = new CSPRandom();
}
if (_Random is IHardwareRNG) {
if (!((IHardwareRNG)_Random).IsSupported()) {
_Random = new CSPRandom();
}
if (_Random is IHardwareRNG rng && !rng.IsSupported()) {
_Random = new CSPRandom();
}
}

View file

@ -490,10 +490,8 @@ namespace Server
if ( obj == null )
return 1;
Region reg = obj as Region;
if ( reg == null )
throw new ArgumentException( "obj is not a Region", "obj" );
if ( !(obj is Region reg) )
throw new ArgumentException( "obj is not a Region", nameof(obj) );
// Dynamic regions go first
if ( this.Dynamic )

View file

@ -771,9 +771,7 @@ namespace Server
if ( attrs != null && attrs.Length > 0 )
{
TypeAliasAttribute attr = attrs[0] as TypeAliasAttribute;
if ( attr != null )
if ( attrs[0] is TypeAliasAttribute attr )
{
for( int j = 0; j < attr.Aliases.Length; ++j )
m_FullNames.Add( attr.Aliases[j], type );

View file

@ -45,10 +45,8 @@ namespace Server {
if ( obj == null )
return 1;
RegionRect regRect = obj as RegionRect;
if ( regRect == null )
throw new ArgumentException( "obj is not a RegionRect", "obj" );
if ( !(obj is RegionRect regRect) )
throw new ArgumentException( "obj is not a RegionRect", nameof(obj) );
return ( ( IComparable ) m_Region ).CompareTo( regRect.m_Region );
}
@ -316,4 +314,4 @@ namespace Server {
}
}
}
}
}

View file

@ -104,9 +104,10 @@ namespace Server
public int CompareTo( object other )
{
if ( other is Serial )
return this.CompareTo( (Serial) other );
else if ( other == null )
if ( other is Serial serial )
return this.CompareTo( serial );
if ( other == null )
return -1;
throw new ArgumentException();
@ -114,9 +115,10 @@ namespace Server
public override bool Equals( object o )
{
if ( o == null || !(o is Serial) ) return false;
if ( !(o is Serial serial) )
return false;
return ((Serial)o).m_Serial == m_Serial;
return serial.m_Serial == m_Serial;
}
public static bool operator == ( Serial l, Serial r )
@ -169,4 +171,4 @@ namespace Server
return new Serial( a );
}
}
}
}

View file

@ -1252,17 +1252,14 @@ namespace Server
List<T> list = new List<T>( count );
for ( int i = 0; i < count; ++i ) {
T item = ReadItem() as T;
if ( item != null ) {
if ( ReadItem() is T item ) {
list.Add( item );
}
}
return list;
} else {
return new List<T>();
}
return new List<T>();
}
public override HashSet<Item> ReadItemSet()
@ -1280,9 +1277,7 @@ namespace Server
for( int i = 0; i < count; ++i )
{
T item = ReadItem() as T;
if ( item != null )
if ( ReadItem() is T item )
{
set.Add( item );
}
@ -1290,10 +1285,8 @@ namespace Server
return set;
}
else
{
return new HashSet<T>();
}
return new HashSet<T>();
}
public override List<Mobile> ReadStrongMobileList()
@ -1309,17 +1302,15 @@ namespace Server
List<T> list = new List<T>( count );
for ( int i = 0; i < count; ++i ) {
T m = ReadMobile() as T;
if ( m != null ) {
if ( ReadMobile() is T m ) {
list.Add( m );
}
}
return list;
} else {
return new List<T>();
}
return new List<T>();
}
public override HashSet<Mobile> ReadMobileSet()
@ -1337,9 +1328,7 @@ namespace Server
for( int i = 0; i < count; ++i )
{
T item = ReadMobile() as T;
if ( item != null )
if ( ReadMobile() is T item )
{
set.Add( item );
}
@ -1347,10 +1336,8 @@ namespace Server
return set;
}
else
{
return new HashSet<T>();
}
return new HashSet<T>();
}
public override List<BaseGuild> ReadStrongGuildList()
@ -1366,17 +1353,15 @@ namespace Server
List<T> list = new List<T>( count );
for ( int i = 0; i < count; ++i ) {
T g = ReadGuild() as T;
if ( g != null ) {
if ( ReadGuild() is T g ) {
list.Add( g );
}
}
return list;
} else {
return new List<T>();
}
return new List<T>();
}
public override HashSet<BaseGuild> ReadGuildSet()
@ -1394,9 +1379,7 @@ namespace Server
for( int i = 0; i < count; ++i )
{
T item = ReadGuild() as T;
if ( item != null )
if ( ReadGuild() is T item )
{
set.Add( item );
}
@ -1404,10 +1387,8 @@ namespace Server
return set;
}
else
{
return new HashSet<T>();
}
return new HashSet<T>();
}
public override Race ReadRace()

View file

@ -205,47 +205,50 @@ namespace Server.Targeting
Point3D loc;
Map map;
if ( targeted is LandTarget )
Item item = targeted as Item;
Mobile mobile = targeted as Mobile;
if ( targeted is LandTarget target )
{
loc = ((LandTarget)targeted).Location;
loc = target.Location;
map = from.Map;
}
else if ( targeted is StaticTarget )
else if ( targeted is StaticTarget staticTarget )
{
loc = ((StaticTarget)targeted).Location;
loc = staticTarget.Location;
map = from.Map;
}
else if ( targeted is Mobile )
else if ( mobile != null )
{
if ( ((Mobile)targeted).Deleted )
if ( mobile.Deleted )
{
OnTargetDeleted( from, targeted );
OnTargetFinish( from );
return;
}
else if ( !((Mobile)targeted).CanTarget )
{
OnTargetUntargetable( from, targeted );
OnTargetDeleted( from, mobile );
OnTargetFinish( from );
return;
}
loc = ((Mobile)targeted).Location;
map = ((Mobile)targeted).Map;
}
else if ( targeted is Item )
{
Item item = (Item)targeted;
if ( !mobile.CanTarget )
{
OnTargetUntargetable( from, mobile );
OnTargetFinish( from );
return;
}
loc = mobile.Location;
map = mobile.Map;
}
else if ( item != null )
{
if ( item.Deleted )
{
OnTargetDeleted( from, targeted );
OnTargetDeleted( from, item );
OnTargetFinish( from );
return;
}
else if ( !item.CanTarget )
if ( !item.CanTarget )
{
OnTargetUntargetable( from, targeted );
OnTargetUntargetable( from, item );
OnTargetFinish( from );
return;
}
@ -254,7 +257,7 @@ namespace Server.Targeting
if ( !m_AllowNonlocal && root is Mobile && root != from && from.AccessLevel == AccessLevel.Player )
{
OnNonlocalTarget( from, targeted );
OnNonlocalTarget( from, item );
OnTargetFinish( from );
return;
}
@ -279,14 +282,14 @@ namespace Server.Targeting
OnCantSeeTarget( from, targeted );
else if ( m_CheckLOS && !from.InLOS( targeted ) )
OnTargetOutOfLOS( from, targeted );
else if ( targeted is Item && ((Item)targeted).InSecureTrade )
else if ( item?.InSecureTrade == true )
OnTargetInSecureTrade( from, targeted );
else if ( targeted is Item && !((Item)targeted).IsAccessibleTo( from ) )
else if ( item?.IsAccessibleTo( from ) == true )
OnTargetNotAccessible( from, targeted );
else if ( targeted is Item && !((Item)targeted).CheckTarget( from, this, targeted ) )
OnTargetUntargetable( from, targeted );
else if ( targeted is Mobile && !((Mobile)targeted).CheckTarget( from, this, targeted ) )
else if ( item?.CheckTarget( from, this, targeted ) == true )
OnTargetUntargetable( from, targeted );
else if ( mobile?.CheckTarget( from, this, mobile ) != true )
OnTargetUntargetable( from, mobile );
else if ( from.Region.OnTarget( from, this, targeted ) )
OnTarget( from, targeted );
}
@ -381,4 +384,4 @@ namespace Server.Targeting
}
}
}
}
}

View file

@ -661,33 +661,19 @@ namespace Server {
while ( _addQueue.Count > 0 ) {
IEntity entity = _addQueue.Dequeue();
Item item = entity as Item;
if ( item != null ) {
if ( entity is Item item )
AddItem( item );
} else {
Mobile mob = entity as Mobile;
if ( mob != null ) {
AddMobile( mob );
}
}
else if ( entity is Mobile mob )
AddMobile( mob );
}
while ( _deleteQueue.Count > 0 ) {
IEntity entity = _deleteQueue.Dequeue();
Item item = entity as Item;
if ( item != null ) {
if ( entity is Item item )
item.Delete();
} else {
Mobile mob = entity as Mobile;
if ( mob != null ) {
mob.Delete();
}
}
else if ( entity is Mobile mob )
mob.Delete();
}
}