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

@ -328,8 +328,7 @@ namespace Server.Engines.CannedEvil
m_Active = true; m_Active = true;
m_HasBeenAdvanced = false; m_HasBeenAdvanced = false;
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = new SliceTimer( this ); m_Timer = new SliceTimer( this );
m_Timer.Start(); m_Timer.Start();
@ -359,8 +358,7 @@ namespace Server.Engines.CannedEvil
m_Active = false; m_Active = false;
m_HasBeenAdvanced = false; m_HasBeenAdvanced = false;
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

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

View file

@ -191,8 +191,7 @@ namespace Server.Engines.ConPVP
{ {
base.OnAfterDelete (); base.OnAfterDelete ();
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
} }
public override void OnDoubleClick( Mobile m ) public override void OnDoubleClick( Mobile m )

View file

@ -122,8 +122,7 @@ namespace Server.Engines.Help
public void Stop() public void Stop()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;
} }

View file

@ -167,8 +167,7 @@ namespace Server.Menus.Questions
public void StopClose() public void StopClose()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Mobile.Frozen = false; m_Mobile.Frozen = false;
} }

View file

@ -73,8 +73,7 @@ namespace Server.Engines.Quests
public virtual void StopTimer() public virtual void StopTimer()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;
} }

View file

@ -663,8 +663,7 @@ namespace Server.Mobiles
m_End = DateTime.UtcNow + delay; m_End = DateTime.UtcNow + delay;
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = new InternalTimer( this, delay ); m_Timer = new InternalTimer( this, delay );
if ( !IsFull ) if ( !IsFull )

View file

@ -39,7 +39,7 @@ namespace Server.Items
{ {
m_Resource = value; m_Resource = value;
Hue = CraftResources.GetHue( m_Resource ); Hue = CraftResources.GetHue( m_Resource );
InvalidateProperties(); InvalidateProperties();
} }
} }
@ -143,7 +143,7 @@ namespace Server.Items
if ( !map.CanFit( p3D.X, p3D.Y, p3D.Z, c.ItemData.Height, false, true, ( c.Z == 0 ) ) ) if ( !map.CanFit( p3D.X, p3D.Y, p3D.Z, c.ItemData.Height, false, true, ( c.Z == 0 ) ) )
return AddonFitResult.Blocked; return AddonFitResult.Blocked;
else if ( !CheckHouse( from, p3D, map, c.ItemData.Height, ref house ) ) if ( !CheckHouse( from, p3D, map, c.ItemData.Height, ref house ) )
return AddonFitResult.NotInHouse; return AddonFitResult.NotInHouse;
if ( c.NeedsWall ) if ( c.NeedsWall )
@ -168,7 +168,7 @@ namespace Server.Items
{ {
Point3D addonLoc = new Point3D( p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z ); Point3D addonLoc = new Point3D( p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z );
int addonHeight = c.ItemData.CalcHeight; int addonHeight = c.ItemData.CalcHeight;
if ( Utility.InRange( doorLoc, addonLoc, 1 ) && (addonLoc.Z == doorLoc.Z || ((addonLoc.Z + addonHeight) > doorLoc.Z && (doorLoc.Z + doorHeight) > addonLoc.Z)) ) if ( Utility.InRange( doorLoc, addonLoc, 1 ) && (addonLoc.Z == doorLoc.Z || ((addonLoc.Z + addonHeight) > doorLoc.Z && (doorLoc.Z + doorHeight) > addonLoc.Z)) )
return AddonFitResult.DoorTooClose; return AddonFitResult.DoorTooClose;
} }
@ -293,4 +293,4 @@ namespace Server.Items
Weight = -1; Weight = -1;
} }
} }
} }

View file

@ -37,7 +37,7 @@ namespace Server.Items
from.Direction = dir; from.Direction = dir;
bool canThrow = true; bool canThrow;
if ( !from.InRange( this, 4 ) || !from.InLOS( this ) ) if ( !from.InRange( this, 4 ) || !from.InLOS( this ) )
canThrow = false; canThrow = false;

View file

@ -63,8 +63,7 @@ namespace Server.Items
public void EndSpin( SpinCallback callback, Mobile from, int hue ) public void EndSpin( SpinCallback callback, Mobile from, int hue )
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -65,8 +65,7 @@ namespace Server.Items
public void EndSpin( SpinCallback callback, Mobile from, int hue ) public void EndSpin( SpinCallback callback, Mobile from, int hue )
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -46,8 +46,7 @@ namespace Server.Items
public void BeginSwing() public void BeginSwing()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = new InternalTimer( this ); m_Timer = new InternalTimer( this );
m_Timer.Start(); m_Timer.Start();
@ -57,8 +56,7 @@ namespace Server.Items
public void EndSwing() public void EndSwing()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -73,8 +73,7 @@ namespace Server.Items
public void EndSpin( SpinCallback callback, Mobile from, int hue ) public void EndSpin( SpinCallback callback, Mobile from, int hue )
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -65,8 +65,7 @@ namespace Server.Items
public void EndSpin( SpinCallback callback, Mobile from, int hue ) public void EndSpin( SpinCallback callback, Mobile from, int hue )
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -52,8 +52,7 @@ namespace Server.Items
public void BeginSwing() public void BeginSwing()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = new InternalTimer( this ); m_Timer = new InternalTimer( this );
m_Timer.Start(); m_Timer.Start();
@ -61,8 +60,7 @@ namespace Server.Items
public void EndSwing() public void EndSwing()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -791,10 +791,8 @@ namespace Server.Items
from.SendLocalizedMessage( 1074514 ); // You have no place to put it. from.SendLocalizedMessage( 1074514 ); // You have no place to put it.
return false; return false;
} }
else
{ from.SendLocalizedMessage( 1074512 ); // You put the gasping creature into your pack.
from.SendLocalizedMessage( 1074512 ); // You put the gasping creature into your pack.
}
} }
if ( !fish.Dead ) if ( !fish.Dead )
@ -871,24 +869,21 @@ namespace Server.Items
if ( IsFull ) if ( IsFull )
{ {
if ( from != null ) from?.SendLocalizedMessage( 1073636 ); // The decoration will not fit in the aquarium.
from.SendLocalizedMessage( 1073636 ); // The decoration will not fit in the aquarium.
return false; return false;
} }
if ( !Accepts( item ) ) if ( !Accepts( item ) )
{ {
if ( from != null ) from?.SendLocalizedMessage( 1073822 ); // The aquarium can not hold that item.
from.SendLocalizedMessage( 1073822 ); // The aquarium can not hold that item.
return false; return false;
} }
AddItem( item ); AddItem( item );
if ( from != null ) from?.SendLocalizedMessage( 1073635, ( item.LabelNumber != 0 ) ? String.Format( "#{0}", item.LabelNumber ) : item.Name ); // You add the following decoration to your aquarium: ~1_NAME~
from.SendLocalizedMessage( 1073635, ( item.LabelNumber != 0 ) ? String.Format( "#{0}", item.LabelNumber ) : item.Name ); // You add the following decoration to your aquarium: ~1_NAME~
InvalidateProperties(); InvalidateProperties();
return true; return true;

View file

@ -30,7 +30,7 @@ namespace Server.Items
DisplayPage( i, edit ); DisplayPage( i, edit );
} }
public virtual void DisplayPage( int page, bool edit ) public void DisplayPage( int page, bool edit )
{ {
AddPage( page ); AddPage( page );

View file

@ -28,8 +28,7 @@ namespace Server.Items
public virtual void StartTimer() public virtual void StartTimer()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = Timer.DelayCall( DeathDelay, new TimerCallback( Kill ) ); m_Timer = Timer.DelayCall( DeathDelay, new TimerCallback( Kill ) );
@ -38,8 +37,7 @@ namespace Server.Items
public virtual void StopTimer() public virtual void StopTimer()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;
@ -64,7 +62,7 @@ namespace Server.Items
// TODO: This will never return "very unusual dead aquarium creature" due to the way it is killed // TODO: This will never return "very unusual dead aquarium creature" due to the way it is killed
if ( ItemID > 0x3B0F ) if ( ItemID > 0x3B0F )
return Dead ? 1074424 : 1074422; // A very unusual [dead/live] aquarium creature return Dead ? 1074424 : 1074422; // A very unusual [dead/live] aquarium creature
else if ( Hue != 0 ) if ( Hue != 0 )
return Dead ? 1074425 : 1074423; // A [dead/live] aquarium creature of unusual color return Dead ? 1074425 : 1074423; // A [dead/live] aquarium creature of unusual color
return Dead ? 1073623 : 1073622; // A [dead/live] aquarium creature return Dead ? 1073623 : 1073622; // A [dead/live] aquarium creature

View file

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

View file

@ -126,8 +126,7 @@ namespace Server.Items
else if ( m_Duration != TimeSpan.Zero ) else if ( m_Duration != TimeSpan.Zero )
m_Duration = m_End - DateTime.UtcNow; m_Duration = m_End - DateTime.UtcNow;
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
PlayUnlitSound(); PlayUnlitSound();
} }
@ -142,8 +141,7 @@ namespace Server.Items
{ {
m_Duration = delay; m_Duration = delay;
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
if ( delay == TimeSpan.Zero ) if ( delay == TimeSpan.Zero )
return; return;

View file

@ -38,8 +38,7 @@ namespace Server.Items
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
} }
private void OnTick() private void OnTick()

View file

@ -40,8 +40,7 @@ namespace Server.Items
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
} }
private void OnTick() private void OnTick()

View file

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

View file

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

View file

@ -192,8 +192,7 @@ namespace Server.Items
{ {
m_Table.Remove( m_Healer ); m_Table.Remove( m_Healer );
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;
} }

View file

