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

@ -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();
}
}
}
}