Sets a default parameter for OnHit. More casting cleanup.

This commit is contained in:
Kamron Batman 2018-09-09 08:54:10 -07:00
parent 74f498c1c8
commit d6c0bf2d4c
96 changed files with 350 additions and 579 deletions

View file

@ -152,8 +152,7 @@ namespace Server.Items
public override void OnDelete()
{
if ( m_Timer != null )
m_Timer.Stop();
m_Timer?.Stop();
base.OnDelete();
}

View file

@ -106,11 +106,8 @@ namespace Server.Items
return;
}
if ( targeted is IDurability && targeted is Item )
if ( targeted is Item item && item is IDurability wearable )
{
IDurability wearable = (IDurability) targeted;
Item item = (Item) targeted;
if ( !wearable.CanFortify )
{
from.SendLocalizedMessage( 1049083 ); // You cannot use the powder on that item.

View file

@ -20,8 +20,8 @@ namespace Server.Items
{
bool allow = base.OnMoveOver( m );
if ( allow && Addon is BedOfNailsAddon )
( (BedOfNailsAddon)Addon ).OnMoveOver( m );
if ( allow && Addon is BedOfNailsAddon addon )
addon.OnMoveOver( m );
return allow;
}

View file

@ -125,8 +125,7 @@ namespace Server.Items
}
}
if ( m_Timer != null )
m_Timer.Stop();
m_Timer?.Stop();
m_Timer = null;
}

View file

@ -32,8 +32,7 @@ namespace Server.Items
{
base.OnAfterDelete();
if ( m_Timer != null )
m_Timer.Stop();
m_Timer?.Stop();
}
public override void Serialize( GenericWriter writer )

View file

