From d6c0bf2d4ce73eba7c857b8623af8ad8426ad1ae Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 9 Sep 2018 08:54:10 -0700 Subject: [PATCH] Sets a default parameter for OnHit. More casting cleanup. --- Scripts/Engines/CannedEvil/ChampionSpawn.cs | 6 +- Scripts/Engines/CannedEvil/StarRoomGate.cs | 3 +- Scripts/Engines/ConPVP/Games/BombingRun.cs | 3 +- Scripts/Engines/Help/PageQueue.cs | 3 +- Scripts/Engines/Help/StuckMenu.cs | 3 +- Scripts/Engines/Quests/Core/QuestSystem.cs | 3 +- Scripts/Engines/Spawner/Spawner.cs | 3 +- Scripts/Items/Addons/BaseAddon.cs | 8 +- Scripts/Items/Addons/DartBoard.cs | 2 +- .../Addons/ElvenSpinningwheelEastAddon.cs | 3 +- .../Addons/ElvenSpinningwheelSouthAddon.cs | 3 +- Scripts/Items/Addons/PickpocketDips.cs | 6 +- .../Items/Addons/SpinningwheelEastAddon.cs | 3 +- .../Items/Addons/SpinningwheelSouthAddon.cs | 3 +- Scripts/Items/Addons/TrainingDummies.cs | 6 +- Scripts/Items/Aquarium/Aquarium.cs | 15 +- Scripts/Items/Aquarium/AquariumGump.cs | 2 +- Scripts/Items/Aquarium/BaseFish.cs | 8 +- Scripts/Items/Containers/TreasureMapChest.cs | 3 +- Scripts/Items/Lights/BaseLight.cs | 6 +- Scripts/Items/Misc/AcidSlime.cs | 3 +- Scripts/Items/Misc/PoolOfAcid.cs | 3 +- Scripts/Items/Misc/TrashBarrel.cs | 3 +- Scripts/Items/Skill Items/Camping/Campfire.cs | 3 +- Scripts/Items/Skill Items/Misc/Bandage.cs | 3 +- .../Items/Skill Items/Misc/RecipeScroll.cs | 2 +- .../Musical Instruments/BaseInstrument.cs | 4 +- .../Items/Skill Items/Tinkering/Spyglass.cs | 2 +- .../8th Anniversary Items/FountainOfLife.cs | 3 +- .../Blacksmithy/PowderOfTemperament.cs | 5 +- .../Evil Home Decor Collection/BedOfNails.cs | 4 +- .../SacrificialAltar.cs | 3 +- .../UnsettlingPortrait.cs | 3 +- .../Items/Special/Heritage Items/Curtains.cs | 4 +- .../Special/Heritage Items/Guillotine.cs | 8 +- .../Special/Heritage Items/IronMaiden.cs | 8 +- Scripts/Items/Special/Holiday/Wreath.cs | 8 +- .../House Raffle/HouseRaffleManagementGump.cs | 4 +- .../Special/House Raffle/HouseRaffleStone.cs | 12 +- .../Mutation Core/PlagueBeastBackpack.cs | 4 +- .../Special/Mutation Core/PlagueBeastBlood.cs | 6 +- .../Mutation Core/PlagueBeastInnard.cs | 4 +- .../Mutation Core/PlagueBeastOrgans.cs | 4 +- .../Special/Mutation Core/PlagueBeastVein.cs | 4 +- .../Items/Special/Solen Items/BagOfSending.cs | 3 +- .../Special/Solen Items/BallOfSummoning.cs | 18 +- .../Special/Solen Items/BraceletOfBinding.cs | 14 +- .../Solen Items/PowderOfTranslocation.cs | 10 +- Scripts/Items/Special/SoulStone.cs | 4 +- .../Special Scrolls/ScrollofAlacrity.cs | 11 +- .../Special Scrolls/ScrollofTranscendence.cs | 4 +- .../Special/Special Scrolls/StatScroll.cs | 6 +- .../Special/Valentines/2007/ValentinesCard.cs | 4 +- .../Veteran Rewards/AnkhOfSacrifice.cs | 8 +- .../Items/Special/Veteran Rewards/Cannon.cs | 10 +- .../Special/Veteran Rewards/StoneAnkh.cs | 2 +- .../Veteran Rewards/WeaponEngravingTool.cs | 4 +- Scripts/Items/Suits/BaseSuit.cs | 4 +- Scripts/Items/Talismans/BaseTalisman.cs | 25 +- Scripts/Items/Talismans/Items/RunedSwitch.cs | 4 +- Scripts/Items/Traps/FlameSpurtTrap.cs | 5 +- .../TreasureChests/TreasureChestLevel3.cs | 6 +- .../TreasureChests/TreasureChestLevel4.cs | 6 +- Scripts/Items/Wands/IDWand.cs | 19 +- .../Items/Weapons/Abilities/BleedAttack.cs | 5 +- Scripts/Items/Weapons/Abilities/Block.cs | 11 +- .../Items/Weapons/Abilities/DefenseMastery.cs | 11 +- Scripts/Items/Weapons/Abilities/Disarm.cs | 4 +- Scripts/Items/Weapons/Abilities/Dismount.cs | 24 +- .../Weapons/Abilities/FrenziedWhirlwind.cs | 8 +- .../Weapons/Abilities/InfectiousStrike.cs | 4 +- .../Items/Weapons/Abilities/ParalyzingBlow.cs | 4 +- .../Items/Weapons/Abilities/WeaponAbility.cs | 10 +- .../Weapons/Abilities/WhirlwindAttack.cs | 4 +- Scripts/Items/Weapons/Axes/BaseAxe.cs | 2 +- Scripts/Items/Weapons/BaseWeapon.cs | 276 +++++++----------- Scripts/Items/Weapons/Knives/BaseKnife.cs | 2 +- .../Items/Weapons/Knives/ThrowingDagger.cs | 9 +- Scripts/Items/Weapons/Maces/BaseBashing.cs | 2 +- Scripts/Items/Weapons/PoleArms/BasePoleArm.cs | 2 +- Scripts/Items/Weapons/Ranged/BaseRanged.cs | 26 +- Scripts/Items/Weapons/Ranged/JukaBow.cs | 4 +- .../Items/Weapons/SpearsAndForks/BaseSpear.cs | 2 +- Scripts/Items/Weapons/Staves/BaseStaff.cs | 2 +- .../Items/Weapons/Staves/ShepherdsCrook.cs | 14 +- Scripts/Items/Weapons/Swords/BaseSword.cs | 2 +- .../Monsters/Humanoid/Melee/ShadowFiend.cs | 3 +- Scripts/Mobiles/Special/HarrowerTentacles.cs | 3 +- Scripts/Multis/PreviewHouse.cs | 5 +- .../Spellweaving/Items/TransientItem.cs | 3 +- Server/Attributes.cs | 7 +- Server/Commands.cs | 15 +- Server/Effects.cs | 26 +- Server/Geometry.cs | 18 +- Server/Item.cs | 7 +- Server/Mobile.cs | 48 ++- 96 files changed, 350 insertions(+), 579 deletions(-) diff --git a/Scripts/Engines/CannedEvil/ChampionSpawn.cs b/Scripts/Engines/CannedEvil/ChampionSpawn.cs index 04600c88b..cf258f3a3 100644 --- a/Scripts/Engines/CannedEvil/ChampionSpawn.cs +++ b/Scripts/Engines/CannedEvil/ChampionSpawn.cs @@ -328,8 +328,7 @@ namespace Server.Engines.CannedEvil m_Active = true; m_HasBeenAdvanced = false; - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = new SliceTimer( this ); m_Timer.Start(); @@ -359,8 +358,7 @@ namespace Server.Engines.CannedEvil m_Active = false; m_HasBeenAdvanced = false; - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Engines/CannedEvil/StarRoomGate.cs b/Scripts/Engines/CannedEvil/StarRoomGate.cs index 216848a6f..728ee1e5b 100644 --- a/Scripts/Engines/CannedEvil/StarRoomGate.cs +++ b/Scripts/Engines/CannedEvil/StarRoomGate.cs @@ -45,8 +45,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); base.OnAfterDelete(); } diff --git a/Scripts/Engines/ConPVP/Games/BombingRun.cs b/Scripts/Engines/ConPVP/Games/BombingRun.cs index a1e44ef0a..622148ad5 100644 --- a/Scripts/Engines/ConPVP/Games/BombingRun.cs +++ b/Scripts/Engines/ConPVP/Games/BombingRun.cs @@ -191,8 +191,7 @@ namespace Server.Engines.ConPVP { base.OnAfterDelete (); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } public override void OnDoubleClick( Mobile m ) diff --git a/Scripts/Engines/Help/PageQueue.cs b/Scripts/Engines/Help/PageQueue.cs index 81a2019ec..d2703ef03 100644 --- a/Scripts/Engines/Help/PageQueue.cs +++ b/Scripts/Engines/Help/PageQueue.cs @@ -122,8 +122,7 @@ namespace Server.Engines.Help public void Stop() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } diff --git a/Scripts/Engines/Help/StuckMenu.cs b/Scripts/Engines/Help/StuckMenu.cs index 22246aaf5..acefcad70 100644 --- a/Scripts/Engines/Help/StuckMenu.cs +++ b/Scripts/Engines/Help/StuckMenu.cs @@ -167,8 +167,7 @@ namespace Server.Menus.Questions public void StopClose() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Mobile.Frozen = false; } diff --git a/Scripts/Engines/Quests/Core/QuestSystem.cs b/Scripts/Engines/Quests/Core/QuestSystem.cs index 358e0e13a..278111992 100644 --- a/Scripts/Engines/Quests/Core/QuestSystem.cs +++ b/Scripts/Engines/Quests/Core/QuestSystem.cs @@ -73,8 +73,7 @@ namespace Server.Engines.Quests public virtual void StopTimer() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } diff --git a/Scripts/Engines/Spawner/Spawner.cs b/Scripts/Engines/Spawner/Spawner.cs index 320ecf514..d0e4144a7 100644 --- a/Scripts/Engines/Spawner/Spawner.cs +++ b/Scripts/Engines/Spawner/Spawner.cs @@ -663,8 +663,7 @@ namespace Server.Mobiles m_End = DateTime.UtcNow + delay; - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = new InternalTimer( this, delay ); if ( !IsFull ) diff --git a/Scripts/Items/Addons/BaseAddon.cs b/Scripts/Items/Addons/BaseAddon.cs index 638dc8a50..4d370588b 100644 --- a/Scripts/Items/Addons/BaseAddon.cs +++ b/Scripts/Items/Addons/BaseAddon.cs @@ -39,7 +39,7 @@ namespace Server.Items { m_Resource = value; Hue = CraftResources.GetHue( m_Resource ); - + 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 ) ) ) 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; 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 ); 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)) ) return AddonFitResult.DoorTooClose; } @@ -293,4 +293,4 @@ namespace Server.Items Weight = -1; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Addons/DartBoard.cs b/Scripts/Items/Addons/DartBoard.cs index 6e0217103..68f636fea 100644 --- a/Scripts/Items/Addons/DartBoard.cs +++ b/Scripts/Items/Addons/DartBoard.cs @@ -37,7 +37,7 @@ namespace Server.Items from.Direction = dir; - bool canThrow = true; + bool canThrow; if ( !from.InRange( this, 4 ) || !from.InLOS( this ) ) canThrow = false; diff --git a/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs b/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs index 02d501aba..0e99b4ec8 100644 --- a/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs +++ b/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs @@ -63,8 +63,7 @@ namespace Server.Items public void EndSpin( SpinCallback callback, Mobile from, int hue ) { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs b/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs index 13e0364a3..6e469a13d 100644 --- a/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs +++ b/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs @@ -65,8 +65,7 @@ namespace Server.Items public void EndSpin( SpinCallback callback, Mobile from, int hue ) { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Items/Addons/PickpocketDips.cs b/Scripts/Items/Addons/PickpocketDips.cs index ca8ce7ca3..66ed6adca 100644 --- a/Scripts/Items/Addons/PickpocketDips.cs +++ b/Scripts/Items/Addons/PickpocketDips.cs @@ -46,8 +46,7 @@ namespace Server.Items public void BeginSwing() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = new InternalTimer( this ); m_Timer.Start(); @@ -57,8 +56,7 @@ namespace Server.Items public void EndSwing() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Items/Addons/SpinningwheelEastAddon.cs b/Scripts/Items/Addons/SpinningwheelEastAddon.cs index 6fa853f75..115853dac 100644 --- a/Scripts/Items/Addons/SpinningwheelEastAddon.cs +++ b/Scripts/Items/Addons/SpinningwheelEastAddon.cs @@ -73,8 +73,7 @@ namespace Server.Items public void EndSpin( SpinCallback callback, Mobile from, int hue ) { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Items/Addons/SpinningwheelSouthAddon.cs b/Scripts/Items/Addons/SpinningwheelSouthAddon.cs index e3e45a6dd..c77d83289 100644 --- a/Scripts/Items/Addons/SpinningwheelSouthAddon.cs +++ b/Scripts/Items/Addons/SpinningwheelSouthAddon.cs @@ -65,8 +65,7 @@ namespace Server.Items public void EndSpin( SpinCallback callback, Mobile from, int hue ) { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Items/Addons/TrainingDummies.cs b/Scripts/Items/Addons/TrainingDummies.cs index 130cd824e..46304dcb6 100644 --- a/Scripts/Items/Addons/TrainingDummies.cs +++ b/Scripts/Items/Addons/TrainingDummies.cs @@ -52,8 +52,7 @@ namespace Server.Items public void BeginSwing() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = new InternalTimer( this ); m_Timer.Start(); @@ -61,8 +60,7 @@ namespace Server.Items public void EndSwing() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Items/Aquarium/Aquarium.cs b/Scripts/Items/Aquarium/Aquarium.cs index 797ed5cc8..7ea21fc1a 100644 --- a/Scripts/Items/Aquarium/Aquarium.cs +++ b/Scripts/Items/Aquarium/Aquarium.cs @@ -791,10 +791,8 @@ namespace Server.Items from.SendLocalizedMessage( 1074514 ); // You have no place to put it. 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 ) @@ -871,24 +869,21 @@ namespace Server.Items 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; } 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; } 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(); return true; diff --git a/Scripts/Items/Aquarium/AquariumGump.cs b/Scripts/Items/Aquarium/AquariumGump.cs index 5288fccc1..fb86138bf 100644 --- a/Scripts/Items/Aquarium/AquariumGump.cs +++ b/Scripts/Items/Aquarium/AquariumGump.cs @@ -30,7 +30,7 @@ namespace Server.Items DisplayPage( i, edit ); } - public virtual void DisplayPage( int page, bool edit ) + public void DisplayPage( int page, bool edit ) { AddPage( page ); diff --git a/Scripts/Items/Aquarium/BaseFish.cs b/Scripts/Items/Aquarium/BaseFish.cs index 74937d247..2f8fd1fd9 100644 --- a/Scripts/Items/Aquarium/BaseFish.cs +++ b/Scripts/Items/Aquarium/BaseFish.cs @@ -28,8 +28,7 @@ namespace Server.Items public virtual void StartTimer() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = Timer.DelayCall( DeathDelay, new TimerCallback( Kill ) ); @@ -38,8 +37,7 @@ namespace Server.Items public virtual void StopTimer() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); 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 if ( ItemID > 0x3B0F ) 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 ? 1073623 : 1073622; // A [dead/live] aquarium creature diff --git a/Scripts/Items/Containers/TreasureMapChest.cs b/Scripts/Items/Containers/TreasureMapChest.cs index bcba998fd..4465c1228 100644 --- a/Scripts/Items/Containers/TreasureMapChest.cs +++ b/Scripts/Items/Containers/TreasureMapChest.cs @@ -444,8 +444,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Items/Lights/BaseLight.cs b/Scripts/Items/Lights/BaseLight.cs index 65058580f..992b8a1f0 100644 --- a/Scripts/Items/Lights/BaseLight.cs +++ b/Scripts/Items/Lights/BaseLight.cs @@ -126,8 +126,7 @@ namespace Server.Items else if ( m_Duration != TimeSpan.Zero ) m_Duration = m_End - DateTime.UtcNow; - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); PlayUnlitSound(); } @@ -142,8 +141,7 @@ namespace Server.Items { m_Duration = delay; - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); if ( delay == TimeSpan.Zero ) return; diff --git a/Scripts/Items/Misc/AcidSlime.cs b/Scripts/Items/Misc/AcidSlime.cs index c52ae32f5..ed43522e1 100644 --- a/Scripts/Items/Misc/AcidSlime.cs +++ b/Scripts/Items/Misc/AcidSlime.cs @@ -38,8 +38,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } private void OnTick() diff --git a/Scripts/Items/Misc/PoolOfAcid.cs b/Scripts/Items/Misc/PoolOfAcid.cs index 74cb9611e..643810da4 100644 --- a/Scripts/Items/Misc/PoolOfAcid.cs +++ b/Scripts/Items/Misc/PoolOfAcid.cs @@ -40,8 +40,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } private void OnTick() diff --git a/Scripts/Items/Misc/TrashBarrel.cs b/Scripts/Items/Misc/TrashBarrel.cs index 14391810f..177745ab2 100644 --- a/Scripts/Items/Misc/TrashBarrel.cs +++ b/Scripts/Items/Misc/TrashBarrel.cs @@ -124,8 +124,7 @@ namespace Server.Items } } - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } diff --git a/Scripts/Items/Skill Items/Camping/Campfire.cs b/Scripts/Items/Skill Items/Camping/Campfire.cs index 3827a7d7c..198ddd859 100644 --- a/Scripts/Items/Skill Items/Camping/Campfire.cs +++ b/Scripts/Items/Skill Items/Camping/Campfire.cs @@ -159,8 +159,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); ClearEntries(); } diff --git a/Scripts/Items/Skill Items/Misc/Bandage.cs b/Scripts/Items/Skill Items/Misc/Bandage.cs index a727bdd04..5d8e2c31f 100644 --- a/Scripts/Items/Skill Items/Misc/Bandage.cs +++ b/Scripts/Items/Skill Items/Misc/Bandage.cs @@ -192,8 +192,7 @@ namespace Server.Items { m_Table.Remove( m_Healer ); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } diff --git a/Scripts/Items/Skill Items/Misc/RecipeScroll.cs b/Scripts/Items/Skill Items/Misc/RecipeScroll.cs index 7a4d02d2f..c59c494e7 100644 --- a/Scripts/Items/Skill Items/Misc/RecipeScroll.cs +++ b/Scripts/Items/Skill Items/Misc/RecipeScroll.cs @@ -67,7 +67,7 @@ namespace Server.Items Recipe r = this.Recipe; - if ( r != null && @from is PlayerMobile pm ) + if ( r != null && from is PlayerMobile pm ) { if ( !pm.HasRecipe( r ) ) { diff --git a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs index 8852fe871..c1805f27b 100644 --- a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs +++ b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs @@ -165,7 +165,7 @@ namespace Server.Items public static BaseInstrument GetInstrument( Mobile from ) { - if ( !(m_Instruments[@from] is BaseInstrument item) ) + if ( !(m_Instruments[from] is BaseInstrument item) ) return null; if ( !item.IsChildOf( from.Backpack ) ) @@ -210,7 +210,7 @@ namespace Server.Items InstrumentPickedCallback callback = state as InstrumentPickedCallback; - callback?.Invoke( @from, instrument ); + callback?.Invoke( from, instrument ); } } diff --git a/Scripts/Items/Skill Items/Tinkering/Spyglass.cs b/Scripts/Items/Skill Items/Tinkering/Spyglass.cs index 891a26c37..8b48f6cfc 100644 --- a/Scripts/Items/Skill Items/Tinkering/Spyglass.cs +++ b/Scripts/Items/Skill Items/Tinkering/Spyglass.cs @@ -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.Felucca, from.X, from.Y ), "", AffixType.Prepend, "Felucca : ", "" ) ); - if ( @from is PlayerMobile player ) + if ( from is PlayerMobile player ) { QuestSystem qs = player.Quest; diff --git a/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs b/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs index f0217926f..565a2eb4a 100644 --- a/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs +++ b/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs @@ -152,8 +152,7 @@ namespace Server.Items public override void OnDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); base.OnDelete(); } diff --git a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs index 2078d4c76..363c045df 100644 --- a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs +++ b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/PowderOfTemperament.cs @@ -106,11 +106,8 @@ namespace Server.Items return; } - if ( targeted is IDurability && targeted is Item ) + if ( targeted is Item item && item is IDurability wearable ) { - IDurability wearable = (IDurability) targeted; - Item item = (Item) targeted; - if ( !wearable.CanFortify ) { from.SendLocalizedMessage( 1049083 ); // You cannot use the powder on that item. diff --git a/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs b/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs index 087c88d52..18d6f908b 100644 --- a/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs +++ b/Scripts/Items/Special/Evil Home Decor Collection/BedOfNails.cs @@ -20,8 +20,8 @@ namespace Server.Items { bool allow = base.OnMoveOver( m ); - if ( allow && Addon is BedOfNailsAddon ) - ( (BedOfNailsAddon)Addon ).OnMoveOver( m ); + if ( allow && Addon is BedOfNailsAddon addon ) + addon.OnMoveOver( m ); return allow; } diff --git a/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs b/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs index 53ca2b3ad..1cc715916 100644 --- a/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs +++ b/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs @@ -125,8 +125,7 @@ namespace Server.Items } } - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } diff --git a/Scripts/Items/Special/Evil Home Decor Collection/UnsettlingPortrait.cs b/Scripts/Items/Special/Evil Home Decor Collection/UnsettlingPortrait.cs index 7bfd148ba..35b59a300 100644 --- a/Scripts/Items/Special/Evil Home Decor Collection/UnsettlingPortrait.cs +++ b/Scripts/Items/Special/Evil Home Decor Collection/UnsettlingPortrait.cs @@ -32,8 +32,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Items/Special/Heritage Items/Curtains.cs b/Scripts/Items/Special/Heritage Items/Curtains.cs index 34f1654b5..b2601232f 100644 --- a/Scripts/Items/Special/Heritage Items/Curtains.cs +++ b/Scripts/Items/Special/Heritage Items/Curtains.cs @@ -38,10 +38,8 @@ namespace Server.Items { foreach ( AddonComponent c in Addon.Components ) { - if ( c is CurtainsComponent ) + if ( c is CurtainsComponent curtain ) { - CurtainsComponent curtain = (CurtainsComponent) c; - int temp = curtain.ItemID; curtain.ItemID = curtain.ClosedID; curtain.ClosedID = temp; diff --git a/Scripts/Items/Special/Heritage Items/Guillotine.cs b/Scripts/Items/Special/Heritage Items/Guillotine.cs index 6c2b5bba9..a6a9f1107 100644 --- a/Scripts/Items/Special/Heritage Items/Guillotine.cs +++ b/Scripts/Items/Special/Heritage Items/Guillotine.cs @@ -82,8 +82,8 @@ namespace Server.Items { object[] param = (object[]) obj; - if ( param[ 0 ] is AddonComponent && param[ 1 ] is Mobile ) - Activate( (AddonComponent) param[ 0 ], (Mobile) param[ 1 ] ); + if ( param[ 0 ] is AddonComponent component && param[ 1 ] is Mobile mobile ) + Activate( component, mobile ); } public virtual void Activate( AddonComponent c, Mobile from ) @@ -127,10 +127,8 @@ namespace Server.Items private void Deactivate( object obj ) { - if ( obj is AddonComponent ) + if ( obj is AddonComponent c ) { - AddonComponent c = (AddonComponent) obj; - if ( c.ItemID == 0x1269 ) c.ItemID = 0x1260; else if ( c.ItemID == 0x1260 ) diff --git a/Scripts/Items/Special/Heritage Items/IronMaiden.cs b/Scripts/Items/Special/Heritage Items/IronMaiden.cs index 0504128da..6826e25cd 100644 --- a/Scripts/Items/Special/Heritage Items/IronMaiden.cs +++ b/Scripts/Items/Special/Heritage Items/IronMaiden.cs @@ -54,8 +54,8 @@ namespace Server.Items { object[] param = (object[]) obj; - if ( param[ 0 ] is AddonComponent && param[ 1 ] is Mobile ) - Activate( (AddonComponent) param[ 0 ], (Mobile) param[ 1 ] ); + if ( param[ 0 ] is AddonComponent component && param[ 1 ] is Mobile mobile ) + Activate( component, mobile ); } public virtual void Activate( AddonComponent c, Mobile from ) @@ -99,8 +99,8 @@ namespace Server.Items private void Deactivate( object obj ) { - if ( obj is AddonComponent ) - ( (AddonComponent) obj ).ItemID = 0x1249; + if ( obj is AddonComponent component ) + component.ItemID = 0x1249; } } diff --git a/Scripts/Items/Special/Holiday/Wreath.cs b/Scripts/Items/Special/Holiday/Wreath.cs index 8f97a0929..7474baac0 100644 --- a/Scripts/Items/Special/Holiday/Wreath.cs +++ b/Scripts/Items/Special/Holiday/Wreath.cs @@ -62,9 +62,9 @@ namespace Server.Items { Item deed = this.Deed; - if ( this.Parent is Item ) + if ( this.Parent is Item item ) { - ((Item)this.Parent).AddItem( deed ); + item.AddItem( deed ); deed.Location = this.Location; } else @@ -227,9 +227,7 @@ namespace Server.Items public void Placement_OnTarget( Mobile from, object targeted, object state ) { - IPoint3D p = targeted as IPoint3D; - - if ( p == null ) + if ( !(targeted is IPoint3D p) ) return; Point3D loc = new Point3D( p ); diff --git a/Scripts/Items/Special/House Raffle/HouseRaffleManagementGump.cs b/Scripts/Items/Special/House Raffle/HouseRaffleManagementGump.cs index 454b127db..f07e1d6e4 100644 --- a/Scripts/Items/Special/House Raffle/HouseRaffleManagementGump.cs +++ b/Scripts/Items/Special/House Raffle/HouseRaffleManagementGump.cs @@ -205,9 +205,7 @@ namespace Server.Gumps if ( entry.From != null ) { - Account acc = entry.From.Account as Account; - - if ( acc != null ) + if ( entry.From.Account is Account acc ) name = String.Format( "{0} ({1})", entry.From.Name, acc ); else name = entry.From.Name; diff --git a/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs b/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs index a14fdc288..8f718bc9d 100644 --- a/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs +++ b/Scripts/Items/Special/House Raffle/HouseRaffleStone.cs @@ -322,9 +322,7 @@ namespace Server.Items private bool HasEntered( Mobile from ) { - Account acc = from.Account as Account; - - if ( acc == null ) + if ( !(from.Account is Account acc) ) return false; foreach ( RaffleEntry entry in m_Entries ) @@ -370,7 +368,7 @@ namespace Server.Items bool xEast = false, ySouth = false; if ( Sextant.Format( loc, map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth ) ) - result.AppendFormat( "{0}°{1}'{2},{3}°{4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" ); + result.AppendFormat( "{0}°{1}'{2},{3}°{4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" ); else result.AppendFormat( "{0},{1}", loc.X, loc.Y ); @@ -492,9 +490,7 @@ namespace Server.Items if ( Deleted || m_State != HouseRaffleState.Active || !from.CheckAlive() || HasEntered( from ) || IsAtIPLimit( from ) ) return; - Account acc = from.Account as Account; - - if ( acc == null ) + if ( !(from.Account is Account) ) return; if ( okay ) @@ -619,7 +615,7 @@ namespace Server.Items } case 0: { - bool oldActive = ( version < 3 ) ? reader.ReadBool() : false; + bool oldActive = ( version < 3 ) && reader.ReadBool(); m_Bounds = reader.ReadRect2D(); m_Facet = reader.ReadMap(); diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastBackpack.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastBackpack.cs index ff57d53ac..dea9e8b4b 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastBackpack.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastBackpack.cs @@ -130,9 +130,7 @@ namespace Server.Items for ( int i = Items.Count - 1; i >= 0; i-- ) { - PlagueBeastComponent innard = Items[ i ] as PlagueBeastComponent; - - if ( innard != null ) + if ( Items[ i ] is PlagueBeastComponent innard ) { Rectangle2D r = ItemBounds.Table[ innard.ItemID ]; diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs index be78eacc5..064b8889f 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs @@ -62,9 +62,7 @@ namespace Server.Items { for ( int i = 0; i < pack.Items.Count; i++ ) { - PlagueBeastMainOrgan main = pack.Items[ i ] as PlagueBeastMainOrgan; - - if ( main != null && main.Complete ) + if ( pack.Items[ i ] is PlagueBeastMainOrgan main && main.Complete ) main.FinishOpening( from ); } } @@ -104,7 +102,7 @@ namespace Server.Items ItemID--; } - } + } public PlagueBeastBlood( Serial serial ) : base( serial ) { diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastInnard.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastInnard.cs index 41d59b276..d9f58e18e 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastInnard.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastInnard.cs @@ -136,8 +136,8 @@ namespace Server.Items { if ( m_Organ != null && m_Organ.OnDropped( from, dropped, this ) ) { - if ( dropped is PlagueBeastComponent ) - m_Organ.Components.Add( (PlagueBeastComponent) dropped ); + if ( dropped is PlagueBeastComponent component ) + m_Organ.Components.Add( component ); } return true; diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs index ea59f064e..9cc2d8291 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs @@ -55,9 +55,7 @@ namespace Server.Items public void AddComponent( PlagueBeastComponent c, int x, int y ) { - Container pack = Parent as Container; - - if ( pack != null ) + if ( Parent is Container pack ) pack.DropItem( c ); c.Organ = this; diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs index ed24bd293..67eb5102c 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs @@ -56,9 +56,7 @@ namespace Server.Items if ( Owner != null ) Owner.PlaySound( 0x199 ); - PlagueBeastRubbleOrgan organ = Organ as PlagueBeastRubbleOrgan; - - if ( organ != null ) + if ( Organ is PlagueBeastRubbleOrgan organ ) organ.OnVeinCut( from, this ); } diff --git a/Scripts/Items/Special/Solen Items/BagOfSending.cs b/Scripts/Items/Special/Solen Items/BagOfSending.cs index 7ef1d54c6..3f7bb1a27 100644 --- a/Scripts/Items/Special/Solen Items/BagOfSending.cs +++ b/Scripts/Items/Special/Solen Items/BagOfSending.cs @@ -199,9 +199,8 @@ namespace Server.Items { MessageHelper.SendLocalizedMessageTo( m_Bag, from, 1042544, 0x59 ); // This item is out of charges. } - else if ( targeted is Item ) + else if ( targeted is Item item ) { - Item item = (Item)targeted; int reqCharges = (int)Math.Max( 1, Math.Ceiling( item.TotalWeight / 10.0 ) ); if ( !item.IsChildOf( from.Backpack ) ) diff --git a/Scripts/Items/Special/Solen Items/BallOfSummoning.cs b/Scripts/Items/Special/Solen Items/BallOfSummoning.cs index f0a1b6f7c..095e18b08 100644 --- a/Scripts/Items/Special/Solen Items/BallOfSummoning.cs +++ b/Scripts/Items/Special/Solen Items/BallOfSummoning.cs @@ -199,10 +199,8 @@ namespace Server.Items { from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1042001 ); // That must be in your pack for you to use it. } - else if ( targeted is BaseCreature ) + else if ( targeted is BaseCreature creature ) { - BaseCreature creature = (BaseCreature)targeted; - if ( !creature.Controlled || creature.ControlMaster != from ) { MessageHelper.SendLocalizedMessageTo( m_Ball, from, 1054117, 0x59 ); // You may only link your own pets to a Crystal Ball of Pet Summoning. @@ -240,7 +238,7 @@ namespace Server.Items { SendLocalizedMessageTo( from, 1054122 ); // The Crystal Ball darkens. It must be charged before it can be used again. } - else if ( pet is BaseMount && ((BaseMount)pet).Rider == from ) + else if ( pet is BaseMount mount && mount.Rider == from ) { MessageHelper.SendLocalizedMessageTo( this, from, 1054124, 0x36 ); // The Crystal Ball fills with a yellow mist. Why would you summon your pet while riding it? } @@ -260,9 +258,9 @@ namespace Server.Items { from.Send( new AsciiMessage( this.Serial, this.ItemID, MessageType.Regular, 0x22, 3, "", "You cannot summon your pet to this location." ) ); } - else if ( Core.ML && from is PlayerMobile && DateTime.UtcNow < ((PlayerMobile)from).LastPetBallTime.AddSeconds( 15.0 ) ) + else if ( Core.ML && from is PlayerMobile mobile && DateTime.UtcNow < mobile.LastPetBallTime.AddSeconds( 15.0 ) ) { - MessageHelper.SendLocalizedMessageTo( this, from, 1080072, 0x22 ); // You must wait a few seconds before you can summon your pet. + MessageHelper.SendLocalizedMessageTo( this, mobile, 1080072, 0x22 ); // You must wait a few seconds before you can summon your pet. } else { @@ -298,17 +296,17 @@ namespace Server.Items pet.StabledBy = null; from.Stabled.Remove( pet ); - if ( from is PlayerMobile ) - ((PlayerMobile)from).AutoStabled.Remove( pet ); + if ( from is PlayerMobile mobile ) + mobile.AutoStabled.Remove( pet ); } pet.MoveToWorld( from.Location, from.Map ); MessageHelper.SendLocalizedMessageTo( this, from, 1054128, 0x43 ); // The Crystal Ball fills with a green mist. Your pet has been summoned. - if ( from is PlayerMobile ) + if ( from is PlayerMobile playerMobile ) { - ((PlayerMobile)from).LastPetBallTime = DateTime.UtcNow; + playerMobile.LastPetBallTime = DateTime.UtcNow; } } diff --git a/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs b/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs index 3109a39d1..f05ece20b 100644 --- a/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs +++ b/Scripts/Items/Special/Solen Items/BraceletOfBinding.cs @@ -204,9 +204,7 @@ namespace Server.Items if ( m_Bracelet.CheckUse( m_From, false ) ) { - Mobile boundRoot = m_Bracelet.Bound.RootParent as Mobile; - - if ( boundRoot != null ) + if ( m_Bracelet.Bound.RootParent is Mobile boundRoot ) { m_Bracelet.Charges--; @@ -279,9 +277,9 @@ namespace Server.Items { return false; } - else if ( boundRoot.Map == Map.Felucca && from is PlayerMobile && ((PlayerMobile)from).Young ) + else if ( boundRoot.Map == Map.Felucca && from is PlayerMobile mobile && mobile.Young ) { - from.SendLocalizedMessage( 1049543 ); // You decide against traveling to Felucca while you are still young. + mobile.SendLocalizedMessage( 1049543 ); // You decide against traveling to Felucca while you are still young. return false; } else if ( from.Kills >= 5 && boundRoot.Map != Map.Felucca ) @@ -357,10 +355,8 @@ namespace Server.Items { from.SendLocalizedMessage( 1042664 ); // You must have the object in your backpack to use it. } - else if ( targeted is BraceletOfBinding ) + else if ( targeted is BraceletOfBinding bindBracelet ) { - BraceletOfBinding bindBracelet = (BraceletOfBinding)targeted; - if ( bindBracelet == m_Bracelet ) { from.SendLocalizedMessage( 1054012 ); // You cannot bind a bracelet of binding to itself! @@ -471,4 +467,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Special/Solen Items/PowderOfTranslocation.cs b/Scripts/Items/Special/Solen Items/PowderOfTranslocation.cs index a32287773..208c5caf5 100644 --- a/Scripts/Items/Special/Solen Items/PowderOfTranslocation.cs +++ b/Scripts/Items/Special/Solen Items/PowderOfTranslocation.cs @@ -59,10 +59,8 @@ namespace Server.Items { from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that. } - else if ( targeted is TranslocationItem ) + else if ( targeted is TranslocationItem transItem ) { - TranslocationItem transItem = (TranslocationItem)targeted; - if ( transItem.Charges >= transItem.MaxCharges ) { MessageHelper.SendLocalizedMessageTo( m_Powder, from, 1054137, 0x59 ); // This item cannot absorb any more powder of translocation. @@ -88,10 +86,10 @@ namespace Server.Items m_Powder.Delete(); } - if ( transItem is Item ) + if ( transItem is Item item ) { // The ~1_translocationItem~ glows with green energy and absorbs magical power from the powder. - MessageHelper.SendLocalizedMessageTo( (Item)transItem, from, 1054139, transItem.TranslocationItemName, 0x43 ); + MessageHelper.SendLocalizedMessageTo( item, from, 1054139, transItem.TranslocationItemName, 0x43 ); } } } @@ -120,4 +118,4 @@ namespace Server.Items int version = reader.ReadEncodedInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Special/SoulStone.cs b/Scripts/Items/Special/SoulStone.cs index 023c3e002..3d96cde30 100644 --- a/Scripts/Items/Special/SoulStone.cs +++ b/Scripts/Items/Special/SoulStone.cs @@ -642,10 +642,8 @@ namespace Server.Items Effects.SendTargetParticles( from, 0x375A, 35, 90, 0x00, 0x00, 9502, (EffectLayer)255, 0x100 ); - if ( m_Stone is SoulstoneFragment ) + if ( m_Stone is SoulstoneFragment frag ) { - SoulstoneFragment frag = m_Stone as SoulstoneFragment; - if ( --frag.UsesRemaining <= 0 ) from.SendLocalizedMessage( 1070974 ); // You have used up your soulstone fragment. } diff --git a/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs b/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs index b0302b17f..1e35ee6cc 100644 --- a/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs +++ b/Scripts/Items/Special/Special Scrolls/ScrollofAlacrity.cs @@ -66,9 +66,7 @@ namespace Server.Items if ( !base.CanUse( from ) ) return false; - PlayerMobile pm = from as PlayerMobile; - - if ( pm == null ) + if ( !(from is PlayerMobile pm) ) return false; #region Mondain's Legacy @@ -109,9 +107,7 @@ namespace Server.Items if ( !CanUse( from ) ) return; - PlayerMobile pm = from as PlayerMobile; - - if ( pm == null ) + if ( !(from is PlayerMobile pm) ) return; double tskill = from.Skills[Skill].Base; @@ -130,9 +126,6 @@ namespace Server.Items Effects.SendTargetParticles( from, 0x373A, 35, 45, 0x00, 0x00, 9502, (EffectLayer)255, 0x100 ); pm.AcceleratedStart = DateTime.UtcNow + TimeSpan.FromMinutes(15); - - Timer t = (Timer)m_Table[from]; - m_Table[from] = Timer.DelayCall( TimeSpan.FromMinutes( 15 ), new TimerStateCallback( Expire_Callback ), from ); pm.AcceleratedSkill = Skill; diff --git a/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs b/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs index b3f9d252f..d53fd4c6a 100644 --- a/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs +++ b/Scripts/Items/Special/Special Scrolls/ScrollofTranscendence.cs @@ -54,9 +54,7 @@ namespace Server.Items if ( !base.CanUse( from ) ) return false; - PlayerMobile pm = from as PlayerMobile; - - if ( pm == null ) + if ( !(from is PlayerMobile pm) ) return false; #region Mondain's Legacy diff --git a/Scripts/Items/Special/Special Scrolls/StatScroll.cs b/Scripts/Items/Special/Special Scrolls/StatScroll.cs index 32827b186..228b82264 100644 --- a/Scripts/Items/Special/Special Scrolls/StatScroll.cs +++ b/Scripts/Items/Special/Special Scrolls/StatScroll.cs @@ -76,7 +76,7 @@ namespace Server.Items int newValue = (int)Value; - if ( from is PlayerMobile && ((PlayerMobile)from).HasStatReward ) + if ( from is PlayerMobile mobile && mobile.HasStatReward ) newValue += 5; if ( from.StatCap >= newValue ) @@ -95,8 +95,8 @@ namespace Server.Items from.SendLocalizedMessage( 1049512 ); // You feel a surge of magic as the scroll enhances your powers! - if ( from is PlayerMobile && ((PlayerMobile)from).HasStatReward ) - from.StatCap = (int)Value + 5; + if ( from is PlayerMobile mobile && mobile.HasStatReward ) + mobile.StatCap = (int)Value + 5; else from.StatCap = (int)Value; diff --git a/Scripts/Items/Special/Valentines/2007/ValentinesCard.cs b/Scripts/Items/Special/Valentines/2007/ValentinesCard.cs index 3faa3008d..d41ba873d 100644 --- a/Scripts/Items/Special/Valentines/2007/ValentinesCard.cs +++ b/Scripts/Items/Special/Valentines/2007/ValentinesCard.cs @@ -73,10 +73,8 @@ namespace Server.Items { if (!Deleted) { - if (targeted != null && targeted is Mobile) + if (targeted != null && targeted is Mobile to) { - Mobile to = targeted as Mobile; - if (to is PlayerMobile) { if (to != from) diff --git a/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs b/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs index 4757b8440..9fa549e3a 100644 --- a/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs +++ b/Scripts/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs @@ -26,8 +26,8 @@ namespace Server.Items { base.GetContextMenuEntries( from, list ); - if ( from is PlayerMobile ) - list.Add( new LockKarmaEntry( (PlayerMobile)from, Addon as AnkhOfSacrificeAddon ) ); + if ( from is PlayerMobile mobile ) + list.Add( new LockKarmaEntry( mobile, Addon as AnkhOfSacrificeAddon ) ); list.Add( new ResurrectEntry( from, Addon as AnkhOfSacrificeAddon ) ); } @@ -140,9 +140,9 @@ namespace Server.Items return; } - if ( from is PlayerMobile ) + if ( from is PlayerMobile mobile ) { - ((PlayerMobile) from).AnkhNextUse = DateTime.UtcNow + TimeSpan.FromHours( 1 ); + mobile.AnkhNextUse = DateTime.UtcNow + TimeSpan.FromHours( 1 ); } base.OnResponse( state, info ); diff --git a/Scripts/Items/Special/Veteran Rewards/Cannon.cs b/Scripts/Items/Special/Veteran Rewards/Cannon.cs index 6c5a58034..e3573a4b8 100644 --- a/Scripts/Items/Special/Veteran Rewards/Cannon.cs +++ b/Scripts/Items/Special/Veteran Rewards/Cannon.cs @@ -26,12 +26,12 @@ namespace Server.Items { base.GetProperties( list ); - if ( Addon is CannonAddon ) + if ( Addon is CannonAddon addon ) { - if ( ((CannonAddon) Addon).IsRewardItem ) + if ( addon.IsRewardItem ) list.Add( 1076223 ); // 7th Year Veteran Reward - list.Add( 1076207, ((CannonAddon) Addon).Charges.ToString() ); // Remaining Charges: ~1_val~ + list.Add( 1076207, addon.Charges.ToString() ); // Remaining Charges: ~1_val~ } } @@ -260,9 +260,7 @@ namespace Server.Items if ( m_Cannon == null || m_Cannon.Deleted ) return; - IPoint3D p = targeted as IPoint3D; - - if ( p == null ) + if ( !(targeted is IPoint3D p) ) return; if ( from.InLOS( new Point3D( p ) ) ) diff --git a/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs b/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs index 1c949e660..79a9954bc 100644 --- a/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs +++ b/Scripts/Items/Special/Veteran Rewards/StoneAnkh.cs @@ -24,7 +24,7 @@ namespace Server.Items { base.GetProperties( list ); - if ( Addon is StoneAnkh && ((StoneAnkh) Addon).IsRewardItem ) + if ( Addon is StoneAnkh ankh && ankh.IsRewardItem ) list.Add( 1076221 ); // 5th Year Veteran Reward } diff --git a/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs b/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs index 82dd6597e..1feeb16be 100644 --- a/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs +++ b/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs @@ -189,10 +189,8 @@ namespace Server.Items if ( m_Tool == null || m_Tool.Deleted ) return; - if ( targeted is BaseWeapon ) + if ( targeted is BaseWeapon item ) { - BaseWeapon item = (BaseWeapon) targeted; - from.CloseGump( typeof( InternalGump ) ); from.SendGump( new InternalGump( m_Tool, item ) ); } diff --git a/Scripts/Items/Suits/BaseSuit.cs b/Scripts/Items/Suits/BaseSuit.cs index 2d857554c..ccc145e5b 100644 --- a/Scripts/Items/Suits/BaseSuit.cs +++ b/Scripts/Items/Suits/BaseSuit.cs @@ -54,7 +54,7 @@ namespace Server.Items { object root = RootParent; - if ( root is Mobile && ((Mobile)root).AccessLevel < m_AccessLevel ) + if ( root is Mobile mobile && mobile.AccessLevel < m_AccessLevel ) { Delete(); return false; @@ -88,4 +88,4 @@ namespace Server.Items return ( from.AccessLevel >= m_AccessLevel ); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Talismans/BaseTalisman.cs b/Scripts/Items/Talismans/BaseTalisman.cs index ad593cd7e..a2c62daa4 100644 --- a/Scripts/Items/Talismans/BaseTalisman.cs +++ b/Scripts/Items/Talismans/BaseTalisman.cs @@ -211,9 +211,7 @@ namespace Server.Items public override void OnAfterDuped(Item newItem) { - BaseTalisman talisman = newItem as BaseTalisman; - - if (talisman == null) + if (!(newItem is BaseTalisman talisman)) return; talisman.m_Summoner = new TalismanAttribute(m_Summoner); @@ -236,10 +234,8 @@ namespace Server.Items public override void OnAdded(IEntity parent) { - if (parent is Mobile) + if (parent is Mobile from) { - Mobile from = (Mobile)parent; - m_AosSkillBonuses.AddTo(from); m_AosAttributes.AddStatBonuses(from); @@ -261,10 +257,8 @@ namespace Server.Items public override void OnRemoved(IEntity parent) { - if (parent is Mobile) + if (parent is Mobile from) { - Mobile from = (Mobile)parent; - m_AosSkillBonuses.Remove(); m_AosAttributes.RemoveStatBonuses(from); @@ -304,9 +298,8 @@ namespace Server.Items try { obj = Activator.CreateInstance(type); } catch { obj = null; } - if (obj is Item) + if (obj is Item item) { - Item item = (Item)obj; int count = 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. else if (item is Bandage) 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~ } - 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) { 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_AosSkillBonuses.AddTo(m); diff --git a/Scripts/Items/Talismans/Items/RunedSwitch.cs b/Scripts/Items/Talismans/Items/RunedSwitch.cs index 524527587..252a2e5bc 100644 --- a/Scripts/Items/Talismans/Items/RunedSwitch.cs +++ b/Scripts/Items/Talismans/Items/RunedSwitch.cs @@ -57,10 +57,8 @@ namespace Server.Items if ( m_Item == null || m_Item.Deleted ) return; - if ( o is BaseTalisman ) + if ( o is BaseTalisman talisman ) { - BaseTalisman talisman = (BaseTalisman) o; - if ( talisman.Charges == 0 ) { talisman.Charges = talisman.MaxCharges; diff --git a/Scripts/Items/Traps/FlameSpurtTrap.cs b/Scripts/Items/Traps/FlameSpurtTrap.cs index 03c75c418..07d9dee74 100644 --- a/Scripts/Items/Traps/FlameSpurtTrap.cs +++ b/Scripts/Items/Traps/FlameSpurtTrap.cs @@ -21,8 +21,7 @@ namespace Server.Items public virtual void StopTimer() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } @@ -178,4 +177,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/TreasureChests/TreasureChestLevel3.cs b/Scripts/Items/TreasureChests/TreasureChestLevel3.cs index 8433177e0..714fbdc92 100644 --- a/Scripts/Items/TreasureChests/TreasureChestLevel3.cs +++ b/Scripts/Items/TreasureChests/TreasureChestLevel3.cs @@ -117,17 +117,15 @@ namespace Server.Items { 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.AccuracyLevel = ( WeaponAccuracyLevel )Utility.Random( m_Level ); weapon.DurabilityLevel = ( WeaponDurabilityLevel )Utility.Random( m_Level ); 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.Durability = ( ArmorDurabilityLevel )Utility.Random( m_Level ); armor.Quality = ArmorQuality.Regular; diff --git a/Scripts/Items/TreasureChests/TreasureChestLevel4.cs b/Scripts/Items/TreasureChests/TreasureChestLevel4.cs index c8b99b428..f352ef957 100644 --- a/Scripts/Items/TreasureChests/TreasureChestLevel4.cs +++ b/Scripts/Items/TreasureChests/TreasureChestLevel4.cs @@ -124,17 +124,15 @@ namespace Server.Items { 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.AccuracyLevel = ( WeaponAccuracyLevel )Utility.Random( m_Level ); weapon.DurabilityLevel = ( WeaponDurabilityLevel )Utility.Random( m_Level ); 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.Durability = ( ArmorDurabilityLevel )Utility.Random( m_Level ); armor.Quality = ArmorQuality.Regular; diff --git a/Scripts/Items/Wands/IDWand.cs b/Scripts/Items/Wands/IDWand.cs index 4cc4f1469..2c241289b 100644 --- a/Scripts/Items/Wands/IDWand.cs +++ b/Scripts/Items/Wands/IDWand.cs @@ -33,15 +33,20 @@ namespace Server.Items public override bool OnWandTarget( Mobile from, object o ) { - if ( o is BaseWeapon ) - ((BaseWeapon)o).Identified = true; - else if ( o is BaseArmor ) - ((BaseArmor)o).Identified = true; + if (o is Item item) + { + if ( item is BaseWeapon weapon ) + weapon.Identified = true; + else if ( item is BaseArmor armor ) + armor.Identified = true; - if ( !Core.AOS && o is Item ) - ((Item)o).OnSingleClick( from ); + if (!Core.AOS) + item.OnSingleClick( from ); - return ( o is Item ); + return true; + } + + return false; } } } diff --git a/Scripts/Items/Weapons/Abilities/BleedAttack.cs b/Scripts/Items/Weapons/Abilities/BleedAttack.cs index 094f727f7..571a5578f 100644 --- a/Scripts/Items/Weapons/Abilities/BleedAttack.cs +++ b/Scripts/Items/Weapons/Abilities/BleedAttack.cs @@ -31,7 +31,7 @@ namespace Server.Items TransformContext context = TransformationSpellHelper.GetContext( defender ); 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! return; @@ -63,8 +63,7 @@ namespace Server.Items { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new InternalTimer( from, m ); m_Table[m] = t; diff --git a/Scripts/Items/Weapons/Abilities/Block.cs b/Scripts/Items/Weapons/Abilities/Block.cs index 82eef4b1c..cf19525d1 100644 --- a/Scripts/Items/Weapons/Abilities/Block.cs +++ b/Scripts/Items/Weapons/Abilities/Block.cs @@ -60,9 +60,7 @@ namespace Server.Items public static bool GetBonus( Mobile targ, ref int bonus ) { - BlockInfo info = m_Table[targ] as BlockInfo; - - if ( info == null ) + if ( !(m_Table[targ] is BlockInfo info) ) return false; bonus = info.m_Bonus; @@ -81,12 +79,9 @@ namespace Server.Items public static void EndBlock( Mobile m ) { - BlockInfo info = m_Table[m] as BlockInfo; - - if ( info != null ) + if ( m_Table[m] is BlockInfo info ) { - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); m_Table.Remove( m ); } diff --git a/Scripts/Items/Weapons/Abilities/DefenseMastery.cs b/Scripts/Items/Weapons/Abilities/DefenseMastery.cs index f91f64ad8..765271abb 100644 --- a/Scripts/Items/Weapons/Abilities/DefenseMastery.cs +++ b/Scripts/Items/Weapons/Abilities/DefenseMastery.cs @@ -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)); - DefenseMasteryInfo info = m_Table[attacker] as DefenseMasteryInfo; - - if ( info != null ) + if ( m_Table[attacker] is DefenseMasteryInfo info ) EndDefense( (object)info ); ResistanceMod mod = new ResistanceMod( ResistanceType.Physical, 50 + modifier ); @@ -74,9 +72,7 @@ namespace Server.Items public static bool GetMalus( Mobile targ, ref int damageMalus ) { - DefenseMasteryInfo info = m_Table[targ] as DefenseMasteryInfo; - - if ( info == null ) + if ( !(m_Table[targ] is DefenseMasteryInfo info) ) return false; damageMalus = info.m_DamageMalus; @@ -90,8 +86,7 @@ namespace Server.Items if ( info.m_Mod != null ) 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. diff --git a/Scripts/Items/Weapons/Abilities/Disarm.cs b/Scripts/Items/Weapons/Abilities/Disarm.cs index 0dbb44e16..f2ab34f5f 100644 --- a/Scripts/Items/Weapons/Abilities/Disarm.cs +++ b/Scripts/Items/Weapons/Abilities/Disarm.cs @@ -35,9 +35,7 @@ namespace Server.Items public override bool RequiresTactics( Mobile from ) { - BaseWeapon weapon = from.Weapon as BaseWeapon; - - if ( weapon == null ) + if ( !(from.Weapon is BaseWeapon weapon) ) return false; return weapon.Skill != SkillName.Wrestling; diff --git a/Scripts/Items/Weapons/Abilities/Dismount.cs b/Scripts/Items/Weapons/Abilities/Dismount.cs index 179cb487d..a15b7200f 100644 --- a/Scripts/Items/Weapons/Abilities/Dismount.cs +++ b/Scripts/Items/Weapons/Abilities/Dismount.cs @@ -72,36 +72,32 @@ namespace Server.Items defender.PlaySound( 0x140 ); 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 { 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 ) + if ( bc.ControlMaster is PlayerMobile pm ) { - PlayerMobile pm = bc.ControlMaster as PlayerMobile; - pm.SetMountBlock(BlockMountType.DismountRecovery, RemountDelay, false ); } } diff --git a/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs b/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs index 20b0da9c2..34fb78c72 100644 --- a/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs +++ b/Scripts/Items/Weapons/Abilities/FrenziedWhirlwind.cs @@ -43,9 +43,7 @@ namespace Server.Items if ( map == null ) return; - BaseWeapon weapon = attacker.Weapon as BaseWeapon; - - if ( weapon == null ) + if ( !(attacker.Weapon is BaseWeapon weapon) ) return; ArrayList list = new ArrayList(); @@ -88,9 +86,7 @@ namespace Server.Items Mobile m = (Mobile)targets[i]; attacker.DoHarmful( m, true ); - Timer t = Registry[m] as Timer; - - if ( t != null ) + if ( Registry[m] is Timer t ) { t.Stop(); Registry.Remove( m ); diff --git a/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs b/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs index 3181f9c4c..e379bc8a8 100644 --- a/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs +++ b/Scripts/Items/Weapons/Abilities/InfectiousStrike.cs @@ -32,9 +32,7 @@ namespace Server.Items ClearCurrentAbility( attacker ); - BaseWeapon weapon = attacker.Weapon as BaseWeapon; - - if ( weapon == null ) + if ( !(attacker.Weapon is BaseWeapon weapon) ) return; Poison p = weapon.Poison; diff --git a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs index cc198fea2..7dffade8e 100644 --- a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs +++ b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs @@ -40,9 +40,7 @@ namespace Server.Items public override bool RequiresTactics( Mobile from ) { - BaseWeapon weapon = from.Weapon as BaseWeapon; - - if ( weapon == null ) + if ( !(from.Weapon is BaseWeapon weapon) ) return true; return weapon.Skill != SkillName.Wrestling; diff --git a/Scripts/Items/Weapons/Abilities/WeaponAbility.cs b/Scripts/Items/Weapons/Abilities/WeaponAbility.cs index 139f96a17..69ce81c67 100644 --- a/Scripts/Items/Weapons/Abilities/WeaponAbility.cs +++ b/Scripts/Items/Weapons/Abilities/WeaponAbility.cs @@ -85,9 +85,7 @@ namespace Server.Items public virtual bool CheckWeaponSkill( Mobile from ) { - BaseWeapon weapon = from.Weapon as BaseWeapon; - - if ( weapon == null ) + if ( !(from.Weapon is BaseWeapon weapon) ) return false; Skill skill = from.Skills[weapon.Skill]; @@ -141,7 +139,7 @@ namespace Server.Items if ( from.Mana < mana ) { - if ( ( from is BaseCreature ) && ( from as BaseCreature ).HasManaOveride ) + if ( from is BaseCreature creature && creature.HasManaOveride ) { return true; } @@ -336,9 +334,7 @@ namespace Server.Items if ( !m.Player ) return true; - BaseWeapon weapon = m.Weapon as BaseWeapon; - - return ( weapon != null && (weapon.PrimaryAbility == a || weapon.SecondaryAbility == a) ); + return ( m.Weapon is BaseWeapon weapon && (weapon.PrimaryAbility == a || weapon.SecondaryAbility == a) ); } public virtual bool ValidatesDuringHit => true; diff --git a/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs b/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs index c843568c0..747e8c329 100644 --- a/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs +++ b/Scripts/Items/Weapons/Abilities/WhirlwindAttack.cs @@ -28,9 +28,7 @@ namespace Server.Items if ( map == null ) return; - BaseWeapon weapon = attacker.Weapon as BaseWeapon; - - if ( weapon == null ) + if ( !(attacker.Weapon is BaseWeapon weapon) ) return; if ( !CheckMana( attacker, true ) ) diff --git a/Scripts/Items/Weapons/Axes/BaseAxe.cs b/Scripts/Items/Weapons/Axes/BaseAxe.cs index 3d055f002..a22a8a190 100644 --- a/Scripts/Items/Weapons/Axes/BaseAxe.cs +++ b/Scripts/Items/Weapons/Axes/BaseAxe.cs @@ -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 ); diff --git a/Scripts/Items/Weapons/BaseWeapon.cs b/Scripts/Items/Weapons/BaseWeapon.cs index a9d4de9eb..6b64fc31f 100644 --- a/Scripts/Items/Weapons/BaseWeapon.cs +++ b/Scripts/Items/Weapons/BaseWeapon.cs @@ -413,15 +413,14 @@ namespace Server.Items { if ( m_AccuracyLevel == WeaponAccuracyLevel.Regular ) { - if ( m_SkillMod != null ) - m_SkillMod.Remove(); + m_SkillMod?.Remove(); 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 ); - ((Mobile)Parent).AddSkillMod( m_SkillMod ); + mobile.AddSkillMod( m_SkillMod ); } else if ( m_SkillMod != null ) { @@ -438,9 +437,7 @@ namespace Server.Items public override void OnAfterDuped( Item newItem ) { - BaseWeapon weap = newItem as BaseWeapon; - - if ( weap == null ) + if ( !(newItem is BaseWeapon weap) ) return; weap.m_AosAttributes = new AosAttributes( newItem, m_AosAttributes ); @@ -507,15 +504,10 @@ namespace Server.Items int v = m_AosWeaponAttributes.LowerStatReq; - CraftResourceInfo info = CraftResources.GetInfo( m_Resource ); + CraftAttributeInfo attrInfo = CraftResources.GetInfo( m_Resource )?.AttributeInfo; - if ( info != null ) - { - CraftAttributeInfo attrInfo = info.AttributeInfo; - - if ( attrInfo != null ) - v += attrInfo.WeaponLowerRequirements; - } + if ( attrInfo != null ) + v += attrInfo.WeaponLowerRequirements; if ( v > 100 ) v = 100; @@ -587,29 +579,27 @@ namespace Server.Items return false; } - else if ( from.Dex < DexRequirement ) + if ( from.Dex < DexRequirement ) { from.SendMessage( "You are not nimble enough to equip that." ); 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. return false; } - else if ( from.Int < IntRequirement ) + if ( from.Int < IntRequirement ) { from.SendMessage( "You are not smart enough to equip that." ); return false; } - else if ( !from.CanBeginAction( typeof( BaseWeapon ) ) ) + if ( !from.CanBeginAction( typeof( BaseWeapon ) ) ) { return false; } - else - { - return base.CanEquip( from ); - } + + return base.CanEquip( from ); } public virtual bool UseSkillMod{ get{ return !Core.AOS; } } @@ -640,8 +630,7 @@ namespace Server.Items 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 ); from.AddSkillMod( m_SkillMod ); @@ -649,8 +638,7 @@ namespace Server.Items 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 ); from.AddSkillMod( m_MageMod ); @@ -663,10 +651,8 @@ namespace Server.Items { base.OnAdded( parent ); - if ( parent is Mobile ) + if ( parent is Mobile from ) { - Mobile from = (Mobile)parent; - if ( Core.AOS ) m_AosSkillBonuses.AddTo( from ); @@ -677,9 +663,8 @@ namespace Server.Items 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; string modName = this.Serial.ToString(); @@ -729,7 +714,7 @@ namespace Server.Items val = swrd; 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 ) { @@ -770,7 +755,7 @@ namespace Server.Items BaseWeapon defWeapon = defender.Weapon as BaseWeapon; 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 defValue = defWeapon.GetDefendSkillValue( attacker, defender ); @@ -901,8 +886,8 @@ namespace Server.Items TransformContext context = TransformationSpellHelper.GetContext( m ); - if ( context != null && context.Spell is ReaperFormSpell ) - bonus += ((ReaperFormSpell)context.Spell).SwingSpeedBonus; + if ( context?.Spell is ReaperFormSpell spell ) + bonus += spell.SwingSpeedBonus; int discordanceEffect = 0; @@ -1009,24 +994,18 @@ namespace Server.Items if ( canSwing ) { - Spell sp = attacker.Spell as Spell; - - canSwing = ( sp == null || !sp.IsCasting || !sp.BlocksMovement ); + canSwing = ( !(attacker.Spell is Spell sp) || !sp.IsCasting || !sp.BlocksMovement ); } if ( canSwing ) { - PlayerMobile p = attacker as PlayerMobile; - - canSwing = ( p == null || p.PeacedUntil <= DateTime.UtcNow ); + canSwing = ( !(attacker is PlayerMobile p) || p.PeacedUntil <= DateTime.UtcNow ); } } #region Dueling - if ( attacker is PlayerMobile ) + if ( attacker is PlayerMobile pm ) { - PlayerMobile pm = (PlayerMobile)attacker; - if ( pm.DuelContext != null && !pm.DuelContext.CheckItemEquip( attacker, this ) ) canSwing = false; } @@ -1039,9 +1018,8 @@ namespace Server.Items if ( attacker.NetState != null ) attacker.Send( new Swing( 0, attacker, defender ) ); - if ( attacker is BaseCreature ) + if ( attacker is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)attacker; WeaponAbility ab = bc.GetWeaponAbility(); if ( ab != null ) @@ -1080,10 +1058,7 @@ namespace Server.Items public virtual int GetMissAttackSound( Mobile attacker, Mobile defender ) { - if ( attacker.GetAttackSound() == -1 ) - return MissSound; - else - return -1; + return attacker.GetAttackSound() == -1 ? MissSound : -1; } public virtual int GetMissDefendSound( Mobile attacker, Mobile defender ) @@ -1124,7 +1099,7 @@ namespace Server.Items 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; @@ -1155,8 +1130,8 @@ namespace Server.Items if ( chance > aosChance ) 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; @@ -1180,9 +1155,7 @@ namespace Server.Items if ( CounterAttack.IsCountering( defender ) ) { - BaseWeapon weapon = defender.Weapon as BaseWeapon; - - if ( weapon != null ) + if ( defender.Weapon is BaseWeapon weapon ) { defender.FixedParticles(0x3779, 1, 15, 0x158B, 0x0, 0x3, EffectLayer.Waist); weapon.OnSwing( defender, attacker ); @@ -1203,10 +1176,7 @@ namespace Server.Items 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 armorItem = defender.ChestArmor; - IWearableDurability armor = armorItem as IWearableDurability; - - if ( armor != null ) + if ( armorItem is IWearableDurability armor ) armor.OnHit( this, damage ); // call OnHit to lose durability } @@ -1243,8 +1211,7 @@ namespace Server.Items if ( Core.AOS ) return AbsorbDamageAOS( attacker, defender, damage ); - BaseShield shield = defender.FindItemOnLayer( Layer.TwoHanded ) as BaseShield; - if ( shield != null ) + if ( defender.FindItemOnLayer( Layer.TwoHanded ) is BaseShield shield ) damage = shield.OnHit( this, damage ); double chance = Utility.RandomDouble(); @@ -1264,9 +1231,7 @@ namespace Server.Items else armorItem = defender.ChestArmor; - IWearableDurability armor = armorItem as IWearableDurability; - - if ( armor != null ) + if ( armorItem is IWearableDurability armor ) damage = armor.OnHit( this, damage ); int virtualArmor = defender.VirtualArmor + defender.VirtualArmorMod; @@ -1300,9 +1265,7 @@ namespace Server.Items if ( attacker.Player || defender.Player ) return 0; - BaseCreature bc = attacker as BaseCreature; - - if ( bc == null || bc.PackInstinct == PackInstinct.None || (!bc.Controlled && !bc.Summoned) ) + if ( !(attacker is BaseCreature bc) || bc.PackInstinct == PackInstinct.None || (!bc.Controlled && !bc.Summoned) ) return 0; Mobile master = bc.ControlMaster; @@ -1336,11 +1299,11 @@ namespace Server.Items if ( inPack >= 5 ) return 100; - else if ( inPack >= 4 ) + if ( inPack >= 4 ) return 75; - else if ( inPack >= 3 ) + if ( inPack >= 3 ) return 50; - else if ( inPack >= 2 ) + if ( inPack >= 2 ) return 25; return 0; @@ -1354,12 +1317,7 @@ namespace Server.Items set{ m_InDoubleStrike = value; } } - public void OnHit( Mobile attacker, Mobile defender ) - { - OnHit( attacker, defender, 1.0 ); - } - - public virtual void OnHit( Mobile attacker, Mobile defender, double damageBonus ) + public virtual void OnHit( Mobile attacker, Mobile defender, double damageBonus = 1.0) { if ( MirrorImage.HasClone( defender ) && (defender.Skills.Ninjitsu.Value / 150.0) > Utility.RandomDouble() ) { @@ -1436,10 +1394,8 @@ namespace Server.Items } else if ( !defender.Player ) { - if ( attacker is PlayerMobile ) + if ( attacker is PlayerMobile pm ) { - PlayerMobile pm = (PlayerMobile)attacker; - if ( pm.WaitingForEnemy ) { pm.EnemyOfOneType = defender.GetType(); @@ -1469,16 +1425,14 @@ namespace Server.Items 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 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 ) ) { percentageBonus += 25; @@ -1490,9 +1444,7 @@ namespace Server.Items } } - BaseTalisman talisman = attacker.Talisman as BaseTalisman; - - if ( talisman != null && talisman.Killer != null ) + if ( attacker.Talisman is BaseTalisman talisman && talisman.Killer != null ) percentageBonus += talisman.Killer.DamageBonus( defender ); percentageBonus = Math.Min( percentageBonus, 300 ); @@ -1647,8 +1599,8 @@ namespace Server.Items { --MaxHitPoints; - if ( Parent is Mobile ) - ((Mobile)Parent).LocalOverheadMessage( MessageType.Regular, 0x3B2, 1061121 ); // Your equipment is severely damaged. + if ( Parent is Mobile mobile ) + mobile.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1061121 ); // Your equipment is severely damaged. } else { @@ -1763,8 +1715,8 @@ namespace Server.Items TransformContext context = TransformationSpellHelper.GetContext( attacker ); - if ( context != null && context.Spell is ReaperFormSpell ) - damageBonus += ((ReaperFormSpell)context.Spell).SpellDamageBonus; + if ( context?.Spell is ReaperFormSpell spell ) + damageBonus += spell.SpellDamageBonus; } damage = AOS.Scale( damage, 100 + damageBonus ); @@ -1841,8 +1793,8 @@ namespace Server.Items { bool dispellable = false; - if ( defender is BaseCreature ) - dispellable = ((BaseCreature)defender).Summoned && !((BaseCreature)defender).IsAnimatedDead; + if ( defender is BaseCreature creature ) + dispellable = creature.Summoned && !creature.IsAnimatedDead; if ( !dispellable ) return; @@ -1944,9 +1896,7 @@ namespace Server.Items if ( atkSlayer != null && atkSlayer.Slays( defender ) || atkSlayer2 != null && atkSlayer2.Slays( defender ) ) return CheckSlayerResult.Slayer; - BaseTalisman talisman = attacker.Talisman as BaseTalisman; - - if ( talisman != null && TalismanSlayer.Slays( talisman.Slayer, defender ) ) + if ( attacker.Talisman is BaseTalisman talisman && TalismanSlayer.Slays( talisman.Slayer, defender ) ) return CheckSlayerResult.Slayer; 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 ) { - if ( wielder is BaseCreature ) + if ( wielder is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)wielder; - phys = bc.PhysicalDamage; fire = bc.FireDamage; cold = bc.ColdDamage; @@ -2012,25 +1960,20 @@ namespace Server.Items 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 ) - { - int left = phys; + left = ApplyCraftAttributeElementDamage( attrInfo.WeaponColdDamage, ref cold, 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 ); - left = ApplyCraftAttributeElementDamage( attrInfo.WeaponColdDamage, ref cold, 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; - } + phys = left; } } } @@ -2064,24 +2007,22 @@ namespace Server.Items WeaponAbility ability = WeaponAbility.GetCurrentAbility( attacker ); - if ( ability != null ) - ability.OnMiss( attacker, defender ); + ability?.OnMiss( attacker, defender ); SpecialMove move = SpecialMove.GetCurrentMove( attacker ); - if ( move != null ) - move.OnMiss( attacker, defender ); + move?.OnMiss( attacker, defender ); - if ( defender is IHonorTarget && ((IHonorTarget)defender).ReceivedHonorContext != null ) - ((IHonorTarget)defender).ReceivedHonorContext.OnTargetMissed( attacker ); + if ( defender is IHonorTarget target ) + { + target.ReceivedHonorContext?.OnTargetMissed( attacker ); + } } 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 ) { min = c.DamageMin; @@ -2089,10 +2030,10 @@ namespace Server.Items return; } - if ( this is Fists && !attacker.Body.IsHuman ) + if ( this is Fists && !c.Body.IsHuman ) { - min = attacker.Str / 28; - max = attacker.Str / 28; + min = c.Str / 28; + max = c.Str / 28; return; } } @@ -2103,9 +2044,7 @@ namespace Server.Items public virtual double GetBaseDamage( Mobile attacker ) { - int min, max; - - GetBaseDamageRange( attacker, out min, out max ); + GetBaseDamageRange( attacker, out int min, out int 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 ) { - int baseMin, baseMax; - - GetBaseDamageRange( from, out baseMin, out baseMax ); + GetBaseDamageRange( from, out int baseMin, out int baseMax ); if ( Core.AOS ) { @@ -2474,7 +2411,7 @@ namespace Server.Items SetSaveFlag( ref flags, SaveFlag.Poison, m_Poison != null ); SetSaveFlag( ref flags, SaveFlag.PoisonCharges, m_PoisonCharges != 0 ); 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.DexReq, m_DexReq != -1 ); SetSaveFlag( ref flags, SaveFlag.IntReq, m_IntReq != -1 ); @@ -2629,6 +2566,8 @@ namespace Server.Items int version = reader.ReadInt(); + Mobile parentMobile = Parent as Mobile; + switch ( version ) { case 9: @@ -2769,19 +2708,19 @@ namespace Server.Items else 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 ); - ((Mobile)Parent).AddSkillMod( m_SkillMod ); + parentMobile.AddSkillMod( m_SkillMod ); } if ( version < 7 && m_AosWeaponAttributes.MageWeapon != 0 ) 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 ); - ((Mobile)Parent).AddSkillMod( m_MageMod ); + parentMobile.AddSkillMod( m_MageMod ); } if ( GetSaveFlag( flags, SaveFlag.PlayerConstructed ) ) @@ -2902,41 +2841,38 @@ namespace Server.Items if ( m_Animation == OldAnimation ) 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); - ((Mobile)Parent).AddSkillMod( m_SkillMod ); + parentMobile.AddSkillMod( m_SkillMod ); } break; } } - if ( Core.AOS && Parent is Mobile ) - m_AosSkillBonuses.AddTo( (Mobile)Parent ); + if ( Core.AOS && parentMobile != null ) + m_AosSkillBonuses.AddTo( parentMobile ); int strBonus = m_AosAttributes.BonusStr; int dexBonus = m_AosAttributes.BonusDex; 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(); 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 ) - 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 ) - 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 ) - ((Mobile)Parent).CheckStatTimers(); + parentMobile?.CheckStatTimers(); if ( m_Hits <= 0 && m_MaxHits <= 0 ) { @@ -2999,8 +2935,7 @@ namespace Server.Items public int GetElementalDamageHue() { - int phys, fire, cold, pois, nrgy, chaos, direct; - GetDamageTypes( null, out phys, out fire, out cold, out pois, out nrgy, out chaos, out direct ); + GetDamageTypes( null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct ); //Order is Cold, Energy, Fire, Poison, Physical left int currentMax = 50; @@ -3027,7 +2962,6 @@ namespace Server.Items if ( cold >= currentMax ) { hue = 1261 + (cold - 50) / 10; - currentMax = cold; } return hue; @@ -3102,10 +3036,7 @@ namespace Server.Items { CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource ); - if ( resInfo == null ) - return 0; - - CraftAttributeInfo attrInfo = resInfo.AttributeInfo; + CraftAttributeInfo attrInfo = resInfo?.AttributeInfo; if ( attrInfo == null ) return 0; @@ -3125,8 +3056,7 @@ namespace Server.Items list.Add( 1041350 ); // faction item #endregion - if ( m_AosSkillBonuses != null ) - m_AosSkillBonuses.GetProperties( list ); + m_AosSkillBonuses?.GetProperties( list ); if ( m_Quality == WeaponQuality.Exceptional ) list.Add( 1060636 ); // exceptional @@ -3137,8 +3067,8 @@ namespace Server.Items if ( ArtifactRarity > 0 ) list.Add( 1061078, ArtifactRarity.ToString() ); // artifact rarity ~1_val~ - if ( this is IUsesRemaining && ((IUsesRemaining)this).ShowUsesRemaining ) - list.Add( 1060584, ((IUsesRemaining)this).UsesRemaining.ToString() ); // uses remaining: ~1_val~ + if ( this is IUsesRemaining usesRemaining && usesRemaining.ShowUsesRemaining ) + list.Add( 1060584, usesRemaining.UsesRemaining.ToString() ); // uses remaining: ~1_val~ if ( m_Poison != null && m_PoisonCharges > 0 ) list.Add( 1062412 + m_Poison.Level, m_PoisonCharges.ToString() ); @@ -3162,7 +3092,9 @@ namespace Server.Items 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 if ( (prop = m_AosWeaponAttributes.UseBestSkill) != 0 ) @@ -3234,7 +3166,7 @@ namespace Server.Items if ( ImmolatingWeaponSpell.IsImmolating( this ) ) 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~% if ( (prop = m_AosAttributes.BonusDex) != 0 ) @@ -3300,9 +3232,7 @@ namespace Server.Items if ( Core.ML && (prop = m_AosAttributes.IncreasedKarmaLoss) != 0 ) list.Add( 1075210, prop.ToString() ); // Increased Karma Loss ~1val~% - int phys, fire, cold, pois, nrgy, chaos, direct; - - GetDamageTypes( null, out phys, out fire, out cold, out pois, out nrgy, out chaos, out direct ); + GetDamageTypes( null, out int phys, out int fire, out int cold, out int pois, out int nrgy, out int chaos, out int direct ); if ( phys != 0 ) list.Add( 1060403, phys.ToString() ); // physical damage ~1_val~% @@ -3464,8 +3394,8 @@ namespace Server.Items if ( context != null && context.DoNotColor ) Hue = 0; - if ( tool is BaseRunicTool ) - ((BaseRunicTool)tool).ApplyAttributesTo( this ); + if ( tool is BaseRunicTool runicTool ) + runicTool.ApplyAttributesTo( this ); 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 ); - if ( thisResource == ((BaseRunicTool)tool).Resource ) + if ( thisResource == runicTool.Resource ) { Resource = thisResource; diff --git a/Scripts/Items/Weapons/Knives/BaseKnife.cs b/Scripts/Items/Weapons/Knives/BaseKnife.cs index b992e9f82..23b4c7fc7 100644 --- a/Scripts/Items/Weapons/Knives/BaseKnife.cs +++ b/Scripts/Items/Weapons/Knives/BaseKnife.cs @@ -43,7 +43,7 @@ namespace Server.Items 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 ); diff --git a/Scripts/Items/Weapons/Knives/ThrowingDagger.cs b/Scripts/Items/Weapons/Knives/ThrowingDagger.cs index 8009980d3..78d153248 100644 --- a/Scripts/Items/Weapons/Knives/ThrowingDagger.cs +++ b/Scripts/Items/Weapons/Knives/ThrowingDagger.cs @@ -65,14 +65,13 @@ namespace Server.Items { 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." ); } - else if ( targeted is Mobile ) + else if ( targeted is Mobile m ) { - Mobile m = (Mobile)targeted; - if ( m != from && from.HarmfulCheck( m ) ) { Direction to = from.GetDirectionTo( m ); @@ -122,4 +121,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/Maces/BaseBashing.cs b/Scripts/Items/Weapons/Maces/BaseBashing.cs index f4b76cc01..3aee40dc8 100644 --- a/Scripts/Items/Weapons/Maces/BaseBashing.cs +++ b/Scripts/Items/Weapons/Maces/BaseBashing.cs @@ -35,7 +35,7 @@ namespace Server.Items 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 ); diff --git a/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs b/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs index 1dee40ac6..61bd5055a 100644 --- a/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs +++ b/Scripts/Items/Weapons/PoleArms/BasePoleArm.cs @@ -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 ); diff --git a/Scripts/Items/Weapons/Ranged/BaseRanged.cs b/Scripts/Items/Weapons/Ranged/BaseRanged.cs index 323e9e8ec..2aec481ad 100644 --- a/Scripts/Items/Weapons/Ranged/BaseRanged.cs +++ b/Scripts/Items/Weapons/Ranged/BaseRanged.cs @@ -49,7 +49,7 @@ namespace Server.Items 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 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 ) { - Spell sp = attacker.Spell as Spell; - - canSwing = ( sp == null || !sp.IsCasting || !sp.BlocksMovement ); + canSwing = ( !(attacker.Spell is Spell sp) || !sp.IsCasting || !sp.BlocksMovement ); } } #region Dueling - if ( attacker is PlayerMobile ) + if ( attacker is PlayerMobile pm ) { - PlayerMobile pm = (PlayerMobile)attacker; - if ( pm.DuelContext != null && !pm.DuelContext.CheckItemEquip( attacker, this ) ) 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() ) defender.AddToBackpack( Ammo ); @@ -134,21 +130,19 @@ namespace Server.Items { if ( Core.SE ) { - PlayerMobile p = attacker as PlayerMobile; - - if ( p != null ) + if ( attacker is PlayerMobile pm ) { Type ammo = AmmoType; - if ( p.RecoverableAmmo.ContainsKey( ammo ) ) - p.RecoverableAmmo[ ammo ]++; + if ( pm.RecoverableAmmo.ContainsKey( ammo ) ) + pm.RecoverableAmmo[ ammo ]++; else - p.RecoverableAmmo.Add( ammo, 1 ); + pm.RecoverableAmmo.Add( ammo, 1 ); - if ( !p.Warmode ) + if ( !pm.Warmode ) { 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 ) m_RecoveryTimer.Start(); diff --git a/Scripts/Items/Weapons/Ranged/JukaBow.cs b/Scripts/Items/Weapons/Ranged/JukaBow.cs index 92fbf2b73..5df1d8bb8 100644 --- a/Scripts/Items/Weapons/Ranged/JukaBow.cs +++ b/Scripts/Items/Weapons/Ranged/JukaBow.cs @@ -47,9 +47,7 @@ namespace Server.Items public void OnTargetGears( Mobile from, object targ ) { - Gears g = targ as Gears; - - if ( g == null || !g.IsChildOf( from.Backpack ) ) + if ( !(targ is Gears g) || !g.IsChildOf( from.Backpack ) ) { from.SendMessage( "Those are not gears." ); // Apparently gears that aren't in your backpack aren't really gears at all. :-( } diff --git a/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs b/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs index 3c8d28eb6..819a9d2f7 100644 --- a/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs +++ b/Scripts/Items/Weapons/SpearsAndForks/BaseSpear.cs @@ -35,7 +35,7 @@ namespace Server.Items 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 ); diff --git a/Scripts/Items/Weapons/Staves/BaseStaff.cs b/Scripts/Items/Weapons/Staves/BaseStaff.cs index 225393708..c37827da9 100644 --- a/Scripts/Items/Weapons/Staves/BaseStaff.cs +++ b/Scripts/Items/Weapons/Staves/BaseStaff.cs @@ -35,7 +35,7 @@ namespace Server.Items 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 ); diff --git a/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs b/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs index fa6bb0124..7018b0bff 100644 --- a/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs +++ b/Scripts/Items/Weapons/Staves/ShepherdsCrook.cs @@ -68,10 +68,8 @@ namespace Server.Items 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 ( bc.Controlled ) @@ -114,9 +112,7 @@ namespace Server.Items Map map = bc.Map; - ChampionSpawnRegion region = Region.Find( bc.Home, map ) as ChampionSpawnRegion; - - if ( region != null ) + if ( Region.Find( bc.Home, map ) is ChampionSpawnRegion region ) { ChampionSpawn spawn = region.ChampionSpawn; @@ -144,7 +140,7 @@ namespace Server.Items protected override void OnTarget( Mobile from, object targ ) { - if ( targ is IPoint2D ) + if ( targ is IPoint2D p ) { double min = m_Creature.MinTameSkill - 30; 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 ) ) { - IPoint2D p = (IPoint2D) targ; - - if ( targ != from ) + if ( p != from ) p = new Point2D( p.X, p.Y ); m_Creature.TargetLocation = p; diff --git a/Scripts/Items/Weapons/Swords/BaseSword.cs b/Scripts/Items/Weapons/Swords/BaseSword.cs index 5513c739d..36ed4b07f 100644 --- a/Scripts/Items/Weapons/Swords/BaseSword.cs +++ b/Scripts/Items/Weapons/Swords/BaseSword.cs @@ -40,7 +40,7 @@ namespace Server.Items 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 ); diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs index cfb09813b..92d735b29 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs @@ -108,8 +108,7 @@ namespace Server.Mobiles public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Mobiles/Special/HarrowerTentacles.cs b/Scripts/Mobiles/Special/HarrowerTentacles.cs index 91284ea03..5e4b1f44a 100644 --- a/Scripts/Mobiles/Special/HarrowerTentacles.cs +++ b/Scripts/Mobiles/Special/HarrowerTentacles.cs @@ -151,8 +151,7 @@ namespace Server.Mobiles public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Multis/PreviewHouse.cs b/Scripts/Multis/PreviewHouse.cs index 89ad01342..94fbcb23e 100644 --- a/Scripts/Multis/PreviewHouse.cs +++ b/Scripts/Multis/PreviewHouse.cs @@ -86,8 +86,7 @@ namespace Server.Multis public override void OnAfterDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; @@ -142,4 +141,4 @@ namespace Server.Multis } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/Items/TransientItem.cs b/Scripts/Spells/Spellweaving/Items/TransientItem.cs index 3413da9b0..e9c0f7e1b 100644 --- a/Scripts/Spells/Spellweaving/Items/TransientItem.cs +++ b/Scripts/Spells/Spellweaving/Items/TransientItem.cs @@ -56,8 +56,7 @@ namespace Server.Items public override void OnDelete() { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); base.OnDelete(); } diff --git a/Server/Attributes.cs b/Server/Attributes.cs index d4ccca550..9eaeb25a6 100644 --- a/Server/Attributes.cs +++ b/Server/Attributes.cs @@ -102,15 +102,10 @@ namespace Server { object[] objs = mi.GetCustomAttributes( typeof( CallPriorityAttribute ), true ); - if ( objs == null ) - return 0; - if ( objs.Length == 0 ) return 0; - CallPriorityAttribute attr = objs[0] as CallPriorityAttribute; - - if ( attr == null ) + if ( !(objs[0] is CallPriorityAttribute attr) ) return 0; return attr.Priority; diff --git a/Server/Commands.cs b/Server/Commands.cs index 0565d5da5..e1afcf9ad 100644 --- a/Server/Commands.cs +++ b/Server/Commands.cs @@ -171,12 +171,10 @@ namespace Server.Commands { if ( obj == this ) return 0; - else if ( obj == null ) + if ( obj == null ) return 1; - CommandEntry e = obj as CommandEntry; - - if ( e == null ) + if ( !(obj is CommandEntry e) ) throw new ArgumentException(); return m_Command.CompareTo( e.m_Command ); @@ -204,7 +202,7 @@ namespace Server.Commands char[] array = value.ToCharArray(); List list = new List(); - int start = 0, end = 0; + int start = 0; while ( start < array.Length ) { @@ -213,7 +211,7 @@ namespace Server.Commands if ( c == '"' ) { ++start; - end = start; + int end = start; while ( end < array.Length ) { @@ -229,7 +227,7 @@ namespace Server.Commands } else if ( c != ' ' ) { - end = start; + int end = start; while ( end < array.Length ) { @@ -308,8 +306,7 @@ namespace Server.Commands args = new string[0]; } - CommandEntry entry = null; - m_Entries.TryGetValue( command, out entry ); + m_Entries.TryGetValue( command, out CommandEntry entry ); if ( entry != null ) { diff --git a/Server/Effects.cs b/Server/Effects.cs index 486277b87..0fc6e53a0 100644 --- a/Server/Effects.cs +++ b/Server/Effects.cs @@ -219,8 +219,8 @@ namespace Server public static void SendTargetEffect( IEntity target, int itemID, int speed, int duration, int hue, int renderMode ) { - if ( target is Mobile ) - ((Mobile)target).ProcessDelta(); + if ( target is Mobile mobile ) + mobile.ProcessDelta(); 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 ) { - if ( target is Mobile ) - ((Mobile)target).ProcessDelta(); + if ( target is Mobile mobile ) + mobile.ProcessDelta(); 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 ) { - if ( from is Mobile ) - ((Mobile)from).ProcessDelta(); + if ( from is Mobile mobile ) + mobile.ProcessDelta(); - if ( to is Mobile ) - ((Mobile)to).ProcessDelta(); + if ( to is Mobile mobile1 ) + mobile1.ProcessDelta(); 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 ) { - if ( from is Mobile ) - ((Mobile)from).ProcessDelta(); + if ( from is Mobile mobile ) + mobile.ProcessDelta(); - if ( to is Mobile ) - ((Mobile)to).ProcessDelta(); + if ( to is Mobile mobile1 ) + mobile1.ProcessDelta(); Map map = from.Map; @@ -382,4 +382,4 @@ namespace Server } } } -} \ No newline at end of file +} diff --git a/Server/Geometry.cs b/Server/Geometry.cs index c3cce6e59..2a0a29370 100644 --- a/Server/Geometry.cs +++ b/Server/Geometry.cs @@ -98,9 +98,9 @@ namespace Server public int CompareTo( object other ) { - if ( other is Point2D ) - return this.CompareTo( (Point2D) other ); - else if ( other == null ) + if ( other is Point2D d ) + return this.CompareTo( d ); + if ( other == null ) return -1; throw new ArgumentException(); @@ -108,7 +108,7 @@ namespace Server public override bool Equals( object o ) { - if ( o == null || !(o is IPoint2D) ) return false; + if ( !(o is IPoint2D) ) return false; IPoint2D p = (IPoint2D)o; @@ -291,7 +291,7 @@ namespace Server public override bool Equals( object o ) { - if ( o == null || !( o is IPoint3D ) ) + if ( !(o is IPoint3D) ) return false; IPoint3D p = (IPoint3D) o; @@ -367,9 +367,9 @@ namespace Server public int CompareTo( object other ) { - if ( other is Point3D ) - return this.CompareTo( (Point3D) other ); - else if ( other == null ) + if ( other is Point3D d ) + return this.CompareTo( d ); + if ( other == null ) return -1; throw new ArgumentException(); @@ -635,4 +635,4 @@ namespace Server && ( p.Z < m_End.m_Z ); } } -} \ No newline at end of file +} diff --git a/Server/Item.cs b/Server/Item.cs index 3e7662025..c3edd984c 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -1544,11 +1544,8 @@ namespace Server public virtual bool OnDragDrop( Mobile from, Item dropped ) { - bool success = false; - if ( Parent is Container ) - success = ((Container)Parent).OnStackAttempt( from, this, dropped ); - else - success = StackWith( from, dropped ); + bool success = Parent is Container container && container.OnStackAttempt( from, this, dropped ) || + StackWith( from, dropped ); if ( success && Spawner != null ) { diff --git a/Server/Mobile.cs b/Server/Mobile.cs index 5ec070852..014e792cb 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -2620,7 +2620,7 @@ namespace Server 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 ) { - 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) { - m_Callback?.Invoke(@from, targeted, m_State); + m_Callback?.Invoke(from, targeted, m_State); } } public Target BeginTarget(int range, bool allowGround, TargetFlags flags, TargetStateCallback 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 ); return null; } + item.Visible = oldItem.Visible; item.Movable = oldItem.Movable; item.LootType = oldItem.LootType; @@ -4376,13 +4377,13 @@ namespace Server oldItem.Amount = amount; 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 ); @@ -4581,8 +4582,8 @@ namespace Server if (item.HandlesOnSpeech) list.Add( item ); - if (item is Container) - AddSpeechItemsFrom(list, (Container)item); + if (item is Container container) + AddSpeechItemsFrom(list, container); } } @@ -6543,14 +6544,10 @@ namespace Server IPooledEnumerable eable = m_Map.GetObjectsInRange( m_Location, Core.GlobalMaxUpdateRange ); foreach ( IEntity o in eable ) { - if ( o is Mobile ) { - Mobile m = (Mobile)o; - + if ( o is Mobile m ) { if ( m != this && Utility.InUpdateRange( m_Location, m.m_Location ) ) ns.Send( m.RemovePacket ); - } else if ( o is Item ) { - Item item = (Item)o; - + } else if ( o is Item item ) { if ( InRange( item.Location, item.GetUpdateRange( this ) ) ) ns.Send( item.RemovePacket ); } @@ -6583,14 +6580,17 @@ namespace Server } public bool SendHuePicker( HuePicker p, bool throwOnOffline ) { - if ( m_NetState != null ) { - p.SendTo( m_NetState ); + if (m_NetState != null) + { + p.SendTo(m_NetState); 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 ) { @@ -6598,7 +6598,7 @@ namespace Server if ( ns != null ) { foreach ( Gump gump in ns.Gumps ) { - if ( type.IsAssignableFrom( gump.GetType() ) ) { + if ( type.IsInstanceOfType( gump ) ) { return gump; } } @@ -10108,9 +10108,7 @@ namespace Server if ( sendStam || sendMana ) { - IParty ip = m_Party as IParty; - - if (ip != null) + if (m_Party is IParty ip) { if ( sendStam ) ip.OnStamChanged( this );