@ -67,7 +67,7 @@ namespace Server.Items
Recipe r = this.Recipe; Recipe r = this.Recipe;
if ( r != null && @from is PlayerMobile pm ) if ( r != null && from is PlayerMobile pm )
{ {
if ( !pm.HasRecipe( r ) ) if ( !pm.HasRecipe( r ) )
{ {

View file

@ -165,7 +165,7 @@ namespace Server.Items
public static BaseInstrument GetInstrument( Mobile from ) public static BaseInstrument GetInstrument( Mobile from )
{ {
if ( !(m_Instruments[@from] is BaseInstrument item) ) if ( !(m_Instruments[from] is BaseInstrument item) )
return null; return null;
if ( !item.IsChildOf( from.Backpack ) ) if ( !item.IsChildOf( from.Backpack ) )
@ -210,7 +210,7 @@ namespace Server.Items
InstrumentPickedCallback callback = state as InstrumentPickedCallback; InstrumentPickedCallback callback = state as InstrumentPickedCallback;
callback?.Invoke( @from, instrument ); callback?.Invoke( from, instrument );
} }
} }

View file

@ -26,7 +26,7 @@ namespace Server.Items
from.Send( new MessageLocalizedAffix( from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 1008146 + (int)Clock.GetMoonPhase( Map.Trammel, from.X, from.Y ), "", AffixType.Prepend, "Trammel : ", "" ) ); from.Send( new MessageLocalizedAffix( from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 1008146 + (int)Clock.GetMoonPhase( Map.Trammel, from.X, from.Y ), "", AffixType.Prepend, "Trammel : ", "" ) );
from.Send( new MessageLocalizedAffix( from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 1008146 + (int)Clock.GetMoonPhase( Map.Felucca, from.X, from.Y ), "", AffixType.Prepend, "Felucca : ", "" ) ); from.Send( new MessageLocalizedAffix( from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 1008146 + (int)Clock.GetMoonPhase( Map.Felucca, from.X, from.Y ), "", AffixType.Prepend, "Felucca : ", "" ) );
if ( @from is PlayerMobile player ) if ( from is PlayerMobile player )
{ {
QuestSystem qs = player.Quest; QuestSystem qs = player.Quest;

View file

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

View file

@ -106,11 +106,8 @@ namespace Server.Items
return; 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 ) if ( !wearable.CanFortify )
{ {
from.SendLocalizedMessage( 1049083 ); // You cannot use the powder on that item. 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 ); bool allow = base.OnMoveOver( m );
if ( allow && Addon is BedOfNailsAddon ) if ( allow && Addon is BedOfNailsAddon addon )
( (BedOfNailsAddon)Addon ).OnMoveOver( m ); addon.OnMoveOver( m );
return allow; return allow;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -62,9 +62,7 @@ namespace Server.Items
{ {
for ( int i = 0; i < pack.Items.Count; i++ ) for ( int i = 0; i < pack.Items.Count; i++ )
{ {
PlagueBeastMainOrgan main = pack.Items[ i ] as PlagueBeastMainOrgan; if ( pack.Items[ i ] is PlagueBeastMainOrgan main && main.Complete )
if ( main != null && main.Complete )
main.FinishOpening( from ); main.FinishOpening( from );
} }
} }
@ -104,7 +102,7 @@ namespace Server.Items
ItemID--; ItemID--;
} }
} }
public PlagueBeastBlood( Serial serial ) : base( serial ) 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 ( m_Organ != null && m_Organ.OnDropped( from, dropped, this ) )
{ {
if ( dropped is PlagueBeastComponent ) if ( dropped is PlagueBeastComponent component )
m_Organ.Components.Add( (PlagueBeastComponent) dropped ); m_Organ.Components.Add( component );
} }
return true; return true;

View file

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

View file

@ -56,9 +56,7 @@ namespace Server.Items
if ( Owner != null ) if ( Owner != null )
Owner.PlaySound( 0x199 ); Owner.PlaySound( 0x199 );
PlagueBeastRubbleOrgan organ = Organ as PlagueBeastRubbleOrgan; if ( Organ is PlagueBeastRubbleOrgan organ )
if ( organ != null )
organ.OnVeinCut( from, this ); 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. 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 ) ); int reqCharges = (int)Math.Max( 1, Math.Ceiling( item.TotalWeight / 10.0 ) );
if ( !item.IsChildOf( from.Backpack ) ) 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. 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 ) 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. 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. 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? 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." ) ); 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 else
{ {
@ -298,17 +296,17 @@ namespace Server.Items
pet.StabledBy = null; pet.StabledBy = null;
from.Stabled.Remove( pet ); from.Stabled.Remove( pet );
if ( from is PlayerMobile ) if ( from is PlayerMobile mobile )
((PlayerMobile)from).AutoStabled.Remove( pet ); mobile.AutoStabled.Remove( pet );
} }
pet.MoveToWorld( from.Location, from.Map ); 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. 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 ) ) if ( m_Bracelet.CheckUse( m_From, false ) )
{ {
Mobile boundRoot = m_Bracelet.Bound.RootParent as Mobile; if ( m_Bracelet.Bound.RootParent is Mobile boundRoot )
if ( boundRoot != null )
{ {
m_Bracelet.Charges--; m_Bracelet.Charges--;
@ -279,9 +277,9 @@ namespace Server.Items
{ {
return false; 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; return false;
} }
else if ( from.Kills >= 5 && boundRoot.Map != Map.Felucca ) 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. 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 ) if ( bindBracelet == m_Bracelet )
{ {
from.SendLocalizedMessage( 1054012 ); // You cannot bind a bracelet of binding to itself! 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. 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 ) if ( transItem.Charges >= transItem.MaxCharges )
{ {
MessageHelper.SendLocalizedMessageTo( m_Powder, from, 1054137, 0x59 ); // This item cannot absorb any more powder of translocation. 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(); 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. // 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(); 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 ); 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 ) if ( --frag.UsesRemaining <= 0 )
from.SendLocalizedMessage( 1070974 ); // You have used up your soulstone fragment. from.SendLocalizedMessage( 1070974 ); // You have used up your soulstone fragment.
} }

View file

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

View file

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

View file

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

View file

@ -73,10 +73,8 @@ namespace Server.Items
{ {
if (!Deleted) 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 is PlayerMobile)
{ {
if (to != from) if (to != from)

View file

@ -26,8 +26,8 @@ namespace Server.Items
{ {
base.GetContextMenuEntries( from, list ); base.GetContextMenuEntries( from, list );
if ( from is PlayerMobile ) if ( from is PlayerMobile mobile )
list.Add( new LockKarmaEntry( (PlayerMobile)from, Addon as AnkhOfSacrificeAddon ) ); list.Add( new LockKarmaEntry( mobile, Addon as AnkhOfSacrificeAddon ) );
list.Add( new ResurrectEntry( from, Addon as AnkhOfSacrificeAddon ) ); list.Add( new ResurrectEntry( from, Addon as AnkhOfSacrificeAddon ) );
} }
@ -140,9 +140,9 @@ namespace Server.Items
return; 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 ); base.OnResponse( state, info );

View file

@ -26,12 +26,12 @@ namespace Server.Items
{ {
base.GetProperties( list ); 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( 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 ) if ( m_Cannon == null || m_Cannon.Deleted )
return; return;
IPoint3D p = targeted as IPoint3D; if ( !(targeted is IPoint3D p) )
if ( p == null )
return; return;
if ( from.InLOS( new Point3D( p ) ) ) if ( from.InLOS( new Point3D( p ) ) )

View file

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

View file

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

View file

@ -54,7 +54,7 @@ namespace Server.Items
{ {
object root = RootParent; object root = RootParent;
if ( root is Mobile && ((Mobile)root).AccessLevel < m_AccessLevel ) if ( root is Mobile mobile && mobile.AccessLevel < m_AccessLevel )
{ {
Delete(); Delete();
return false; return false;
@ -88,4 +88,4 @@ namespace Server.Items
return ( from.AccessLevel >= m_AccessLevel ); return ( from.AccessLevel >= m_AccessLevel );
} }
} }
} }

View file

@ -211,9 +211,7 @@ namespace Server.Items
public override void OnAfterDuped(Item newItem) public override void OnAfterDuped(Item newItem)
{ {
BaseTalisman talisman = newItem as BaseTalisman; if (!(newItem is BaseTalisman talisman))
if (talisman == null)
return; return;
talisman.m_Summoner = new TalismanAttribute(m_Summoner); talisman.m_Summoner = new TalismanAttribute(m_Summoner);
@ -236,10 +234,8 @@ namespace Server.Items
public override void OnAdded(IEntity parent) public override void OnAdded(IEntity parent)
{ {
if (parent is Mobile) if (parent is Mobile from)
{ {
Mobile from = (Mobile)parent;
m_AosSkillBonuses.AddTo(from); m_AosSkillBonuses.AddTo(from);
m_AosAttributes.AddStatBonuses(from); m_AosAttributes.AddStatBonuses(from);
@ -261,10 +257,8 @@ namespace Server.Items
public override void OnRemoved(IEntity parent) public override void OnRemoved(IEntity parent)
{ {
if (parent is Mobile) if (parent is Mobile from)
{ {
Mobile from = (Mobile)parent;
m_AosSkillBonuses.Remove(); m_AosSkillBonuses.Remove();
m_AosAttributes.RemoveStatBonuses(from); m_AosAttributes.RemoveStatBonuses(from);
@ -304,9 +298,8 @@ namespace Server.Items
try { obj = Activator.CreateInstance(type); } try { obj = Activator.CreateInstance(type); }
catch { obj = null; } catch { obj = null; }
if (obj is Item) if (obj is Item item)
{ {
Item item = (Item)obj;
int count = 1; int count = 1;
if (m_Summoner != null && m_Summoner.Amount > 1) if (m_Summoner != null && m_Summoner.Amount > 1)
@ -340,13 +333,11 @@ namespace Server.Items
from.SendLocalizedMessage(1075001); // You have been given some ingots. from.SendLocalizedMessage(1075001); // You have been given some ingots.
else if (item is Bandage) else if (item is Bandage)
from.SendLocalizedMessage(1075002); // You have been given some clean bandages. from.SendLocalizedMessage(1075002); // You have been given some clean bandages.
else if (m_Summoner != null && m_Summoner.Name != null) else if (m_Summoner?.Name != null)
from.SendLocalizedMessage(1074853, m_Summoner.Name.ToString()); // You have been given ~1_name~ from.SendLocalizedMessage(1074853, m_Summoner.Name.ToString()); // You have been given ~1_name~
} }
else if (obj is BaseCreature) else if (obj is BaseCreature mob)
{ {
BaseCreature mob = (BaseCreature)obj;
if ((m_Creature != null && !m_Creature.Deleted) || from.Followers + mob.ControlSlots > from.FollowersMax) if ((m_Creature != null && !m_Creature.Deleted) || from.Followers + mob.ControlSlots > from.FollowersMax)
{ {
from.SendLocalizedMessage(1074270); // You have too many followers to summon another one. from.SendLocalizedMessage(1074270); // You have too many followers to summon another one.
@ -682,10 +673,8 @@ namespace Server.Items
} }
} }
if (Parent is Mobile) if (Parent is Mobile m)
{ {
Mobile m = (Mobile)Parent;
m_AosAttributes.AddStatBonuses(m); m_AosAttributes.AddStatBonuses(m);
m_AosSkillBonuses.AddTo(m); m_AosSkillBonuses.AddTo(m);

View file

@ -57,10 +57,8 @@ namespace Server.Items
if ( m_Item == null || m_Item.Deleted ) if ( m_Item == null || m_Item.Deleted )
return; return;
if ( o is BaseTalisman ) if ( o is BaseTalisman talisman )
{ {
BaseTalisman talisman = (BaseTalisman) o;
if ( talisman.Charges == 0 ) if ( talisman.Charges == 0 )
{ {
talisman.Charges = talisman.MaxCharges; talisman.Charges = talisman.MaxCharges;

View file

@ -21,8 +21,7 @@ namespace Server.Items
public virtual void StopTimer() public virtual void StopTimer()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;
} }
@ -178,4 +177,4 @@ namespace Server.Items
} }
} }
} }
} }

View file

@ -117,17 +117,15 @@ namespace Server.Items
{ {
Item item = Loot.RandomArmorOrShieldOrWeapon(); Item item = Loot.RandomArmorOrShieldOrWeapon();
if ( item is BaseWeapon ) if ( item is BaseWeapon weapon )
{ {
BaseWeapon weapon = ( BaseWeapon )item;
weapon.DamageLevel = ( WeaponDamageLevel )Utility.Random( m_Level ); weapon.DamageLevel = ( WeaponDamageLevel )Utility.Random( m_Level );
weapon.AccuracyLevel = ( WeaponAccuracyLevel )Utility.Random( m_Level ); weapon.AccuracyLevel = ( WeaponAccuracyLevel )Utility.Random( m_Level );
weapon.DurabilityLevel = ( WeaponDurabilityLevel )Utility.Random( m_Level ); weapon.DurabilityLevel = ( WeaponDurabilityLevel )Utility.Random( m_Level );
weapon.Quality = WeaponQuality.Regular; weapon.Quality = WeaponQuality.Regular;
} }
else if ( item is BaseArmor ) else if ( item is BaseArmor armor )
{ {
BaseArmor armor = ( BaseArmor )item;
armor.ProtectionLevel = ( ArmorProtectionLevel )Utility.Random( m_Level ); armor.ProtectionLevel = ( ArmorProtectionLevel )Utility.Random( m_Level );
armor.Durability = ( ArmorDurabilityLevel )Utility.Random( m_Level ); armor.Durability = ( ArmorDurabilityLevel )Utility.Random( m_Level );
armor.Quality = ArmorQuality.Regular; armor.Quality = ArmorQuality.Regular;

View file

@ -124,17 +124,15 @@ namespace Server.Items
{ {
Item item = Loot.RandomArmorOrShieldOrWeapon(); Item item = Loot.RandomArmorOrShieldOrWeapon();
if ( item is BaseWeapon ) if ( item is BaseWeapon weapon )
{ {
BaseWeapon weapon = ( BaseWeapon )item;
weapon.DamageLevel = ( WeaponDamageLevel )Utility.Random( m_Level ); weapon.DamageLevel = ( WeaponDamageLevel )Utility.Random( m_Level );
weapon.AccuracyLevel = ( WeaponAccuracyLevel )Utility.Random( m_Level ); weapon.AccuracyLevel = ( WeaponAccuracyLevel )Utility.Random( m_Level );
weapon.DurabilityLevel = ( WeaponDurabilityLevel )Utility.Random( m_Level ); weapon.DurabilityLevel = ( WeaponDurabilityLevel )Utility.Random( m_Level );
weapon.Quality = WeaponQuality.Regular; weapon.Quality = WeaponQuality.Regular;
} }
else if ( item is BaseArmor ) else if ( item is BaseArmor armor )
{ {
BaseArmor armor = ( BaseArmor )item;
armor.ProtectionLevel = ( ArmorProtectionLevel )Utility.Random( m_Level ); armor.ProtectionLevel = ( ArmorProtectionLevel )Utility.Random( m_Level );
armor.Durability = ( ArmorDurabilityLevel )Utility.Random( m_Level ); armor.Durability = ( ArmorDurabilityLevel )Utility.Random( m_Level );
armor.Quality = ArmorQuality.Regular; armor.Quality = ArmorQuality.Regular;

View file

@ -33,15 +33,20 @@ namespace Server.Items
public override bool OnWandTarget( Mobile from, object o ) public override bool OnWandTarget( Mobile from, object o )
{ {
if ( o is BaseWeapon ) if (o is Item item)
((BaseWeapon)o).Identified = true; {
else if ( o is BaseArmor ) if ( item is BaseWeapon weapon )
((BaseArmor)o).Identified = true; weapon.Identified = true;
else if ( item is BaseArmor armor )
armor.Identified = true;
if ( !Core.AOS && o is Item ) if (!Core.AOS)
((Item)o).OnSingleClick( from ); item.OnSingleClick( from );
return ( o is Item ); return true;
}
return false;
} }
} }
} }

View file

@ -31,7 +31,7 @@ namespace Server.Items
TransformContext context = TransformationSpellHelper.GetContext( defender ); TransformContext context = TransformationSpellHelper.GetContext( defender );
if ( (context != null && ( context.Type == typeof( LichFormSpell ) || context.Type == typeof( WraithFormSpell ))) || if ( (context != null && ( context.Type == typeof( LichFormSpell ) || context.Type == typeof( WraithFormSpell ))) ||
(defender is BaseCreature && ((BaseCreature)defender).BleedImmune) ) (defender is BaseCreature creature && creature.BleedImmune) )
{ {
attacker.SendLocalizedMessage( 1062052 ); // Your target is not affected by the bleed attack! attacker.SendLocalizedMessage( 1062052 ); // Your target is not affected by the bleed attack!
return; return;
@ -63,8 +63,7 @@ namespace Server.Items
{ {
Timer t = (Timer)m_Table[m]; Timer t = (Timer)m_Table[m];
if ( t != null ) t?.Stop();
t.Stop();
t = new InternalTimer( from, m ); t = new InternalTimer( from, m );
m_Table[m] = t; m_Table[m] = t;

View file

@ -60,9 +60,7 @@ namespace Server.Items
public static bool GetBonus( Mobile targ, ref int bonus ) public static bool GetBonus( Mobile targ, ref int bonus )
{ {
BlockInfo info = m_Table[targ] as BlockInfo; if ( !(m_Table[targ] is BlockInfo info) )
if ( info == null )
return false; return false;
bonus = info.m_Bonus; bonus = info.m_Bonus;
@ -81,12 +79,9 @@ namespace Server.Items
public static void EndBlock( Mobile m ) public static void EndBlock( Mobile m )
{ {
BlockInfo info = m_Table[m] as BlockInfo; if ( m_Table[m] is BlockInfo info )
if ( info != null )
{ {
if ( info.m_Timer != null ) info.m_Timer?.Stop();
info.m_Timer.Stop();
m_Table.Remove( m ); m_Table.Remove( m );
} }

View file

@ -39,9 +39,7 @@ namespace Server.Items
int modifier = (int)(30.0 * ((Math.Max( attacker.Skills[SkillName.Bushido].Value, attacker.Skills[SkillName.Ninjitsu].Value ) - 50.0) / 70.0)); int modifier = (int)(30.0 * ((Math.Max( attacker.Skills[SkillName.Bushido].Value, attacker.Skills[SkillName.Ninjitsu].Value ) - 50.0) / 70.0));
DefenseMasteryInfo info = m_Table[attacker] as DefenseMasteryInfo; if ( m_Table[attacker] is DefenseMasteryInfo info )
if ( info != null )
EndDefense( (object)info ); EndDefense( (object)info );
ResistanceMod mod = new ResistanceMod( ResistanceType.Physical, 50 + modifier ); ResistanceMod mod = new ResistanceMod( ResistanceType.Physical, 50 + modifier );
@ -74,9 +72,7 @@ namespace Server.Items
public static bool GetMalus( Mobile targ, ref int damageMalus ) public static bool GetMalus( Mobile targ, ref int damageMalus )
{ {
DefenseMasteryInfo info = m_Table[targ] as DefenseMasteryInfo; if ( !(m_Table[targ] is DefenseMasteryInfo info) )
if ( info == null )
return false; return false;
damageMalus = info.m_DamageMalus; damageMalus = info.m_DamageMalus;
@ -90,8 +86,7 @@ namespace Server.Items
if ( info.m_Mod != null ) if ( info.m_Mod != null )
info.m_From.RemoveResistanceMod( info.m_Mod ); info.m_From.RemoveResistanceMod( info.m_Mod );
if ( info.m_Timer != null ) info.m_Timer?.Stop();
info.m_Timer.Stop();
// No message is sent to the player. // No message is sent to the player.

View file

@ -35,9 +35,7 @@ namespace Server.Items
public override bool RequiresTactics( Mobile from ) public override bool RequiresTactics( Mobile from )
{ {
BaseWeapon weapon = from.Weapon as BaseWeapon; if ( !(from.Weapon is BaseWeapon weapon) )
if ( weapon == null )
return false; return false;
return weapon.Skill != SkillName.Wrestling; return weapon.Skill != SkillName.Wrestling;

View file

@ -72,36 +72,32 @@ namespace Server.Items
defender.PlaySound( 0x140 ); defender.PlaySound( 0x140 );
defender.FixedParticles( 0x3728, 10, 15, 9955, EffectLayer.Waist ); defender.FixedParticles( 0x3728, 10, 15, 9955, EffectLayer.Waist );
if (defender is PlayerMobile) if (defender is PlayerMobile mobile)
{ {
if (Server.Spells.Ninjitsu.AnimalForm.UnderTransformation(defender)) if (Server.Spells.Ninjitsu.AnimalForm.UnderTransformation(mobile))
{ {
defender.SendLocalizedMessage(1114066, attacker.Name); // ~1_NAME~ knocked you out of animal form! mobile.SendLocalizedMessage(1114066, attacker.Name); // ~1_NAME~ knocked you out of animal form!
} }
else if (defender.Mounted) else if (mobile.Mounted)
{ {
defender.SendLocalizedMessage(1040023); // You have been knocked off of your mount! mobile.SendLocalizedMessage(1040023); // You have been knocked off of your mount!
} }
(defender as PlayerMobile).SetMountBlock(BlockMountType.Dazed, TimeSpan.FromSeconds(10), true); mobile.SetMountBlock(BlockMountType.Dazed, TimeSpan.FromSeconds(10), true);
} }
else else
{ {
defender.Mount.Rider = null; defender.Mount.Rider = null;
} }
if ( attacker is PlayerMobile ) if ( attacker is PlayerMobile playerMobile )
{ {
(attacker as PlayerMobile).SetMountBlock(BlockMountType.DismountRecovery, RemountDelay, true ); playerMobile.SetMountBlock(BlockMountType.DismountRecovery, RemountDelay, true );
} }
else if ( Core.ML && attacker is BaseCreature ) else if ( Core.ML && attacker is BaseCreature bc )
{ {
BaseCreature bc = attacker as BaseCreature; if ( bc.ControlMaster is PlayerMobile pm )
if ( bc.ControlMaster is PlayerMobile )
{ {
PlayerMobile pm = bc.ControlMaster as PlayerMobile;
pm.SetMountBlock(BlockMountType.DismountRecovery, RemountDelay, false ); pm.SetMountBlock(BlockMountType.DismountRecovery, RemountDelay, false );
} }
} }

View file

@ -43,9 +43,7 @@ namespace Server.Items
if ( map == null ) if ( map == null )
return; return;
BaseWeapon weapon = attacker.Weapon as BaseWeapon; if ( !(attacker.Weapon is BaseWeapon weapon) )
if ( weapon == null )
return; return;
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
@ -88,9 +86,7 @@ namespace Server.Items
Mobile m = (Mobile)targets[i]; Mobile m = (Mobile)targets[i];
attacker.DoHarmful( m, true ); attacker.DoHarmful( m, true );
Timer t = Registry[m] as Timer; if ( Registry[m] is Timer t )
if ( t != null )
{ {
t.Stop(); t.Stop();
Registry.Remove( m ); Registry.Remove( m );

View file

@ -32,9 +32,7 @@ namespace Server.Items
ClearCurrentAbility( attacker ); ClearCurrentAbility( attacker );
BaseWeapon weapon = attacker.Weapon as BaseWeapon; if ( !(attacker.Weapon is BaseWeapon weapon) )
if ( weapon == null )
return; return;
Poison p = weapon.Poison; Poison p = weapon.Poison;

View file

@ -40,9 +40,7 @@ namespace Server.Items
public override bool RequiresTactics( Mobile from ) public override bool RequiresTactics( Mobile from )
{ {
BaseWeapon weapon = from.Weapon as BaseWeapon; if ( !(from.Weapon is BaseWeapon weapon) )
if ( weapon == null )
return true; return true;
return weapon.Skill != SkillName.Wrestling; return weapon.Skill != SkillName.Wrestling;

View file

@ -85,9 +85,7 @@ namespace Server.Items
public virtual bool CheckWeaponSkill( Mobile from ) public virtual bool CheckWeaponSkill( Mobile from )
{ {
BaseWeapon weapon = from.Weapon as BaseWeapon; if ( !(from.Weapon is BaseWeapon weapon) )
if ( weapon == null )
return false; return false;
Skill skill = from.Skills[weapon.Skill]; Skill skill = from.Skills[weapon.Skill];
@ -141,7 +139,7 @@ namespace Server.Items
if ( from.Mana < mana ) if ( from.Mana < mana )
{ {
if ( ( from is BaseCreature ) && ( from as BaseCreature ).HasManaOveride ) if ( from is BaseCreature creature && creature.HasManaOveride )
{ {
return true; return true;
} }
@ -336,9 +334,7 @@ namespace Server.Items
if ( !m.Player ) if ( !m.Player )
return true; return true;
BaseWeapon weapon = m.Weapon as BaseWeapon; return ( m.Weapon is BaseWeapon weapon && (weapon.PrimaryAbility == a || weapon.SecondaryAbility == a) );
return ( weapon != null && (weapon.PrimaryAbility == a || weapon.SecondaryAbility == a) );
} }
public virtual bool ValidatesDuringHit => true; public virtual bool ValidatesDuringHit => true;

View file

@ -28,9 +28,7 @@ namespace Server.Items
if ( map == null ) if ( map == null )
return; return;
BaseWeapon weapon = attacker.Weapon as BaseWeapon; if ( !(attacker.Weapon is BaseWeapon weapon) )
if ( weapon == null )
return; return;
if ( !CheckMana( attacker, true ) ) if ( !CheckMana( attacker, true ) )

View file

@ -150,7 +150,7 @@ namespace Server.Items
} }
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1 )
{ {
base.OnHit( attacker, defender, damageBonus ); base.OnHit( attacker, defender, damageBonus );

View file

@ -413,15 +413,14 @@ namespace Server.Items
{ {
if ( m_AccuracyLevel == WeaponAccuracyLevel.Regular ) if ( m_AccuracyLevel == WeaponAccuracyLevel.Regular )
{ {
if ( m_SkillMod != null ) m_SkillMod?.Remove();
m_SkillMod.Remove();
m_SkillMod = null; m_SkillMod = null;
} }
else if ( m_SkillMod == null && Parent is Mobile ) else if ( m_SkillMod == null && Parent is Mobile mobile )
{ {
m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5 ); m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5 );
((Mobile)Parent).AddSkillMod( m_SkillMod ); mobile.AddSkillMod( m_SkillMod );
} }
else if ( m_SkillMod != null ) else if ( m_SkillMod != null )
{ {
@ -438,9 +437,7 @@ namespace Server.Items
public override void OnAfterDuped( Item newItem ) public override void OnAfterDuped( Item newItem )
{ {
BaseWeapon weap = newItem as BaseWeapon; if ( !(newItem is BaseWeapon weap) )
if ( weap == null )
return; return;
weap.m_AosAttributes = new AosAttributes( newItem, m_AosAttributes ); weap.m_AosAttributes = new AosAttributes( newItem, m_AosAttributes );
@ -507,15 +504,10 @@ namespace Server.Items
int v = m_AosWeaponAttributes.LowerStatReq; int v = m_AosWeaponAttributes.LowerStatReq;
CraftResourceInfo info = CraftResources.GetInfo( m_Resource ); CraftAttributeInfo attrInfo = CraftResources.GetInfo( m_Resource )?.AttributeInfo;
if ( info != null ) if ( attrInfo != null )
{ v += attrInfo.WeaponLowerRequirements;
CraftAttributeInfo attrInfo = info.AttributeInfo;
if ( attrInfo != null )
v += attrInfo.WeaponLowerRequirements;
}
if ( v > 100 ) if ( v > 100 )
v = 100; v = 100;
@ -587,29 +579,27 @@ namespace Server.Items
return false; return false;
} }
else if ( from.Dex < DexRequirement ) if ( from.Dex < DexRequirement )
{ {
from.SendMessage( "You are not nimble enough to equip that." ); from.SendMessage( "You are not nimble enough to equip that." );
return false; return false;
} }
else if ( from.Str < AOS.Scale( StrRequirement, 100 - GetLowerStatReq() ) ) if ( from.Str < AOS.Scale( StrRequirement, 100 - GetLowerStatReq() ) )
{ {
from.SendLocalizedMessage( 500213 ); // You are not strong enough to equip that. from.SendLocalizedMessage( 500213 ); // You are not strong enough to equip that.
return false; return false;
} }
else if ( from.Int < IntRequirement ) if ( from.Int < IntRequirement )
{ {
from.SendMessage( "You are not smart enough to equip that." ); from.SendMessage( "You are not smart enough to equip that." );
return false; return false;
} }
else if ( !from.CanBeginAction( typeof( BaseWeapon ) ) ) if ( !from.CanBeginAction( typeof( BaseWeapon ) ) )
{ {
return false; return false;
} }
else
{ return base.CanEquip( from );
return base.CanEquip( from );
}
} }
public virtual bool UseSkillMod{ get{ return !Core.AOS; } } public virtual bool UseSkillMod{ get{ return !Core.AOS; } }
@ -640,8 +630,7 @@ namespace Server.Items
if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular ) if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular )
{ {
if ( m_SkillMod != null ) m_SkillMod?.Remove();
m_SkillMod.Remove();
m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5 ); m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5 );
from.AddSkillMod( m_SkillMod ); from.AddSkillMod( m_SkillMod );
@ -649,8 +638,7 @@ namespace Server.Items
if ( Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && m_AosWeaponAttributes.MageWeapon != 30 ) if ( Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && m_AosWeaponAttributes.MageWeapon != 30 )
{ {
if ( m_MageMod != null ) m_MageMod?.Remove();
m_MageMod.Remove();
m_MageMod = new DefaultSkillMod( SkillName.Magery, true, -30 + m_AosWeaponAttributes.MageWeapon ); m_MageMod = new DefaultSkillMod( SkillName.Magery, true, -30 + m_AosWeaponAttributes.MageWeapon );
from.AddSkillMod( m_MageMod ); from.AddSkillMod( m_MageMod );
@ -663,10 +651,8 @@ namespace Server.Items
{ {
base.OnAdded( parent ); base.OnAdded( parent );
if ( parent is Mobile ) if ( parent is Mobile from )
{ {
Mobile from = (Mobile)parent;
if ( Core.AOS ) if ( Core.AOS )
m_AosSkillBonuses.AddTo( from ); m_AosSkillBonuses.AddTo( from );
@ -677,9 +663,8 @@ namespace Server.Items
public override void OnRemoved(IEntity parent) public override void OnRemoved(IEntity parent)
{ {
if ( parent is Mobile ) if ( parent is Mobile m )
{ {
Mobile m = (Mobile)parent;
BaseWeapon weapon = m.Weapon as BaseWeapon; BaseWeapon weapon = m.Weapon as BaseWeapon;
string modName = this.Serial.ToString(); string modName = this.Serial.ToString();
@ -729,7 +714,7 @@ namespace Server.Items
val = swrd; val = swrd;
if ( fenc > val ){ sk = SkillName.Fencing; val = fenc; } if ( fenc > val ){ sk = SkillName.Fencing; val = fenc; }
if ( mcng > val ){ sk = SkillName.Macing; val = mcng; } if ( mcng > val ){ sk = SkillName.Macing; }
} }
else if ( m_AosWeaponAttributes.MageWeapon != 0 ) else if ( m_AosWeaponAttributes.MageWeapon != 0 )
{ {
@ -770,7 +755,7 @@ namespace Server.Items
BaseWeapon defWeapon = defender.Weapon as BaseWeapon; BaseWeapon defWeapon = defender.Weapon as BaseWeapon;
Skill atkSkill = attacker.Skills[atkWeapon.Skill]; Skill atkSkill = attacker.Skills[atkWeapon.Skill];
Skill defSkill = defender.Skills[defWeapon.Skill]; // Skill defSkill = defender.Skills[defWeapon.Skill];
double atkValue = atkWeapon.GetAttackSkillValue( attacker, defender ); double atkValue = atkWeapon.GetAttackSkillValue( attacker, defender );
double defValue = defWeapon.GetDefendSkillValue( attacker, defender ); double defValue = defWeapon.GetDefendSkillValue( attacker, defender );
@ -901,8 +886,8 @@ namespace Server.Items
TransformContext context = TransformationSpellHelper.GetContext( m ); TransformContext context = TransformationSpellHelper.GetContext( m );
if ( context != null && context.Spell is ReaperFormSpell ) if ( context?.Spell is ReaperFormSpell spell )
bonus += ((ReaperFormSpell)context.Spell).SwingSpeedBonus; bonus += spell.SwingSpeedBonus;
int discordanceEffect = 0; int discordanceEffect = 0;
@ -1009,24 +994,18 @@ namespace Server.Items
if ( canSwing ) if ( canSwing )
{ {
Spell sp = attacker.Spell as Spell; canSwing = ( !(attacker.Spell is Spell sp) || !sp.IsCasting || !sp.BlocksMovement );
canSwing = ( sp == null || !sp.IsCasting || !sp.BlocksMovement );
} }
if ( canSwing ) if ( canSwing )
{ {
PlayerMobile p = attacker as PlayerMobile; canSwing = ( !(attacker is PlayerMobile p) || p.PeacedUntil <= DateTime.UtcNow );
canSwing = ( p == null || p.PeacedUntil <= DateTime.UtcNow );
} }
} }
#region Dueling #region Dueling
if ( attacker is PlayerMobile ) if ( attacker is PlayerMobile pm )
{ {
PlayerMobile pm = (PlayerMobile)attacker;
if ( pm.DuelContext != null && !pm.DuelContext.CheckItemEquip( attacker, this ) ) if ( pm.DuelContext != null && !pm.DuelContext.CheckItemEquip( attacker, this ) )
canSwing = false; canSwing = false;
} }
@ -1039,9 +1018,8 @@ namespace Server.Items
if ( attacker.NetState != null ) if ( attacker.NetState != null )
attacker.Send( new Swing( 0, attacker, defender ) ); attacker.Send( new Swing( 0, attacker, defender ) );
if ( attacker is BaseCreature ) if ( attacker is BaseCreature bc )
{ {
BaseCreature bc = (BaseCreature)attacker;
WeaponAbility ab = bc.GetWeaponAbility(); WeaponAbility ab = bc.GetWeaponAbility();
if ( ab != null ) if ( ab != null )
@ -1080,10 +1058,7 @@ namespace Server.Items
public virtual int GetMissAttackSound( Mobile attacker, Mobile defender ) public virtual int GetMissAttackSound( Mobile attacker, Mobile defender )
{ {
if ( attacker.GetAttackSound() == -1 ) return attacker.GetAttackSound() == -1 ? MissSound : -1;
return MissSound;
else
return -1;
} }
public virtual int GetMissDefendSound( Mobile attacker, Mobile defender ) public virtual int GetMissDefendSound( Mobile attacker, Mobile defender )
@ -1124,7 +1099,7 @@ namespace Server.Items
return defender.CheckSkill( SkillName.Parry, chance ); return defender.CheckSkill( SkillName.Parry, chance );
} }
else if ( !(defender.Weapon is Fists) && !(defender.Weapon is BaseRanged) ) if ( !(defender.Weapon is Fists) && !(defender.Weapon is BaseRanged) )
{ {
BaseWeapon weapon = defender.Weapon as BaseWeapon; BaseWeapon weapon = defender.Weapon as BaseWeapon;
@ -1155,8 +1130,8 @@ namespace Server.Items
if ( chance > aosChance ) if ( chance > aosChance )
return defender.CheckSkill( SkillName.Parry, chance ); return defender.CheckSkill( SkillName.Parry, chance );
else
return (aosChance > Utility.RandomDouble()); // Only skillcheck if wielding a shield & there's no effect from Bushido return (aosChance > Utility.RandomDouble()); // Only skillcheck if wielding a shield & there's no effect from Bushido
} }
return false; return false;
@ -1180,9 +1155,7 @@ namespace Server.Items
if ( CounterAttack.IsCountering( defender ) ) if ( CounterAttack.IsCountering( defender ) )
{ {
BaseWeapon weapon = defender.Weapon as BaseWeapon; if ( defender.Weapon is BaseWeapon weapon )
if ( weapon != null )
{ {
defender.FixedParticles(0x3779, 1, 15, 0x158B, 0x0, 0x3, EffectLayer.Waist); defender.FixedParticles(0x3779, 1, 15, 0x158B, 0x0, 0x3, EffectLayer.Waist);
weapon.OnSwing( defender, attacker ); weapon.OnSwing( defender, attacker );
@ -1203,10 +1176,7 @@ namespace Server.Items
BaseShield shield = defender.FindItemOnLayer( Layer.TwoHanded ) as BaseShield; BaseShield shield = defender.FindItemOnLayer( Layer.TwoHanded ) as BaseShield;
if ( shield != null ) shield?.OnHit( this, damage );
{
shield.OnHit( this, damage );
}
} }
} }
@ -1229,9 +1199,7 @@ namespace Server.Items
else else
armorItem = defender.ChestArmor; armorItem = defender.ChestArmor;
IWearableDurability armor = armorItem as IWearableDurability; if ( armorItem is IWearableDurability armor )
if ( armor != null )
armor.OnHit( this, damage ); // call OnHit to lose durability armor.OnHit( this, damage ); // call OnHit to lose durability
} }
@ -1243,8 +1211,7 @@ namespace Server.Items
if ( Core.AOS ) if ( Core.AOS )
return AbsorbDamageAOS( attacker, defender, damage ); return AbsorbDamageAOS( attacker, defender, damage );
BaseShield shield = defender.FindItemOnLayer( Layer.TwoHanded ) as BaseShield; if ( defender.FindItemOnLayer( Layer.TwoHanded ) is BaseShield shield )
if ( shield != null )
damage = shield.OnHit( this, damage ); damage = shield.OnHit( this, damage );
double chance = Utility.RandomDouble(); double chance = Utility.RandomDouble();
@ -1264,9 +1231,7 @@ namespace Server.Items
else else
armorItem = defender.ChestArmor; armorItem = defender.ChestArmor;
IWearableDurability armor = armorItem as IWearableDurability; if ( armorItem is IWearableDurability armor )
if ( armor != null )
damage = armor.OnHit( this, damage ); damage = armor.OnHit( this, damage );
int virtualArmor = defender.VirtualArmor + defender.VirtualArmorMod; int virtualArmor = defender.VirtualArmor + defender.VirtualArmorMod;
@ -1300,9 +1265,7 @@ namespace Server.Items
if ( attacker.Player || defender.Player ) if ( attacker.Player || defender.Player )
return 0; return 0;
BaseCreature bc = attacker as BaseCreature; if ( !(attacker is BaseCreature bc) || bc.PackInstinct == PackInstinct.None || (!bc.Controlled && !bc.Summoned) )
if ( bc == null || bc.PackInstinct == PackInstinct.None || (!bc.Controlled && !bc.Summoned) )
return 0; return 0;
Mobile master = bc.ControlMaster; Mobile master = bc.ControlMaster;
@ -1336,11 +1299,11 @@ namespace Server.Items
if ( inPack >= 5 ) if ( inPack >= 5 )
return 100; return 100;
else if ( inPack >= 4 ) if ( inPack >= 4 )
return 75; return 75;
else if ( inPack >= 3 ) if ( inPack >= 3 )
return 50; return 50;
else if ( inPack >= 2 ) if ( inPack >= 2 )
return 25; return 25;
return 0; return 0;
@ -1354,12 +1317,7 @@ namespace Server.Items
set{ m_InDoubleStrike = value; } set{ m_InDoubleStrike = value; }
} }
public void OnHit( Mobile attacker, Mobile defender ) public virtual void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1.0)
{
OnHit( attacker, defender, 1.0 );
}
public virtual void OnHit( Mobile attacker, Mobile defender, double damageBonus )
{ {
if ( MirrorImage.HasClone( defender ) && (defender.Skills.Ninjitsu.Value / 150.0) > Utility.RandomDouble() ) if ( MirrorImage.HasClone( defender ) && (defender.Skills.Ninjitsu.Value / 150.0) > Utility.RandomDouble() )
{ {
@ -1436,10 +1394,8 @@ namespace Server.Items
} }
else if ( !defender.Player ) else if ( !defender.Player )
{ {
if ( attacker is PlayerMobile ) if ( attacker is PlayerMobile pm )
{ {
PlayerMobile pm = (PlayerMobile)attacker;
if ( pm.WaitingForEnemy ) if ( pm.WaitingForEnemy )
{ {
pm.EnemyOfOneType = defender.GetType(); pm.EnemyOfOneType = defender.GetType();
@ -1469,16 +1425,14 @@ namespace Server.Items
TransformContext context = TransformationSpellHelper.GetContext( defender ); TransformContext context = TransformationSpellHelper.GetContext( defender );
if ( (m_Slayer == SlayerName.Silver || m_Slayer2 == SlayerName.Silver) && context != null && context.Spell is NecromancerSpell && context.Type != typeof( HorrificBeastSpell ) ) if ( (m_Slayer == SlayerName.Silver || m_Slayer2 == SlayerName.Silver) && context?.Spell is NecromancerSpell && context.Type != typeof( HorrificBeastSpell ) )
{ {
// Every necromancer transformation other than horrific beast takes an additional 25% damage // Every necromancer transformation other than horrific beast takes an additional 25% damage
percentageBonus += 25; percentageBonus += 25;
} }
if ( attacker is PlayerMobile && !(Core.ML && defender is PlayerMobile )) if ( attacker is PlayerMobile pmAttacker && !(Core.ML && defender is PlayerMobile ))
{ {
PlayerMobile pmAttacker = (PlayerMobile) attacker;
if ( pmAttacker.HonorActive && pmAttacker.InRange( defender, 1 ) ) if ( pmAttacker.HonorActive && pmAttacker.InRange( defender, 1 ) )
{ {
percentageBonus += 25; percentageBonus += 25;
@ -1490,9 +1444,7 @@ namespace Server.Items
} }
} }
BaseTalisman talisman = attacker.Talisman as BaseTalisman; if ( attacker.Talisman is BaseTalisman talisman && talisman.Killer != null )
if ( talisman != null && talisman.Killer != null )
percentageBonus += talisman.Killer.DamageBonus( defender ); percentageBonus += talisman.Killer.DamageBonus( defender );
percentageBonus = Math.Min( percentageBonus, 300 ); percentageBonus = Math.Min( percentageBonus, 300 );
@ -1647,8 +1599,8 @@ namespace Server.Items
{ {
--MaxHitPoints; --MaxHitPoints;
if ( Parent is Mobile ) if ( Parent is Mobile mobile )
((Mobile)Parent).LocalOverheadMessage( MessageType.Regular, 0x3B2, 1061121 ); // Your equipment is severely damaged. mobile.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1061121 ); // Your equipment is severely damaged.
} }
else else
{ {
@ -1763,8 +1715,8 @@ namespace Server.Items
TransformContext context = TransformationSpellHelper.GetContext( attacker ); TransformContext context = TransformationSpellHelper.GetContext( attacker );
if ( context != null && context.Spell is ReaperFormSpell ) if ( context?.Spell is ReaperFormSpell spell )
damageBonus += ((ReaperFormSpell)context.Spell).SpellDamageBonus; damageBonus += spell.SpellDamageBonus;
} }
damage = AOS.Scale( damage, 100 + damageBonus ); damage = AOS.Scale( damage, 100 + damageBonus );
@ -1841,8 +1793,8 @@ namespace Server.Items
{ {
bool dispellable = false; bool dispellable = false;
if ( defender is BaseCreature ) if ( defender is BaseCreature creature )
dispellable = ((BaseCreature)defender).Summoned && !((BaseCreature)defender).IsAnimatedDead; dispellable = creature.Summoned && !creature.IsAnimatedDead;
if ( !dispellable ) if ( !dispellable )
return; return;
@ -1944,9 +1896,7 @@ namespace Server.Items
if ( atkSlayer != null && atkSlayer.Slays( defender ) || atkSlayer2 != null && atkSlayer2.Slays( defender ) ) if ( atkSlayer != null && atkSlayer.Slays( defender ) || atkSlayer2 != null && atkSlayer2.Slays( defender ) )
return CheckSlayerResult.Slayer; return CheckSlayerResult.Slayer;
BaseTalisman talisman = attacker.Talisman as BaseTalisman; if ( attacker.Talisman is BaseTalisman talisman && TalismanSlayer.Slays( talisman.Slayer, defender ) )
if ( talisman != null && TalismanSlayer.Slays( talisman.Slayer, defender ) )
return CheckSlayerResult.Slayer; return CheckSlayerResult.Slayer;
if ( !Core.SE ) if ( !Core.SE )
@ -1989,10 +1939,8 @@ namespace Server.Items
public virtual void GetDamageTypes( Mobile wielder, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct ) public virtual void GetDamageTypes( Mobile wielder, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct )
{ {
if ( wielder is BaseCreature ) if ( wielder is BaseCreature bc )
{ {
BaseCreature bc = (BaseCreature)wielder;
phys = bc.PhysicalDamage; phys = bc.PhysicalDamage;
fire = bc.FireDamage; fire = bc.FireDamage;
cold = bc.ColdDamage; cold = bc.ColdDamage;
@ -2012,25 +1960,20 @@ namespace Server.Items
phys = 100 - fire - cold - pois - nrgy - chaos - direct; phys = 100 - fire - cold - pois - nrgy - chaos - direct;
CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource ); CraftAttributeInfo attrInfo = CraftResources.GetInfo( m_Resource )?.AttributeInfo;
if ( resInfo != null ) if ( attrInfo != null )
{ {
CraftAttributeInfo attrInfo = resInfo.AttributeInfo; int left = phys;
if ( attrInfo != null ) left = ApplyCraftAttributeElementDamage( attrInfo.WeaponColdDamage, ref cold, left );
{ left = ApplyCraftAttributeElementDamage( attrInfo.WeaponEnergyDamage, ref nrgy, left );
int left = phys; left = ApplyCraftAttributeElementDamage( attrInfo.WeaponFireDamage, ref fire, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponPoisonDamage, ref pois, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponChaosDamage, ref chaos, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponDirectDamage, ref direct, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponColdDamage, ref cold, left ); phys = left;
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponEnergyDamage, ref nrgy, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponFireDamage, ref fire, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponPoisonDamage, ref pois, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponChaosDamage, ref chaos, left );
left = ApplyCraftAttributeElementDamage( attrInfo.WeaponDirectDamage, ref direct, left );
phys = left;
}
} }
} }
} }
@ -2064,24 +2007,22 @@ namespace Server.Items
WeaponAbility ability = WeaponAbility.GetCurrentAbility( attacker ); WeaponAbility ability = WeaponAbility.GetCurrentAbility( attacker );
if ( ability != null ) ability?.OnMiss( attacker, defender );
ability.OnMiss( attacker, defender );
SpecialMove move = SpecialMove.GetCurrentMove( attacker ); SpecialMove move = SpecialMove.GetCurrentMove( attacker );
if ( move != null ) move?.OnMiss( attacker, defender );
move.OnMiss( attacker, defender );
if ( defender is IHonorTarget && ((IHonorTarget)defender).ReceivedHonorContext != null ) if ( defender is IHonorTarget target )
((IHonorTarget)defender).ReceivedHonorContext.OnTargetMissed( attacker ); {
target.ReceivedHonorContext?.OnTargetMissed( attacker );
}
} }
public virtual void GetBaseDamageRange( Mobile attacker, out int min, out int max ) public virtual void GetBaseDamageRange( Mobile attacker, out int min, out int max )
{ {
if ( attacker is BaseCreature ) if ( attacker is BaseCreature c )
{ {
BaseCreature c = (BaseCreature)attacker;
if ( c.DamageMin >= 0 ) if ( c.DamageMin >= 0 )
{ {
min = c.DamageMin; min = c.DamageMin;
@ -2089,10 +2030,10 @@ namespace Server.Items
return; return;
} }
if ( this is Fists && !attacker.Body.IsHuman ) if ( this is Fists && !c.Body.IsHuman )
{ {
min = attacker.Str / 28; min = c.Str / 28;
max = attacker.Str / 28; max = c.Str / 28;
return; return;
} }
} }
@ -2103,9 +2044,7 @@ namespace Server.Items
public virtual double GetBaseDamage( Mobile attacker ) public virtual double GetBaseDamage( Mobile attacker )
{ {
int min, max; GetBaseDamageRange( attacker, out int min, out int max );
GetBaseDamageRange( attacker, out min, out max );
int damage = Utility.RandomMinMax( min, max ); int damage = Utility.RandomMinMax( min, max );
@ -2178,9 +2117,7 @@ namespace Server.Items
public virtual void GetStatusDamage( Mobile from, out int min, out int max ) public virtual void GetStatusDamage( Mobile from, out int min, out int max )
{ {
int baseMin, baseMax; GetBaseDamageRange( from, out int baseMin, out int baseMax );
GetBaseDamageRange( from, out baseMin, out baseMax );
if ( Core.AOS ) if ( Core.AOS )
{ {
@ -2474,7 +2411,7 @@ namespace Server.Items
SetSaveFlag( ref flags, SaveFlag.Poison, m_Poison != null ); SetSaveFlag( ref flags, SaveFlag.Poison, m_Poison != null );
SetSaveFlag( ref flags, SaveFlag.PoisonCharges, m_PoisonCharges != 0 ); SetSaveFlag( ref flags, SaveFlag.PoisonCharges, m_PoisonCharges != 0 );
SetSaveFlag( ref flags, SaveFlag.Crafter, m_Crafter != null ); SetSaveFlag( ref flags, SaveFlag.Crafter, m_Crafter != null );
SetSaveFlag( ref flags, SaveFlag.Identified, m_Identified != false ); SetSaveFlag( ref flags, SaveFlag.Identified, m_Identified );
SetSaveFlag( ref flags, SaveFlag.StrReq, m_StrReq != -1 ); SetSaveFlag( ref flags, SaveFlag.StrReq, m_StrReq != -1 );
SetSaveFlag( ref flags, SaveFlag.DexReq, m_DexReq != -1 ); SetSaveFlag( ref flags, SaveFlag.DexReq, m_DexReq != -1 );
SetSaveFlag( ref flags, SaveFlag.IntReq, m_IntReq != -1 ); SetSaveFlag( ref flags, SaveFlag.IntReq, m_IntReq != -1 );
@ -2629,6 +2566,8 @@ namespace Server.Items
int version = reader.ReadInt(); int version = reader.ReadInt();
Mobile parentMobile = Parent as Mobile;
switch ( version ) switch ( version )
{ {
case 9: case 9:
@ -2769,19 +2708,19 @@ namespace Server.Items
else else
m_AosWeaponAttributes = new AosWeaponAttributes( this ); m_AosWeaponAttributes = new AosWeaponAttributes( this );
if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular && Parent is Mobile ) if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular && parentMobile != null )
{ {
m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5 ); m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5 );
((Mobile)Parent).AddSkillMod( m_SkillMod ); parentMobile.AddSkillMod( m_SkillMod );
} }
if ( version < 7 && m_AosWeaponAttributes.MageWeapon != 0 ) if ( version < 7 && m_AosWeaponAttributes.MageWeapon != 0 )
m_AosWeaponAttributes.MageWeapon = 30 - m_AosWeaponAttributes.MageWeapon; m_AosWeaponAttributes.MageWeapon = 30 - m_AosWeaponAttributes.MageWeapon;
if ( Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && m_AosWeaponAttributes.MageWeapon != 30 && Parent is Mobile ) if ( Core.AOS && m_AosWeaponAttributes.MageWeapon != 0 && m_AosWeaponAttributes.MageWeapon != 30 && parentMobile != null )
{ {
m_MageMod = new DefaultSkillMod( SkillName.Magery, true, -30 + m_AosWeaponAttributes.MageWeapon ); m_MageMod = new DefaultSkillMod( SkillName.Magery, true, -30 + m_AosWeaponAttributes.MageWeapon );
((Mobile)Parent).AddSkillMod( m_MageMod ); parentMobile.AddSkillMod( m_MageMod );
} }
if ( GetSaveFlag( flags, SaveFlag.PlayerConstructed ) ) if ( GetSaveFlag( flags, SaveFlag.PlayerConstructed ) )
@ -2902,41 +2841,38 @@ namespace Server.Items
if ( m_Animation == OldAnimation ) if ( m_Animation == OldAnimation )
m_Animation = (WeaponAnimation)(-1); m_Animation = (WeaponAnimation)(-1);
if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular && Parent is Mobile ) if ( UseSkillMod && m_AccuracyLevel != WeaponAccuracyLevel.Regular && parentMobile != null )
{ {
m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5); m_SkillMod = new DefaultSkillMod( AccuracySkill, true, (int)m_AccuracyLevel * 5);
((Mobile)Parent).AddSkillMod( m_SkillMod ); parentMobile.AddSkillMod( m_SkillMod );
} }
break; break;
} }
} }
if ( Core.AOS && Parent is Mobile ) if ( Core.AOS && parentMobile != null )
m_AosSkillBonuses.AddTo( (Mobile)Parent ); m_AosSkillBonuses.AddTo( parentMobile );
int strBonus = m_AosAttributes.BonusStr; int strBonus = m_AosAttributes.BonusStr;
int dexBonus = m_AosAttributes.BonusDex; int dexBonus = m_AosAttributes.BonusDex;
int intBonus = m_AosAttributes.BonusInt; int intBonus = m_AosAttributes.BonusInt;
if ( this.Parent is Mobile && (strBonus != 0 || dexBonus != 0 || intBonus != 0) ) if ( parentMobile != null && (strBonus != 0 || dexBonus != 0 || intBonus != 0) )
{ {
Mobile m = (Mobile)this.Parent;
string modName = this.Serial.ToString(); string modName = this.Serial.ToString();
if ( strBonus != 0 ) if ( strBonus != 0 )
m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) ); parentMobile.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) );
if ( dexBonus != 0 ) if ( dexBonus != 0 )
m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) ); parentMobile.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) );
if ( intBonus != 0 ) if ( intBonus != 0 )
m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) ); parentMobile.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) );
} }
if ( Parent is Mobile ) parentMobile?.CheckStatTimers();
((Mobile)Parent).CheckStatTimers();
if ( m_Hits <= 0 && m_MaxHits <= 0 ) if ( m_Hits <= 0 && m_MaxHits <= 0 )
{ {
@ -2999,8 +2935,7 @@ namespace Server.Items
public int GetElementalDamageHue() public int GetElementalDamageHue()
{ {
int phys, fire, cold, pois, nrgy, chaos, direct; GetDamageTypes( null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct );
GetDamageTypes( null, out phys, out fire, out cold, out pois, out nrgy, out chaos, out direct );
//Order is Cold, Energy, Fire, Poison, Physical left //Order is Cold, Energy, Fire, Poison, Physical left
int currentMax = 50; int currentMax = 50;
@ -3027,7 +2962,6 @@ namespace Server.Items
if ( cold >= currentMax ) if ( cold >= currentMax )
{ {
hue = 1261 + (cold - 50) / 10; hue = 1261 + (cold - 50) / 10;
currentMax = cold;
} }
return hue; return hue;
@ -3102,10 +3036,7 @@ namespace Server.Items
{ {
CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource ); CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource );
if ( resInfo == null ) CraftAttributeInfo attrInfo = resInfo?.AttributeInfo;
return 0;
CraftAttributeInfo attrInfo = resInfo.AttributeInfo;
if ( attrInfo == null ) if ( attrInfo == null )
return 0; return 0;
@ -3125,8 +3056,7 @@ namespace Server.Items
list.Add( 1041350 ); // faction item list.Add( 1041350 ); // faction item
#endregion #endregion
if ( m_AosSkillBonuses != null ) m_AosSkillBonuses?.GetProperties( list );
m_AosSkillBonuses.GetProperties( list );
if ( m_Quality == WeaponQuality.Exceptional ) if ( m_Quality == WeaponQuality.Exceptional )
list.Add( 1060636 ); // exceptional list.Add( 1060636 ); // exceptional
@ -3137,8 +3067,8 @@ namespace Server.Items
if ( ArtifactRarity > 0 ) if ( ArtifactRarity > 0 )
list.Add( 1061078, ArtifactRarity.ToString() ); // artifact rarity ~1_val~ list.Add( 1061078, ArtifactRarity.ToString() ); // artifact rarity ~1_val~
if ( this is IUsesRemaining && ((IUsesRemaining)this).ShowUsesRemaining ) if ( this is IUsesRemaining usesRemaining && usesRemaining.ShowUsesRemaining )
list.Add( 1060584, ((IUsesRemaining)this).UsesRemaining.ToString() ); // uses remaining: ~1_val~ list.Add( 1060584, usesRemaining.UsesRemaining.ToString() ); // uses remaining: ~1_val~
if ( m_Poison != null && m_PoisonCharges > 0 ) if ( m_Poison != null && m_PoisonCharges > 0 )
list.Add( 1062412 + m_Poison.Level, m_PoisonCharges.ToString() ); list.Add( 1062412 + m_Poison.Level, m_PoisonCharges.ToString() );
@ -3162,7 +3092,9 @@ namespace Server.Items
int prop; int prop;
if ( Core.ML && this is BaseRanged && ( (BaseRanged) this ).Balanced ) BaseRanged ranged = this as BaseRanged;
if ( Core.ML && ranged?.Balanced == true )
list.Add( 1072792 ); // Balanced list.Add( 1072792 ); // Balanced
if ( (prop = m_AosWeaponAttributes.UseBestSkill) != 0 ) if ( (prop = m_AosWeaponAttributes.UseBestSkill) != 0 )
@ -3234,7 +3166,7 @@ namespace Server.Items
if ( ImmolatingWeaponSpell.IsImmolating( this ) ) if ( ImmolatingWeaponSpell.IsImmolating( this ) )
list.Add( 1111917 ); // Immolated list.Add( 1111917 ); // Immolated
if ( Core.ML && this is BaseRanged && ( prop = ( (BaseRanged) this ).Velocity ) != 0 ) if ( Core.ML && (ranged?.Velocity ?? 0) != 0 )
list.Add( 1072793, prop.ToString() ); // Velocity ~1_val~% list.Add( 1072793, prop.ToString() ); // Velocity ~1_val~%
if ( (prop = m_AosAttributes.BonusDex) != 0 ) if ( (prop = m_AosAttributes.BonusDex) != 0 )
@ -3300,9 +3232,7 @@ namespace Server.Items
if ( Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0 ) if ( Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0 )
list.Add( 1075210, prop.ToString() ); // Increased Karma Loss ~1val~% list.Add( 1075210, prop.ToString() ); // Increased Karma Loss ~1val~%
int phys, fire, cold, pois, nrgy, chaos, direct; GetDamageTypes( null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct );
GetDamageTypes( null, out phys, out fire, out cold, out pois, out nrgy, out chaos, out direct );
if ( phys != 0 ) if ( phys != 0 )
list.Add( 1060403, phys.ToString() ); // physical damage ~1_val~% list.Add( 1060403, phys.ToString() ); // physical damage ~1_val~%
@ -3464,8 +3394,8 @@ namespace Server.Items
if ( context != null && context.DoNotColor ) if ( context != null && context.DoNotColor )
Hue = 0; Hue = 0;
if ( tool is BaseRunicTool ) if ( tool is BaseRunicTool runicTool )
((BaseRunicTool)tool).ApplyAttributesTo( this ); runicTool.ApplyAttributesTo( this );
if ( Quality == WeaponQuality.Exceptional ) if ( Quality == WeaponQuality.Exceptional )
{ {
@ -3485,11 +3415,11 @@ namespace Server.Items
} }
} }
} }
else if ( tool is BaseRunicTool ) else if ( tool is BaseRunicTool runicTool )
{ {
CraftResource thisResource = CraftResources.GetFromType( resourceType ); CraftResource thisResource = CraftResources.GetFromType( resourceType );
if ( thisResource == ((BaseRunicTool)tool).Resource ) if ( thisResource == runicTool.Resource )
{ {
Resource = thisResource; Resource = thisResource;

View file

@ -43,7 +43,7 @@ namespace Server.Items
from.Target = new BladedItemTarget( this ); from.Target = new BladedItemTarget( this );
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1 )
{ {
base.OnHit( attacker, defender, damageBonus ); base.OnHit( attacker, defender, damageBonus );

View file

@ -65,14 +65,13 @@ namespace Server.Items
{ {
return; return;
} }
else if ( !from.Items.Contains( m_Dagger ) )
if ( !from.Items.Contains( m_Dagger ) )
{ {
from.SendMessage( "You must be holding that weapon to use it." ); from.SendMessage( "You must be holding that weapon to use it." );
} }
else if ( targeted is Mobile ) else if ( targeted is Mobile m )
{ {
Mobile m = (Mobile)targeted;
if ( m != from && from.HarmfulCheck( m ) ) if ( m != from && from.HarmfulCheck( m ) )
{ {
Direction to = from.GetDirectionTo( m ); Direction to = from.GetDirectionTo( m );
@ -122,4 +121,4 @@ namespace Server.Items
} }
} }
} }
} }

View file

@ -35,7 +35,7 @@ namespace Server.Items
int version = reader.ReadInt(); int version = reader.ReadInt();
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1 )
{ {
base.OnHit( attacker, defender, damageBonus ); base.OnHit( attacker, defender, damageBonus );

View file

@ -103,7 +103,7 @@ namespace Server.Items
} }
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1 )
{ {
base.OnHit( attacker, defender, damageBonus ); base.OnHit( attacker, defender, damageBonus );

View file

@ -49,7 +49,7 @@ namespace Server.Items
public override TimeSpan OnSwing( Mobile attacker, Mobile defender ) public override TimeSpan OnSwing( Mobile attacker, Mobile defender )
{ {
WeaponAbility a = WeaponAbility.GetCurrentAbility( attacker ); // WeaponAbility a = WeaponAbility.GetCurrentAbility( attacker );
// Make sure we've been standing still for .25/.5/1 second depending on Era // Make sure we've been standing still for .25/.5/1 second depending on Era
if (Core.TickCount - attacker.LastMoveTime >= (Core.SE ? 250 : Core.AOS ? 500 : 1000) || (Core.AOS && WeaponAbility.GetCurrentAbility(attacker) is MovingShot)) if (Core.TickCount - attacker.LastMoveTime >= (Core.SE ? 250 : Core.AOS ? 500 : 1000) || (Core.AOS && WeaponAbility.GetCurrentAbility(attacker) is MovingShot))
@ -62,17 +62,13 @@ namespace Server.Items
if ( canSwing ) if ( canSwing )
{ {
Spell sp = attacker.Spell as Spell; canSwing = ( !(attacker.Spell is Spell sp) || !sp.IsCasting || !sp.BlocksMovement );
canSwing = ( sp == null || !sp.IsCasting || !sp.BlocksMovement );
} }
} }
#region Dueling #region Dueling
if ( attacker is PlayerMobile ) if ( attacker is PlayerMobile pm )
{ {
PlayerMobile pm = (PlayerMobile)attacker;
if ( pm.DuelContext != null && !pm.DuelContext.CheckItemEquip( attacker, this ) ) if ( pm.DuelContext != null && !pm.DuelContext.CheckItemEquip( attacker, this ) )
canSwing = false; canSwing = false;
} }
@ -104,7 +100,7 @@ namespace Server.Items
} }
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1)
{ {
if ( attacker.Player && !defender.Player && (defender.Body.IsAnimal || defender.Body.IsMonster) && 0.4 >= Utility.RandomDouble() ) if ( attacker.Player && !defender.Player && (defender.Body.IsAnimal || defender.Body.IsMonster) && 0.4 >= Utility.RandomDouble() )
defender.AddToBackpack( Ammo ); defender.AddToBackpack( Ammo );
@ -134,21 +130,19 @@ namespace Server.Items
{ {
if ( Core.SE ) if ( Core.SE )
{ {
PlayerMobile p = attacker as PlayerMobile; if ( attacker is PlayerMobile pm )
if ( p != null )
{ {
Type ammo = AmmoType; Type ammo = AmmoType;
if ( p.RecoverableAmmo.ContainsKey( ammo ) ) if ( pm.RecoverableAmmo.ContainsKey( ammo ) )
p.RecoverableAmmo[ ammo ]++; pm.RecoverableAmmo[ ammo ]++;
else else
p.RecoverableAmmo.Add( ammo, 1 ); pm.RecoverableAmmo.Add( ammo, 1 );
if ( !p.Warmode ) if ( !pm.Warmode )
{ {
if ( m_RecoveryTimer == null ) if ( m_RecoveryTimer == null )
m_RecoveryTimer = Timer.DelayCall( TimeSpan.FromSeconds( 10 ), new TimerCallback( p.RecoverAmmo ) ); m_RecoveryTimer = Timer.DelayCall( TimeSpan.FromSeconds( 10 ), new TimerCallback( pm.RecoverAmmo ) );
if ( !m_RecoveryTimer.Running ) if ( !m_RecoveryTimer.Running )
m_RecoveryTimer.Start(); m_RecoveryTimer.Start();

View file

@ -47,9 +47,7 @@ namespace Server.Items
public void OnTargetGears( Mobile from, object targ ) public void OnTargetGears( Mobile from, object targ )
{ {
Gears g = targ as Gears; if ( !(targ is Gears g) || !g.IsChildOf( from.Backpack ) )
if ( g == null || !g.IsChildOf( from.Backpack ) )
{ {
from.SendMessage( "Those are not gears." ); // Apparently gears that aren't in your backpack aren't really gears at all. :-( from.SendMessage( "Those are not gears." ); // Apparently gears that aren't in your backpack aren't really gears at all. :-(
} }

View file

@ -35,7 +35,7 @@ namespace Server.Items
int version = reader.ReadInt(); int version = reader.ReadInt();
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1 )
{ {
base.OnHit( attacker, defender, damageBonus ); base.OnHit( attacker, defender, damageBonus );

View file

@ -35,7 +35,7 @@ namespace Server.Items
int version = reader.ReadInt(); int version = reader.ReadInt();
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1 )
{ {
base.OnHit( attacker, defender, damageBonus ); base.OnHit( attacker, defender, damageBonus );

View file

@ -68,10 +68,8 @@ namespace Server.Items
protected override void OnTarget( Mobile from, object targ ) protected override void OnTarget( Mobile from, object targ )
{ {
if ( targ is BaseCreature ) if ( targ is BaseCreature bc )
{ {
BaseCreature bc = (BaseCreature)targ;
if ( IsHerdable( bc ) ) if ( IsHerdable( bc ) )
{ {
if ( bc.Controlled ) if ( bc.Controlled )
@ -114,9 +112,7 @@ namespace Server.Items
Map map = bc.Map; Map map = bc.Map;
ChampionSpawnRegion region = Region.Find( bc.Home, map ) as ChampionSpawnRegion; if ( Region.Find( bc.Home, map ) is ChampionSpawnRegion region )
if ( region != null )
{ {
ChampionSpawn spawn = region.ChampionSpawn; ChampionSpawn spawn = region.ChampionSpawn;
@ -144,7 +140,7 @@ namespace Server.Items
protected override void OnTarget( Mobile from, object targ ) protected override void OnTarget( Mobile from, object targ )
{ {
if ( targ is IPoint2D ) if ( targ is IPoint2D p )
{ {
double min = m_Creature.MinTameSkill - 30; double min = m_Creature.MinTameSkill - 30;
double max = m_Creature.MinTameSkill + 30 + Utility.Random( 10 ); double max = m_Creature.MinTameSkill + 30 + Utility.Random( 10 );
@ -154,9 +150,7 @@ namespace Server.Items
if ( from.CheckTargetSkill( SkillName.Herding, m_Creature, min, max ) ) if ( from.CheckTargetSkill( SkillName.Herding, m_Creature, min, max ) )
{ {
IPoint2D p = (IPoint2D) targ; if ( p != from )
if ( targ != from )
p = new Point2D( p.X, p.Y ); p = new Point2D( p.X, p.Y );
m_Creature.TargetLocation = p; m_Creature.TargetLocation = p;

View file

@ -40,7 +40,7 @@ namespace Server.Items
from.Target = new BladedItemTarget( this ); from.Target = new BladedItemTarget( this );
} }
public override void OnHit( Mobile attacker, Mobile defender, double damageBonus ) public override void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1 )
{ {
base.OnHit( attacker, defender, damageBonus ); base.OnHit( attacker, defender, damageBonus );

View file

@ -108,8 +108,7 @@ namespace Server.Mobiles
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -151,8 +151,7 @@ namespace Server.Mobiles
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;

View file

@ -86,8 +86,7 @@ namespace Server.Multis
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
if ( m_Timer != null ) m_Timer?.Stop();
m_Timer.Stop();
m_Timer = null; m_Timer = null;
@ -142,4 +141,4 @@ namespace Server.Multis
} }
} }
} }
} }

View file

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

View file

@ -102,15 +102,10 @@ namespace Server
{ {
object[] objs = mi.GetCustomAttributes( typeof( CallPriorityAttribute ), true ); object[] objs = mi.GetCustomAttributes( typeof( CallPriorityAttribute ), true );
if ( objs == null )
return 0;
if ( objs.Length == 0 ) if ( objs.Length == 0 )
return 0; return 0;
CallPriorityAttribute attr = objs[0] as CallPriorityAttribute; if ( !(objs[0] is CallPriorityAttribute attr) )
if ( attr == null )
return 0; return 0;
return attr.Priority; return attr.Priority;

View file

@ -171,12 +171,10 @@ namespace Server.Commands
{ {
if ( obj == this ) if ( obj == this )
return 0; return 0;
else if ( obj == null ) if ( obj == null )
return 1; return 1;
CommandEntry e = obj as CommandEntry; if ( !(obj is CommandEntry e) )
if ( e == null )
throw new ArgumentException(); throw new ArgumentException();
return m_Command.CompareTo( e.m_Command ); return m_Command.CompareTo( e.m_Command );
@ -204,7 +202,7 @@ namespace Server.Commands
char[] array = value.ToCharArray(); char[] array = value.ToCharArray();
List<string> list = new List<string>(); List<string> list = new List<string>();
int start = 0, end = 0; int start = 0;
while ( start < array.Length ) while ( start < array.Length )
{ {
@ -213,7 +211,7 @@ namespace Server.Commands
if ( c == '"' ) if ( c == '"' )
{ {
++start; ++start;
end = start; int end = start;
while ( end < array.Length ) while ( end < array.Length )
{ {
@ -229,7 +227,7 @@ namespace Server.Commands
} }
else if ( c != ' ' ) else if ( c != ' ' )
{ {
end = start; int end = start;
while ( end < array.Length ) while ( end < array.Length )
{ {
@ -308,8 +306,7 @@ namespace Server.Commands
args = new string[0]; args = new string[0];
} }
CommandEntry entry = null; m_Entries.TryGetValue( command, out CommandEntry entry );
m_Entries.TryGetValue( command, out entry );
if ( entry != null ) if ( entry != null )
{ {

View file

@ -219,8 +219,8 @@ namespace Server
public static void SendTargetEffect( IEntity target, int itemID, int speed, int duration, int hue, int renderMode ) public static void SendTargetEffect( IEntity target, int itemID, int speed, int duration, int hue, int renderMode )
{ {
if ( target is Mobile ) if ( target is Mobile mobile )
((Mobile)target).ProcessDelta(); mobile.ProcessDelta();
SendPacket( target.Location, target.Map, new TargetEffect( target, itemID, speed, duration, hue, renderMode ) ); SendPacket( target.Location, target.Map, new TargetEffect( target, itemID, speed, duration, hue, renderMode ) );
} }
@ -237,8 +237,8 @@ namespace Server
public static void SendTargetParticles( IEntity target, int itemID, int speed, int duration, int hue, int renderMode, int effect, EffectLayer layer, int unknown ) public static void SendTargetParticles( IEntity target, int itemID, int speed, int duration, int hue, int renderMode, int effect, EffectLayer layer, int unknown )
{ {
if ( target is Mobile ) if ( target is Mobile mobile )
((Mobile)target).ProcessDelta(); mobile.ProcessDelta();
Map map = target.Map; Map map = target.Map;
@ -280,11 +280,11 @@ namespace Server
public static void SendMovingEffect( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int hue, int renderMode ) public static void SendMovingEffect( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int hue, int renderMode )
{ {
if ( from is Mobile ) if ( from is Mobile mobile )
((Mobile)from).ProcessDelta(); mobile.ProcessDelta();
if ( to is Mobile ) if ( to is Mobile mobile1 )
((Mobile)to).ProcessDelta(); mobile1.ProcessDelta();
SendPacket( from.Location, from.Map, new MovingEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode ) ); SendPacket( from.Location, from.Map, new MovingEffect( from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode ) );
} }
@ -306,11 +306,11 @@ namespace Server
public static void SendMovingParticles( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int hue, int renderMode, int effect, int explodeEffect, int explodeSound, EffectLayer layer, int unknown ) public static void SendMovingParticles( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool explodes, int hue, int renderMode, int effect, int explodeEffect, int explodeSound, EffectLayer layer, int unknown )
{ {
if ( from is Mobile ) if ( from is Mobile mobile )
((Mobile)from).ProcessDelta(); mobile.ProcessDelta();
if ( to is Mobile ) if ( to is Mobile mobile1 )
((Mobile)to).ProcessDelta(); mobile1.ProcessDelta();
Map map = from.Map; Map map = from.Map;
@ -382,4 +382,4 @@ namespace Server
} }
} }
} }
} }

View file

@ -98,9 +98,9 @@ namespace Server
public int CompareTo( object other ) public int CompareTo( object other )
{ {
if ( other is Point2D ) if ( other is Point2D d )
return this.CompareTo( (Point2D) other ); return this.CompareTo( d );
else if ( other == null ) if ( other == null )
return -1; return -1;
throw new ArgumentException(); throw new ArgumentException();
@ -108,7 +108,7 @@ namespace Server
public override bool Equals( object o ) public override bool Equals( object o )
{ {
if ( o == null || !(o is IPoint2D) ) return false; if ( !(o is IPoint2D) ) return false;
IPoint2D p = (IPoint2D)o; IPoint2D p = (IPoint2D)o;
@ -291,7 +291,7 @@ namespace Server
public override bool Equals( object o ) public override bool Equals( object o )
{ {
if ( o == null || !( o is IPoint3D ) ) if ( !(o is IPoint3D) )
return false; return false;
IPoint3D p = (IPoint3D) o; IPoint3D p = (IPoint3D) o;
@ -367,9 +367,9 @@ namespace Server
public int CompareTo( object other ) public int CompareTo( object other )
{ {
if ( other is Point3D ) if ( other is Point3D d )
return this.CompareTo( (Point3D) other ); return this.CompareTo( d );
else if ( other == null ) if ( other == null )
return -1; return -1;
throw new ArgumentException(); throw new ArgumentException();
@ -635,4 +635,4 @@ namespace Server
&& ( p.Z < m_End.m_Z ); && ( p.Z < m_End.m_Z );
} }
} }
} }

View file

@ -1544,11 +1544,8 @@ namespace Server
public virtual bool OnDragDrop( Mobile from, Item dropped ) public virtual bool OnDragDrop( Mobile from, Item dropped )
{ {
bool success = false; bool success = Parent is Container container && container.OnStackAttempt( from, this, dropped ) ||
if ( Parent is Container ) StackWith( from, dropped );
success = ((Container)Parent).OnStackAttempt( from, this, dropped );
else
success = StackWith( from, dropped );
if ( success && Spawner != null ) if ( success && Spawner != null )
{ {

View file

@ -2620,7 +2620,7 @@ namespace Server
protected override void OnTarget( Mobile from, object targeted ) protected override void OnTarget( Mobile from, object targeted )
{ {
m_Callback?.Invoke( @from, targeted ); m_Callback?.Invoke( from, targeted );
} }
} }
@ -2647,7 +2647,7 @@ namespace Server
protected override void OnTarget( Mobile from, object targeted ) protected override void OnTarget( Mobile from, object targeted )
{ {
m_Callback?.Invoke( @from, targeted, m_State ); m_Callback?.Invoke( from, targeted, m_State );
} }
} }
@ -2674,7 +2674,7 @@ namespace Server
protected override void OnTarget(Mobile from, object targeted) protected override void OnTarget(Mobile from, object targeted)
{ {
m_Callback?.Invoke(@from, targeted, m_State); m_Callback?.Invoke(from, targeted, m_State);
} }
} }
public Target BeginTarget<T>(int range, bool allowGround, TargetFlags flags, TargetStateCallback<T> callback, T state) public Target BeginTarget<T>(int range, bool allowGround, TargetFlags flags, TargetStateCallback<T> callback, T state)
@ -4359,6 +4359,7 @@ namespace Server
Console.WriteLine( "Warning: 0x{0:X}: Item must have a zero paramater constructor to be separated from a stack. '{1}'.", oldItem.Serial.Value, oldItem.GetType().Name ); Console.WriteLine( "Warning: 0x{0:X}: Item must have a zero paramater constructor to be separated from a stack. '{1}'.", oldItem.Serial.Value, oldItem.GetType().Name );
return null; return null;
} }
item.Visible = oldItem.Visible; item.Visible = oldItem.Visible;
item.Movable = oldItem.Movable; item.Movable = oldItem.Movable;
item.LootType = oldItem.LootType; item.LootType = oldItem.LootType;
@ -4376,13 +4377,13 @@ namespace Server
oldItem.Amount = amount; oldItem.Amount = amount;
oldItem.OnAfterDuped( item ); oldItem.OnAfterDuped( item );
if ( oldItem.Parent is Mobile ) if ( oldItem.Parent is Mobile parentMobile )
{ {
((Mobile)oldItem.Parent).AddItem( item ); parentMobile.AddItem( item );
} }
else if ( oldItem.Parent is Item ) else if ( oldItem.Parent is Item parentItem )
{ {
((Item)oldItem.Parent).AddItem( item ); parentItem.AddItem( item );
} }
item.Delta( ItemDelta.Update ); item.Delta( ItemDelta.Update );
@ -4581,8 +4582,8 @@ namespace Server
if (item.HandlesOnSpeech) if (item.HandlesOnSpeech)
list.Add( item ); list.Add( item );
if (item is Container) if (item is Container container)
AddSpeechItemsFrom(list, (Container)item); AddSpeechItemsFrom(list, container);
} }
} }
@ -6543,14 +6544,10 @@ namespace Server
IPooledEnumerable<IEntity> eable = m_Map.GetObjectsInRange( m_Location, Core.GlobalMaxUpdateRange ); IPooledEnumerable<IEntity> eable = m_Map.GetObjectsInRange( m_Location, Core.GlobalMaxUpdateRange );
foreach ( IEntity o in eable ) { foreach ( IEntity o in eable ) {
if ( o is Mobile ) { if ( o is Mobile m ) {
Mobile m = (Mobile)o;
if ( m != this && Utility.InUpdateRange( m_Location, m.m_Location ) ) if ( m != this && Utility.InUpdateRange( m_Location, m.m_Location ) )
ns.Send( m.RemovePacket ); ns.Send( m.RemovePacket );
} else if ( o is Item ) { } else if ( o is Item item ) {
Item item = (Item)o;
if ( InRange( item.Location, item.GetUpdateRange( this ) ) ) if ( InRange( item.Location, item.GetUpdateRange( this ) ) )
ns.Send( item.RemovePacket ); ns.Send( item.RemovePacket );
} }
@ -6583,14 +6580,17 @@ namespace Server
} }
public bool SendHuePicker( HuePicker p, bool throwOnOffline ) { public bool SendHuePicker( HuePicker p, bool throwOnOffline ) {
if ( m_NetState != null ) { if (m_NetState != null)
p.SendTo( m_NetState ); {
p.SendTo(m_NetState);
return true; return true;
} else if ( throwOnOffline ) {
throw new MobileNotConnectedException( this, "Hue picker could not be sent." );
} else {
return false;
} }
if ( throwOnOffline ) {
throw new MobileNotConnectedException( this, "Hue picker could not be sent." );
}
return false;
} }
public Gump FindGump( Type type ) { public Gump FindGump( Type type ) {
@ -6598,7 +6598,7 @@ namespace Server
if ( ns != null ) { if ( ns != null ) {
foreach ( Gump gump in ns.Gumps ) { foreach ( Gump gump in ns.Gumps ) {
if ( type.IsAssignableFrom( gump.GetType() ) ) { if ( type.IsInstanceOfType( gump ) ) {
return gump; return gump;
} }
} }
@ -10108,9 +10108,7 @@ namespace Server
if ( sendStam || sendMana ) if ( sendStam || sendMana )
{ {
IParty ip = m_Party as IParty; if (m_Party is IParty ip)
if (ip != null)
{ {
if ( sendStam ) if ( sendStam )
ip.OnStamChanged( this ); ip.OnStamChanged( this );