diff --git a/Scripts/Misc/AOS.cs b/Scripts/Misc/AOS.cs index bbc76a1d8..7ed405f6e 100644 --- a/Scripts/Misc/AOS.cs +++ b/Scripts/Misc/AOS.cs @@ -146,11 +146,9 @@ namespace Server } #region Dragon Barding - if ( (from == null || !from.Player) && m.Player && m.Mount is SwampDragon ) + if ( (from == null || !from.Player) && m.Player && m.Mount is SwampDragon pet ) { - SwampDragon pet = m.Mount as SwampDragon; - - if ( pet != null && pet.HasBarding ) + if ( pet.HasBarding ) { int percent = (pet.BardingExceptional ? 20 : 10); int absorbed = Scale( totalDamage, percent ); @@ -178,7 +176,7 @@ namespace Server if ( reflectPhys != 0 ) { - if ( from is ExodusMinion && ((ExodusMinion)from).FieldActive || from is ExodusOverseer && ((ExodusOverseer)from).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 ); @@ -289,57 +287,57 @@ namespace Server { Item obj = items[i]; - if ( obj is BaseWeapon ) + if ( obj is BaseWeapon weapon ) { - AosAttributes attrs = ((BaseWeapon)obj).Attributes; + AosAttributes attrs = weapon.Attributes; if ( attrs != null ) value += attrs[attribute]; if ( attribute == AosAttribute.Luck ) - value += ((BaseWeapon)obj).GetLuckBonus(); + value += weapon.GetLuckBonus(); } - else if ( obj is BaseArmor ) + else if ( obj is BaseArmor armor ) { - AosAttributes attrs = ((BaseArmor)obj).Attributes; + AosAttributes attrs = armor.Attributes; if ( attrs != null ) value += attrs[attribute]; if ( attribute == AosAttribute.Luck ) - value += ((BaseArmor)obj).GetLuckBonus(); + value += armor.GetLuckBonus(); } - else if ( obj is BaseJewel ) + else if ( obj is BaseJewel jewel ) { - AosAttributes attrs = ((BaseJewel)obj).Attributes; + AosAttributes attrs = jewel.Attributes; if ( attrs != null ) value += attrs[attribute]; } - else if ( obj is BaseClothing ) + else if ( obj is BaseClothing clothing ) { - AosAttributes attrs = ((BaseClothing)obj).Attributes; + AosAttributes attrs = clothing.Attributes; if ( attrs != null ) value += attrs[attribute]; } - else if ( obj is Spellbook ) + else if ( obj is Spellbook spellbook ) { - AosAttributes attrs = ((Spellbook)obj).Attributes; + AosAttributes attrs = spellbook.Attributes; if ( attrs != null ) value += attrs[attribute]; } - else if ( obj is BaseQuiver ) + else if ( obj is BaseQuiver quiver ) { - AosAttributes attrs = ((BaseQuiver)obj).Attributes; + AosAttributes attrs = quiver.Attributes; if ( attrs != null ) value += attrs[attribute]; } - else if ( obj is BaseTalisman ) + else if ( obj is BaseTalisman talisman ) { - AosAttributes attrs = ((BaseTalisman)obj).Attributes; + AosAttributes attrs = talisman.Attributes; if (attrs != null) value += attrs[attribute]; @@ -526,16 +524,16 @@ namespace Server { Item obj = items[i]; - if ( obj is BaseWeapon ) + if ( obj is BaseWeapon weapon ) { - AosWeaponAttributes attrs = ((BaseWeapon)obj).WeaponAttributes; + AosWeaponAttributes attrs = weapon.WeaponAttributes; if ( attrs != null ) value += attrs[attribute]; } - else if ( obj is ElvenGlasses ) + else if ( obj is ElvenGlasses glasses ) { - AosWeaponAttributes attrs = ((ElvenGlasses)obj).WeaponAttributes; + AosWeaponAttributes attrs = glasses.WeaponAttributes; if ( attrs != null ) value += attrs[attribute]; @@ -670,16 +668,16 @@ namespace Server { Item obj = items[i]; - if ( obj is BaseArmor ) + if ( obj is BaseArmor armor ) { - AosArmorAttributes attrs = ((BaseArmor)obj).ArmorAttributes; + AosArmorAttributes attrs = armor.ArmorAttributes; if ( attrs != null ) value += attrs[attribute]; } - else if ( obj is BaseClothing ) + else if ( obj is BaseClothing clothing ) { - AosArmorAttributes attrs = ((BaseClothing)obj).ClothingAttributes; + AosArmorAttributes attrs = clothing.ClothingAttributes; if ( attrs != null ) value += attrs[attribute]; @@ -763,10 +761,7 @@ namespace Server for( int i = 0; i < 5; ++i ) { - SkillName skill; - double bonus; - - if ( !GetValues( i, out skill, out bonus ) ) + if ( !GetValues( i, out SkillName skill, out double bonus ) ) continue; if ( m_Mods == null ) @@ -906,8 +901,8 @@ namespace Server BaseClothing.ValidateMobile( m ); } if ( !m.CanBeginAction ( typeof ( IncognitoSpell ) ) && m.Skills[SkillName.Magery].Value < 38.1 ) { - if ( m is PlayerMobile ) - ((PlayerMobile)m).SetHairMods( -1, -1 ); + if ( m is PlayerMobile mobile ) + mobile.SetHairMods( -1, -1 ); m.BodyMod = 0; m.HueMod = -1; m.NameMod = null; @@ -916,7 +911,6 @@ namespace Server BaseClothing.ValidateMobile( m ); BuffInfo.RemoveBuff( m, BuffIcon.Incognito ); } - return; } @@ -1103,15 +1097,15 @@ namespace Server { if ( (bitmask == (int)AosWeaponAttribute.DurabilityBonus) && (this is AosWeaponAttributes) ) { - if ( m_Owner is BaseWeapon ) - ((BaseWeapon)m_Owner).UnscaleDurability(); + if ( m_Owner is BaseWeapon weapon ) + weapon.UnscaleDurability(); } else if ( (bitmask == (int)AosArmorAttribute.DurabilityBonus) && (this is AosArmorAttributes) ) { - if ( m_Owner is BaseArmor ) - ((BaseArmor)m_Owner).UnscaleDurability(); - else if ( m_Owner is BaseClothing ) - ((BaseClothing)m_Owner).UnscaleDurability(); + if ( m_Owner is BaseArmor armor ) + armor.UnscaleDurability(); + else if ( m_Owner is BaseClothing clothing ) + clothing.UnscaleDurability(); } uint mask = (uint)bitmask; @@ -1174,21 +1168,19 @@ namespace Server if ( (bitmask == (int)AosWeaponAttribute.DurabilityBonus) && (this is AosWeaponAttributes) ) { - if ( m_Owner is BaseWeapon ) - ((BaseWeapon)m_Owner).ScaleDurability(); + if ( m_Owner is BaseWeapon weapon ) + weapon.ScaleDurability(); } else if ( (bitmask == (int)AosArmorAttribute.DurabilityBonus) && (this is AosArmorAttributes) ) { - if ( m_Owner is BaseArmor ) - ((BaseArmor)m_Owner).ScaleDurability(); - else if ( m_Owner is BaseClothing ) - ((BaseClothing)m_Owner).ScaleDurability(); + if ( m_Owner is BaseArmor armor ) + armor.ScaleDurability(); + else if ( m_Owner is BaseClothing clothing ) + clothing.ScaleDurability(); } - if ( m_Owner.Parent is Mobile ) + if ( m_Owner.Parent is Mobile m ) { - Mobile m = (Mobile)m_Owner.Parent; - m.CheckStatTimers(); m.UpdateResistances(); m.Delta( MobileDelta.Stat | MobileDelta.WeaponDamage | MobileDelta.Hits | MobileDelta.Stam | MobileDelta.Mana ); diff --git a/Scripts/Misc/Assistants.cs b/Scripts/Misc/Assistants.cs index 4b7732f8d..622f10646 100644 --- a/Scripts/Misc/Assistants.cs +++ b/Scripts/Misc/Assistants.cs @@ -130,8 +130,7 @@ namespace Server.Misc Mobile m = state.Mobile; if (m_Dictionary.TryGetValue( m, out Timer t )) { - if (t != null) - t.Stop(); + t?.Stop(); m_Dictionary.Remove(m); } @@ -139,24 +138,23 @@ namespace Server.Misc private static void OnHandshakeTimeout(object state) { - Timer t = null; - Mobile m = state as Mobile; - - if (m == null) + if (!(state is Mobile m)) return; m_Dictionary.Remove(m); - if (!Settings.KickOnFailure) - { - Console.WriteLine("Player '{0}' failed to negotiate features.", m); - } - else if (m.NetState != null && m.NetState.Running) +// if (!Settings.KickOnFailure) +// { +// Console.WriteLine("Player '{0}' failed to negotiate features.", m); +// } + + if (m.NetState != null && m.NetState.Running) { m.SendGump(new Gumps.WarningGump(1060635, 30720, Settings.WarningMessage, 0xFFC000, 420, 250, null, null)); if (m.AccessLevel <= AccessLevel.Player) { + Timer t; m_Dictionary[m] = t = Timer.DelayCall(Settings.DisconnectDelay, OnForceDisconnect_Callback, m); t.Start(); } @@ -165,10 +163,8 @@ namespace Server.Misc private static void OnForceDisconnect(object state) { - if (state is Mobile) + if (state is Mobile m) { - Mobile m = (Mobile)state; - if (m.NetState != null && m.NetState.Running) m.NetState.Dispose(); diff --git a/Scripts/Misc/BuffIcons.cs b/Scripts/Misc/BuffIcons.cs index e0a6dd23d..97640a5f7 100644 --- a/Scripts/Misc/BuffIcons.cs +++ b/Scripts/Misc/BuffIcons.cs @@ -16,9 +16,7 @@ namespace Server { EventSink.ClientVersionReceived += new ClientVersionReceivedHandler( delegate( ClientVersionReceivedArgs args ) { - PlayerMobile pm = args.State.Mobile as PlayerMobile; - - if ( pm != null ) + if ( args.State.Mobile is PlayerMobile pm ) Timer.DelayCall( TimeSpan.Zero, pm.ResendBuffs ); } ); } @@ -79,9 +77,7 @@ namespace Server m_Timer = Timer.DelayCall( length, new TimerCallback( delegate { - PlayerMobile pm = m as PlayerMobile; - - if ( pm == null ) + if ( !(m is PlayerMobile pm) ) return; pm.RemoveBuff( this ); @@ -150,25 +146,19 @@ namespace Server #region Convenience Methods public static void AddBuff( Mobile m, BuffInfo b ) { - PlayerMobile pm = m as PlayerMobile; - - if ( pm != null ) + if ( m is PlayerMobile pm ) pm.AddBuff( b ); } public static void RemoveBuff( Mobile m, BuffInfo b ) { - PlayerMobile pm = m as PlayerMobile; - - if ( pm != null ) + if ( m is PlayerMobile pm ) pm.RemoveBuff( b ); } public static void RemoveBuff( Mobile m, BuffIcon b ) { - PlayerMobile pm = m as PlayerMobile; - - if ( pm != null ) + if ( m is PlayerMobile pm ) pm.RemoveBuff( b ); } #endregion diff --git a/Scripts/Misc/CharacterCreation.cs b/Scripts/Misc/CharacterCreation.cs index 14313db8a..3435db8f6 100644 --- a/Scripts/Misc/CharacterCreation.cs +++ b/Scripts/Misc/CharacterCreation.cs @@ -405,9 +405,7 @@ namespace Server.Misc for( int i = 0; i < cont.Items.Count; i++ ) { - BaseRanged bow = cont.Items[i] as BaseRanged; - - if ( bow != null ) + if ( cont.Items[i] is BaseRanged bow ) { bow.Attributes.WeaponSpeed = 35; bow.Attributes.WeaponDamage = 35; @@ -648,10 +646,8 @@ namespace Server.Misc bool young = false; - if ( newChar is PlayerMobile ) + if ( newChar is PlayerMobile pm ) { - PlayerMobile pm = (PlayerMobile) newChar; - pm.Profession = args.Profession; if ( pm.AccessLevel == AccessLevel.Player && ((Account)pm.Account).Young ) @@ -711,14 +707,14 @@ namespace Server.Misc { if ( profession < 0 ) return false; - else if ( profession < 4 ) + if ( profession < 4 ) return true; - else if ( Core.AOS && profession < 6 ) + if ( Core.AOS && profession < 6 ) return true; - else if ( Core.SE && profession < 8 ) + if ( Core.SE && profession < 8 ) return true; - else - return false; + + return false; } private class BadStartMessage : Timer @@ -752,7 +748,7 @@ namespace Server.Misc bool useHaven = isYoung; - ClientFlags flags = args.State == null ? ClientFlags.None : args.State.Flags; + ClientFlags flags = args.State?.Flags ?? ClientFlags.None; Mobile m = args.Mobile; switch ( args.Profession ) @@ -763,19 +759,17 @@ namespace Server.Misc { return new CityInfo( "Umbra", "Mardoth's Tower", 2114, 1301, -50, Map.Malas ); } - else - { - useHaven = true; - new BadStartMessage( m, 1062205 ); - /* - * Unfortunately you are playing on a *NON-Age-Of-Shadows* game - * installation and cannot be transported to Malas. - * You will not be able to take your new player quest in Malas - * without an AOS client. You are now being taken to the city of - * Haven on the Trammel facet. - * */ - } + useHaven = true; + + new BadStartMessage( m, 1062205 ); + /* + * Unfortunately you are playing on a *NON-Age-Of-Shadows* game + * installation and cannot be transported to Malas. + * You will not be able to take your new player quest in Malas + * without an AOS client. You are now being taken to the city of + * Haven on the Trammel facet. + * */ break; } @@ -789,19 +783,17 @@ namespace Server.Misc { return new CityInfo( "Samurai DE", "Haoti's Grounds", 368, 780, -1, Map.Malas ); } - else - { - useHaven = true; - new BadStartMessage( m, 1063487 ); - /* - * Unfortunately you are playing on a *NON-Samurai-Empire* game - * installation and cannot be transported to Tokuno. - * You will not be able to take your new player quest in Tokuno - * without an SE client. You are now being taken to the city of - * Haven on the Trammel facet. - * */ - } + useHaven = true; + + new BadStartMessage( m, 1063487 ); + /* + * Unfortunately you are playing on a *NON-Samurai-Empire* game + * installation and cannot be transported to Tokuno. + * You will not be able to take your new player quest in Tokuno + * without an SE client. You are now being taken to the city of + * Haven on the Trammel facet. + * */ break; } @@ -811,19 +803,17 @@ namespace Server.Misc { return new CityInfo( "Ninja DE", "Enimo's Residence", 414, 823, -1, Map.Malas ); } - else - { - useHaven = true; - new BadStartMessage( m, 1063487 ); - /* - * Unfortunately you are playing on a *NON-Samurai-Empire* game - * installation and cannot be transported to Tokuno. - * You will not be able to take your new player quest in Tokuno - * without an SE client. You are now being taken to the city of - * Haven on the Trammel facet. - * */ - } + useHaven = true; + + new BadStartMessage( m, 1063487 ); + /* + * Unfortunately you are playing on a *NON-Samurai-Empire* game + * installation and cannot be transported to Tokuno. + * You will not be able to take your new player quest in Tokuno + * without an SE client. You are now being taken to the city of + * Haven on the Trammel facet. + * */ break; } @@ -831,8 +821,8 @@ namespace Server.Misc if ( useHaven ) return m_NewHavenInfo; - else - return args.City; + + return args.City; } private static void FixStats( ref int str, ref int dex, ref int intel, int max ) @@ -1193,12 +1183,7 @@ namespace Server.Misc } } - private static void EquipItem( Item item ) - { - EquipItem( item, false ); - } - - private static void EquipItem( Item item, bool mustEquip ) + private static void EquipItem( Item item, bool mustEquip = false) { if ( !Core.AOS ) item.LootType = LootType.Newbied; @@ -1671,13 +1656,9 @@ namespace Server.Misc } case SkillName.Tracking: { - if ( m_Mobile != null ) - { - Item shoes = m_Mobile.FindItemOnLayer( Layer.Shoes ); + Item shoes = m_Mobile?.FindItemOnLayer( Layer.Shoes ); - if ( shoes != null ) - shoes.Delete(); - } + shoes?.Delete(); int hue = Utility.RandomYellowHue(); diff --git a/Scripts/Misc/Cleanup.cs b/Scripts/Misc/Cleanup.cs index 7fcae3581..6b7017f13 100644 --- a/Scripts/Misc/Cleanup.cs +++ b/Scripts/Misc/Cleanup.cs @@ -29,23 +29,19 @@ namespace Server.Misc items.Add( item ); continue; } - else if ( item is CommodityDeed ) + if ( item is CommodityDeed deed ) { - CommodityDeed deed = (CommodityDeed)item; - if ( deed.Commodity != null ) validItems.Add( deed.Commodity ); continue; } - else if ( item is BaseHouse ) + if ( item is BaseHouse house ) { - BaseHouse house = (BaseHouse)item; - foreach ( RelocatedEntity relEntity in house.RelocatedEntities ) { - if ( relEntity.Entity is Item ) - validItems.Add( (Item)relEntity.Entity ); + if ( relEntity.Entity is Item item1 ) + validItems.Add( item1 ); } foreach ( VendorInventory inventory in house.VendorInventories ) @@ -54,9 +50,8 @@ namespace Server.Misc validItems.Add( subItem ); } } - else if ( item is BankBox ) + else if ( item is BankBox box ) { - BankBox box = (BankBox)item; Mobile owner = box.Owner; if ( owner == null ) @@ -76,15 +71,14 @@ namespace Server.Misc { object rootParent = item.RootParent; - if ( rootParent is Mobile ) + if ( rootParent is Mobile rootMobile ) { - Mobile rootMobile = (Mobile)rootParent; if ( item.Parent != rootMobile && rootMobile.AccessLevel == AccessLevel.Player ) { items.Add( item ); continue; } - else if ( item.Parent == rootMobile ) + if ( item.Parent == rootMobile ) { hairCleanup.Add( rootMobile ); continue; diff --git a/Scripts/Misc/ClientVerification.cs b/Scripts/Misc/ClientVerification.cs index cc1027f11..a7cdd1413 100644 --- a/Scripts/Misc/ClientVerification.cs +++ b/Scripts/Misc/ClientVerification.cs @@ -129,7 +129,7 @@ namespace Server.Misc if ( state.Mobile == null || state.Mobile.AccessLevel > AccessLevel.Player ) return; - if ( Required != null && version < Required && ( m_OldClientResponse == OldClientResponse.Kick ||( m_OldClientResponse == OldClientResponse.LenientKick && (DateTime.UtcNow - state.Mobile.CreationTime) > m_AgeLeniency && state.Mobile is PlayerMobile && ((PlayerMobile)state.Mobile).GameTime > m_GameTimeLeniency ))) + if ( Required != null && version < Required && ( m_OldClientResponse == OldClientResponse.Kick ||( m_OldClientResponse == OldClientResponse.LenientKick && (DateTime.UtcNow - state.Mobile.CreationTime) > m_AgeLeniency && state.Mobile is PlayerMobile mobile && mobile.GameTime > m_GameTimeLeniency ))) { kickMessage = String.Format( "This server requires your client version be at least {0}.", Required ); }