From 9542c79ea44e0faa463e9558c24d66cd2bcd7d27 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sat, 15 Sep 2018 23:31:51 -0700 Subject: [PATCH] Fixes several more expression issues and cast type check merges. --- Scripts/Engines/Factions/Core/Faction.cs | 2 +- Scripts/Engines/Factions/Core/Generator.cs | 7 +- .../MLQuests/Objectives/DeliverObjective.cs | 2 +- Scripts/Gumps/Props/SetObjectTarget.cs | 2 +- Scripts/Misc/Emitter.cs | 9 +-- Scripts/Mobiles/PlayerMobile.cs | 7 +- Scripts/Mobiles/Special/BaseChampion.cs | 6 +- Scripts/Mobiles/Special/BaseShieldGuard.cs | 5 +- Scripts/Mobiles/Special/Harrower.cs | 4 +- Scripts/Mobiles/Special/Rikktor.cs | 4 +- Scripts/Mobiles/Special/Semidar.cs | 4 +- Scripts/Mobiles/Special/Serado.cs | 67 +++++++++---------- Scripts/Mobiles/Townfolk/BaseEscortable.cs | 14 ++-- Scripts/Mobiles/Vendors/BaseVendor.cs | 5 +- Scripts/Mobiles/Vendors/GenericBuy.cs | 10 +-- Scripts/Mobiles/Vendors/GenericSell.cs | 18 ++--- Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs | 4 +- Scripts/Mobiles/Vendors/NPC/Blacksmith.cs | 12 ++-- .../NPC/Guildmasters/BaseGuildmaster.cs | 30 ++++----- .../NPC/Guildmasters/ThiefGuildmaster.cs | 14 ++-- .../Mobiles/Vendors/NPC/RealEstateBroker.cs | 9 +-- Scripts/Mobiles/Vendors/NPC/Tailor.cs | 12 ++-- Server/Items/Container.cs | 2 +- Server/Region.cs | 2 +- 24 files changed, 106 insertions(+), 145 deletions(-) diff --git a/Scripts/Engines/Factions/Core/Faction.cs b/Scripts/Engines/Factions/Core/Faction.cs index 33623d81d..2c4672dc5 100644 --- a/Scripts/Engines/Factions/Core/Faction.cs +++ b/Scripts/Engines/Factions/Core/Faction.cs @@ -242,7 +242,7 @@ namespace Server.Factions IPooledEnumerable eable = mob.Map.GetObjectsInRange(mob.Location, range, items, mobs); foreach (IEntity obj in eable) - if (type.IsAssignableFrom(obj.GetType())) + if (type.IsInstanceOfType(obj)) { eable.Free(); return true; diff --git a/Scripts/Engines/Factions/Core/Generator.cs b/Scripts/Engines/Factions/Core/Generator.cs index 5940970de..22f2b49f5 100644 --- a/Scripts/Engines/Factions/Core/Generator.cs +++ b/Scripts/Engines/Factions/Core/Generator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Server.Commands; namespace Server.Factions @@ -68,11 +69,7 @@ namespace Server.Factions private static bool CheckExistance(Point3D loc, Map facet, Type type) { - foreach (Item item in facet.GetItemsInRange(loc, 0)) - if (type.IsAssignableFrom(item.GetType())) - return true; - - return false; + return facet.GetItemsInRange(loc, 0).Any(type.IsInstanceOfType); } } } \ No newline at end of file diff --git a/Scripts/Engines/MLQuests/Objectives/DeliverObjective.cs b/Scripts/Engines/MLQuests/Objectives/DeliverObjective.cs index 97fcd05e0..27604a68d 100644 --- a/Scripts/Engines/MLQuests/Objectives/DeliverObjective.cs +++ b/Scripts/Engines/MLQuests/Objectives/DeliverObjective.cs @@ -136,7 +136,7 @@ namespace Server.Engines.MLQuests.Objectives { Type destType = Objective.Destination; - return destType != null && destType.IsAssignableFrom(type); + return destType?.IsAssignableFrom(type) == true; } public override bool IsCompleted() diff --git a/Scripts/Gumps/Props/SetObjectTarget.cs b/Scripts/Gumps/Props/SetObjectTarget.cs index 2ec03c1f8..b8ca0cfa9 100644 --- a/Scripts/Gumps/Props/SetObjectTarget.cs +++ b/Scripts/Gumps/Props/SetObjectTarget.cs @@ -40,7 +40,7 @@ namespace Server.Gumps targeted is AddonComponent) targeted = ((AddonComponent)targeted).Addon; - if (m_Type.IsAssignableFrom(targeted.GetType())) + if (m_Type.IsInstanceOfType(targeted)) { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, targeted.ToString()); m_Property.SetValue(m_Object, targeted, null); diff --git a/Scripts/Misc/Emitter.cs b/Scripts/Misc/Emitter.cs index 455f9f559..a01e1383c 100644 --- a/Scripts/Misc/Emitter.cs +++ b/Scripts/Misc/Emitter.cs @@ -503,12 +503,9 @@ namespace Server * Bleh. */ - Type[] ifaces = active.FindInterfaces( delegate( Type type, object obj ) - { - return ( type.IsGenericType ) - && ( type.GetGenericTypeDefinition() == typeof( IComparable<> ) ) - && ( type.GetGenericArguments()[0].IsAssignableFrom( active ) ); - }, null ); + Type[] ifaces = active.FindInterfaces((type, obj) => (type.IsGenericType) + && (type.GetGenericTypeDefinition() == typeof(IComparable<>)) + && (type.GetGenericArguments()[0].IsAssignableFrom(active)), null ); if ( ifaces.Length > 0 ) { diff --git a/Scripts/Mobiles/PlayerMobile.cs b/Scripts/Mobiles/PlayerMobile.cs index 9e8c8f36c..ebc21f22e 100644 --- a/Scripts/Mobiles/PlayerMobile.cs +++ b/Scripts/Mobiles/PlayerMobile.cs @@ -3552,12 +3552,7 @@ namespace Server.Mobiles private Item[] m_Items; private int m_Page; - public ItemInsuranceMenuGump(PlayerMobile from, Item[] items) - : this(from, items, null, 0) - { - } - - public ItemInsuranceMenuGump(PlayerMobile from, Item[] items, bool[] insure, int page) + public ItemInsuranceMenuGump(PlayerMobile from, Item[] items, bool[] insure = null, int page = 0) : base(25, 50) { m_From = from; diff --git a/Scripts/Mobiles/Special/BaseChampion.cs b/Scripts/Mobiles/Special/BaseChampion.cs index 546664dbb..d38329a10 100644 --- a/Scripts/Mobiles/Special/BaseChampion.cs +++ b/Scripts/Mobiles/Special/BaseChampion.cs @@ -69,10 +69,10 @@ namespace Server.Mobiles Item artifact = Loot.Construct(type); - if (artifact is MonsterStatuette && StatueTypes.Length > 0) + if (artifact is MonsterStatuette statuette && StatueTypes.Length > 0) { - ((MonsterStatuette)artifact).Type = StatueTypes[Utility.Random(StatueTypes.Length)]; - ((MonsterStatuette)artifact).LootType = LootType.Regular; + statuette.Type = StatueTypes[Utility.Random(StatueTypes.Length)]; + statuette.LootType = LootType.Regular; } return artifact; diff --git a/Scripts/Mobiles/Special/BaseShieldGuard.cs b/Scripts/Mobiles/Special/BaseShieldGuard.cs index 8154bba7b..1b5f7a07d 100644 --- a/Scripts/Mobiles/Special/BaseShieldGuard.cs +++ b/Scripts/Mobiles/Special/BaseShieldGuard.cs @@ -111,9 +111,8 @@ namespace Server.Mobiles e.Handled = true; Mobile from = e.Mobile; - Guild g = from.Guild as Guild; - if (g == null || g.Type != Type) + if (!(from.Guild is Guild g) || g.Type != Type) { Say(SignupNumber); } @@ -124,7 +123,7 @@ namespace Server.Mobiles Item twoHanded = from.FindItemOnLayer(Layer.TwoHanded); if (pack?.FindItemByType(shield.GetType()) != null || - twoHanded != null && shield.GetType().IsAssignableFrom(twoHanded.GetType())) + twoHanded != null && shield.GetType().IsInstanceOfType(twoHanded)) { Say(1007110); // Why dost thou ask about virtue guards when thou art one? shield.Delete(); diff --git a/Scripts/Mobiles/Special/Harrower.cs b/Scripts/Mobiles/Special/Harrower.cs index 43acf18b6..a715ac21d 100644 --- a/Scripts/Mobiles/Special/Harrower.cs +++ b/Scripts/Mobiles/Special/Harrower.cs @@ -323,8 +323,8 @@ namespace Server.Mobiles { DamageStore ds = rights[i]; - if (ds.m_HasRight && ds.m_Mobile is PlayerMobile) - PlayerMobile.ChampionTitleInfo.AwardHarrowerTitle((PlayerMobile)ds.m_Mobile); + if (ds.m_HasRight && ds.m_Mobile is PlayerMobile mobile) + PlayerMobile.ChampionTitleInfo.AwardHarrowerTitle(mobile); } if (!NoKillAwards) diff --git a/Scripts/Mobiles/Special/Rikktor.cs b/Scripts/Mobiles/Special/Rikktor.cs index ac39ea1a6..6c56b769d 100644 --- a/Scripts/Mobiles/Special/Rikktor.cs +++ b/Scripts/Mobiles/Special/Rikktor.cs @@ -102,8 +102,8 @@ namespace Server.Mobiles if (m == this || !CanBeHarmful(m)) continue; - if (m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || - ((BaseCreature)m).Team != Team)) + if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || + creature.Team != Team)) targets.Add(m); else if (m.Player) targets.Add(m); diff --git a/Scripts/Mobiles/Special/Semidar.cs b/Scripts/Mobiles/Special/Semidar.cs index 1e167eac1..81cd07a75 100644 --- a/Scripts/Mobiles/Special/Semidar.cs +++ b/Scripts/Mobiles/Special/Semidar.cs @@ -94,8 +94,8 @@ namespace Server.Mobiles if (m == this || !CanBeHarmful(m)) continue; - if (m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || - ((BaseCreature)m).Team != Team)) + if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || + creature.Team != Team)) list.Add(m); else if (m.Player) list.Add(m); diff --git a/Scripts/Mobiles/Special/Serado.cs b/Scripts/Mobiles/Special/Serado.cs index 25a6707ac..2d3f755a8 100644 --- a/Scripts/Mobiles/Special/Serado.cs +++ b/Scripts/Mobiles/Special/Serado.cs @@ -122,58 +122,55 @@ namespace Server.Mobiles private void DoCounter(Mobile attacker) { - if (Map == null || attacker is BaseCreature && ((BaseCreature)attacker).BardProvoked) + if (Map == null) return; - if (0.2 > Utility.RandomDouble()) - { - /* Counterattack with Hit Poison Area + if (!(0.2 > Utility.RandomDouble())) + return; + + BaseCreature bc = attacker as BaseCreature; + + if (bc?.BardProvoked == true) + return; + + /* Counterattack with Hit Poison Area * 20-25 damage, unresistable * Lethal poison, 100% of the time * Particle effect: Type: "2" From: "0x4061A107" To: "0x0" ItemId: "0x36BD" ItemIdName: "explosion" FromLocation: "(296 615, 17)" ToLocation: "(296 615, 17)" Speed: "1" Duration: "10" FixedDirection: "True" Explode: "False" Hue: "0xA6" RenderMode: "0x0" Effect: "0x1F78" ExplodeEffect: "0x1" ExplodeSound: "0x0" Serial: "0x4061A107" Layer: "255" Unknown: "0x0" * Doesn't work on provoked monsters */ - Mobile target = null; + Mobile target = bc?.GetMaster(); - if (attacker is BaseCreature) - { - Mobile m = ((BaseCreature)attacker).GetMaster(); + if (target == null || !target.InRange(this, 25)) + target = attacker; - if (m != null) - target = m; - } + Animate(10, 4, 1, true, false, 0); - if (target == null || !target.InRange(this, 25)) - target = attacker; + ArrayList targets = new ArrayList(); - Animate(10, 4, 1, true, false, 0); + foreach (Mobile m in target.GetMobilesInRange(8)) + { + if (m == this || !CanBeHarmful(m)) + continue; - ArrayList targets = new ArrayList(); + if (m is BaseCreature creature && (creature.Controlled || creature.Summoned || + creature.Team != Team)) + targets.Add(m); + else if (m.Player) + targets.Add(m); + } - foreach (Mobile m in target.GetMobilesInRange(8)) - { - if (m == this || !CanBeHarmful(m)) - continue; + for (int i = 0; i < targets.Count; ++i) + { + Mobile m = (Mobile)targets[i]; - if (m is BaseCreature && (((BaseCreature)m).Controlled || ((BaseCreature)m).Summoned || - ((BaseCreature)m).Team != Team)) - targets.Add(m); - else if (m.Player) - targets.Add(m); - } + DoHarmful(m); - for (int i = 0; i < targets.Count; ++i) - { - Mobile m = (Mobile)targets[i]; + AOS.Damage(m, this, Utility.RandomMinMax(20, 25), true, 0, 0, 0, 100, 0); - DoHarmful(m); - - AOS.Damage(m, this, Utility.RandomMinMax(20, 25), true, 0, 0, 0, 100, 0); - - m.FixedParticles(0x36BD, 1, 10, 0x1F78, 0xA6, 0, (EffectLayer)255); - m.ApplyPoison(this, Poison.Lethal); - } + m.FixedParticles(0x36BD, 1, 10, 0x1F78, 0xA6, 0, (EffectLayer)255); + m.ApplyPoison(this, Poison.Lethal); } } diff --git a/Scripts/Mobiles/Townfolk/BaseEscortable.cs b/Scripts/Mobiles/Townfolk/BaseEscortable.cs index d5891c79b..4dea0636e 100644 --- a/Scripts/Mobiles/Townfolk/BaseEscortable.cs +++ b/Scripts/Mobiles/Townfolk/BaseEscortable.cs @@ -149,7 +149,7 @@ namespace Server.Mobiles bool okay = true; foreach (BaseObjective obj in quest.Objectives) - if (obj is EscortObjective && ((EscortObjective)obj).Destination.Contains(reg)) + if (obj is EscortObjective objective && objective.Destination.Contains(reg)) { okay = false; // We're already there! break; @@ -271,10 +271,10 @@ namespace Server.Mobiles return false; } - if (m is PlayerMobile && ((PlayerMobile)m).LastEscortTime + EscortDelay >= DateTime.UtcNow) + if (m is PlayerMobile mobile && mobile.LastEscortTime + EscortDelay >= DateTime.UtcNow) { int minutes = - (int)Math.Ceiling((((PlayerMobile)m).LastEscortTime + EscortDelay - DateTime.UtcNow).TotalMinutes); + (int)Math.Ceiling((mobile.LastEscortTime + EscortDelay - DateTime.UtcNow).TotalMinutes); Say("You must rest {0} minute{1} before we set out on this journey.", minutes, minutes == 1 ? "" : "s"); return false; @@ -284,8 +284,8 @@ namespace Server.Mobiles { m_LastSeenEscorter = DateTime.UtcNow; - if (m is PlayerMobile) - ((PlayerMobile)m).LastEscortTime = DateTime.UtcNow; + if (m is PlayerMobile playerMobile) + playerMobile.LastEscortTime = DateTime.UtcNow; Say("Lead on! Payment will be made when we arrive in {0}.", dest.Name == "Ocllo" && m.Map == Map.Trammel ? "Haven" : dest.Name); @@ -473,9 +473,7 @@ namespace Server.Mobiles bool gainedPath = false; - PlayerMobile pm = escorter as PlayerMobile; - - if (pm != null) + if (escorter is PlayerMobile pm) { if (pm.CompassionGains > 0 && DateTime.UtcNow > pm.NextCompassionDay) { diff --git a/Scripts/Mobiles/Vendors/BaseVendor.cs b/Scripts/Mobiles/Vendors/BaseVendor.cs index a7bcd8d7b..2a44cb85a 100644 --- a/Scripts/Mobiles/Vendors/BaseVendor.cs +++ b/Scripts/Mobiles/Vendors/BaseVendor.cs @@ -1415,9 +1415,8 @@ namespace Server.Mobiles IBuyItemInfo[] buyinfo = (IBuyItemInfo[])m_ArmorBuyInfo.ToArray(typeof(IBuyItemInfo)); - if (buyinfo != null) - foreach (IBuyItemInfo info in buyinfo) - info.PriceScalar = priceScalar; + foreach (IBuyItemInfo info in buyinfo) + info.PriceScalar = priceScalar; } #endregion diff --git a/Scripts/Mobiles/Vendors/GenericBuy.cs b/Scripts/Mobiles/Vendors/GenericBuy.cs index d064f6313..90623ddfa 100644 --- a/Scripts/Mobiles/Vendors/GenericBuy.cs +++ b/Scripts/Mobiles/Vendors/GenericBuy.cs @@ -159,7 +159,7 @@ namespace Server.Mobiles object Obj_Disp = GetDisplayEntity(); - if (Core.ML && Obj_Disp is Item && !(Obj_Disp as Item).Stackable) + if (Core.ML && Obj_Disp is Item item && !item.Stackable) MaxAmount = Math.Min(20, MaxAmount); else MaxAmount = Math.Min(999, MaxAmount * 2); @@ -257,10 +257,10 @@ namespace Server.Mobiles if (cache) m_Table[key] = obj; - if (obj is Item) - AddItem((Item)obj); - else if (obj is Mobile) - m_Mobiles.Add((Mobile)obj); + if (obj is Item item) + AddItem(item); + else if (obj is Mobile mobile) + m_Mobiles.Add(mobile); } public override void OnAfterDelete() diff --git a/Scripts/Mobiles/Vendors/GenericSell.cs b/Scripts/Mobiles/Vendors/GenericSell.cs index cda000922..29550e23d 100644 --- a/Scripts/Mobiles/Vendors/GenericSell.cs +++ b/Scripts/Mobiles/Vendors/GenericSell.cs @@ -23,9 +23,7 @@ namespace Server.Mobiles { m_Table.TryGetValue( item.GetType(), out int price ); - if ( item is BaseArmor ) { - BaseArmor armor = (BaseArmor)item; - + if ( item is BaseArmor armor ) { if ( armor.Quality == ArmorQuality.Low ) price = (int)( price * 0.60 ); else if ( armor.Quality == ArmorQuality.Exceptional ) @@ -38,9 +36,7 @@ namespace Server.Mobiles if ( price < 1 ) price = 1; } - else if ( item is BaseWeapon ) { - BaseWeapon weapon = (BaseWeapon)item; - + else if ( item is BaseWeapon weapon ) { if ( weapon.Quality == WeaponQuality.Low ) price = (int)( price * 0.60 ); else if ( weapon.Quality == WeaponQuality.Exceptional ) @@ -53,18 +49,16 @@ namespace Server.Mobiles if ( price < 1 ) price = 1; } - else if ( item is BaseBeverage ) { + else if ( item is BaseBeverage bev ) { int price1 = price, price2 = price; - if ( item is Pitcher ) + if ( bev is Pitcher ) { price1 = 3; price2 = 5; } - else if ( item is BeverageBottle ) + else if ( bev is BeverageBottle ) { price1 = 3; price2 = 3; } - else if ( item is Jug ) + else if ( bev is Jug ) { price1 = 6; price2 = 6; } - BaseBeverage bev = (BaseBeverage)item; - if ( bev.IsEmpty || bev.Content == BeverageType.Milk ) price = price1; else diff --git a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs index b4e0f3ccb..1160368fa 100644 --- a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs +++ b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs @@ -466,8 +466,8 @@ namespace Server.Mobiles protected override void OnTarget(Mobile from, object targeted) { - if (targeted is BaseCreature) - m_Trainer.EndStable(from, (BaseCreature)targeted); + if (targeted is BaseCreature creature) + m_Trainer.EndStable(from, creature); else if (targeted == from) m_Trainer.SayTo(from, 502672); // HA HA HA! Sorry, I am not an inn. else diff --git a/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs b/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs index 8f7af7c52..8e288f5b3 100644 --- a/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs +++ b/Scripts/Mobiles/Vendors/NPC/Blacksmith.cs @@ -97,9 +97,7 @@ namespace Server.Mobiles public override Item CreateBulkOrder(Mobile from, bool fromContextMenu) { - PlayerMobile pm = from as PlayerMobile; - - if (pm != null && pm.NextSmithBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) + if (from is PlayerMobile pm && pm.NextSmithBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) { double theirSkill = pm.Skills[SkillName.Blacksmith].Base; @@ -131,16 +129,16 @@ namespace Server.Mobiles public override TimeSpan GetNextBulkOrder(Mobile from) { - if (from is PlayerMobile) - return ((PlayerMobile)from).NextSmithBulkOrder; + if (from is PlayerMobile mobile) + return mobile.NextSmithBulkOrder; return TimeSpan.Zero; } public override void OnSuccessfulBulkOrderReceive(Mobile from) { - if (Core.SE && from is PlayerMobile) - ((PlayerMobile)from).NextSmithBulkOrder = TimeSpan.Zero; + if (Core.SE && from is PlayerMobile mobile) + mobile.NextSmithBulkOrder = TimeSpan.Zero; } #endregion diff --git a/Scripts/Mobiles/Vendors/NPC/Guildmasters/BaseGuildmaster.cs b/Scripts/Mobiles/Vendors/NPC/Guildmasters/BaseGuildmaster.cs index 1df95146f..9a2d03aad 100644 --- a/Scripts/Mobiles/Vendors/NPC/Guildmasters/BaseGuildmaster.cs +++ b/Scripts/Mobiles/Vendors/NPC/Guildmasters/BaseGuildmaster.cs @@ -73,20 +73,18 @@ namespace Server.Mobiles { Mobile from = e.Mobile; - if (!e.Handled && from is PlayerMobile && from.InRange(Location, 2) && WasNamed(e.Speech)) + if (!e.Handled && from is PlayerMobile pm && pm.InRange(Location, 2) && WasNamed(e.Speech)) { - PlayerMobile pm = (PlayerMobile)from; - if (e.HasKeyword(0x0004)) // *join* | *member* { if (pm.NpcGuild == NpcGuild) - SayTo(from, 501047); // Thou art already a member of our guild. + SayTo(pm, 501047); // Thou art already a member of our guild. else if (pm.NpcGuild != NpcGuild.None) - SayTo(from, 501046); // Thou must resign from thy other guild first. + SayTo(pm, 501046); // Thou must resign from thy other guild first. else if (pm.GameTime < JoinGameAge || pm.CreationTime + JoinAge > DateTime.UtcNow) - SayTo(from, 501048); // You are too young to join my guild... + SayTo(pm, 501048); // You are too young to join my guild... else if (CheckCustomReqs(pm)) - SayPriceTo(from); + SayPriceTo(pm); e.Handled = true; } @@ -94,16 +92,16 @@ namespace Server.Mobiles { if (pm.NpcGuild != NpcGuild) { - SayTo(from, 501052); // Thou dost not belong to my guild! + SayTo(pm, 501052); // Thou dost not belong to my guild! } else if (pm.NpcGuildJoinTime + QuitAge > DateTime.UtcNow || pm.NpcGuildGameTime + QuitGameAge > pm.GameTime) { - SayTo(from, 501053); // You just joined my guild! You must wait a week to resign. + SayTo(pm, 501053); // You just joined my guild! You must wait a week to resign. } else { - SayTo(from, 501054); // I accept thy resignation. + SayTo(pm, 501054); // I accept thy resignation. pm.NpcGuild = NpcGuild.None; } @@ -116,25 +114,23 @@ namespace Server.Mobiles public override bool OnGoldGiven(Mobile from, Gold dropped) { - if (from is PlayerMobile && dropped.Amount == JoinCost) + if (from is PlayerMobile pm && dropped.Amount == JoinCost) { - PlayerMobile pm = (PlayerMobile)from; - if (pm.NpcGuild == NpcGuild) { - SayTo(from, 501047); // Thou art already a member of our guild. + SayTo(pm, 501047); // Thou art already a member of our guild. } else if (pm.NpcGuild != NpcGuild.None) { - SayTo(from, 501046); // Thou must resign from thy other guild first. + SayTo(pm, 501046); // Thou must resign from thy other guild first. } else if (pm.GameTime < JoinGameAge || pm.CreationTime + JoinAge > DateTime.UtcNow) { - SayTo(from, 501048); // You are too young to join my guild... + SayTo(pm, 501048); // You are too young to join my guild... } else if (CheckCustomReqs(pm)) { - SayWelcomeTo(from); + SayWelcomeTo(pm); pm.NpcGuild = NpcGuild; pm.NpcGuildJoinTime = DateTime.UtcNow; diff --git a/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs b/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs index fa6c18ed9..a59c73020 100644 --- a/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs +++ b/Scripts/Mobiles/Vendors/NPC/Guildmasters/ThiefGuildmaster.cs @@ -77,14 +77,12 @@ namespace Server.Mobiles { Mobile from = e.Mobile; - if (!e.Handled && from is PlayerMobile && from.InRange(Location, 2) && e.HasKeyword(0x1F)) // *disguise* + if (!e.Handled && from is PlayerMobile pm && pm.InRange(Location, 2) && e.HasKeyword(0x1F)) // *disguise* { - PlayerMobile pm = (PlayerMobile)from; - if (pm.NpcGuild == NpcGuild.ThievesGuild) - SayTo(from, 501839); // That particular item costs 700 gold pieces. + SayTo(pm, 501839); // That particular item costs 700 gold pieces. else - SayTo(from, 501838); // I don't know what you're talking about. + SayTo(pm, 501838); // I don't know what you're talking about. e.Handled = true; } @@ -94,13 +92,11 @@ namespace Server.Mobiles public override bool OnGoldGiven(Mobile from, Gold dropped) { - if (from is PlayerMobile && dropped.Amount == 700) + if (from is PlayerMobile pm && dropped.Amount == 700) { - PlayerMobile pm = (PlayerMobile)from; - if (pm.NpcGuild == NpcGuild.ThievesGuild) { - from.AddToBackpack(new DisguiseKit()); + pm.AddToBackpack(new DisguiseKit()); dropped.Delete(); return true; diff --git a/Scripts/Mobiles/Vendors/NPC/RealEstateBroker.cs b/Scripts/Mobiles/Vendors/NPC/RealEstateBroker.cs index 2f9171cbc..387558f7d 100644 --- a/Scripts/Mobiles/Vendors/NPC/RealEstateBroker.cs +++ b/Scripts/Mobiles/Vendors/NPC/RealEstateBroker.cs @@ -69,9 +69,8 @@ namespace Server.Mobiles public override bool OnDragDrop(Mobile from, Item dropped) { - if (dropped is HouseDeed) + if (dropped is HouseDeed deed) { - HouseDeed deed = (HouseDeed)dropped; int price = ComputePriceFor(deed); if (price > 0) @@ -98,9 +97,8 @@ namespace Server.Mobiles public void Appraise_OnTarget(Mobile from, object obj) { - if (obj is HouseDeed) + if (obj is HouseDeed deed) { - HouseDeed deed = (HouseDeed)obj; int price = ComputePriceFor(deed); if (price > 0) @@ -126,8 +124,7 @@ namespace Server.Mobiles { int price = 0; - if (deed is SmallBrickHouseDeed || deed is StonePlasterHouseDeed || deed is FieldStoneHouseDeed || - deed is SmallBrickHouseDeed || deed is WoodHouseDeed || deed is WoodPlasterHouseDeed || + if (deed is SmallBrickHouseDeed || deed is StonePlasterHouseDeed || deed is FieldStoneHouseDeed || deed is WoodHouseDeed || deed is WoodPlasterHouseDeed || deed is ThatchedRoofCottageDeed) price = 43800; else if (deed is BrickHouseDeed) diff --git a/Scripts/Mobiles/Vendors/NPC/Tailor.cs b/Scripts/Mobiles/Vendors/NPC/Tailor.cs index d3fd5b757..cbc637832 100644 --- a/Scripts/Mobiles/Vendors/NPC/Tailor.cs +++ b/Scripts/Mobiles/Vendors/NPC/Tailor.cs @@ -47,9 +47,7 @@ namespace Server.Mobiles public override Item CreateBulkOrder(Mobile from, bool fromContextMenu) { - PlayerMobile pm = from as PlayerMobile; - - if (pm != null && pm.NextTailorBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) + if (from is PlayerMobile pm && pm.NextTailorBulkOrder == TimeSpan.Zero && (fromContextMenu || 0.2 > Utility.RandomDouble())) { double theirSkill = pm.Skills[SkillName.Tailoring].Base; @@ -81,16 +79,16 @@ namespace Server.Mobiles public override TimeSpan GetNextBulkOrder(Mobile from) { - if (from is PlayerMobile) - return ((PlayerMobile)from).NextTailorBulkOrder; + if (from is PlayerMobile mobile) + return mobile.NextTailorBulkOrder; return TimeSpan.Zero; } public override void OnSuccessfulBulkOrderReceive(Mobile from) { - if (Core.SE && from is PlayerMobile) - ((PlayerMobile)from).NextTailorBulkOrder = TimeSpan.Zero; + if (Core.SE && from is PlayerMobile mobile) + mobile.NextTailorBulkOrder = TimeSpan.Zero; } #endregion diff --git a/Server/Items/Container.cs b/Server/Items/Container.cs index de2b2c000..8662fe4a1 100644 --- a/Server/Items/Container.cs +++ b/Server/Items/Container.cs @@ -1272,7 +1272,7 @@ namespace Server.Items { Item item = list[i]; - if (type.IsAssignableFrom(item.GetType())) + if (type.IsInstanceOfType(item)) { int need = amount - consumed; int theirAmount = item.Amount; diff --git a/Server/Region.cs b/Server/Region.cs index 662f769f2..750ae967e 100644 --- a/Server/Region.cs +++ b/Server/Region.cs @@ -425,7 +425,7 @@ namespace Server do { - if (regionType.IsAssignableFrom(r.GetType())) + if (regionType.IsInstanceOfType(r)) return r; r = r.Parent;