From 20a80ea2f3f9159c3d3f6dd5e14865daa64595f0 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 11 Sep 2018 18:59:11 -0700 Subject: [PATCH] More casting fixes --- Scripts/Misc/AOS.cs | 2 +- Scripts/Misc/Guild.cs | 2 +- Scripts/Misc/Keywords.cs | 4 +- Scripts/Misc/MapUO.cs | 2 +- Scripts/Misc/MondainsLegacy.cs | 2 +- Scripts/Misc/Notoriety.cs | 12 +++--- Scripts/Misc/RegenRates.cs | 4 +- Scripts/Misc/SkillCheck.cs | 16 ++++---- Scripts/Misc/WeightOverloading.cs | 2 +- Scripts/Mobiles/AI/BaseAI.cs | 8 ++-- Scripts/Mobiles/BaseCreature.cs | 12 +++--- Scripts/Mobiles/Guards/ArcherGuard.cs | 8 ++-- Scripts/Mobiles/Guards/BaseGuard.cs | 6 +-- Scripts/Mobiles/Guards/WarriorGuard.cs | 4 +- Scripts/Mobiles/Healers/BaseHealer.cs | 4 +- Scripts/Mobiles/Monsters/Ants/SolenHelper.cs | 38 ++++++------------- .../Monsters/Humanoid/Magic/Betrayer.cs | 7 +--- .../Humanoid/Magic/GolemController.cs | 3 +- .../Monsters/Humanoid/Magic/SavageShaman.cs | 4 +- .../Monsters/Humanoid/Magic/Succubus.cs | 2 +- .../Monsters/Humanoid/Melee/Juggernaut.cs | 7 +--- .../Monsters/Humanoid/Melee/RestlessSoul.cs | 4 +- .../Mobiles/Monsters/Humanoid/Melee/Savage.cs | 4 +- .../Monsters/Humanoid/Melee/SavageRider.cs | 8 ++-- .../Monsters/LBR/Jukas/ChaosDragoonElite.cs | 4 +- .../Mobiles/Monsters/LBR/Jukas/JukaMage.cs | 4 +- .../Monsters/LBR/Meers/EnragedCreatures.cs | 16 ++------ .../Mobiles/Monsters/LBR/Meers/MeerMage.cs | 15 ++------ Scripts/Mobiles/Monsters/ML/Animal/Ferret.cs | 4 +- .../Mobiles/Monsters/ML/Bedlam/SirPatrick.cs | 6 +-- .../Monsters/ML/Humanoid/Magic/Satyr.cs | 16 +++----- .../Mobiles/Monsters/ML/Special/Ilhenir.cs | 12 ++---- .../Mobiles/Monsters/ML/Special/Meraktus.cs | 11 +++--- Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs | 7 +--- .../Monsters/Misc/Melee/PlagueBeastLord.cs | 6 +-- .../Ore Elementals/ShadowIronElemental.cs | 7 +--- .../Ore Elementals/ValoriteElemental.cs | 4 +- .../Reptile/Magic/SerpentineDragon.cs | 13 ++----- Scripts/Mobiles/Monsters/SE/Yamandon.cs | 8 ++-- Scripts/Mobiles/PlayerMobile.cs | 38 ++++++------------- 40 files changed, 125 insertions(+), 211 deletions(-) diff --git a/Scripts/Misc/AOS.cs b/Scripts/Misc/AOS.cs index 7ed405f6e..73a1d17fe 100644 --- a/Scripts/Misc/AOS.cs +++ b/Scripts/Misc/AOS.cs @@ -176,7 +176,7 @@ namespace Server if ( reflectPhys != 0 ) { - if ( @from is ExodusMinion minion && minion.FieldActive || @from is ExodusOverseer overseer && overseer.FieldActive ) + if ( from is ExodusMinion minion && minion.FieldActive || from is ExodusOverseer overseer && overseer.FieldActive ) { from.FixedParticles( 0x376A, 20, 10, 0x2530, EffectLayer.Waist ); from.PlaySound( 0x2F4 ); diff --git a/Scripts/Misc/Guild.cs b/Scripts/Misc/Guild.cs index bf20c450a..a44b32561 100644 --- a/Scripts/Misc/Guild.cs +++ b/Scripts/Misc/Guild.cs @@ -651,7 +651,7 @@ namespace Server.Guilds from.SendGump( new PropertiesGump( from, g ) ); - if ( NewGuildSystem && from.AccessLevel >= AccessLevel.GameMaster && @from is PlayerMobile pm ) + if ( NewGuildSystem && from.AccessLevel >= AccessLevel.GameMaster && from is PlayerMobile pm ) pm.SendGump( new GuildInfoGump( pm, g ) ); } } diff --git a/Scripts/Misc/Keywords.cs b/Scripts/Misc/Keywords.cs index 12c683e72..75ca6034d 100644 --- a/Scripts/Misc/Keywords.cs +++ b/Scripts/Misc/Keywords.cs @@ -26,7 +26,7 @@ namespace Server.Misc { case 0x002A: // *i resign from my guild* { - ((Guild)@from.Guild)?.RemoveMember( @from ); + ((Guild)from.Guild)?.RemoveMember( from ); break; } @@ -45,7 +45,7 @@ namespace Server.Misc } case 0x0035: // i renounce my young player status* { - if ( @from is PlayerMobile mobile && mobile.Young && !mobile.HasGump( typeof( RenounceYoungGump ) ) ) + if ( from is PlayerMobile mobile && mobile.Young && !mobile.HasGump( typeof( RenounceYoungGump ) ) ) { mobile.SendGump( new RenounceYoungGump() ); } diff --git a/Scripts/Misc/MapUO.cs b/Scripts/Misc/MapUO.cs index 61cb4c287..0be1edf3b 100644 --- a/Scripts/Misc/MapUO.cs +++ b/Scripts/Misc/MapUO.cs @@ -43,7 +43,7 @@ namespace Server.Misc { Mobile from = state.Mobile; - if ( @from.Guild is Guild guild ) + if ( from.Guild is Guild guild ) { bool locations = pvSrc.ReadByte() != 0; diff --git a/Scripts/Misc/MondainsLegacy.cs b/Scripts/Misc/MondainsLegacy.cs index d365a87f2..81ccece27 100644 --- a/Scripts/Misc/MondainsLegacy.cs +++ b/Scripts/Misc/MondainsLegacy.cs @@ -51,7 +51,7 @@ namespace Server public static bool CheckML( Mobile from, bool message = true) { - if ( @from?.NetState == null ) + if ( from?.NetState == null ) return false; if ( from.NetState.SupportsExpansion( Expansion.ML ) ) diff --git a/Scripts/Misc/Notoriety.cs b/Scripts/Misc/Notoriety.cs index d6da03421..1c9699176 100644 --- a/Scripts/Misc/Notoriety.cs +++ b/Scripts/Misc/Notoriety.cs @@ -70,7 +70,7 @@ namespace Server.Misc PlayerMobile pmFrom = from as PlayerMobile; PlayerMobile pmTarg = target as PlayerMobile; - if ( pmFrom == null && @from is BaseCreature bcFrom ) + if ( pmFrom == null && from is BaseCreature bcFrom ) { if ( bcFrom.Summoned ) pmFrom = bcFrom.SummonMaster as PlayerMobile; @@ -103,7 +103,7 @@ namespace Server.Misc if ( (pmFrom?.DuelContext != null && pmFrom.DuelContext.Started) || (pmTarg?.DuelContext != null && pmTarg.DuelContext.Started) ) return false; - if ( @from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) is SafeZone sz /*&& sz.IsDisabled()*/ ) + if ( from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) is SafeZone sz /*&& sz.IsDisabled()*/ ) return false; sz = target.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone; @@ -137,7 +137,7 @@ namespace Server.Misc if ( pmFrom?.Young == true || pmTarg?.Young == true ) return false; // Young players cannot perform beneficial actions towards older players - if ( @from.Guild is Guild fromGuild && target.Guild is Guild targetGuild && (targetGuild == fromGuild || fromGuild.IsAlly( targetGuild )) ) + if ( from.Guild is Guild fromGuild && target.Guild is Guild targetGuild && (targetGuild == fromGuild || fromGuild.IsAlly( targetGuild )) ) return true; // Guild members can be beneficial return CheckBeneficialStatus( GetGuildStatus( from ), GetGuildStatus( target ) ); @@ -153,7 +153,7 @@ namespace Server.Misc PlayerMobile pmTarg = target as PlayerMobile; BaseCreature bcTarg = target as BaseCreature; - if ( pmFrom == null && @from is BaseCreature bcFrom && bcFrom.Summoned ) + if ( pmFrom == null && from is BaseCreature bcFrom && bcFrom.Summoned ) pmFrom = bcFrom.SummonMaster as PlayerMobile; if ( pmTarg == null && bcTarg?.Summoned == true ) @@ -177,7 +177,7 @@ namespace Server.Misc if ( (pmFrom?.DuelContext != null && pmFrom.DuelContext.Started) || (pmTarg?.DuelContext != null && pmTarg.DuelContext.Started) ) return false; - if ( @from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) is SafeZone sz /*&& sz.IsDisabled()*/ ) + if ( from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) is SafeZone sz /*&& sz.IsDisabled()*/ ) return false; sz = target.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone; @@ -191,7 +191,7 @@ namespace Server.Misc if ( map != null && (map.Rules & MapRules.HarmfulRestrictions) == 0 ) return true; // In felucca, anything goes - if ( !from.Player && !(@from is BaseCreature bc && bc.GetMaster() != null && bc.GetMaster().AccessLevel == AccessLevel.Player ) ) + if ( !from.Player && !(from is BaseCreature bc && bc.GetMaster() != null && bc.GetMaster().AccessLevel == AccessLevel.Player ) ) { if ( !CheckAggressor( from.Aggressors, target ) && !CheckAggressed( from.Aggressed, target ) && pmTarg?.CheckYoungProtection( from ) == true ) return false; diff --git a/Scripts/Misc/RegenRates.cs b/Scripts/Misc/RegenRates.cs index c285e6f44..f88eaa384 100644 --- a/Scripts/Misc/RegenRates.cs +++ b/Scripts/Misc/RegenRates.cs @@ -89,7 +89,7 @@ namespace Server.Misc int points =(int)(from.Skills[SkillName.Focus].Value * 0.1); - if ( (@from is BaseCreature creature && creature.IsParagon) || from is Leviathan ) + if ( (from is BaseCreature creature && creature.IsParagon) || from is Leviathan ) points += 40; int cappedPoints = AosAttributes.GetValue( from, AosAttribute.RegenStam ); @@ -137,7 +137,7 @@ namespace Server.Misc double totalPoints = focusPoints + medPoints + (from.Meditating ? (medPoints > 13.0 ? 13.0 : medPoints) : 0.0); - if ( (@from is BaseCreature creature && creature.IsParagon) || from is Leviathan ) + if ( (from is BaseCreature creature && creature.IsParagon) || from is Leviathan ) totalPoints += 40; int cappedPoints = AosAttributes.GetValue( from, AosAttribute.RegenMana ); diff --git a/Scripts/Misc/SkillCheck.cs b/Scripts/Misc/SkillCheck.cs index 06558955f..09e3664af 100644 --- a/Scripts/Misc/SkillCheck.cs +++ b/Scripts/Misc/SkillCheck.cs @@ -135,7 +135,7 @@ namespace Server.Misc if ( gc < 0.01 ) gc = 0.01; - if ( @from is BaseCreature creature && creature.Controlled ) + if ( from is BaseCreature creature && creature.Controlled ) gc *= 2; if ( from.Alive && ( ( gc >= Utility.RandomDouble() && AllowGain( from, skill, amObj ) ) || skill.Base < 10.0 ) ) @@ -183,7 +183,7 @@ namespace Server.Misc if ( Core.AOS && Faction.InSkillLoss( from ) ) //Changed some time between the introduction of AoS and SE. return false; - if ( AntiMacroCode && @from is PlayerMobile mobile && UseAntiMacro[skill.Info.SkillID] ) + if ( AntiMacroCode && from is PlayerMobile mobile && UseAntiMacro[skill.Info.SkillID] ) return mobile.AntiMacroCheck( skill, obj ); return true; @@ -196,7 +196,7 @@ namespace Server.Misc if ( from.Region.IsPartOf( typeof( Regions.Jail ) ) ) return; - if ( @from is BaseCreature creature && creature.IsDeadPet ) + if ( from is BaseCreature creature && creature.IsDeadPet ) return; if ( skill.SkillName == SkillName.Focus && from is BaseCreature ) @@ -227,7 +227,7 @@ namespace Server.Misc #region Scroll of Alacrity - if ( @from is PlayerMobile pm && skill.SkillName == pm.AcceleratedSkill && pm.AcceleratedStart > DateTime.UtcNow ) + if ( from is PlayerMobile pm && skill.SkillName == pm.AcceleratedSkill && pm.AcceleratedStart > DateTime.UtcNow ) toGain *= Utility.RandomMinMax(2, 5); #endregion @@ -264,7 +264,7 @@ namespace Server.Misc public static bool CanRaise( Mobile from, Stat stat ) { - if ( !(@from is BaseCreature creature && creature.Controlled) ) + if ( !(from is BaseCreature creature && creature.Controlled) ) { if ( from.RawStatTotal >= from.StatCap ) return false; @@ -343,7 +343,7 @@ namespace Server.Misc { case Stat.Str: { - if ( @from is BaseCreature creature && creature.Controlled ) { + if ( from is BaseCreature creature && creature.Controlled ) { if ( (creature.LastStrGain + m_PetStatGainDelay) >= DateTime.UtcNow ) return; } @@ -355,7 +355,7 @@ namespace Server.Misc } case Stat.Dex: { - if ( @from is BaseCreature creature && creature.Controlled ) { + if ( from is BaseCreature creature && creature.Controlled ) { if ( (creature.LastDexGain + m_PetStatGainDelay) >= DateTime.UtcNow ) return; } @@ -367,7 +367,7 @@ namespace Server.Misc } case Stat.Int: { - if ( @from is BaseCreature creature && creature.Controlled ) { + if ( from is BaseCreature creature && creature.Controlled ) { if ( (creature.LastIntGain + m_PetStatGainDelay) >= DateTime.UtcNow ) return; } diff --git a/Scripts/Misc/WeightOverloading.cs b/Scripts/Misc/WeightOverloading.cs index 535c966fd..19627f7f5 100644 --- a/Scripts/Misc/WeightOverloading.cs +++ b/Scripts/Misc/WeightOverloading.cs @@ -96,7 +96,7 @@ namespace Server.Misc return; } - if ( @from is PlayerMobile pm ) + if ( from is PlayerMobile pm ) { int amt = ( pm.Mounted ? 48 : 16 ); diff --git a/Scripts/Mobiles/AI/BaseAI.cs b/Scripts/Mobiles/AI/BaseAI.cs index 16cfe848d..9dac7a9b9 100644 --- a/Scripts/Mobiles/AI/BaseAI.cs +++ b/Scripts/Mobiles/AI/BaseAI.cs @@ -225,7 +225,7 @@ namespace Server.Mobiles from.Target = new AIControlMobileTarget(this, order); } - else if (@from.Target is AIControlMobileTarget t) + else if (from.Target is AIControlMobileTarget t) { if (t.Order == order) t.AddAI(this); @@ -1321,7 +1321,7 @@ namespace Server.Mobiles } else { - bool youngFrom = @from is PlayerMobile mobile && mobile.Young; + bool youngFrom = from is PlayerMobile mobile && mobile.Young; bool youngTo = to is PlayerMobile playerMobile && playerMobile.Young; if (youngFrom && !youngTo) @@ -1675,7 +1675,7 @@ namespace Server.Mobiles if (from.Map != m_Creature.Map || !from.InRange(m_Creature, 14)) return false; - bool youngFrom = @from is PlayerMobile mobile && mobile.Young; + bool youngFrom = from is PlayerMobile mobile && mobile.Young; bool youngTo = to is PlayerMobile playerMobile && playerMobile.Young; if (accepted && youngFrom && !youngTo) @@ -1769,7 +1769,7 @@ namespace Server.Mobiles { m_Mobile.DebugSay("Begin transfer with {0}", to.Name); - bool youngFrom = @from is PlayerMobile mobile && mobile.Young; + bool youngFrom = from is PlayerMobile mobile && mobile.Young; bool youngTo = to is PlayerMobile playerMobile && playerMobile.Young; if (youngFrom && !youngTo) diff --git a/Scripts/Mobiles/BaseCreature.cs b/Scripts/Mobiles/BaseCreature.cs index 45e39781f..6096663d3 100644 --- a/Scripts/Mobiles/BaseCreature.cs +++ b/Scripts/Mobiles/BaseCreature.cs @@ -1471,7 +1471,7 @@ namespace Server.Mobiles if ( speechType != null && !willKill ) speechType.OnDamage( this, amount ); - m_ReceivedHonorContext?.OnTargetDamaged( @from, amount ); + m_ReceivedHonorContext?.OnTargetDamaged( from, amount ); if ( !willKill ) { @@ -1480,7 +1480,7 @@ namespace Server.Mobiles CheckDistracted( from ); } } - else if ( @from is PlayerMobile mobile ) + else if ( from is PlayerMobile mobile ) { Timer.DelayCall( TimeSpan.FromSeconds( 10 ), new TimerCallback( mobile.RecoverAmmo ) ); } @@ -2367,7 +2367,7 @@ namespace Server.Mobiles // Note: Yes, this happens for all questers (regardless of type, e.g. escorts), // even if they can't offer you anything at the moment - if ( MLQuestSystem.Enabled && CanGiveMLQuest && @from is PlayerMobile mobile ) + if ( MLQuestSystem.Enabled && CanGiveMLQuest && from is PlayerMobile mobile ) { MLQuestSystem.Tell( this, mobile, 1074893 ); // You need to mark your quest items so I don't take the wrong object. Then speak to me. return false; @@ -4370,7 +4370,7 @@ namespace Server.Mobiles { Container pack = this.Backpack; - pack?.DisplayTo( @from ); + pack?.DisplayTo( from ); } if ( this.DeathAdderCharmable && from.CanBeHarmful( this, false ) ) @@ -4382,7 +4382,7 @@ namespace Server.Mobiles } } - if ( MLQuestSystem.Enabled && CanGiveMLQuest && @from is PlayerMobile mobile ) + if ( MLQuestSystem.Enabled && CanGiveMLQuest && from is PlayerMobile mobile ) MLQuestSystem.OnDoubleClick( this, mobile ); base.OnDoubleClick( from ); @@ -4402,7 +4402,7 @@ namespace Server.Mobiles if ( !m_Charmed.DeathAdderCharmable || m_Charmed.Combatant != null || !from.CanBeHarmful( m_Charmed, false ) ) return; - if ( !(SummonFamiliarSpell.Table[@from] is DeathAdder da) || da.Deleted ) + if ( !(SummonFamiliarSpell.Table[from] is DeathAdder da) || da.Deleted ) return; if ( !(targeted is Mobile targ) || !from.CanBeHarmful( targ, false ) ) diff --git a/Scripts/Mobiles/Guards/ArcherGuard.cs b/Scripts/Mobiles/Guards/ArcherGuard.cs index 92eb33fa4..037ee85ff 100644 --- a/Scripts/Mobiles/Guards/ArcherGuard.cs +++ b/Scripts/Mobiles/Guards/ArcherGuard.cs @@ -249,7 +249,7 @@ namespace Server.Mobiles Mobile target = m_Owner.Focus; - if ( target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful( target )) ) + if ( target != null && (target.Deleted || !target.Alive || !m_Owner.CanBeHarmful( target )) ) { m_Owner.Focus = null; Stop(); @@ -274,8 +274,8 @@ namespace Server.Mobiles TeleportTo( target ); target.BoltEffect( 0 ); - if ( target is BaseCreature ) - ((BaseCreature)target).NoKillAwards = true; + if ( target is BaseCreature creature ) + creature.NoKillAwards = true; target.Damage( target.HitsMax, m_Owner ); target.Kill(); // just in case, maybe Damage is overridden on some shard @@ -394,4 +394,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Guards/BaseGuard.cs b/Scripts/Mobiles/Guards/BaseGuard.cs index bcca3093a..85602ff1b 100644 --- a/Scripts/Mobiles/Guards/BaseGuard.cs +++ b/Scripts/Mobiles/Guards/BaseGuard.cs @@ -20,10 +20,8 @@ namespace Server.Mobiles foreach ( Mobile m in target.GetMobilesInRange( 15 ) ) { - if ( m is BaseGuard ) + if ( m is BaseGuard g ) { - BaseGuard g = (BaseGuard)m; - if ( g.Focus == null ) // idling { g.Focus = target; @@ -83,4 +81,4 @@ namespace Server.Mobiles int version = reader.ReadInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Guards/WarriorGuard.cs b/Scripts/Mobiles/Guards/WarriorGuard.cs index 5239965ba..49ec2b0a8 100644 --- a/Scripts/Mobiles/Guards/WarriorGuard.cs +++ b/Scripts/Mobiles/Guards/WarriorGuard.cs @@ -289,8 +289,8 @@ namespace Server.Mobiles TeleportTo( target ); target.BoltEffect( 0 ); - if ( target is BaseCreature ) - ((BaseCreature)target).NoKillAwards = true; + if ( target is BaseCreature creature ) + creature.NoKillAwards = true; target.Damage( target.HitsMax, m_Owner ); target.Kill(); // just in case, maybe Damage is overridden on some shard diff --git a/Scripts/Mobiles/Healers/BaseHealer.cs b/Scripts/Mobiles/Healers/BaseHealer.cs index 1ae8de63a..fb15e9b9e 100644 --- a/Scripts/Mobiles/Healers/BaseHealer.cs +++ b/Scripts/Mobiles/Healers/BaseHealer.cs @@ -132,9 +132,9 @@ namespace Server.Mobiles OfferResurrection( m ); } } - else if ( this.HealsYoungPlayers && m.Hits < m.HitsMax && m is PlayerMobile && ((PlayerMobile)m).Young ) + else if ( this.HealsYoungPlayers && m.Hits < m.HitsMax && m is PlayerMobile mobile && mobile.Young ) { - OfferHeal( (PlayerMobile) m ); + OfferHeal( mobile ); } } } diff --git a/Scripts/Mobiles/Monsters/Ants/SolenHelper.cs b/Scripts/Mobiles/Monsters/Ants/SolenHelper.cs index 308eb08f5..089a4e9b7 100644 --- a/Scripts/Mobiles/Monsters/Ants/SolenHelper.cs +++ b/Scripts/Mobiles/Monsters/Ants/SolenHelper.cs @@ -22,53 +22,41 @@ namespace Server.Mobiles public static bool CheckRedFriendship( Mobile m ) { - if ( m is BaseCreature ) + if ( m is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)m; - if ( bc.Controlled && bc.ControlMaster is PlayerMobile ) return CheckRedFriendship( bc.ControlMaster ); - else if ( bc.Summoned && bc.SummonMaster is PlayerMobile ) + if ( bc.Summoned && bc.SummonMaster is PlayerMobile ) return CheckRedFriendship( bc.SummonMaster ); } - PlayerMobile player = m as PlayerMobile; - - return player != null && player.SolenFriendship == SolenFriendship.Red; + return m is PlayerMobile player && player.SolenFriendship == SolenFriendship.Red; } public static bool CheckBlackFriendship( Mobile m ) { - if ( m is BaseCreature ) + if ( m is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)m; - if ( bc.Controlled && bc.ControlMaster is PlayerMobile ) return CheckBlackFriendship( bc.ControlMaster ); - else if ( bc.Summoned && bc.SummonMaster is PlayerMobile ) + if ( bc.Summoned && bc.SummonMaster is PlayerMobile ) return CheckBlackFriendship( bc.SummonMaster ); } - PlayerMobile player = m as PlayerMobile; - - return player != null && player.SolenFriendship == SolenFriendship.Black; + return m is PlayerMobile player && player.SolenFriendship == SolenFriendship.Black; } public static void OnRedDamage( Mobile from ) { - if ( from is BaseCreature ) + if ( from is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)from; - if ( bc.Controlled && bc.ControlMaster is PlayerMobile ) OnRedDamage( bc.ControlMaster ); else if ( bc.Summoned && bc.SummonMaster is PlayerMobile ) OnRedDamage( bc.SummonMaster ); } - PlayerMobile player = from as PlayerMobile; - - if ( player != null && player.SolenFriendship == SolenFriendship.Red ) + if ( from is PlayerMobile player && player.SolenFriendship == SolenFriendship.Red ) { player.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1054103 ); // The solen revoke their friendship. You will now be considered an intruder. @@ -78,19 +66,15 @@ namespace Server.Mobiles public static void OnBlackDamage( Mobile from ) { - if ( from is BaseCreature ) + if ( from is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)from; - if ( bc.Controlled && bc.ControlMaster is PlayerMobile ) OnBlackDamage( bc.ControlMaster ); else if ( bc.Summoned && bc.SummonMaster is PlayerMobile ) OnBlackDamage( bc.SummonMaster ); } - PlayerMobile player = from as PlayerMobile; - - if ( player != null && player.SolenFriendship == SolenFriendship.Black ) + if ( from is PlayerMobile player && player.SolenFriendship == SolenFriendship.Black ) { player.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1054103 ); // The solen revoke their friendship. You will now be considered an intruder. @@ -98,4 +82,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs index 2a5a41221..a5c4c1dbd 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/Betrayer.cs @@ -114,8 +114,7 @@ namespace Server.Mobiles this.PlaySound( 0xEE ); defender.LocalOverheadMessage( MessageType.Regular, 0x3B2, false, "You have been stunned by a colossal blow!" ); - BaseWeapon weapon = this.Weapon as BaseWeapon; - if ( weapon != null ) + if ( this.Weapon is BaseWeapon weapon ) weapon.OnHit( this, defender ); if ( defender.Alive ) @@ -128,9 +127,7 @@ namespace Server.Mobiles private void Recover_Callback( object state ) { - Mobile defender = state as Mobile; - - if ( defender != null ) + if ( state is Mobile defender ) { defender.Frozen = false; defender.Combatant = null; diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/GolemController.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/GolemController.cs index 101e76206..6520b90f0 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/GolemController.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/GolemController.cs @@ -60,9 +60,8 @@ namespace Server.Mobiles public void AddArcane( Item item ) { - if ( item is IArcaneEquip ) + if ( item is IArcaneEquip eq ) { - IArcaneEquip eq = (IArcaneEquip)item; eq.CurArcaneCharges = eq.MaxArcaneCharges = 20; } diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs index 833259e0a..8666dd5dd 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs @@ -94,8 +94,8 @@ namespace Server.Mobiles aggressor.PlaySound( 0x307 ); aggressor.SendLocalizedMessage( 1040008 ); // Your skin is scorched as the tribal paint burns away! - if ( aggressor is PlayerMobile ) - ((PlayerMobile)aggressor).SavagePaintExpiration = TimeSpan.Zero; + if ( aggressor is PlayerMobile mobile ) + mobile.SavagePaintExpiration = TimeSpan.Zero; } } diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs index aa73b69a8..c625e1cad 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/Succubus.cs @@ -64,7 +64,7 @@ namespace Server.Mobiles if ( m == this || !CanBeHarmful( m ) ) continue; - if ( m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team) ) + if ( m is BaseCreature creature && (creature.Controlled || creature.Summoned || creature.Team != this.Team) ) list.Add( m ); else if ( m.Player ) list.Add( m ); diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs index e558be8b9..054716260 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/Juggernaut.cs @@ -112,8 +112,7 @@ namespace Server.Mobiles this.PlaySound( 0xEE ); defender.LocalOverheadMessage( MessageType.Regular, 0x3B2, false, "You have been stunned by a colossal blow!" ); - BaseWeapon weapon = this.Weapon as BaseWeapon; - if ( weapon != null ) + if ( this.Weapon is BaseWeapon weapon ) weapon.OnHit( this, defender ); if ( defender.Alive ) @@ -126,9 +125,7 @@ namespace Server.Mobiles private void Recover_Callback( object state ) { - Mobile defender = state as Mobile; - - if ( defender != null ) + if ( state is Mobile defender ) { defender.Frozen = false; defender.Combatant = null; diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs index 12a8e8413..76bdee420 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs @@ -87,9 +87,7 @@ namespace Server.Mobiles public override bool IsEnemy( Mobile m ) { - PlayerMobile player = m as PlayerMobile; - - if ( player != null && Map == Map.Trammel && X >= 5199 && X <= 5271 && Y >= 1812 && Y <= 1865 ) // Schmendrick's cave + if ( m is PlayerMobile player && Map == Map.Trammel && X >= 5199 && X <= 5271 && Y >= 1812 && Y <= 1865 ) // Schmendrick's cave { QuestSystem qs = player.Quest; diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/Savage.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/Savage.cs index a6e21ab38..1e4e7c49c 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/Savage.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/Savage.cs @@ -88,8 +88,8 @@ namespace Server.Mobiles aggressor.PlaySound( 0x307 ); aggressor.SendLocalizedMessage( 1040008 ); // Your skin is scorched as the tribal paint burns away! - if ( aggressor is PlayerMobile ) - ((PlayerMobile)aggressor).SavagePaintExpiration = TimeSpan.Zero; + if ( aggressor is PlayerMobile mobile ) + mobile.SavagePaintExpiration = TimeSpan.Zero; } } diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/SavageRider.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/SavageRider.cs index 195ab1dad..98ad54346 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/SavageRider.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/SavageRider.cs @@ -71,8 +71,8 @@ namespace Server.Mobiles if ( mount != null ) mount.Rider = null; - if ( mount is Mobile ) - ((Mobile)mount).Delete(); + if ( mount is Mobile mobile ) + mobile.Delete(); return base.OnBeforeDeath(); } @@ -98,8 +98,8 @@ namespace Server.Mobiles aggressor.PlaySound( 0x307 ); aggressor.SendLocalizedMessage( 1040008 ); // Your skin is scorched as the tribal paint burns away! - if ( aggressor is PlayerMobile ) - ((PlayerMobile)aggressor).SavagePaintExpiration = TimeSpan.Zero; + if ( aggressor is PlayerMobile mobile ) + mobile.SavagePaintExpiration = TimeSpan.Zero; } } diff --git a/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs b/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs index 4a88873f3..b4553d985 100644 --- a/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs +++ b/Scripts/Mobiles/Monsters/LBR/Jukas/ChaosDragoonElite.cs @@ -172,8 +172,8 @@ namespace Server.Mobiles if ( mount != null ) { - if ( mount is SwampDragon ) - ((SwampDragon)mount).HasBarding = false; + if ( mount is SwampDragon dragon ) + dragon.HasBarding = false; mount.Rider = null; } diff --git a/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs b/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs index a25b460fa..a10f0f66a 100644 --- a/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs +++ b/Scripts/Mobiles/Monsters/LBR/Jukas/JukaMage.cs @@ -111,9 +111,9 @@ namespace Server.Mobiles foreach ( Mobile m in this.GetMobilesInRange( 8 ) ) { - if ( m is JukaLord && IsFriend( m ) && m.Combatant != null && CanBeBeneficial( m ) && m.CanBeginAction( typeof( JukaMage ) ) && InLOS( m ) ) + if ( m is JukaLord lord && IsFriend( lord ) && lord.Combatant != null && CanBeBeneficial( lord ) && lord.CanBeginAction( typeof( JukaMage ) ) && InLOS( lord ) ) { - toBuff = (JukaLord)m; + toBuff = lord; break; } } diff --git a/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs b/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs index e26827986..015c74a9b 100644 --- a/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs +++ b/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs @@ -239,12 +239,7 @@ namespace Server.Mobiles else if ( !Combat( SummonMaster )) { - BaseCreature bc = null; - if ( Combatant is BaseCreature ) - { - bc = (BaseCreature)Combatant; - } - if ( Combatant.Player || ( bc != null && ( bc.Controlled || bc.SummonMaster != null ))) + if ( Combatant.Player || ( Combatant is BaseCreature bc && ( bc.Controlled || bc.SummonMaster != null ))) { SummonMaster.Combatant = Combatant; } @@ -258,14 +253,9 @@ namespace Server.Mobiles private bool Combat( Mobile mobile ) { Mobile combatant = mobile.Combatant; - if ( combatant == null || combatant.Deleted ) - { + if ( combatant == null || combatant.Deleted || combatant.IsDeadBondedPet || !combatant.Alive ) return false; - } - else if ( combatant.IsDeadBondedPet || !combatant.Alive ) - { - return false; - } + return true; } diff --git a/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs b/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs index 97a160668..4d098f26e 100644 --- a/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs +++ b/Scripts/Mobiles/Monsters/LBR/Meers/MeerMage.cs @@ -89,10 +89,8 @@ namespace Server.Mobiles { m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds( Utility.RandomMinMax( 20, 30 ) ); - if ( combatant is BaseCreature ) + if ( combatant is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)combatant; - if ( bc.Controlled && bc.ControlMaster != null && !bc.ControlMaster.Deleted && bc.ControlMaster.Alive ) { if ( bc.ControlMaster.Map == this.Map && bc.ControlMaster.InRange( this, 12 ) && !UnderEffect( bc.ControlMaster ) ) @@ -109,8 +107,6 @@ namespace Server.Mobiles new int[]{-4,-6}, new int[]{4,-6}, new int[]{0,-8}, new int[]{-5,5}, new int[]{5,5} }; - BaseCreature rabid; - for( int i=0; i<5; i++ ) { int x = combatant.X + coord[i][0]; @@ -121,6 +117,7 @@ namespace Server.Mobiles if ( !combatant.Map.CanSpawnMobile( loc ) ) continue; + BaseCreature rabid; switch ( i ) { case 0: rabid = new EnragedRabbit( this ); break; @@ -155,9 +152,7 @@ namespace Server.Mobiles public static void StopEffect( Mobile m, bool message ) { - Timer t = (Timer)m_Table[m]; - - if ( t != null ) + if ( m_Table[m] is Timer t ) { if ( message ) m.PublicOverheadMessage( Network.MessageType.Emote, m.SpeechHue, true, "* The open flame begins to scatter the swarm of insects *" ); @@ -180,9 +175,7 @@ namespace Server.Mobiles } else { - Torch torch = m.FindItemOnLayer( Layer.TwoHanded ) as Torch; - - if ( torch != null && torch.Burning ) + if ( m.FindItemOnLayer( Layer.TwoHanded ) is Torch torch && torch.Burning ) { StopEffect( m, true ); } diff --git a/Scripts/Mobiles/Monsters/ML/Animal/Ferret.cs b/Scripts/Mobiles/Monsters/ML/Animal/Ferret.cs index b60b72227..9e21637d8 100644 --- a/Scripts/Mobiles/Monsters/ML/Animal/Ferret.cs +++ b/Scripts/Mobiles/Monsters/ML/Animal/Ferret.cs @@ -50,8 +50,8 @@ namespace Server.Mobiles public override void OnMovement( Mobile m, Point3D oldLocation ) { - if ( m is Ferret && m.InRange( this, 3 ) && m.Alive ) - Talk( (Ferret) m ); + if ( m is Ferret ferret && ferret.InRange( this, 3 ) && ferret.Alive ) + Talk( ferret ); } private static string[] m_Vocabulary = new string[] diff --git a/Scripts/Mobiles/Monsters/ML/Bedlam/SirPatrick.cs b/Scripts/Mobiles/Monsters/ML/Bedlam/SirPatrick.cs index 579d8b3c6..ce1508ac1 100644 --- a/Scripts/Mobiles/Monsters/ML/Bedlam/SirPatrick.cs +++ b/Scripts/Mobiles/Monsters/ML/Bedlam/SirPatrick.cs @@ -74,12 +74,10 @@ namespace Server.Mobiles if ( m == this || !CanBeHarmful( m, false ) || ( Core.AOS && !InLOS( m ) ) ) continue; - if ( m is BaseCreature ) + if ( m is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)m; - if ( bc.Controlled || bc.Summoned || bc.Team != Team ) - list.Add( m ); + list.Add( bc ); } else if ( m.Player ) { diff --git a/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs b/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs index de4116b47..7857608e1 100644 --- a/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs +++ b/Scripts/Mobiles/Monsters/ML/Humanoid/Magic/Satyr.cs @@ -70,9 +70,7 @@ namespace Server.Mobiles if ( target == null || Deleted || !Alive || m_NextPeace > DateTime.UtcNow || 0.1 < Utility.RandomDouble() ) return; - PlayerMobile p = target as PlayerMobile; - - if ( p != null && p.PeacedUntil < DateTime.UtcNow && !p.Hidden && CanBeHarmful( p ) ) + if ( target is PlayerMobile p && p.PeacedUntil < DateTime.UtcNow && !p.Hidden && CanBeHarmful( p ) ) { p.PeacedUntil = DateTime.UtcNow + TimeSpan.FromMinutes( 1 ); p.SendLocalizedMessage( 500616 ); // You hear lovely music, and forget to continue battling! @@ -121,12 +119,10 @@ namespace Server.Mobiles public static void SuppressRemove( Mobile target ) { - if ( target != null && m_Suppressed.ContainsKey( target ) ) + if ( target != null && m_Suppressed[target] is Timer t ) { - Timer timer = m_Suppressed[ target ]; - - if ( timer != null || timer.Running ) - timer.Stop(); + if ( t.Running ) + t.Stop(); m_Suppressed.Remove( target ); } @@ -196,10 +192,8 @@ namespace Server.Mobiles foreach ( Mobile m in GetMobilesInRange( RangePerception ) ) { - if ( m is BaseCreature ) + if ( m is BaseCreature c ) { - BaseCreature c = (BaseCreature) m; - if ( c == this || c == target || c.Unprovokable || c.IsParagon || c.BardProvoked || c.AccessLevel != AccessLevel.Player || !c.CanBeHarmful( target ) ) continue; diff --git a/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs b/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs index 5af8d5a0f..fe9a8c229 100644 --- a/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs +++ b/Scripts/Mobiles/Monsters/ML/Special/Ilhenir.cs @@ -231,8 +231,8 @@ namespace Server.Mobiles private void EndCacophonic_Callback( object state ) { - if ( state is Mobile ) - CacophonicEnd( (Mobile)state ); + if ( state is Mobile mobile ) + CacophonicEnd( mobile ); } public virtual void CacophonicEnd( Mobile from ) @@ -362,10 +362,8 @@ namespace Server.Mobiles foreach ( Mobile m in GetMobilesInRange( 0 ) ) { - if ( m is BaseCreature ) + if ( m is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)m; - if ( !bc.Controlled && !bc.Summoned ) continue; } @@ -398,9 +396,7 @@ namespace Server.Mobiles for ( int i = 0; i < items.Count; ++i ) { - IDurability wearable = items[i] as IDurability; - - if ( wearable != null && wearable.HitPoints >= 10 && Utility.RandomDouble() < 0.25 ) + if ( items[i] is IDurability wearable && wearable.HitPoints >= 10 && Utility.RandomDouble() < 0.25 ) { wearable.HitPoints -= ( wearable.HitPoints == 10 ) ? Utility.Random( 1, 5 ) : 10; damaged = true; diff --git a/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs b/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs index 932b7b6a3..59564f1e2 100644 --- a/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs +++ b/Scripts/Mobiles/Monsters/ML/Special/Meraktus.cs @@ -178,7 +178,7 @@ namespace Server.Mobiles { if (m == this || !CanBeHarmful(m)) continue; - if (m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team)) + if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || creature.Team != this.Team)) targets.Add(m); else if (m.Player) targets.Add(m); @@ -187,15 +187,14 @@ namespace Server.Mobiles for (int i = 0; i < targets.Count; ++i) { Mobile m = (Mobile)targets[i]; - if ( m != null && !m.Deleted && m is PlayerMobile ) + if ( m != null && !m.Deleted && m is PlayerMobile pm ) { - PlayerMobile pm = m as PlayerMobile; - if (pm != null && pm.Mounted) + if (pm.Mounted) { - pm.Mount.Rider=null; + pm.Mount.Rider = null; } } - double damage = m.Hits * 0.6;//was .6 + double damage = m.Hits * 0.6; //was .6 if (damage < 10.0) damage = 10.0; else if (damage > 75.0) diff --git a/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs b/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs index 823f9314f..adb21d52d 100644 --- a/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs +++ b/Scripts/Mobiles/Monsters/Misc/Melee/Golem.cs @@ -158,8 +158,7 @@ namespace Server.Mobiles this.PlaySound( 0xEE ); defender.LocalOverheadMessage( MessageType.Regular, 0x3B2, false, "You have been stunned by a colossal blow!" ); - BaseWeapon weapon = this.Weapon as BaseWeapon; - if ( weapon != null ) + if ( this.Weapon is BaseWeapon weapon ) weapon.OnHit( this, defender ); if ( defender.Alive ) @@ -172,9 +171,7 @@ namespace Server.Mobiles private void Recover_Callback( object state ) { - Mobile defender = state as Mobile; - - if ( defender != null ) + if ( state is Mobile defender ) { defender.Frozen = false; defender.Combatant = null; diff --git a/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs b/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs index 0172c7f4a..493b1118f 100644 --- a/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs +++ b/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeastLord.cs @@ -29,9 +29,7 @@ namespace Server.Mobiles { for ( int i = 0; i < pack.Items.Count; i++ ) { - PlagueBeastBlood blood = pack.Items[ i ] as PlagueBeastBlood; - - if ( blood != null && !blood.Patched ) + if ( pack.Items[ i ] is PlagueBeastBlood blood && !blood.Patched ) return true; } } @@ -107,7 +105,7 @@ namespace Server.Mobiles public override void OnDelete() { - if ( m_OpenedBy != null && m_OpenedBy.Holding is PlagueBeastInnard ) + if ( m_OpenedBy?.Holding is PlagueBeastInnard ) m_OpenedBy.Holding.Delete(); if ( Backpack != null ) diff --git a/Scripts/Mobiles/Monsters/Ore Elementals/ShadowIronElemental.cs b/Scripts/Mobiles/Monsters/Ore Elementals/ShadowIronElemental.cs index 60401a19f..ee768aa5c 100644 --- a/Scripts/Mobiles/Monsters/Ore Elementals/ShadowIronElemental.cs +++ b/Scripts/Mobiles/Monsters/Ore Elementals/ShadowIronElemental.cs @@ -64,12 +64,9 @@ namespace Server.Mobiles public override void AlterMeleeDamageFrom( Mobile from, ref int damage ) { - if ( from is BaseCreature ) + if ( from is BaseCreature bc && (bc.Controlled || bc.BardTarget == this) ) { - BaseCreature bc = (BaseCreature)from; - - if ( bc.Controlled || bc.BardTarget == this ) - damage = 0; // Immune to pets and provoked creatures + damage = 0; // Immune to pets and provoked creatures } } diff --git a/Scripts/Mobiles/Monsters/Ore Elementals/ValoriteElemental.cs b/Scripts/Mobiles/Monsters/Ore Elementals/ValoriteElemental.cs index 9d726bbbc..94cdba313 100644 --- a/Scripts/Mobiles/Monsters/Ore Elementals/ValoriteElemental.cs +++ b/Scripts/Mobiles/Monsters/Ore Elementals/ValoriteElemental.cs @@ -66,10 +66,8 @@ namespace Server.Mobiles public override void AlterMeleeDamageFrom( Mobile from, ref int damage ) { - if ( from is BaseCreature ) + if ( @from is BaseCreature bc ) { - BaseCreature bc = (BaseCreature)from; - if ( bc.Controlled || bc.BardTarget == this ) damage = 0; // Immune to pets and provoked creatures } diff --git a/Scripts/Mobiles/Monsters/Reptile/Magic/SerpentineDragon.cs b/Scripts/Mobiles/Monsters/Reptile/Magic/SerpentineDragon.cs index b159016ce..8d28990dd 100644 --- a/Scripts/Mobiles/Monsters/Reptile/Magic/SerpentineDragon.cs +++ b/Scripts/Mobiles/Monsters/Reptile/Magic/SerpentineDragon.cs @@ -99,16 +99,11 @@ namespace Server.Mobiles { base.OnGotMeleeAttack( attacker ); - if ( !Core.SE && 0.2 > Utility.RandomDouble() && attacker is BaseCreature ) + if ( !Core.SE && 0.2 > Utility.RandomDouble() && attacker is BaseCreature c && c.Controlled && c.ControlMaster != null ) { - BaseCreature c = (BaseCreature)attacker; - - if ( c.Controlled && c.ControlMaster != null ) - { - c.ControlTarget = c.ControlMaster; - c.ControlOrder = OrderType.Attack; - c.Combatant = c.ControlMaster; - } + c.ControlTarget = c.ControlMaster; + c.ControlOrder = OrderType.Attack; + c.Combatant = c.ControlMaster; } } diff --git a/Scripts/Mobiles/Monsters/SE/Yamandon.cs b/Scripts/Mobiles/Monsters/SE/Yamandon.cs index a6527522b..1f724bb76 100644 --- a/Scripts/Mobiles/Monsters/SE/Yamandon.cs +++ b/Scripts/Mobiles/Monsters/SE/Yamandon.cs @@ -81,7 +81,7 @@ namespace Server.Mobiles if ( this.Map == null ) return; - if ( attacker is BaseCreature && ((BaseCreature)attacker).BardProvoked ) + if ( attacker is BaseCreature creature && creature.BardProvoked ) return; if ( 0.2 > Utility.RandomDouble() ) @@ -95,9 +95,9 @@ namespace Server.Mobiles Mobile target = null; - if ( attacker is BaseCreature ) + if ( attacker is BaseCreature baseCreature ) { - Mobile m = ((BaseCreature)attacker).GetMaster(); + Mobile m = baseCreature.GetMaster(); if ( m != null ) target = m; @@ -115,7 +115,7 @@ namespace Server.Mobiles if ( m == this || !CanBeHarmful( m ) ) continue; - if ( m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || ((BaseCreature)m).Team != this.Team) ) + if ( m is BaseCreature bc && (bc.Controlled || bc.Summoned || bc.Team != this.Team)) targets.Add( m ); else if ( m.Player && m.Alive ) targets.Add( m ); diff --git a/Scripts/Mobiles/PlayerMobile.cs b/Scripts/Mobiles/PlayerMobile.cs index 43ccd74c2..90cacaa86 100644 --- a/Scripts/Mobiles/PlayerMobile.cs +++ b/Scripts/Mobiles/PlayerMobile.cs @@ -140,11 +140,9 @@ namespace Server.Mobiles if (!Flying) { // No message? - if (Spell is FlySpell) - { - FlySpell spell = (FlySpell)Spell; + if (Spell is FlySpell spell) spell.Stop(); - } + new FlySpell(this).Cast(); } else @@ -629,11 +627,9 @@ namespace Server.Mobiles { object[] objs = type.GetCustomAttributes( typeof( FlippableAttribute ), true ); - if ( objs != null && objs.Length > 0 ) + if ( objs.Length > 0 ) { - FlippableAttribute fp = objs[0] as FlippableAttribute; - - if ( fp != null ) + if ( objs[0] is FlippableAttribute fp ) { int[] itemIDs = fp.ItemIDs; @@ -732,11 +728,9 @@ namespace Server.Mobiles { foreach( Mobile m in World.Mobiles.Values ) { - if ( m is PlayerMobile ) + if ( m is PlayerMobile pm ) { - PlayerMobile pm = (PlayerMobile)m; - - if ((( !pm.Mounted || ( pm.Mount != null && pm.Mount is EtherealMount )) && ( pm.AllFollowers.Count > pm.AutoStabled.Count )) || + if ((( !pm.Mounted || ( pm.Mount is EtherealMount )) && ( pm.AllFollowers.Count > pm.AutoStabled.Count )) || ( pm.Mounted && ( pm.AllFollowers.Count > ( pm.AutoStabled.Count +1 )))) { pm.AutoStablePets(); /* autostable checks summons, et al: no need here */ @@ -915,9 +909,7 @@ namespace Server.Mobiles { string notice; - Accounting.Account acct = from.Account as Accounting.Account; - - if ( acct == null || !acct.HasAccess( from.NetState ) ) + if ( !(@from.Account is Account acct) || !acct.HasAccess( from.NetState ) ) { if ( from.AccessLevel == AccessLevel.Player ) notice = "The server is currently under lockdown. No players are allowed to log in at this time."; @@ -939,8 +931,8 @@ namespace Server.Mobiles return; } - if ( from is PlayerMobile ) - ((PlayerMobile)from).ClaimAutoStabledPets(); + if ( @from is PlayerMobile mobile ) + mobile.ClaimAutoStabledPets(); } private bool m_NoDeltaRecursion; @@ -1021,10 +1013,8 @@ namespace Server.Mobiles } #endregion - if ( item is BaseWeapon ) + if ( item is BaseWeapon weapon ) { - BaseWeapon weapon = (BaseWeapon)item; - bool drop = false; if ( dex < weapon.DexRequirement ) @@ -1048,10 +1038,8 @@ namespace Server.Mobiles moved = true; } } - else if ( item is BaseArmor ) + else if ( item is BaseArmor armor ) { - BaseArmor armor = (BaseArmor)item; - bool drop = false; if ( !armor.AllowMaleWearer && !from.Female && from.AccessLevel < AccessLevel.GameMaster ) @@ -1096,10 +1084,8 @@ namespace Server.Mobiles moved = true; } } - else if ( item is BaseClothing ) + else if ( item is BaseClothing clothing ) { - BaseClothing clothing = (BaseClothing)item; - bool drop = false; if ( !clothing.AllowMaleWearer && !from.Female && from.AccessLevel < AccessLevel.GameMaster )