@ -38,10 +38,8 @@ namespace Server.Items
{
foreach ( AddonComponent c in Addon.Components )
{
if ( c is CurtainsComponent )
if ( c is CurtainsComponent curtain )
{
CurtainsComponent curtain = (CurtainsComponent) c;
int temp = curtain.ItemID;
curtain.ItemID = curtain.ClosedID;
curtain.ClosedID = temp;

View file

@ -82,8 +82,8 @@ namespace Server.Items
{
object[] param = (object[]) obj;
if ( param[ 0 ] is AddonComponent && param[ 1 ] is Mobile )
Activate( (AddonComponent) param[ 0 ], (Mobile) param[ 1 ] );
if ( param[ 0 ] is AddonComponent component && param[ 1 ] is Mobile mobile )
Activate( component, mobile );
}
public virtual void Activate( AddonComponent c, Mobile from )
@ -127,10 +127,8 @@ namespace Server.Items
private void Deactivate( object obj )
{
if ( obj is AddonComponent )
if ( obj is AddonComponent c )
{
AddonComponent c = (AddonComponent) obj;
if ( c.ItemID == 0x1269 )
c.ItemID = 0x1260;
else if ( c.ItemID == 0x1260 )

View file

@ -54,8 +54,8 @@ namespace Server.Items
{
object[] param = (object[]) obj;
if ( param[ 0 ] is AddonComponent && param[ 1 ] is Mobile )
Activate( (AddonComponent) param[ 0 ], (Mobile) param[ 1 ] );
if ( param[ 0 ] is AddonComponent component && param[ 1 ] is Mobile mobile )
Activate( component, mobile );
}
public virtual void Activate( AddonComponent c, Mobile from )
@ -99,8 +99,8 @@ namespace Server.Items
private void Deactivate( object obj )
{
if ( obj is AddonComponent )
( (AddonComponent) obj ).ItemID = 0x1249;
if ( obj is AddonComponent component )
component.ItemID = 0x1249;
}
}

View file

@ -62,9 +62,9 @@ namespace Server.Items
{
Item deed = this.Deed;
if ( this.Parent is Item )
if ( this.Parent is Item item )
{
((Item)this.Parent).AddItem( deed );
item.AddItem( deed );
deed.Location = this.Location;
}
else
@ -227,9 +227,7 @@ namespace Server.Items
public void Placement_OnTarget( Mobile from, object targeted, object state )
{
IPoint3D p = targeted as IPoint3D;
if ( p == null )
if ( !(targeted is IPoint3D p) )
return;
Point3D loc = new Point3D( p );

View file

@ -205,9 +205,7 @@ namespace Server.Gumps
if ( entry.From != null )
{
Account acc = entry.From.Account as Account;
if ( acc != null )
if ( entry.From.Account is Account acc )
name = String.Format( "{0} ({1})", entry.From.Name, acc );
else
name = entry.From.Name;

View file

@ -322,9 +322,7 @@ namespace Server.Items
private bool HasEntered( Mobile from )
{
Account acc = from.Account as Account;
if ( acc == null )
if ( !(from.Account is Account acc) )
return false;
foreach ( RaffleEntry entry in m_Entries )
@ -370,7 +368,7 @@ namespace Server.Items
bool xEast = false, ySouth = false;
if ( Sextant.Format( loc, map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth ) )
result.AppendFormat( "{0}°{1}'{2},{3}°{4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" );
result.AppendFormat( "{0}°{1}'{2},{3}°{4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" );
else
result.AppendFormat( "{0},{1}", loc.X, loc.Y );
@ -492,9 +490,7 @@ namespace Server.Items
if ( Deleted || m_State != HouseRaffleState.Active || !from.CheckAlive() || HasEntered( from ) || IsAtIPLimit( from ) )
return;
Account acc = from.Account as Account;
if ( acc == null )
if ( !(from.Account is Account) )
return;
if ( okay )
@ -619,7 +615,7 @@ namespace Server.Items
}
case 0:
{
bool oldActive = ( version < 3 ) ? reader.ReadBool() : false;
bool oldActive = ( version < 3 ) && reader.ReadBool();
m_Bounds = reader.ReadRect2D();
m_Facet = reader.ReadMap();

View file

@ -130,9 +130,7 @@ namespace Server.Items
for ( int i = Items.Count - 1; i >= 0; i-- )
{
PlagueBeastComponent innard = Items[ i ] as PlagueBeastComponent;
if ( innard != null )
if ( Items[ i ] is PlagueBeastComponent innard )
{
Rectangle2D r = ItemBounds.Table[ innard.ItemID ];

View file

@ -62,9 +62,7 @@ namespace Server.Items
{
for ( int i = 0; i < pack.Items.Count; i++ )
{
PlagueBeastMainOrgan main = pack.Items[ i ] as PlagueBeastMainOrgan;
if ( main != null && main.Complete )
if ( pack.Items[ i ] is PlagueBeastMainOrgan main && main.Complete )
main.FinishOpening( from );
}
}
@ -104,7 +102,7 @@ namespace Server.Items
ItemID--;
}
}
}
public PlagueBeastBlood( Serial serial ) : base( serial )
{

View file

@ -136,8 +136,8 @@ namespace Server.Items
{
if ( m_Organ != null && m_Organ.OnDropped( from, dropped, this ) )
{
if ( dropped is PlagueBeastComponent )
m_Organ.Components.Add( (PlagueBeastComponent) dropped );
if ( dropped is PlagueBeastComponent component )
m_Organ.Components.Add( component );
}
return true;

View file

@ -55,9 +55,7 @@ namespace Server.Items
public void AddComponent( PlagueBeastComponent c, int x, int y )
{
Container pack = Parent as Container;
if ( pack != null )
if ( Parent is Container pack )
pack.DropItem( c );
c.Organ = this;

View file

@ -56,9 +56,7 @@ namespace Server.Items
if ( Owner != null )
Owner.PlaySound( 0x199 );
PlagueBeastRubbleOrgan organ = Organ as PlagueBeastRubbleOrgan;
if ( organ != null )
if ( Organ is PlagueBeastRubbleOrgan organ )
organ.OnVeinCut( from, this );
}

View file

@ -199,9 +199,8 @@ namespace Server.Items
{
MessageHelper.SendLocalizedMessageTo( m_Bag, from, 1042544, 0x59 ); // This item is out of charges.
}
else if ( targeted is Item )
else if ( targeted is Item item )
{
Item item = (Item)targeted;
int reqCharges = (int)Math.Max( 1, Math.Ceiling( item.TotalWeight / 10.0 ) );
if ( !item.IsChildOf( from.Backpack ) )

View file

@ -199,10 +199,8 @@ namespace Server.Items
{
from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1042001 ); // That must be in your pack for you to use it.
}
else if ( targeted is BaseCreature )
else if ( targeted is BaseCreature creature )
{
BaseCreature creature = (BaseCreature)targeted;
if ( !creature.Controlled || creature.ControlMaster != from )
{
MessageHelper.SendLocalizedMessageTo( m_Ball, from, 1054117, 0x59 ); // You may only link your own pets to a Crystal Ball of Pet Summoning.
@ -240,7 +238,7 @@ namespace Server.Items
{
SendLocalizedMessageTo( from, 1054122 ); // The Crystal Ball darkens. It must be charged before it can be used again.
}
else if ( pet is BaseMount && ((BaseMount)pet).Rider == from )
else if ( pet is BaseMount mount && mount.Rider == from )
{
MessageHelper.SendLocalizedMessageTo( this, from, 1054124, 0x36 ); // The Crystal Ball fills with a yellow mist. Why would you summon your pet while riding it?
}
@ -260,9 +258,9 @@ namespace Server.Items
{
from.Send( new AsciiMessage( this.Serial, this.ItemID, MessageType.Regular, 0x22, 3, "", "You cannot summon your pet to this location." ) );
}
else if ( Core.ML && from is PlayerMobile && DateTime.UtcNow < ((PlayerMobile)from).LastPetBallTime.AddSeconds( 15.0 ) )
else if ( Core.ML && from is PlayerMobile mobile && DateTime.UtcNow < mobile.LastPetBallTime.AddSeconds( 15.0 ) )
{
MessageHelper.SendLocalizedMessageTo( this, from, 1080072, 0x22 ); // You must wait a few seconds before you can summon your pet.
MessageHelper.SendLocalizedMessageTo( this, mobile, 1080072, 0x22 ); // You must wait a few seconds before you can summon your pet.
}
else
{
@ -298,17 +296,17 @@ namespace Server.Items
pet.StabledBy = null;
from.Stabled.Remove( pet );
if ( from is PlayerMobile )
((PlayerMobile)from).AutoStabled.Remove( pet );
if ( from is PlayerMobile mobile )
mobile.AutoStabled.Remove( pet );
}
pet.MoveToWorld( from.Location, from.Map );
MessageHelper.SendLocalizedMessageTo( this, from, 1054128, 0x43 ); // The Crystal Ball fills with a green mist. Your pet has been summoned.
if ( from is PlayerMobile )
if ( from is PlayerMobile playerMobile )
{
((PlayerMobile)from).LastPetBallTime = DateTime.UtcNow;
playerMobile.LastPetBallTime = DateTime.UtcNow;
}
}

View file

@ -204,9 +204,7 @@ namespace Server.Items
if ( m_Bracelet.CheckUse( m_From, false ) )
{
Mobile boundRoot = m_Bracelet.Bound.RootParent as Mobile;
if ( boundRoot != null )
if ( m_Bracelet.Bound.RootParent is Mobile boundRoot )
{
m_Bracelet.Charges--;
@ -279,9 +277,9 @@ namespace Server.Items
{
return false;
}
else if ( boundRoot.Map == Map.Felucca && from is PlayerMobile && ((PlayerMobile)from).Young )
else if ( boundRoot.Map == Map.Felucca && from is PlayerMobile mobile && mobile.Young )
{
from.SendLocalizedMessage( 1049543 ); // You decide against traveling to Felucca while you are still young.
mobile.SendLocalizedMessage( 1049543 ); // You decide against traveling to Felucca while you are still young.
return false;
}
else if ( from.Kills >= 5 && boundRoot.Map != Map.Felucca )
@ -357,10 +355,8 @@ namespace Server.Items
{
from.SendLocalizedMessage( 1042664 ); // You must have the object in your backpack to use it.
}
else if ( targeted is BraceletOfBinding )
else if ( targeted is BraceletOfBinding bindBracelet )
{
BraceletOfBinding bindBracelet = (BraceletOfBinding)targeted;
if ( bindBracelet == m_Bracelet )
{
from.SendLocalizedMessage( 1054012 ); // You cannot bind a bracelet of binding to itself!
@ -471,4 +467,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -59,10 +59,8 @@ namespace Server.Items
{
from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
}
else if ( targeted is TranslocationItem )
else if ( targeted is TranslocationItem transItem )
{
TranslocationItem transItem = (TranslocationItem)targeted;
if ( transItem.Charges >= transItem.MaxCharges )
{
MessageHelper.SendLocalizedMessageTo( m_Powder, from, 1054137, 0x59 ); // This item cannot absorb any more powder of translocation.
@ -88,10 +86,10 @@ namespace Server.Items
m_Powder.Delete();
}
if ( transItem is Item )
if ( transItem is Item item )
{
// The ~1_translocationItem~ glows with green energy and absorbs magical power from the powder.
MessageHelper.SendLocalizedMessageTo( (Item)transItem, from, 1054139, transItem.TranslocationItemName, 0x43 );
MessageHelper.SendLocalizedMessageTo( item, from, 1054139, transItem.TranslocationItemName, 0x43 );
}
}
}
@ -120,4 +118,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
}
}

View file

@ -642,10 +642,8 @@ namespace Server.Items
Effects.SendTargetParticles( from, 0x375A, 35, 90, 0x00, 0x00, 9502, (EffectLayer)255, 0x100 );
if ( m_Stone is SoulstoneFragment )
if ( m_Stone is SoulstoneFragment frag )
{
SoulstoneFragment frag = m_Stone as SoulstoneFragment;
if ( --frag.UsesRemaining <= 0 )
from.SendLocalizedMessage( 1070974 ); // You have used up your soulstone fragment.
}

View file

@ -66,9 +66,7 @@ namespace Server.Items
if ( !base.CanUse( from ) )
return false;
PlayerMobile pm = from as PlayerMobile;
if ( pm == null )
if ( !(from is PlayerMobile pm) )
return false;
#region Mondain's Legacy
@ -109,9 +107,7 @@ namespace Server.Items
if ( !CanUse( from ) )
return;
PlayerMobile pm = from as PlayerMobile;
if ( pm == null )
if ( !(from is PlayerMobile pm) )
return;
double tskill = from.Skills[Skill].Base;
@ -130,9 +126,6 @@ namespace Server.Items
Effects.SendTargetParticles( from, 0x373A, 35, 45, 0x00, 0x00, 9502, (EffectLayer)255, 0x100 );
pm.AcceleratedStart = DateTime.UtcNow + TimeSpan.FromMinutes(15);
Timer t = (Timer)m_Table[from];
m_Table[from] = Timer.DelayCall( TimeSpan.FromMinutes( 15 ), new TimerStateCallback( Expire_Callback ), from );
pm.AcceleratedSkill = Skill;

View file

@ -54,9 +54,7 @@ namespace Server.Items
if ( !base.CanUse( from ) )
return false;
PlayerMobile pm = from as PlayerMobile;
if ( pm == null )
if ( !(from is PlayerMobile pm) )
return false;
#region Mondain's Legacy

View file

@ -76,7 +76,7 @@ namespace Server.Items
int newValue = (int)Value;
if ( from is PlayerMobile && ((PlayerMobile)from).HasStatReward )
if ( from is PlayerMobile mobile && mobile.HasStatReward )
newValue += 5;
if ( from.StatCap >= newValue )
@ -95,8 +95,8 @@ namespace Server.Items
from.SendLocalizedMessage( 1049512 ); // You feel a surge of magic as the scroll enhances your powers!
if ( from is PlayerMobile && ((PlayerMobile)from).HasStatReward )
from.StatCap = (int)Value + 5;
if ( from is PlayerMobile mobile && mobile.HasStatReward )
mobile.StatCap = (int)Value + 5;
else
from.StatCap = (int)Value;

View file

@ -73,10 +73,8 @@ namespace Server.Items
{
if (!Deleted)
{
if (targeted != null && targeted is Mobile)
if (targeted != null && targeted is Mobile to)
{
Mobile to = targeted as Mobile;
if (to is PlayerMobile)
{
if (to != from)

View file

@ -26,8 +26,8 @@ namespace Server.Items
{
base.GetContextMenuEntries( from, list );
if ( from is PlayerMobile )
list.Add( new LockKarmaEntry( (PlayerMobile)from, Addon as AnkhOfSacrificeAddon ) );
if ( from is PlayerMobile mobile )
list.Add( new LockKarmaEntry( mobile, Addon as AnkhOfSacrificeAddon ) );
list.Add( new ResurrectEntry( from, Addon as AnkhOfSacrificeAddon ) );
}
@ -140,9 +140,9 @@ namespace Server.Items
return;
}
if ( from is PlayerMobile )
if ( from is PlayerMobile mobile )
{
((PlayerMobile) from).AnkhNextUse = DateTime.UtcNow + TimeSpan.FromHours( 1 );
mobile.AnkhNextUse = DateTime.UtcNow + TimeSpan.FromHours( 1 );
}
base.OnResponse( state, info );

View file

@ -26,12 +26,12 @@ namespace Server.Items
{
base.GetProperties( list );
if ( Addon is CannonAddon )
if ( Addon is CannonAddon addon )
{
if ( ((CannonAddon) Addon).IsRewardItem )
if ( addon.IsRewardItem )
list.Add( 1076223 ); // 7th Year Veteran Reward
list.Add( 1076207, ((CannonAddon) Addon).Charges.ToString() ); // Remaining Charges: ~1_val~
list.Add( 1076207, addon.Charges.ToString() ); // Remaining Charges: ~1_val~
}
}
@ -260,9 +260,7 @@ namespace Server.Items
if ( m_Cannon == null || m_Cannon.Deleted )
return;
IPoint3D p = targeted as IPoint3D;
if ( p == null )
if ( !(targeted is IPoint3D p) )
return;
if ( from.InLOS( new Point3D( p ) ) )

View file

@ -24,7 +24,7 @@ namespace Server.Items
{
base.GetProperties( list );
if ( Addon is StoneAnkh && ((StoneAnkh) Addon).IsRewardItem )
if ( Addon is StoneAnkh ankh && ankh.IsRewardItem )
list.Add( 1076221 ); // 5th Year Veteran Reward
}

View file

@ -189,10 +189,8 @@ namespace Server.Items
if ( m_Tool == null || m_Tool.Deleted )
return;
if ( targeted is BaseWeapon )
if ( targeted is BaseWeapon item )
{
BaseWeapon item = (BaseWeapon) targeted;
from.CloseGump( typeof( InternalGump ) );
from.SendGump( new InternalGump( m_Tool, item ) );
}