From aba94521612d8d05d0ff606a95130a16f32dcd26 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 6 Sep 2018 18:07:42 -0700 Subject: [PATCH] More cast conversion fixes --- Scripts/Context Menus/EjectPlayer.cs | 10 +- Scripts/Items/Jewels/BaseJewel.cs | 10 +- Scripts/Items/Maps/TreasureMap.cs | 2 +- Scripts/Items/Misc/BankCheck.cs | 2 +- Scripts/Items/Misc/Corpses/Corpse.cs | 4 +- Scripts/Items/Misc/Moonstone.cs | 2 +- Scripts/Items/Misc/PromotionalToken.cs | 2 +- Scripts/Items/Misc/TribalPaint.cs | 2 +- Scripts/Items/Resources/Blacksmithing/Ore.cs | 20 ++- Scripts/Items/Resources/Tailor/Cotton.cs | 12 +- Scripts/Items/Resources/Tailor/Flax.cs | 12 +- Scripts/Items/Resources/Tailor/Wool.cs | 19 +-- .../Items/Resources/Tailor/YarnsAndThreads.cs | 10 +- Scripts/Items/Shields/BaseShield.cs | 100 ++++++------- Scripts/Items/Shields/ChaosShield.cs | 4 +- Scripts/Items/Shields/OrderShield.cs | 4 +- Scripts/Items/Skill Items/Camping/Campfire.cs | 4 +- .../Carpenter Items/TaxidermyKit.cs | 24 ++- .../Fishing/Misc/SpecialFishingNet.cs | 6 +- .../Harvest Tools/BaseHarvestTool.cs | 6 +- .../Skill Items/Magical/Misc/Moongate.cs | 8 +- .../Skill Items/Magical/Misc/PotionKeg.cs | 137 +++++++++--------- .../Skill Items/Magical/Potions/BasePotion.cs | 14 +- .../BaseConflagrationPotion.cs | 34 ++--- .../BaseConfusionBlastPotion.cs | 38 ++--- .../Explosion Potions/BaseExplosionPotion.cs | 48 +++--- .../Magical/Potions/InvisibilityPotion.cs | 8 +- Scripts/Items/Skill Items/Magical/Runebook.cs | 31 ++-- .../Items/Skill Items/Magical/Spellbook.cs | 89 +++++------- Scripts/Items/Skill Items/Misc/Bandage.cs | 25 ++-- Scripts/Items/Skill Items/Misc/FireHorn.cs | 4 +- .../Items/Skill Items/Misc/RecipeScroll.cs | 6 +- .../Musical Instruments/BaseInstrument.cs | 11 +- .../Skill Items/Ninjitsu/NinjaWeapons.cs | 6 +- .../Tailor Items/Dyetubs/DyeTub.cs | 10 +- .../Skill Items/Tailor Items/Misc/Dyes.cs | 8 +- .../Skill Items/Tailor Items/Misc/Scissors.cs | 16 +- .../Items/Skill Items/Thief/DisguiseKit.cs | 10 +- Scripts/Items/Skill Items/Thief/LockPick.cs | 14 +- .../Items/Skill Items/Tinkering/Spyglass.cs | 13 +- .../Dawn's Music Box/DawnsMusicBox.cs | 4 +- .../Dawn's Music Box/DawnsMusicGear.cs | 14 +- .../8th Anniversary Items/FountainOfLife.cs | 4 +- .../8th Anniversary Items/Talismans.cs | 10 +- .../Blacksmithy/AncientSmithyHammer.cs | 24 ++- .../Blacksmithy/GlovesOfMining.cs | 24 ++- 46 files changed, 359 insertions(+), 506 deletions(-) diff --git a/Scripts/Context Menus/EjectPlayer.cs b/Scripts/Context Menus/EjectPlayer.cs index bcbaec098..452331c8f 100644 --- a/Scripts/Context Menus/EjectPlayer.cs +++ b/Scripts/Context Menus/EjectPlayer.cs @@ -9,7 +9,7 @@ namespace Server.ContextMenus private Mobile m_From; private Mobile m_Target; private BaseHouse m_TargetHouse; - + public EjectPlayerEntry( Mobile from, Mobile target ) : base( 6206, 12 ) { m_From = from; @@ -18,14 +18,12 @@ namespace Server.ContextMenus } public override void OnClick() - { + { if ( !m_From.Alive || m_TargetHouse.Deleted || !m_TargetHouse.IsFriend( m_From ) ) return; - if ( m_Target is Mobile ) - { - m_TargetHouse.Kick( m_From, (Mobile)m_Target ); - } + if ( m_Target is Mobile mobile ) + m_TargetHouse.Kick( m_From, mobile ); } } } diff --git a/Scripts/Items/Jewels/BaseJewel.cs b/Scripts/Items/Jewels/BaseJewel.cs index a8da930df..96a2b9bc5 100644 --- a/Scripts/Items/Jewels/BaseJewel.cs +++ b/Scripts/Items/Jewels/BaseJewel.cs @@ -169,17 +169,17 @@ namespace Server.Items public override void OnRemoved(IEntity parent) { - if ( Core.AOS && parent is Mobile @from ) + if ( Core.AOS && parent is Mobile from ) { m_AosSkillBonuses.Remove(); string modName = this.Serial.ToString(); - @from.RemoveStatMod( modName + "Str" ); - @from.RemoveStatMod( modName + "Dex" ); - @from.RemoveStatMod( modName + "Int" ); + from.RemoveStatMod( modName + "Str" ); + from.RemoveStatMod( modName + "Dex" ); + from.RemoveStatMod( modName + "Int" ); - @from.CheckStatTimers(); + from.CheckStatTimers(); } } diff --git a/Scripts/Items/Maps/TreasureMap.cs b/Scripts/Items/Maps/TreasureMap.cs index f9c862580..fae4e6f38 100644 --- a/Scripts/Items/Maps/TreasureMap.cs +++ b/Scripts/Items/Maps/TreasureMap.cs @@ -617,7 +617,7 @@ namespace Server.Items if ( from.AccessLevel >= AccessLevel.GameMaster ) return true; - if ( @from is PlayerMobile mobile && mobile.Young ) + if ( from is PlayerMobile mobile && mobile.Young ) return true; if ( from == this.Decoder ) diff --git a/Scripts/Items/Misc/BankCheck.cs b/Scripts/Items/Misc/BankCheck.cs index 26f4f8635..589866e7a 100644 --- a/Scripts/Items/Misc/BankCheck.cs +++ b/Scripts/Items/Misc/BankCheck.cs @@ -233,7 +233,7 @@ namespace Server.Items // Gold was deposited in your account: from.SendLocalizedMessage(1042672, true, deposited.ToString("#,0")); - if (@from is PlayerMobile pm) + if (from is PlayerMobile pm) { var qs = pm.Quest; diff --git a/Scripts/Items/Misc/Corpses/Corpse.cs b/Scripts/Items/Misc/Corpses/Corpse.cs index 2d6173456..ad909381f 100644 --- a/Scripts/Items/Misc/Corpses/Corpse.cs +++ b/Scripts/Items/Misc/Corpses/Corpse.cs @@ -1021,7 +1021,7 @@ namespace Server.Items #region Self Looting if ( checkSelfLoot && from == m_Owner && !GetFlag( CorpseFlag.SelfLooted ) && this.Items.Count != 0 ) { - if ( @from.FindItemOnLayer( Layer.OuterTorso ) is DeathRobe robe ) + if ( from.FindItemOnLayer( Layer.OuterTorso ) is DeathRobe robe ) { Map map = from.Map; @@ -1104,7 +1104,7 @@ namespace Server.Items #region Quests - if ( @from is PlayerMobile player ) + if ( from is PlayerMobile player ) { QuestSystem qs = player.Quest; diff --git a/Scripts/Items/Misc/Moonstone.cs b/Scripts/Items/Misc/Moonstone.cs index 0813381b1..05c6b9c2d 100644 --- a/Scripts/Items/Misc/Moonstone.cs +++ b/Scripts/Items/Misc/Moonstone.cs @@ -75,7 +75,7 @@ namespace Server.Items { from.SendLocalizedMessage( 1005401 ); // You cannot bury the stone here. } - else if ( @from is PlayerMobile mobile && mobile.Young ) + else if ( from is PlayerMobile mobile && mobile.Young ) { mobile.SendLocalizedMessage( 1049543 ); // You decide against traveling to Felucca while you are still young. } diff --git a/Scripts/Items/Misc/PromotionalToken.cs b/Scripts/Items/Misc/PromotionalToken.cs index 3f9e64a16..523cb1d23 100644 --- a/Scripts/Items/Misc/PromotionalToken.cs +++ b/Scripts/Items/Misc/PromotionalToken.cs @@ -122,7 +122,7 @@ namespace Server.Items public override Item CreateItemFor( Mobile from ) { - if ( @from?.Account != null ) + if ( from?.Account != null ) return new SoulstoneFragment( from.Account.ToString() ); return null; diff --git a/Scripts/Items/Misc/TribalPaint.cs b/Scripts/Items/Misc/TribalPaint.cs index 7eaec7122..806d8429d 100644 --- a/Scripts/Items/Misc/TribalPaint.cs +++ b/Scripts/Items/Misc/TribalPaint.cs @@ -54,7 +54,7 @@ namespace Server.Items from.BodyMod = ( from.Female ? 184 : 183 ); from.HueMod = 0; - if ( @from is PlayerMobile mobile ) + if ( from is PlayerMobile mobile ) mobile.SavagePaintExpiration = TimeSpan.FromDays( 7.0 ); from.SendLocalizedMessage( 1042537 ); // You now bear the markings of the savage tribe. Your body paint will last about a week or you can remove it with an oil cloth. diff --git a/Scripts/Items/Resources/Blacksmithing/Ore.cs b/Scripts/Items/Resources/Blacksmithing/Ore.cs index 9de23f477..2f72e9c46 100644 --- a/Scripts/Items/Resources/Blacksmithing/Ore.cs +++ b/Scripts/Items/Resources/Blacksmithing/Ore.cs @@ -166,7 +166,7 @@ namespace Server.Items private bool IsForge( object obj ) { - if ( Core.ML && obj is Mobile && ((Mobile)obj).IsDeadBondedPet ) + if ( Core.ML && obj is Mobile mobile && mobile.IsDeadBondedPet ) return false; if ( obj.GetType().IsDefined( typeof( ForgeAttribute ), false ) ) @@ -174,10 +174,10 @@ namespace Server.Items int itemID = 0; - if ( obj is Item ) - itemID = ((Item)obj).ItemID; - else if ( obj is StaticTarget ) - itemID = ((StaticTarget)obj).ItemID; + if ( obj is Item item ) + itemID = item.ItemID; + else if ( obj is StaticTarget target ) + itemID = target.ItemID; return ( itemID == 4017 || (itemID >= 6522 && itemID <= 6569) ); } @@ -194,21 +194,19 @@ namespace Server.Items } #region Combine Ore - if ( targeted is BaseOre ) + if ( targeted is BaseOre ore ) { - BaseOre ore = (BaseOre)targeted; - if ( !ore.Movable ) { return; } - else if ( m_Ore == ore ) + if ( m_Ore == ore ) { from.SendLocalizedMessage( 501972 ); // Select another pile or ore with which to combine this. from.Target = new InternalTarget( ore ); return; } - else if ( ore.Resource != m_Ore.Resource ) + if ( ore.Resource != m_Ore.Resource ) { from.SendLocalizedMessage( 501979 ); // You cannot combine ores of different metals. return; @@ -259,7 +257,7 @@ namespace Server.Items from.SendLocalizedMessage( 1062844 ); // There is too much ore to combine. return; } - else if ( ore.RootParent is Mobile && ( plusWeight + ((Mobile)ore.RootParent).Backpack.TotalWeight ) > ((Mobile)ore.RootParent).Backpack.MaxWeight ) + if ( ore.RootParent is Mobile mobile && ( plusWeight + mobile.Backpack.TotalWeight ) > mobile.Backpack.MaxWeight ) { from.SendLocalizedMessage( 501978 ); // The weight is too great to combine in a container. return; diff --git a/Scripts/Items/Resources/Tailor/Cotton.cs b/Scripts/Items/Resources/Tailor/Cotton.cs index 2e96d5999..006b82662 100644 --- a/Scripts/Items/Resources/Tailor/Cotton.cs +++ b/Scripts/Items/Resources/Tailor/Cotton.cs @@ -59,7 +59,7 @@ namespace Server.Items } } - public static void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) + public virtual void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) { Item item = new SpoolOfThread( 6 ); item.Hue = hue; @@ -84,13 +84,11 @@ namespace Server.Items ISpinningWheel wheel = targeted as ISpinningWheel; - if ( wheel == null && targeted is AddonComponent ) - wheel = ((AddonComponent)targeted).Addon as ISpinningWheel; + if ( wheel == null && targeted is AddonComponent component ) + wheel = component.Addon as ISpinningWheel; if ( wheel is Item ) { - Item item = (Item)wheel; - if ( !m_Cotton.IsChildOf( from.Backpack ) ) { from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it. @@ -102,7 +100,7 @@ namespace Server.Items else { m_Cotton.Consume(); - wheel.BeginSpin( new SpinCallback( Cotton.OnSpun ), from, m_Cotton.Hue ); + wheel.BeginSpin( m_Cotton.OnSpun, from, m_Cotton.Hue ); } } else @@ -112,4 +110,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Resources/Tailor/Flax.cs b/Scripts/Items/Resources/Tailor/Flax.cs index a329ebb06..719403228 100644 --- a/Scripts/Items/Resources/Tailor/Flax.cs +++ b/Scripts/Items/Resources/Tailor/Flax.cs @@ -49,7 +49,7 @@ namespace Server.Items } } - public static void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) + public virtual void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) { Item item = new SpoolOfThread( 6 ); item.Hue = hue; @@ -74,13 +74,11 @@ namespace Server.Items ISpinningWheel wheel = targeted as ISpinningWheel; - if ( wheel == null && targeted is AddonComponent ) - wheel = ((AddonComponent)targeted).Addon as ISpinningWheel; + if ( wheel == null && targeted is AddonComponent component ) + wheel = component.Addon as ISpinningWheel; if ( wheel is Item ) { - Item item = (Item)wheel; - if ( !m_Flax.IsChildOf( from.Backpack ) ) { from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it. @@ -92,7 +90,7 @@ namespace Server.Items else { m_Flax.Consume(); - wheel.BeginSpin( new SpinCallback( Flax.OnSpun ), from, m_Flax.Hue ); + wheel.BeginSpin( m_Flax.OnSpun, from, m_Flax.Hue ); } } else @@ -102,4 +100,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Resources/Tailor/Wool.cs b/Scripts/Items/Resources/Tailor/Wool.cs index e55b7cb91..8ba59d7ef 100644 --- a/Scripts/Items/Resources/Tailor/Wool.cs +++ b/Scripts/Items/Resources/Tailor/Wool.cs @@ -59,7 +59,7 @@ namespace Server.Items } } - public static void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) + public virtual void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) { Item item = new DarkYarn( 3 ); item.Hue = hue; @@ -84,13 +84,11 @@ namespace Server.Items ISpinningWheel wheel = targeted as ISpinningWheel; - if ( wheel == null && targeted is AddonComponent ) - wheel = ((AddonComponent)targeted).Addon as ISpinningWheel; + if ( wheel == null && targeted is AddonComponent component ) + wheel = component.Addon as ISpinningWheel; if ( wheel is Item ) { - Item item = (Item)wheel; - if ( !m_Wool.IsChildOf( from.Backpack ) ) { from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it. @@ -102,8 +100,7 @@ namespace Server.Items else { m_Wool.Consume(); - if ( m_Wool is TaintedWool ) wheel.BeginSpin( new SpinCallback( TaintedWool.OnSpun ), from, m_Wool.Hue ); - else wheel.BeginSpin( new SpinCallback( Wool.OnSpun ), from, m_Wool.Hue ); + wheel.BeginSpin( m_Wool.OnSpun, from, m_Wool.Hue ); } } else @@ -119,7 +116,7 @@ namespace Server.Items public TaintedWool() : this( 1 ) { } - + [Constructible] public TaintedWool( int amount ) : base( 0x101F ) { @@ -145,8 +142,8 @@ namespace Server.Items int version = reader.ReadInt(); } - - new public static void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) + + public override void OnSpun( ISpinningWheel wheel, Mobile from, int hue ) { Item item = new DarkYarn( 1 ); item.Hue = hue; @@ -155,4 +152,4 @@ namespace Server.Items from.SendLocalizedMessage( 1010574 ); // You put a ball of yarn in your backpack. } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Resources/Tailor/YarnsAndThreads.cs b/Scripts/Items/Resources/Tailor/YarnsAndThreads.cs index 36a418b5c..52ba4625d 100644 --- a/Scripts/Items/Resources/Tailor/YarnsAndThreads.cs +++ b/Scripts/Items/Resources/Tailor/YarnsAndThreads.cs @@ -74,8 +74,8 @@ namespace Server.Items ILoom loom = targeted as ILoom; - if ( loom == null && targeted is AddonComponent ) - loom = ((AddonComponent)targeted).Addon as ILoom; + if ( loom == null && targeted is AddonComponent component ) + loom = component.Addon as ILoom; if ( loom != null ) { @@ -87,8 +87,8 @@ namespace Server.Items { m_Material.Consume(); - if ( targeted is Item ) - ((Item)targeted).SendLocalizedMessageTo( from, 1010001 + loom.Phase++ ); + if ( targeted is Item item ) + item.SendLocalizedMessageTo( from, 1010001 + loom.Phase++ ); } else { @@ -232,4 +232,4 @@ namespace Server.Items int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Shields/BaseShield.cs b/Scripts/Items/Shields/BaseShield.cs index 2c9047d1a..b026b829f 100644 --- a/Scripts/Items/Shields/BaseShield.cs +++ b/Scripts/Items/Shields/BaseShield.cs @@ -100,8 +100,8 @@ namespace Server.Items { MaxHitPoints -= wear; - 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 { @@ -113,73 +113,69 @@ namespace Server.Items return 0; } - else + + if ( !(Parent is Mobile owner) ) + return damage; + + double ar = this.ArmorRating; + double chance = (owner.Skills[SkillName.Parry].Value - (ar * 2.0)) / 100.0; + + if ( chance < 0.01 ) + chance = 0.01; + /* + FORMULA: Displayed AR = ((Parrying Skill * Base AR of Shield) � 200) + 1 + + FORMULA: % Chance of Blocking = parry skill - (shieldAR * 2) + + FORMULA: Melee Damage Absorbed = (AR of Shield) / 2 | Archery Damage Absorbed = AR of Shield + */ + if ( owner.CheckSkill( SkillName.Parry, chance ) ) { - Mobile owner = this.Parent as Mobile; - if ( owner == null ) - return damage; + if ( weapon.Skill == SkillName.Archery ) + damage -= (int)ar; + else + damage -= (int)(ar / 2.0); - double ar = this.ArmorRating; - double chance = (owner.Skills[SkillName.Parry].Value - (ar * 2.0)) / 100.0; + if ( damage < 0 ) + damage = 0; - if ( chance < 0.01 ) - chance = 0.01; - /* - FORMULA: Displayed AR = ((Parrying Skill * Base AR of Shield) � 200) + 1 + owner.FixedEffect( 0x37B9, 10, 16 ); - FORMULA: % Chance of Blocking = parry skill - (shieldAR * 2) - - FORMULA: Melee Damage Absorbed = (AR of Shield) / 2 | Archery Damage Absorbed = AR of Shield - */ - if ( owner.CheckSkill( SkillName.Parry, chance ) ) + if ( 25 > Utility.Random( 100 ) ) // 25% chance to lower durability { - if ( weapon.Skill == SkillName.Archery ) - damage -= (int)ar; - else - damage -= (int)(ar / 2.0); + int wear = Utility.Random( 2 ); - if ( damage < 0 ) - damage = 0; - - owner.FixedEffect( 0x37B9, 10, 16 ); - - if ( 25 > Utility.Random( 100 ) ) // 25% chance to lower durability + if ( wear > 0 && MaxHitPoints > 0 ) { - int wear = Utility.Random( 2 ); - - if ( wear > 0 && MaxHitPoints > 0 ) + if ( HitPoints >= wear ) { - if ( HitPoints >= wear ) + HitPoints -= wear; + wear = 0; + } + else + { + wear -= HitPoints; + HitPoints = 0; + } + + if ( wear > 0 ) + { + if ( MaxHitPoints > wear ) { - HitPoints -= wear; - wear = 0; + MaxHitPoints -= wear; + + ((Mobile)Parent).LocalOverheadMessage( MessageType.Regular, 0x3B2, 1061121 ); // Your equipment is severely damaged. } else { - wear -= HitPoints; - HitPoints = 0; - } - - if ( wear > 0 ) - { - if ( MaxHitPoints > wear ) - { - MaxHitPoints -= wear; - - if ( Parent is Mobile ) - ((Mobile)Parent).LocalOverheadMessage( MessageType.Regular, 0x3B2, 1061121 ); // Your equipment is severely damaged. - } - else - { - Delete(); - } + Delete(); } } } } - - return damage; } + + return damage; } } } diff --git a/Scripts/Items/Shields/ChaosShield.cs b/Scripts/Items/Shields/ChaosShield.cs index b36cfd1ce..a8abbdb87 100644 --- a/Scripts/Items/Shields/ChaosShield.cs +++ b/Scripts/Items/Shields/ChaosShield.cs @@ -62,9 +62,7 @@ namespace Server.Items if ( m == null || !m.Player || m.AccessLevel != AccessLevel.Player || Core.AOS ) return true; - Guild g = m.Guild as Guild; - - if ( g == null || g.Type != GuildType.Chaos ) + if ( !(m.Guild is Guild g) || g.Type != GuildType.Chaos ) { m.FixedEffect( 0x3728, 10, 13 ); Delete(); diff --git a/Scripts/Items/Shields/OrderShield.cs b/Scripts/Items/Shields/OrderShield.cs index ce675d04f..2c626a1aa 100644 --- a/Scripts/Items/Shields/OrderShield.cs +++ b/Scripts/Items/Shields/OrderShield.cs @@ -65,9 +65,7 @@ namespace Server.Items if ( Core.AOS || m == null || !m.Player || m.AccessLevel != AccessLevel.Player ) return true; - Guild g = m.Guild as Guild; - - if ( g == null || g.Type != GuildType.Order ) + if ( !(m.Guild is Guild g) || g.Type != GuildType.Order ) { m.FixedEffect( 0x3728, 10, 13 ); Delete(); diff --git a/Scripts/Items/Skill Items/Camping/Campfire.cs b/Scripts/Items/Skill Items/Camping/Campfire.cs index cb2cf4e06..3827a7d7c 100644 --- a/Scripts/Items/Skill Items/Camping/Campfire.cs +++ b/Scripts/Items/Skill Items/Camping/Campfire.cs @@ -132,9 +132,7 @@ namespace Server.Items foreach ( NetState state in eable ) { - PlayerMobile pm = state.Mobile as PlayerMobile; - - if ( pm != null && GetEntry( pm ) == null ) + if ( state.Mobile is PlayerMobile pm && GetEntry( pm ) == null ) { CampfireEntry entry = new CampfireEntry( pm, this ); diff --git a/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs b/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs index b911dabf5..07f171c1f 100644 --- a/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs +++ b/Scripts/Items/Skill Items/Carpenter Items/TaxidermyKit.cs @@ -103,7 +103,7 @@ namespace Server.Items { from.SendLocalizedMessage( 1042600 ); // That is not a corpse! } - else if ( targeted is Corpse && ((Corpse)targeted).VisitedByTaxidermist ) + else if ( targeted is Corpse corpse && corpse.VisitedByTaxidermist ) { from.SendLocalizedMessage( 1042596 ); // That corpse seems to have been visited by a taxidermist already. } @@ -138,11 +138,9 @@ namespace Server.Items Mobile hunter = null; int weight = 0; - if ( targeted is BigFish ) + if ( targeted is BigFish fish ) { - BigFish fish = targeted as BigFish; - - hunter = fish.Fisher; + hunter = fish.Fisher; weight = (int)fish.Weight; fish.Consume(); @@ -151,17 +149,15 @@ namespace Server.Items from.AddToBackpack( new TrophyDeed( m_Table[i], hunter, weight ) ); - if ( targeted is Corpse ) - ((Corpse)targeted).VisitedByTaxidermist = true; + if ( targeted is Corpse corpse1 ) + corpse1.VisitedByTaxidermist = true; m_Kit.Delete(); return; } - else - { - from.SendLocalizedMessage( 1042598 ); // You do not have enough boards. - return; - } + + from.SendLocalizedMessage( 1042598 ); // You do not have enough boards. + return; } } } @@ -303,9 +299,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 diff --git a/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs b/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs index d6dd0fd8d..38d0e53db 100644 --- a/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs +++ b/Scripts/Items/Skill Items/Fishing/Misc/SpecialFishingNet.cs @@ -114,16 +114,14 @@ namespace Server.Items } } - public virtual bool RequireDeepWater{ get{ return true; } } + public virtual bool RequireDeepWater => true; public void OnTarget( Mobile from, object obj ) { if ( Deleted || m_InUse ) return; - IPoint3D p3D = obj as IPoint3D; - - if ( p3D == null ) + if ( !(obj is IPoint3D p3D) ) return; Map map = from.Map; diff --git a/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs b/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs index 770b96c24..c3f331ad4 100644 --- a/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs +++ b/Scripts/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs @@ -123,9 +123,7 @@ namespace Server.Items if ( !item.IsChildOf( from.Backpack ) && item.Parent != from ) return; - PlayerMobile pm = from as PlayerMobile; - - if ( pm == null ) + if ( !(from is PlayerMobile pm) ) return; ContextMenuEntry miningEntry = new ContextMenuEntry( pm.ToggleMiningStone ? 6179 : 6178 ); @@ -239,4 +237,4 @@ namespace Server.Items #endregion } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs b/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs index 666a13434..4a90c8d89 100644 --- a/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs +++ b/Scripts/Items/Skill Items/Magical/Misc/Moongate.cs @@ -123,9 +123,9 @@ namespace Server.Items { m.SendLocalizedMessage( 1061632 ); // You can't do that while carrying the sigil. } - else if ( m_TargetMap == Map.Felucca && m is PlayerMobile && ((PlayerMobile)m).Young ) + else if ( m_TargetMap == Map.Felucca && m is PlayerMobile mobile && mobile.Young ) { - m.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. } else if ( (m.Kills >= 5 && m_TargetMap != Map.Felucca) || ( m_TargetMap == Map.Tokuno && (flags & ClientFlags.Tokuno) == 0 ) || ( m_TargetMap == Map.Malas && (flags & ClientFlags.Malas) == 0 ) || ( m_TargetMap == Map.Ilshenar && (flags & ClientFlags.Ilshenar) == 0 ) ) { @@ -160,7 +160,7 @@ namespace Server.Items writer.Write( m_Target ); writer.Write( m_TargetMap ); - + // Version 1 writer.Write( m_bDispellable ); } @@ -461,4 +461,4 @@ namespace Server.Items m_Gate.EndConfirmation( m_From ); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Magical/Misc/PotionKeg.cs b/Scripts/Items/Skill Items/Magical/Misc/PotionKeg.cs index 43d58a34f..61ca72fd4 100644 --- a/Scripts/Items/Skill Items/Magical/Misc/PotionKeg.cs +++ b/Scripts/Items/Skill Items/Magical/Misc/PotionKeg.cs @@ -217,82 +217,75 @@ namespace Server.Items public override bool OnDragDrop( Mobile from, Item item ) { - if ( item is BasePotion ) - { - BasePotion pot = (BasePotion)item; - int toHold = Math.Min( 100 - m_Held, pot.Amount ); - - if ( toHold <= 0 ) - { - from.SendLocalizedMessage( 502233 ); // The keg will not hold any more! - return false; - } - else if ( m_Held == 0 ) - { - #region Mondain's Legacy - if ( (int) pot.PotionEffect >= (int) PotionEffect.Invisibility ) - { - from.SendLocalizedMessage( 502232 ); // The keg is not designed to hold that type of object. - return false; - } - #endregion - - if ( GiveBottle( from, toHold ) ) - { - m_Type = pot.PotionEffect; - Held = toHold; - - from.PlaySound( 0x240 ); - - from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack. - - item.Consume( toHold ); - - if ( !item.Deleted ) - item.Bounce( from ); - - return true; - } - else - { - from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack. - return false; - } - } - else if ( pot.PotionEffect != m_Type ) - { - from.SendLocalizedMessage( 502236 ); // You decide that it would be a bad idea to mix different types of potions. - return false; - } - else - { - if ( GiveBottle( from, toHold ) ) - { - Held += toHold; - - from.PlaySound( 0x240 ); - - from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack. - - item.Consume( toHold ); - - if ( !item.Deleted ) - item.Bounce( from ); - - return true; - } - else - { - from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack. - return false; - } - } - } - else + if (!(item is BasePotion pot)) { from.SendLocalizedMessage( 502232 ); // The keg is not designed to hold that type of object. return false; } + + int toHold = Math.Min( 100 - m_Held, pot.Amount ); + + if ( toHold <= 0 ) + { + from.SendLocalizedMessage( 502233 ); // The keg will not hold any more! + return false; + } + + if ( m_Held == 0 ) + { + #region Mondain's Legacy + if ( (int) pot.PotionEffect >= (int) PotionEffect.Invisibility ) + { + from.SendLocalizedMessage( 502232 ); // The keg is not designed to hold that type of object. + return false; + } + #endregion + + if ( GiveBottle( from, toHold ) ) + { + m_Type = pot.PotionEffect; + Held = toHold; + + from.PlaySound( 0x240 ); + + from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack. + + pot.Consume( toHold ); + + if ( !pot.Deleted ) + pot.Bounce( from ); + + return true; + } + + from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack. + return false; + } + + if ( pot.PotionEffect != m_Type ) + { + from.SendLocalizedMessage( 502236 ); // You decide that it would be a bad idea to mix different types of potions. + return false; + } + + if ( GiveBottle( from, toHold ) ) + { + Held += toHold; + + from.PlaySound( 0x240 ); + + from.SendLocalizedMessage( 502237 ); // You place the empty bottle in your backpack. + + pot.Consume( toHold ); + + if ( !pot.Deleted ) + pot.Bounce( from ); + + return true; + } + + from.SendLocalizedMessage( 502238 ); // You don't have room for the empty bottle in your backpack. + return false; } public bool GiveBottle( Mobile m, int amount ) diff --git a/Scripts/Items/Skill Items/Magical/Potions/BasePotion.cs b/Scripts/Items/Skill Items/Magical/Potions/BasePotion.cs index 22c2d1f6f..6a3a1f97d 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/BasePotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/BasePotion.cs @@ -81,13 +81,9 @@ namespace Server.Items if ( handTwo is BaseWeapon ) handOne = handTwo; - if ( handTwo is BaseRanged ) - { - BaseRanged ranged = (BaseRanged) handTwo; - if ( ranged.Balanced ) - return true; - } + if ( handTwo is BaseRanged ranged && ranged.Balanced ) + return true; return ( handOne == null || handTwo == null ); } @@ -223,10 +219,8 @@ namespace Server.Items public override bool StackWith( Mobile from, Item dropped, bool playSound ) { - if ( dropped is BasePotion && ((BasePotion)dropped).m_PotionEffect == m_PotionEffect ) - return base.StackWith( from, dropped, playSound ); - - return false; + return dropped is BasePotion potion && potion.m_PotionEffect == m_PotionEffect && + base.StackWith(from, potion, playSound); } #region ICraftable Members diff --git a/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs index 82c5aec5a..6a33d6897 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs @@ -40,9 +40,7 @@ namespace Server.Items return; } - ThrowTarget targ = from.Target as ThrowTarget; - - if ( targ != null && targ.Potion == this ) + if ( from.Target is ThrowTarget targ && targ.Potion == this ) return; from.RevealingAction(); @@ -86,9 +84,7 @@ namespace Server.Items // Check if any other players are using this potion for ( int i = 0; i < m_Users.Count; i ++ ) { - ThrowTarget targ = m_Users[ i ].Target as ThrowTarget; - - if ( targ != null && targ.Potion == this ) + if ( m_Users[ i ].Target is ThrowTarget targ && targ.Potion == this ) Target.Cancel( from ); } @@ -112,9 +108,7 @@ namespace Server.Items public static void AddDelay( Mobile m ) { - Timer timer = m_Delay[ m ] as Timer; - - if ( timer != null ) + if ( m_Delay[ m ] is Timer timer ) timer.Stop(); m_Delay[ m ] = Timer.DelayCall( TimeSpan.FromSeconds( 30 ), new TimerStateCallback( EndDelay_Callback ), m ); @@ -122,9 +116,7 @@ namespace Server.Items public static int GetDelay( Mobile m ) { - Timer timer = m_Delay[ m ] as Timer; - - if ( timer != null && timer.Next > DateTime.UtcNow ) + if ( m_Delay[ m ] is Timer timer && timer.Next > DateTime.UtcNow ) return (int) (timer.Next - DateTime.UtcNow).TotalSeconds; return 0; @@ -132,15 +124,13 @@ namespace Server.Items private static void EndDelay_Callback( object obj ) { - if ( obj is Mobile ) - EndDelay( (Mobile) obj ); + if ( obj is Mobile mobile ) + EndDelay( mobile ); } public static void EndDelay( Mobile m ) { - Timer timer = m_Delay[ m ] as Timer; - - if ( timer != null ) + if ( m_Delay[ m ] is Timer timer ) { timer.Stop(); m_Delay.Remove( m ); @@ -167,13 +157,11 @@ namespace Server.Items if ( m_Potion.Deleted || m_Potion.Map == Map.Internal ) return; - IPoint3D p = targeted as IPoint3D; - - if ( p == null || from.Map == null ) + if ( !(targeted is IPoint3D p) || from.Map == null ) return; // Add delay - BaseConflagrationPotion.AddDelay( from ); + AddDelay( from ); SpellHelper.GetSurfaceTop( ref p ); @@ -181,8 +169,8 @@ namespace Server.Items IEntity to; - if ( p is Mobile ) - to = (Mobile)p; + if ( p is Mobile mobile ) + to = mobile; else to = new Entity( Serial.Zero, new Point3D( p ), from.Map ); diff --git a/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs index 7ce1d87da..d499e8153 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Confusion Blast Potions/BaseConfusionBlastPotion.cs @@ -41,9 +41,7 @@ namespace Server.Items return; } - ThrowTarget targ = from.Target as ThrowTarget; - - if ( targ != null && targ.Potion == this ) + if ( from.Target is ThrowTarget targ && targ.Potion == this ) return; from.RevealingAction(); @@ -87,9 +85,7 @@ namespace Server.Items // Check if any other players are using this potion for ( int i = 0; i < m_Users.Count; i ++ ) { - ThrowTarget targ = m_Users[ i ].Target as ThrowTarget; - - if ( targ != null && targ.Potion == this ) + if ( m_Users[ i ].Target is ThrowTarget targ && targ.Potion == this ) Target.Cancel( from ); } @@ -102,10 +98,8 @@ namespace Server.Items foreach ( Mobile mobile in map.GetMobilesInRange( loc, Radius ) ) { - if ( mobile is BaseCreature ) + if ( mobile is BaseCreature mon ) { - BaseCreature mon = (BaseCreature) mobile; - if ( mon.Controlled || mon.Summoned ) continue; @@ -134,9 +128,7 @@ namespace Server.Items public static void AddDelay( Mobile m ) { - Timer timer = m_Delay[ m ] as Timer; - - if ( timer != null ) + if ( m_Delay[ m ] is Timer timer ) timer.Stop(); m_Delay[ m ] = Timer.DelayCall( TimeSpan.FromSeconds( 60 ), new TimerStateCallback( EndDelay_Callback ), m ); @@ -144,9 +136,7 @@ namespace Server.Items public static int GetDelay( Mobile m ) { - Timer timer = m_Delay[ m ] as Timer; - - if ( timer != null && timer.Next > DateTime.UtcNow ) + if ( m_Delay[ m ] is Timer timer && timer.Next > DateTime.UtcNow ) return (int) (timer.Next - DateTime.UtcNow).TotalSeconds; return 0; @@ -154,15 +144,13 @@ namespace Server.Items private static void EndDelay_Callback( object obj ) { - if ( obj is Mobile ) - EndDelay( (Mobile) obj ); + if ( obj is Mobile mobile ) + EndDelay( mobile ); } public static void EndDelay( Mobile m ) { - Timer timer = m_Delay[ m ] as Timer; - - if ( timer != null ) + if ( m_Delay[ m ] is Timer timer ) { timer.Stop(); m_Delay.Remove( m ); @@ -189,13 +177,11 @@ namespace Server.Items if ( m_Potion.Deleted || m_Potion.Map == Map.Internal ) return; - IPoint3D p = targeted as IPoint3D; - - if ( p == null || from.Map == null ) + if ( !(targeted is IPoint3D p) || from.Map == null ) return; // Add delay - BaseConfusionBlastPotion.AddDelay( from ); + AddDelay( from ); SpellHelper.GetSurfaceTop( ref p ); @@ -203,8 +189,8 @@ namespace Server.Items IEntity to; - if ( p is Mobile ) - to = (Mobile)p; + if ( p is Mobile mobile ) + to = mobile; else to = new Entity( Serial.Zero, new Point3D( p ), from.Map ); diff --git a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs index c478fb586..bc007b2e3 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs @@ -117,17 +117,13 @@ namespace Server.Items Point3D loc; Map map; - if ( parent is Item ) + if ( parent is Item item ) { - Item item = (Item)parent; - loc = item.GetWorldLocation(); map = item.Map; } - else if ( parent is Mobile ) + else if ( parent is Mobile m ) { - Mobile m = (Mobile)parent; - loc = m.Location; map = m.Map; } @@ -141,10 +137,10 @@ namespace Server.Items } else { - if ( parent is Item ) - ((Item)parent).PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() ); - else if ( parent is Mobile ) - ((Mobile)parent).PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() ); + if ( parent is Item item ) + item.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() ); + else if ( parent is Mobile mobile ) + mobile.PublicOverheadMessage( MessageType.Regular, 0x22, false, timer.ToString() ); states[1] = timer - 1; } @@ -187,9 +183,7 @@ namespace Server.Items if ( m_Potion.Deleted || m_Potion.Map == Map.Internal ) return; - IPoint3D p = targeted as IPoint3D; - - if ( p == null ) + if ( !(targeted is IPoint3D p) ) return; Map map = from.Map; @@ -201,16 +195,14 @@ namespace Server.Items from.RevealingAction(); - IEntity to; + IEntity to = new Entity( Serial.Zero, new Point3D( p ), map ); - to = new Entity( Serial.Zero, new Point3D( p ), map ); - - if ( p is Mobile ) + if ( p is Mobile m ) { if ( !RelativeLocation ) // explosion location = current mob location. - p = ((Mobile)p).Location; + p = m.Location; else - to = (Mobile)p; + to = m; } Effects.SendMovingEffect( from, to, m_Potion.ItemID, 7, 0, false, false, m_Potion.Hue, 0 ); @@ -235,9 +227,8 @@ namespace Server.Items for ( int i = 0; m_Users != null && i < m_Users.Count; ++i ) { Mobile m = m_Users[i]; - ThrowTarget targ = m.Target as ThrowTarget; - if ( targ != null && targ.Potion == this ) + if ( m.Target is ThrowTarget targ && targ.Potion == this ) Target.Cancel( m ); } @@ -259,9 +250,9 @@ namespace Server.Items foreach ( IEntity o in eable ) { - if ( o is Mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, (Mobile)o ) && from.CanBeHarmful( (Mobile)o, false )))) + if ( o is Mobile mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, mobile ) && from.CanBeHarmful( mobile, false )))) { - toExplode.Add( o ); + toExplode.Add( mobile ); ++toDamage; } else if ( o is BaseExplosionPotion && o != this ) @@ -279,12 +270,9 @@ namespace Server.Items { object o = toExplode[i]; - if ( o is Mobile ) + if ( o is Mobile m ) { - Mobile m = (Mobile)o; - - if ( from != null ) - from.DoHarmful( m ); + from?.DoHarmful( m ); int damage = Utility.RandomMinMax( min, max ); @@ -297,10 +285,8 @@ namespace Server.Items AOS.Damage( m, from, damage, 0, 100, 0, 0, 0 ); } - else if ( o is BaseExplosionPotion ) + else if ( o is BaseExplosionPotion pot ) { - BaseExplosionPotion pot = (BaseExplosionPotion)o; - pot.Explode( from, false, pot.GetWorldLocation(), pot.Map ); } } diff --git a/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs index 528b2d33f..94d36f556 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs @@ -39,8 +39,8 @@ namespace Server.Items private static void Hide_Callback( object obj ) { - if ( obj is Mobile ) - Hide( (Mobile) obj ); + if ( obj is Mobile mobile ) + Hide( mobile ); } public static void Hide( Mobile m ) @@ -60,8 +60,8 @@ namespace Server.Items private static void EndHide_Callback( object obj ) { - if ( obj is Mobile ) - EndHide( (Mobile) obj ); + if ( obj is Mobile mobile ) + EndHide( mobile ); } public static void EndHide( Mobile m ) diff --git a/Scripts/Items/Skill Items/Magical/Runebook.cs b/Scripts/Items/Skill Items/Magical/Runebook.cs index c2db026cf..a679f77a8 100644 --- a/Scripts/Items/Skill Items/Magical/Runebook.cs +++ b/Scripts/Items/Skill Items/Magical/Runebook.cs @@ -270,13 +270,14 @@ namespace Server.Items { NetState ns = toCheck.NetState; - if ( ns != null ) { - foreach ( Gump gump in ns.Gumps ) { - RunebookGump bookGump = gump as RunebookGump; + if (ns == null) + return false; - if ( bookGump != null && bookGump.Book == this ) { - return true; - } + foreach ( Gump gump in ns.Gumps ) + { + if ( gump is RunebookGump bookGump && bookGump.Book == this ) + { + return true; } } @@ -295,7 +296,7 @@ namespace Server.Items if ( m_Crafter != null ) list.Add( 1050043, m_Crafter.Name ); // crafted by ~1_NAME~ - if ( m_Description != null && m_Description.Length > 0 ) + if ( !string.IsNullOrEmpty(m_Description) ) list.Add( m_Description ); } @@ -358,9 +359,7 @@ namespace Server.Items public override void OnAfterDuped( Item newItem ) { - Runebook book = newItem as Runebook; - - if ( book == null ) + if ( !(newItem is Runebook book) ) return; book.m_Entries = new List(); @@ -388,7 +387,7 @@ namespace Server.Items public override bool OnDragDrop( Mobile from, Item dropped ) { - if ( dropped is RecallRune ) + if ( dropped is RecallRune rune ) { if ( IsLockedDown && from.AccessLevel < AccessLevel.GameMaster ) { @@ -400,13 +399,11 @@ namespace Server.Items } else if ( m_Entries.Count < 16 ) { - RecallRune rune = (RecallRune)dropped; - if ( rune.Marked && rune.TargetMap != null ) { m_Entries.Add( new RunebookEntry( rune.Target, rune.TargetMap, rune.Description, rune.House ) ); - dropped.Delete(); + rune.Delete(); from.Send( new PlaySound( 0x42, GetWorldLocation() ) ); @@ -419,10 +416,8 @@ namespace Server.Items return true; } - else - { - from.SendLocalizedMessage( 502409 ); // This rune does not have a marked location. - } + + from.SendLocalizedMessage( 502409 ); // This rune does not have a marked location. } else { diff --git a/Scripts/Items/Skill Items/Magical/Spellbook.cs b/Scripts/Items/Skill Items/Magical/Spellbook.cs index f631aacf2..46399a8c2 100644 --- a/Scripts/Items/Skill Items/Magical/Spellbook.cs +++ b/Scripts/Items/Skill Items/Magical/Spellbook.cs @@ -64,10 +64,8 @@ namespace Server.Items private static void AllSpells_OnTarget( Mobile from, object obj ) { - if ( obj is Spellbook ) + if ( obj is Spellbook book ) { - Spellbook book = (Spellbook)obj; - if ( book.BookCount == 64 ) book.Content = ulong.MaxValue; else @@ -268,8 +266,8 @@ namespace Server.Items Item item = from.FindItemOnLayer( Layer.OneHanded ); - if ( item is Spellbook ) - list.Add( (Spellbook)item ); + if ( item is Spellbook spellbook ) + list.Add( spellbook ); Container pack = from.Backpack; @@ -280,8 +278,8 @@ namespace Server.Items { item = pack.Items[i]; - if ( item is Spellbook ) - list.Add( (Spellbook)item ); + if ( item is Spellbook spellbook1 ) + list.Add( spellbook1 ); } return list; @@ -352,45 +350,38 @@ namespace Server.Items public override bool OnDragDrop( Mobile from, Item dropped ) { - if ( dropped is SpellScroll && dropped.Amount == 1 ) + if ( dropped is SpellScroll scroll && scroll.Amount == 1 ) { - SpellScroll scroll = (SpellScroll)dropped; - SpellbookType type = GetTypeForSpell( scroll.SpellID ); if ( type != this.SpellbookType ) { return false; } - else if ( HasSpell( scroll.SpellID ) ) + + if ( HasSpell( scroll.SpellID ) ) { from.SendLocalizedMessage( 500179 ); // That spell is already present in that spellbook. return false; } - else + + int val = scroll.SpellID - BookOffset; + + if ( val >= 0 && val < BookCount ) { - int val = scroll.SpellID - BookOffset; + m_Content |= (ulong)1 << val; + ++m_Count; - if ( val >= 0 && val < BookCount ) - { - m_Content |= (ulong)1 << val; - ++m_Count; + InvalidateProperties(); - InvalidateProperties(); + scroll.Delete(); - scroll.Delete(); - - from.Send( new PlaySound( 0x249, GetWorldLocation() ) ); - return true; - } - - return false; + from.Send( new PlaySound( 0x249, GetWorldLocation() ) ); + return true; } } - else - { - return false; - } + + return false; } [CommandProperty( AccessLevel.GameMaster )] @@ -452,9 +443,7 @@ namespace Server.Items public override void OnAfterDuped( Item newItem ) { - Spellbook book = newItem as Spellbook; - - if ( book == null ) + if ( !(newItem is Spellbook book) ) return; book.m_AosAttributes = new AosAttributes( newItem, m_AosAttributes ); @@ -463,10 +452,8 @@ namespace Server.Items public override void OnAdded(IEntity parent) { - if ( Core.AOS && parent is Mobile ) + if ( Core.AOS && parent is Mobile from ) { - Mobile from = (Mobile)parent; - m_AosSkillBonuses.AddTo( from ); int strBonus = m_AosAttributes.BonusStr; @@ -493,10 +480,8 @@ namespace Server.Items public override void OnRemoved(IEntity parent) { - if ( Core.AOS && parent is Mobile ) + if ( Core.AOS && parent is Mobile from ) { - Mobile from = (Mobile)parent; - m_AosSkillBonuses.Remove(); string modName = this.Serial.ToString(); @@ -802,31 +787,31 @@ namespace Server.Items if ( m_AosSkillBonuses == null ) m_AosSkillBonuses = new AosSkillBonuses( this ); - if ( Core.AOS && Parent is Mobile ) - m_AosSkillBonuses.AddTo( (Mobile) Parent ); + if ( Core.AOS && Parent is Mobile mobile ) + m_AosSkillBonuses.AddTo( mobile ); int strBonus = m_AosAttributes.BonusStr; int dexBonus = m_AosAttributes.BonusDex; int intBonus = m_AosAttributes.BonusInt; - if ( Parent is Mobile && (strBonus != 0 || dexBonus != 0 || intBonus != 0) ) + if ( Parent is Mobile m ) { - Mobile m = (Mobile)Parent; + if (strBonus != 0 || dexBonus != 0 || intBonus != 0) + { + string modName = Serial.ToString(); - string modName = Serial.ToString(); + if ( strBonus != 0 ) + m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) ); - if ( strBonus != 0 ) - m.AddStatMod( new StatMod( StatType.Str, modName + "Str", strBonus, TimeSpan.Zero ) ); + if ( dexBonus != 0 ) + m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) ); - if ( dexBonus != 0 ) - m.AddStatMod( new StatMod( StatType.Dex, modName + "Dex", dexBonus, TimeSpan.Zero ) ); + if ( intBonus != 0 ) + m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) ); + } - if ( intBonus != 0 ) - m.AddStatMod( new StatMod( StatType.Int, modName + "Int", intBonus, TimeSpan.Zero ) ); + m.CheckStatTimers(); } - - if ( Parent is Mobile ) - ((Mobile)Parent).CheckStatTimers(); } private static int[] m_LegendPropertyCounts = new int[] diff --git a/Scripts/Items/Skill Items/Misc/Bandage.cs b/Scripts/Items/Skill Items/Misc/Bandage.cs index 148bb686b..a727bdd04 100644 --- a/Scripts/Items/Skill Items/Misc/Bandage.cs +++ b/Scripts/Items/Skill Items/Misc/Bandage.cs @@ -81,9 +81,7 @@ namespace Server.Items private static void EventSink_BandageTargetRequest(BandageTargetRequestEventArgs e) { - Bandage b = e.Bandage as Bandage; - - if (b == null || b.Deleted) + if (!(e.Bandage is Bandage b) || b.Deleted) return; Mobile from = e.Mobile; @@ -124,11 +122,11 @@ namespace Server.Items if ( m_Bandage.Deleted ) return; - if ( targeted is Mobile ) + if ( targeted is Mobile mobile ) { if ( from.InRange( m_Bandage.GetWorldLocation(), Bandage.Range ) ) { - if ( BandageContext.BeginHeal( from, (Mobile)targeted ) != null ) + if ( BandageContext.BeginHeal( from, mobile ) != null ) { if ( !Engines.ConPVP.DuelContext.IsFreeConsume( from ) ) m_Bandage.Consume(); @@ -139,9 +137,9 @@ namespace Server.Items from.SendLocalizedMessage( 500295 ); // You are too far away to do that. } } - else if ( targeted is PlagueBeastInnard ) + else if ( targeted is PlagueBeastInnard innard ) { - if ( ((PlagueBeastInnard) targeted).OnBandage( from ) ) + if ( innard.OnBandage( from ) ) m_Bandage.Consume(); } else @@ -152,9 +150,9 @@ namespace Server.Items protected override void OnNonlocalTarget( Mobile from, object targeted ) { - if ( targeted is PlagueBeastInnard ) + if ( targeted is PlagueBeastInnard innard ) { - if ( ((PlagueBeastInnard) targeted).OnBandage( from ) ) + if ( innard.OnBandage( from ) ) m_Bandage.Consume(); } else @@ -469,17 +467,17 @@ namespace Server.Items public static BandageContext BeginHeal( Mobile healer, Mobile patient ) { - bool isDeadPet = ( patient is BaseCreature && ((BaseCreature)patient).IsDeadPet ); + BaseCreature creature = patient as BaseCreature; if ( patient is Golem ) { healer.SendLocalizedMessage( 500970 ); // Bandages cannot be used on that. } - else if ( patient is BaseCreature && ((BaseCreature)patient).IsAnimatedDead ) + else if ( creature?.IsAnimatedDead == true ) { healer.SendLocalizedMessage( 500951 ); // You cannot heal that. } - else if ( !patient.Poisoned && patient.Hits == patient.HitsMax && !BleedAttack.IsBleeding( patient ) && !isDeadPet ) + else if ( !patient.Poisoned && patient.Hits == patient.HitsMax && !BleedAttack.IsBleeding( patient ) && creature?.IsDeadPet != true ) { healer.SendLocalizedMessage( 500955 ); // That being is not damaged! } @@ -534,8 +532,7 @@ namespace Server.Items BandageContext context = GetContext( healer ); - if ( context != null ) - context.StopHeal(); + context?.StopHeal(); seconds *= 1000; context = new BandageContext( healer, patient, TimeSpan.FromMilliseconds( seconds ) ); diff --git a/Scripts/Items/Skill Items/Misc/FireHorn.cs b/Scripts/Items/Skill Items/Misc/FireHorn.cs index d962c27f7..0e0855017 100644 --- a/Scripts/Items/Skill Items/Misc/FireHorn.cs +++ b/Scripts/Items/Skill Items/Misc/FireHorn.cs @@ -199,8 +199,8 @@ namespace Server.Items return; IPoint3D loc; - if ( targeted is Item ) - loc = ((Item)targeted).GetWorldLocation(); + if ( targeted is Item item ) + loc = item.GetWorldLocation(); else loc = targeted as IPoint3D; diff --git a/Scripts/Items/Skill Items/Misc/RecipeScroll.cs b/Scripts/Items/Skill Items/Misc/RecipeScroll.cs index 05731acc2..7a4d02d2f 100644 --- a/Scripts/Items/Skill Items/Misc/RecipeScroll.cs +++ b/Scripts/Items/Skill Items/Misc/RecipeScroll.cs @@ -67,14 +67,12 @@ namespace Server.Items Recipe r = this.Recipe; - if ( r != null && from is PlayerMobile ) + if ( r != null && @from is PlayerMobile pm ) { - PlayerMobile pm = from as PlayerMobile; - if ( !pm.HasRecipe( r ) ) { bool allRequiredSkills = true; - double chance = r.CraftItem.GetSuccessChance( from, null, r.CraftSystem, false, ref allRequiredSkills ); + double chance = r.CraftItem.GetSuccessChance( pm, null, r.CraftSystem, false, ref allRequiredSkills ); if ( allRequiredSkills && chance >= 0.0 ) { diff --git a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs index f5c2a6c73..8852fe871 100644 --- a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs +++ b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs @@ -165,9 +165,7 @@ namespace Server.Items public static BaseInstrument GetInstrument( Mobile from ) { - BaseInstrument item = m_Instruments[from] as BaseInstrument; - - if ( item == null ) + if ( !(m_Instruments[@from] is BaseInstrument item) ) return null; if ( !item.IsChildOf( from.Backpack ) ) @@ -202,9 +200,7 @@ namespace Server.Items public static void OnPickedInstrument( Mobile from, object targeted, object state ) { - BaseInstrument instrument = targeted as BaseInstrument; - - if ( instrument == null ) + if ( !(targeted is BaseInstrument instrument) ) { from.SendLocalizedMessage( 500619 ); // That is not a musical instrument. } @@ -214,8 +210,7 @@ namespace Server.Items InstrumentPickedCallback callback = state as InstrumentPickedCallback; - if ( callback != null ) - callback( from, instrument ); + callback?.Invoke( @from, instrument ); } } diff --git a/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs b/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs index e1673af0b..7bcd18d08 100644 --- a/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs +++ b/Scripts/Items/Skill Items/Ninjitsu/NinjaWeapons.cs @@ -316,9 +316,9 @@ namespace Server.Items if (WeaponIsValid(weapon, from)) { - if (targeted is Mobile) + if (targeted is Mobile mobile) { - Shoot(player, (Mobile)targeted, weapon); + Shoot(player, mobile, weapon); } else if (targeted.GetType() == weapon.AmmoType) { @@ -382,4 +382,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs b/Scripts/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs index 26d6ab654..dd5734bfe 100644 --- a/Scripts/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs +++ b/Scripts/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs @@ -173,21 +173,19 @@ namespace Server.Items protected override void OnTarget( Mobile from, object targeted ) { - if ( targeted is Item ) + if ( targeted is Item item ) { - Item item = (Item)targeted; - if ( item.QuestItem ) { from.SendLocalizedMessage( 1151836 ); // You may not dye toggled quest items. } - else if ( item is IDyable && m_Tub.AllowDyables ) + else if ( item is IDyable dyable && m_Tub.AllowDyables ) { if ( !from.InRange( m_Tub.GetWorldLocation(), 1 ) || !from.InRange( item.GetWorldLocation(), 1 ) ) from.SendLocalizedMessage( 500446 ); // That is too far away. else if ( item.Parent is Mobile ) from.SendLocalizedMessage( 500861 ); // Can't Dye clothing that is being worn. - else if ( ((IDyable)item).Dye( from, m_Tub ) ) + else if ( dyable.Dye( from, m_Tub ) ) from.PlaySound( 0x23E ); } else if ( (FurnitureAttribute.Check( item ) || (item is PotionKeg)) && m_Tub.AllowFurniture ) @@ -258,7 +256,7 @@ namespace Server.Items from.PlaySound( 0x23E ); } } - else if ( (item is BaseArmor && (((BaseArmor)item).MaterialType == ArmorMaterialType.Leather || ((BaseArmor)item).MaterialType == ArmorMaterialType.Studded) || item is ElvenBoots || item is WoodlandBelt) && m_Tub.AllowLeather ) + else if ( (item is BaseArmor armor && (armor.MaterialType == ArmorMaterialType.Leather || armor.MaterialType == ArmorMaterialType.Studded) || item is ElvenBoots || item is WoodlandBelt) && m_Tub.AllowLeather ) { if ( !from.InRange( m_Tub.GetWorldLocation(), 1 ) || !from.InRange( item.GetWorldLocation(), 1 ) ) { diff --git a/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs b/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs index 6f3eedd86..16e67d9cf 100644 --- a/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs +++ b/Scripts/Items/Skill Items/Tailor Items/Misc/Dyes.cs @@ -77,10 +77,8 @@ namespace Server.Items public virtual void SetTubHue( Mobile from, object state, int hue ) { - if ( state is DyeTub ) + if ( state is DyeTub tub ) { - DyeTub tub = state as DyeTub; - tub.DyedHue = hue; /* dyes.m_UsesRemaining--; let this change ride till the overhaul */ @@ -89,10 +87,8 @@ namespace Server.Items protected override void OnTarget( Mobile from, object targeted ) { - if ( targeted is DyeTub ) + if ( targeted is DyeTub tub ) { - DyeTub tub = (DyeTub) targeted; - if ( tub.Redyable ) { if ( tub.MetallicHues ) /* OSI has three metallic tubs now */ diff --git a/Scripts/Items/Skill Items/Tailor Items/Misc/Scissors.cs b/Scripts/Items/Skill Items/Tailor Items/Misc/Scissors.cs index f176cb7f1..d2ed418d5 100644 --- a/Scripts/Items/Skill Items/Tailor Items/Misc/Scissors.cs +++ b/Scripts/Items/Skill Items/Tailor Items/Misc/Scissors.cs @@ -71,20 +71,16 @@ namespace Server.Items { from.SendLocalizedMessage( 1063305 ); // Didn't your parents ever tell you not to run with scissors in your hand?! } - else if ( targeted is Item && !((Item)targeted).Movable ) + else if ( targeted is Item item && !item.Movable ) { - if ( targeted is IScissorable && ( targeted is PlagueBeastInnard || targeted is PlagueBeastMutationCore ) ) + if ( item is IScissorable obj && ( obj is PlagueBeastInnard || obj is PlagueBeastMutationCore ) ) { - IScissorable obj = (IScissorable) targeted; - if ( CanScissor( from, obj ) && obj.Scissor( from, m_Item ) ) from.PlaySound( 0x248 ); } } - else if ( targeted is IScissorable ) + else if ( targeted is IScissorable obj ) { - IScissorable obj = (IScissorable)targeted; - if ( CanScissor( from, obj ) && obj.Scissor( from, m_Item ) ) from.PlaySound( 0x248 ); } @@ -96,10 +92,8 @@ namespace Server.Items protected override void OnNonlocalTarget( Mobile from, object targeted ) { - if ( targeted is IScissorable && ( targeted is PlagueBeastInnard || targeted is PlagueBeastMutationCore ) ) + if ( targeted is IScissorable obj && ( obj is PlagueBeastInnard || obj is PlagueBeastMutationCore ) ) { - IScissorable obj = (IScissorable) targeted; - if ( CanScissor( from, obj ) && obj.Scissor( from, m_Item ) ) from.PlaySound( 0x248 ); } @@ -110,7 +104,7 @@ namespace Server.Items public static bool CanScissor( Mobile from, IScissorable obj ) { - if ( obj is Item && ( (Item)obj ).Nontransferable ) + if ( obj is Item item && item.Nontransferable ) { from.SendLocalizedMessage( 502440 ); // Scissors can not be used on that to produce anything. return false; diff --git a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs index a9cd849a8..d8f69dc39 100644 --- a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs +++ b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs @@ -212,10 +212,8 @@ namespace Server.Items m_From.NameMod = NameList.RandomName( m_From.Female ? "female" : "male" ); - if ( m_From is PlayerMobile ) + if ( m_From is PlayerMobile pm ) { - PlayerMobile pm = (PlayerMobile)m_From; - if ( hair ) pm.SetHairMods( entry.m_ItemID, -2 ); else @@ -297,10 +295,10 @@ namespace Server.Items { m_Player.NameMod = null; - if ( m_Player is PlayerMobile ) - ((PlayerMobile)m_Player).SetHairMods( -1, -1 ); + if ( m_Player is PlayerMobile mobile ) + mobile.SetHairMods( -1, -1 ); - DisguiseTimers.RemoveTimer( m_Player ); + RemoveTimer( m_Player ); } } diff --git a/Scripts/Items/Skill Items/Thief/LockPick.cs b/Scripts/Items/Skill Items/Thief/LockPick.cs index 552534982..ea82c8111 100644 --- a/Scripts/Items/Skill Items/Thief/LockPick.cs +++ b/Scripts/Items/Skill Items/Thief/LockPick.cs @@ -73,16 +73,16 @@ namespace Server.Items if ( m_Item.Deleted ) return; - if ( targeted is ILockpickable ) + if ( targeted is ILockpickable lockpickable ) { - Item item = (Item)targeted; + Item item = lockpickable as Item; from.Direction = from.GetDirectionTo( item ); - if ( ((ILockpickable)targeted).Locked ) + if ( lockpickable.Locked ) { from.PlaySound( 0x241 ); - new InternalTimer( from, (ILockpickable)targeted, m_Item ).Start(); + new InternalTimer( from, lockpickable, m_Item ).Start(); } else { @@ -101,7 +101,7 @@ namespace Server.Items private Mobile m_From; private ILockpickable m_Item; private Lockpick m_Lockpick; - + public InternalTimer( Mobile from, ILockpickable item, Lockpick lockpick ) : base( TimeSpan.FromSeconds( 3.0 ) ) { m_From = from; @@ -124,7 +124,7 @@ namespace Server.Items m_Lockpick.Consume(); } } - + protected override void OnTick() { Item item = (Item)m_Item; @@ -168,4 +168,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Tinkering/Spyglass.cs b/Scripts/Items/Skill Items/Tinkering/Spyglass.cs index bfb66ba84..891a26c37 100644 --- a/Scripts/Items/Skill Items/Tinkering/Spyglass.cs +++ b/Scripts/Items/Skill Items/Tinkering/Spyglass.cs @@ -26,20 +26,15 @@ 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 : ", "" ) ); - PlayerMobile player = from as PlayerMobile; - - if ( player != null ) + if ( @from is PlayerMobile player ) { QuestSystem qs = player.Quest; if ( qs is WitchApprenticeQuest ) { - FindIngredientObjective obj = qs.FindObjective( typeof( FindIngredientObjective ) ) as FindIngredientObjective; - - if ( obj != null && !obj.Completed && obj.Ingredient == Ingredient.StarChart ) + if ( qs.FindObjective( typeof( FindIngredientObjective ) ) is FindIngredientObjective obj && !obj.Completed && obj.Ingredient == Ingredient.StarChart ) { - int hours, minutes; - Clock.GetTime( from.Map, from.X, from.Y, out hours, out minutes ); + Clock.GetTime( from.Map, from.X, from.Y, out int hours, out int _ ); if ( hours < 5 || hours > 17 ) { @@ -74,4 +69,4 @@ namespace Server.Items int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs b/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs index 8135d5414..3a411ab14 100644 --- a/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs +++ b/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs @@ -60,9 +60,7 @@ namespace Server.Items public override void OnAfterDuped( Item newItem ) { - DawnsMusicBox box = newItem as DawnsMusicBox; - - if ( box == null ) + if ( !(newItem is DawnsMusicBox box) ) return; box.m_Tracks = new List(); diff --git a/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicGear.cs b/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicGear.cs index 0b14d1728..49495a44b 100644 --- a/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicGear.cs +++ b/Scripts/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicGear.cs @@ -76,7 +76,7 @@ namespace Server.Items base.Serialize( writer ); writer.WriteEncodedInt( (int) 1 ); // version - + writer.Write( (int) m_Music ); } @@ -85,7 +85,7 @@ namespace Server.Items base.Deserialize( reader ); int version = reader.ReadEncodedInt(); - + switch ( version ) { case 1: @@ -94,19 +94,19 @@ namespace Server.Items break; } } - + if ( version == 0 ) // Music wasn't serialized in version 0, pick a new track of random rarity { DawnsMusicRarity rarity; double rand = Utility.RandomDouble(); - + if ( rand < 0.025 ) rarity = DawnsMusicRarity.Rare; else if ( rand < 0.225 ) rarity = DawnsMusicRarity.Uncommon; else rarity = DawnsMusicRarity.Common; - + m_Music = DawnsMusicBox.RandomTrack( rarity ); } } @@ -125,9 +125,7 @@ namespace Server.Items if ( m_Gear == null || m_Gear.Deleted ) return; - DawnsMusicBox box = targeted as DawnsMusicBox; - - if ( box != null ) + if ( targeted is DawnsMusicBox box ) { if ( !box.Tracks.Contains( m_Gear.Music ) ) { diff --git a/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs b/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs index 6a8030c5f..f0217926f 100644 --- a/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs +++ b/Scripts/Items/Special/8th Anniversary Items/FountainOfLife.cs @@ -198,9 +198,7 @@ namespace Server.Items if ( Items[i] is EnhancedBandage ) continue; - Bandage bandage = Items[i] as Bandage; - - if ( bandage != null ) + if ( Items[i] is Bandage bandage ) { Item enhanced; diff --git a/Scripts/Items/Special/8th Anniversary Items/Talismans.cs b/Scripts/Items/Special/8th Anniversary Items/Talismans.cs index e92377bf6..effe374e4 100644 --- a/Scripts/Items/Special/8th Anniversary Items/Talismans.cs +++ b/Scripts/Items/Special/8th Anniversary Items/Talismans.cs @@ -50,10 +50,8 @@ namespace Server.Items { base.OnRemoved( parent ); - if ( parent is Mobile ) + if ( parent is Mobile m ) { - Mobile m = (Mobile) parent; - AnimalForm.RemoveContext( m, true ); } } @@ -62,11 +60,11 @@ namespace Server.Items { if ( type == typeof( Squirrel ) ) return m.Talisman is SquirrelFormTalisman; - else if ( type == typeof( Ferret ) ) + if ( type == typeof( Ferret ) ) return m.Talisman is FerretFormTalisman; - else if ( type == typeof( CuSidhe ) ) + if ( type == typeof( CuSidhe ) ) return m.Talisman is CuSidheFormTalisman; - else if ( type == typeof( Reptalon ) ) + if ( type == typeof( Reptalon ) ) return m.Talisman is ReptalonFormTalisman; return true; diff --git a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/AncientSmithyHammer.cs b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/AncientSmithyHammer.cs index b977fada6..312e6c32f 100644 --- a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/AncientSmithyHammer.cs +++ b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/AncientSmithyHammer.cs @@ -24,15 +24,14 @@ namespace Server.Items if ( m_Bonus == 0 ) { - 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( SkillName.Blacksmith, true, m_Bonus ); - ((Mobile)Parent).AddSkillMod( m_SkillMod ); + mobile.AddSkillMod( m_SkillMod ); } else if ( m_SkillMod != null ) { @@ -45,13 +44,12 @@ namespace Server.Items { base.OnAdded( parent ); - if ( m_Bonus != 0 && parent is Mobile ) + if ( m_Bonus != 0 && parent is Mobile mobile ) { - if ( m_SkillMod != null ) - m_SkillMod.Remove(); + m_SkillMod?.Remove(); m_SkillMod = new DefaultSkillMod( SkillName.Blacksmith, true, m_Bonus ); - ((Mobile)parent).AddSkillMod( m_SkillMod ); + mobile.AddSkillMod( m_SkillMod ); } } @@ -59,8 +57,7 @@ namespace Server.Items { base.OnRemoved( parent ); - if ( m_SkillMod != null ) - m_SkillMod.Remove(); + m_SkillMod?.Remove(); m_SkillMod = null; } @@ -118,13 +115,12 @@ namespace Server.Items } } - if ( m_Bonus != 0 && Parent is Mobile ) + if ( m_Bonus != 0 && Parent is Mobile mobile ) { - if ( m_SkillMod != null ) - m_SkillMod.Remove(); + m_SkillMod?.Remove(); m_SkillMod = new DefaultSkillMod( SkillName.Blacksmith, true, m_Bonus ); - ((Mobile)Parent).AddSkillMod( m_SkillMod ); + mobile.AddSkillMod( m_SkillMod ); } if ( Hue == 0 ) diff --git a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/GlovesOfMining.cs b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/GlovesOfMining.cs index f21bf5f91..89f8984ba 100644 --- a/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/GlovesOfMining.cs +++ b/Scripts/Items/Special/Bulk Order Rewards/Blacksmithy/GlovesOfMining.cs @@ -159,15 +159,14 @@ namespace Server.Items if ( m_Bonus == 0 ) { - 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( SkillName.Mining, true, m_Bonus ); - ((Mobile)Parent).AddSkillMod( m_SkillMod ); + mobile.AddSkillMod( m_SkillMod ); } else if ( m_SkillMod != null ) { @@ -180,13 +179,12 @@ namespace Server.Items { base.OnAdded( parent ); - if ( m_Bonus != 0 && parent is Mobile ) + if ( m_Bonus != 0 && parent is Mobile mobile ) { - if ( m_SkillMod != null ) - m_SkillMod.Remove(); + m_SkillMod?.Remove(); m_SkillMod = new DefaultSkillMod( SkillName.Mining, true, m_Bonus ); - ((Mobile)parent).AddSkillMod( m_SkillMod ); + mobile.AddSkillMod( m_SkillMod ); } } @@ -194,8 +192,7 @@ namespace Server.Items { base.OnRemoved( parent ); - if ( m_SkillMod != null ) - m_SkillMod.Remove(); + m_SkillMod?.Remove(); m_SkillMod = null; } @@ -243,13 +240,12 @@ namespace Server.Items } } - if ( m_Bonus != 0 && Parent is Mobile ) + if ( m_Bonus != 0 && Parent is Mobile mobile ) { - if ( m_SkillMod != null ) - m_SkillMod.Remove(); + m_SkillMod?.Remove(); m_SkillMod = new DefaultSkillMod( SkillName.Mining, true, m_Bonus ); - ((Mobile)Parent).AddSkillMod( m_SkillMod ); + mobile.AddSkillMod( m_SkillMod ); } } }