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

@ -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;