diff --git a/Scripts/Misc/AOS.cs b/Scripts/Misc/AOS.cs index 23c8fce1a..86b44e957 100644 --- a/Scripts/Misc/AOS.cs +++ b/Scripts/Misc/AOS.cs @@ -36,29 +36,23 @@ namespace Server public static int Damage(Mobile m, Mobile from, int damage, int phys, int fire, int cold, int pois, int nrgy) { - return Damage(m, from, damage, false, phys, fire, cold, pois, nrgy, 0, 0, false, false, false); + return Damage(m, from, damage, false, phys, fire, cold, pois, nrgy); } public static int Damage(Mobile m, Mobile from, int damage, int phys, int fire, int cold, int pois, int nrgy, int chaos) { - return Damage(m, from, damage, false, phys, fire, cold, pois, nrgy, chaos, 0, false, false, false); - } - - public static int Damage(Mobile m, Mobile from, int damage, bool ignoreArmor, int phys, int fire, int cold, int pois, - int nrgy) - { - return Damage(m, from, damage, ignoreArmor, phys, fire, cold, pois, nrgy, 0, 0, false, false, false); + return Damage(m, from, damage, false, phys, fire, cold, pois, nrgy, chaos); } public static int Damage(Mobile m, Mobile from, int damage, int phys, int fire, int cold, int pois, int nrgy, bool keepAlive) { - return Damage(m, from, damage, false, phys, fire, cold, pois, nrgy, 0, 0, keepAlive, false, false); + return Damage(m, from, damage, false, phys, fire, cold, pois, nrgy, 0, 0, keepAlive); } public static int Damage(Mobile m, Mobile from, int damage, bool ignoreArmor, int phys, int fire, int cold, int pois, - int nrgy, int chaos, int direct, bool keepAlive, bool archer, bool deathStrike) + int nrgy, int chaos = 0, int direct = 0, bool keepAlive = false, bool archer = false, bool deathStrike = false) { if (m == null || m.Deleted || !m.Alive || damage <= 0) return 0; diff --git a/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs b/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs index 26233d2ab..32b83fdd4 100644 --- a/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs +++ b/Scripts/Mobiles/Animals/Mounts/LesserHiryu.cs @@ -138,7 +138,7 @@ namespace Server.Mobiles AddLoot(LootPack.Gems, 4); } - public override double GetControlChance(Mobile m, bool useBaseSkill) + public override double GetControlChance(Mobile m, bool useBaseSkill = false) { double tamingChance = base.GetControlChance(m, useBaseSkill); diff --git a/Scripts/Mobiles/Animals/Mounts/Ridgeback.cs b/Scripts/Mobiles/Animals/Mounts/Ridgeback.cs index cc990bc7f..6ee813222 100644 --- a/Scripts/Mobiles/Animals/Mounts/Ridgeback.cs +++ b/Scripts/Mobiles/Animals/Mounts/Ridgeback.cs @@ -57,7 +57,7 @@ namespace Server.Mobiles return true; } - public override double GetControlChance(Mobile m, bool useBaseSkill) + public override double GetControlChance(Mobile m, bool useBaseSkill = false) { return 1.0; } diff --git a/Scripts/Mobiles/Animals/Mounts/SavageRidgeback.cs b/Scripts/Mobiles/Animals/Mounts/SavageRidgeback.cs index c66355aa2..b63763ce3 100644 --- a/Scripts/Mobiles/Animals/Mounts/SavageRidgeback.cs +++ b/Scripts/Mobiles/Animals/Mounts/SavageRidgeback.cs @@ -57,7 +57,7 @@ namespace Server.Mobiles return true; } - public override double GetControlChance(Mobile m, bool useBaseSkill) + public override double GetControlChance(Mobile m, bool useBaseSkill = false) { return 1.0; } diff --git a/Scripts/Mobiles/Animals/Mounts/ScaledSwampDragon.cs b/Scripts/Mobiles/Animals/Mounts/ScaledSwampDragon.cs index 6931c6e84..b92069e95 100644 --- a/Scripts/Mobiles/Animals/Mounts/ScaledSwampDragon.cs +++ b/Scripts/Mobiles/Animals/Mounts/ScaledSwampDragon.cs @@ -55,7 +55,7 @@ namespace Server.Mobiles return true; } - public override double GetControlChance(Mobile m, bool useBaseSkill) + public override double GetControlChance(Mobile m, bool useBaseSkill = false) { return 1.0; } diff --git a/Scripts/Mobiles/Animals/Mounts/SwampDragon.cs b/Scripts/Mobiles/Animals/Mounts/SwampDragon.cs index e6786bb0c..1ee7989c8 100644 --- a/Scripts/Mobiles/Animals/Mounts/SwampDragon.cs +++ b/Scripts/Mobiles/Animals/Mounts/SwampDragon.cs @@ -168,7 +168,7 @@ namespace Server.Mobiles return 0x2C8; } - public override double GetControlChance(Mobile m, bool useBaseSkill) + public override double GetControlChance(Mobile m, bool useBaseSkill = false) { return 1.0; } diff --git a/Scripts/Mobiles/Monsters/SE/FireBeetle.cs b/Scripts/Mobiles/Monsters/SE/FireBeetle.cs index bab9cddea..56977f459 100644 --- a/Scripts/Mobiles/Monsters/SE/FireBeetle.cs +++ b/Scripts/Mobiles/Monsters/SE/FireBeetle.cs @@ -99,7 +99,7 @@ namespace Server.Mobiles return 0x21D; } - public override double GetControlChance(Mobile m, bool useBaseSkill) + public override double GetControlChance(Mobile m, bool useBaseSkill = false) { return 1.0; } diff --git a/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs b/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs index a309283a3..47a0445b4 100644 --- a/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs +++ b/Scripts/Mobiles/Vendors/NPC/Weaponsmith.cs @@ -66,9 +66,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; @@ -100,16 +98,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/Weaver.cs b/Scripts/Mobiles/Vendors/NPC/Weaver.cs index 34a6de815..ba5c8f2d9 100644 --- a/Scripts/Mobiles/Vendors/NPC/Weaver.cs +++ b/Scripts/Mobiles/Vendors/NPC/Weaver.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/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs b/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs index 9561a5db0..7a7c6dc65 100644 --- a/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs +++ b/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs @@ -309,33 +309,31 @@ namespace Server.Mobiles public override bool CheckGold(Mobile from, Item dropped) { - if (dropped is Gold) + if (!(dropped is Gold g)) + return false; + + if (g.Amount > 50) { - Gold g = (Gold)dropped; + PrivateOverheadMessage(MessageType.Regular, 0x3B2, false, "I cannot accept so large a tip!", + from.NetState); + } + else + { + string tip = TipMessage; - if (g.Amount > 50) + if (tip == null || (tip = tip.Trim()).Length == 0) { - PrivateOverheadMessage(MessageType.Regular, 0x3B2, false, "I cannot accept so large a tip!", + PrivateOverheadMessage(MessageType.Regular, 0x3B2, false, + "It would not be fair of me to take your money and not offer you information in return.", from.NetState); } else { - string tip = TipMessage; + Direction = GetDirectionTo(from); + PrivateOverheadMessage(MessageType.Regular, 0x3B2, false, tip, from.NetState); - if (tip == null || (tip = tip.Trim()).Length == 0) - { - PrivateOverheadMessage(MessageType.Regular, 0x3B2, false, - "It would not be fair of me to take your money and not offer you information in return.", - from.NetState); - } - else - { - Direction = GetDirectionTo(from); - PrivateOverheadMessage(MessageType.Regular, 0x3B2, false, tip, from.NetState); - - g.Delete(); - return true; - } + g.Delete(); + return true; } } diff --git a/Scripts/Mobiles/Vendors/PlayerVendor.cs b/Scripts/Mobiles/Vendors/PlayerVendor.cs index 8d2b15988..3a3da61ce 100644 --- a/Scripts/Mobiles/Vendors/PlayerVendor.cs +++ b/Scripts/Mobiles/Vendors/PlayerVendor.cs @@ -107,9 +107,9 @@ namespace Server.Mobiles return false; } - if (!BaseHouse.NewVendorSystem && Parent is PlayerVendor) + if (!BaseHouse.NewVendorSystem && Parent is PlayerVendor vendor) { - BaseHouse house = ((PlayerVendor)Parent).House; + BaseHouse house = vendor.House; if (house != null && house.IsAosRules && !house.CheckAosStorage(1 + item.TotalItems + plusItems)) { @@ -155,9 +155,7 @@ namespace Server.Mobiles { base.GetChildContextMenuEntries(from, list, item); - PlayerVendor pv = RootParent as PlayerVendor; - - if (pv == null || pv.IsOwner(from)) + if (!(RootParent is PlayerVendor pv) || pv.IsOwner(from)) return; VendorItem vi = pv.GetVendorItem(item); @@ -199,10 +197,8 @@ namespace Server.Mobiles public override void OnSingleClickContained(Mobile from, Item item) { - if (RootParent is PlayerVendor) + if (RootParent is PlayerVendor vendor) { - PlayerVendor vendor = (PlayerVendor)RootParent; - VendorItem vi = vendor.GetVendorItem(item); if (vi != null) @@ -985,9 +981,7 @@ namespace Server.Mobiles public static void TryToBuy(Item item, Mobile from) { - PlayerVendor vendor = item.RootParent as PlayerVendor; - - if (vendor == null || !vendor.CanInteractWith(from, false)) + if (!(item.RootParent is PlayerVendor vendor) || !vendor.CanInteractWith(from, false)) return; if (vendor.IsOwner(from)) @@ -1330,7 +1324,8 @@ namespace Server.Mobiles protected override void OnTarget(Mobile from, object targeted) { - if (targeted is Item) TryToBuy((Item)targeted, from); + if (targeted is Item item) + TryToBuy(item, from); } } @@ -1358,10 +1353,9 @@ namespace Server.Mobiles else firstWord = text; - int price; string description; - if (int.TryParse(firstWord, out price)) + if (int.TryParse(firstWord, out int price)) { if (sep >= 0) description = text.Substring(sep + 1).Trim(); @@ -1397,7 +1391,7 @@ namespace Server.Mobiles if (item is Container) { - if (item is LockableContainer && ((LockableContainer)item).Locked) + if (item is LockableContainer container && container.Locked) m_Vendor.SayTo(from, 1043298); // Locked items may not be made not-for-sale. else if (item.Items.Count > 0) m_Vendor.SayTo(from, 1043299); // To be not for sale, all items in a container must be for sale. @@ -1448,9 +1442,7 @@ namespace Server.Mobiles text = text.Trim(); - int amount; - - if (!int.TryParse(text, out amount)) + if (!int.TryParse(text, out int amount)) amount = 0; GiveGold(from, amount); diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index 5868e2285..681405edf 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -110,9 +110,7 @@ namespace Server.Multis if (m_Owner == null) return Core.AOS ? DecayType.Condemned : DecayType.ManualRefresh; - Account acct = m_Owner.Account as Account; - - if (acct == null) + if (!(m_Owner.Account is Account acct)) return Core.AOS ? DecayType.Condemned : DecayType.ManualRefresh; if (acct.AccessLevel >= AccessLevel.GameMaster) @@ -751,17 +749,18 @@ namespace Server.Multis if (!addon.Deleted) { Item deed = null; - bool retainDeedHue = false; //if the items aren't hued but the deed itself is + bool retainDeedHue = false; // if the items aren't hued but the deed itself is int hue = 0; - if (addon is IAddon) - { - deed = ((IAddon)addon).Deed; + BaseAddon ba = addon as BaseAddon; - if (addon is BaseAddon && ((BaseAddon)addon).RetainDeedHue - ) //There are things that are IAddon which aren't BaseAddon + if (addon is IAddon baseAddon) + { + deed = baseAddon.Deed; + + // There are things that are IAddon which aren't BaseAddon + if (ba?.RetainDeedHue == true) { - BaseAddon ba = (BaseAddon)addon; retainDeedHue = true; for (int i = 0; hue == 0 && i < ba.Components.Count; ++i) @@ -778,16 +777,14 @@ namespace Server.Multis { #region Mondain's Legacy - if (deed is BaseAddonContainerDeed && addon is BaseAddonContainer) + if (deed is BaseAddonContainerDeed containerDeed && addon is BaseAddonContainer c) { - BaseAddonContainer c = (BaseAddonContainer)addon; c.DropItemsToGround(); - - ((BaseAddonContainerDeed)deed).Resource = c.Resource; + containerDeed.Resource = c.Resource; } - else if (deed is BaseAddonDeed && addon is BaseAddon) + else if (deed is BaseAddonDeed addonDeed && ba != null) { - ((BaseAddonDeed)deed).Resource = ((BaseAddon)addon).Resource; + addonDeed.Resource = ba.Resource; } #endregion @@ -874,10 +871,10 @@ namespace Server.Multis RelocatedEntities.Add(relocEntity); - if (entity is Item) - ((Item)entity).Internalize(); - else - ((Mobile)entity).Internalize(); + if (entity is Item item) + item.Internalize(); + else if (entity is Mobile mobile) + mobile.Internalize(); } } @@ -889,15 +886,14 @@ namespace Server.Multis Point3D location = new Point3D(relLoc.X + X, relLoc.Y + Y, relLoc.Z + Z); IEntity entity = relocEntity.Entity; - if (entity is Item) + if (entity is Item item) { - Item item = (Item)entity; - if (!item.Deleted) { - if (item is IAddon) + IAddon addon = item as IAddon; + if (addon != null) { - if (((IAddon)item).CouldFit(location, Map)) + if (addon.CouldFit(location, Map)) { item.MoveToWorld(location, Map); continue; @@ -939,19 +935,18 @@ namespace Server.Multis Item relocateItem = item; - if (item is StrongBox) - relocateItem = ((StrongBox)item).ConvertToStandardContainer(); + if (item is StrongBox box) + relocateItem = box.ConvertToStandardContainer(); - if (item is IAddon) + if (addon != null) { - Item deed = ((IAddon)item).Deed; + Item deed = addon.Deed; bool retainDeedHue = false; //if the items aren't hued but the deed itself is int hue = 0; - if (item is BaseAddon && ((BaseAddon)item).RetainDeedHue + if (item is BaseAddon ba && ba.RetainDeedHue ) //There are things that are IAddon which aren't BaseAddon { - BaseAddon ba = (BaseAddon)item; retainDeedHue = true; for (int i = 0; hue == 0 && i < ba.Components.Count; ++i) @@ -967,17 +962,14 @@ namespace Server.Multis if (deed != null) { - if (deed is BaseAddonContainerDeed && item is BaseAddonContainer) + if (deed is BaseAddonContainerDeed containerDeed && item is BaseAddonContainer c) { - BaseAddonContainer c = (BaseAddonContainer)item; c.DropItemsToGround(); - ((BaseAddonContainerDeed)deed).Resource = c.Resource; - } - else if (deed is BaseAddonDeed && item is BaseAddon) - { - ((BaseAddonDeed)deed).Resource = ((BaseAddon)item).Resource; + containerDeed.Resource = c.Resource; } + else if (deed is BaseAddonDeed addonDeed && item is BaseAddon baseAddon) + addonDeed.Resource = baseAddon.Resource; if (retainDeedHue) deed.Hue = hue; @@ -1004,17 +996,12 @@ namespace Server.Multis if (((SecureInfo)Secures[i]).Item == item) Secures.RemoveAt(i); } - else + else if (entity is Mobile mobile && !mobile.Deleted) { - Mobile mobile = (Mobile)entity; - - if (!mobile.Deleted) - { - if (Map.CanFit(location, 16, false, false)) - mobile.MoveToWorld(location, Map); - else - InternalizedVendors.Add(mobile); - } + if (Map.CanFit(location, 16, false, false)) + mobile.MoveToWorld(location, Map); + else + InternalizedVendors.Add(mobile); } } @@ -1212,9 +1199,7 @@ namespace Server.Multis for (int i = 0; i < sector.Multis.Count; ++i) { - BaseHouse house = sector.Multis[i] as BaseHouse; - - if (house != null && house.IsInside(loc, height)) + if (sector.Multis[i] is BaseHouse house && house.IsInside(loc, height)) return house; } @@ -1254,8 +1239,8 @@ namespace Server.Multis return true; if (item is Runebook) return true; - if (item is ISecurable) - return HasSecureAccess(from, ((ISecurable)item).Level); + if (item is ISecurable securable) + return HasSecureAccess(from, securable.Level); if (item is Container) return IsCoOwner(from); if (item.Stackable) @@ -1264,8 +1249,6 @@ namespace Server.Multis return IsFriend(from); if (item is PotionKeg) return IsFriend(from); - if (item is BaseBoard) - return true; if (item is Dices) return true; if (item is RecallRune) @@ -1276,7 +1259,7 @@ namespace Server.Multis return true; if (item is BaseInstrument) return true; - if (item is Dyes || item is DyeTub) + if (item is Dyes) return true; if (item is VendorRentalContract) return true; @@ -1358,10 +1341,10 @@ namespace Server.Multis item.Map = Map; foreach (IEntity entity in GetHouseEntities()) - if (entity is Item) - ((Item)entity).Map = Map; - else - ((Mobile)entity).Map = Map; + if (entity is Item item) + item.Map = Map; + else if (entity is Mobile mobile) + mobile.Map = Map; } public virtual void ChangeSignType(int itemID) @@ -1408,10 +1391,10 @@ namespace Server.Multis { Point3D newLocation = new Point3D(entity.X + x, entity.Y + y, entity.Z + z); - if (entity is Item) - ((Item)entity).Location = newLocation; - else - ((Mobile)entity).Location = newLocation; + if (entity is Item item) + item.Location = newLocation; + else if (entity is Mobile mobile) + mobile.Location = newLocation; } } @@ -1499,7 +1482,7 @@ namespace Server.Multis AddDoor(westDoor, x, y, z); AddDoor(eastDoor, x + 1, y, z); - return new BaseDoor[2] { westDoor, eastDoor }; + return new BaseDoor[] { westDoor, eastDoor }; } public uint CreateKeys(Mobile m) @@ -1544,7 +1527,7 @@ namespace Server.Multis AddDoor(westDoor, x, y, z); AddDoor(eastDoor, x + 1, y, z); - return new BaseDoor[2] { westDoor, eastDoor }; + return new BaseDoor[] { westDoor, eastDoor }; } public BaseDoor MakeDoor(bool wood, DoorFacing facing) @@ -1583,9 +1566,7 @@ namespace Server.Multis if (m_Trash == null || m_Trash.Deleted) { - m_Trash = new TrashBarrel(); - - m_Trash.Movable = false; + m_Trash = new TrashBarrel { Movable = false }; m_Trash.MoveToWorld(from.Location, from.Map); from.SendLocalizedMessage(502121); /* You have a new trash barrel. @@ -1604,25 +1585,16 @@ namespace Server.Multis Sign.MoveToWorld(new Point3D(X + xoff, Y + yoff, Z + zoff), Map); } - private void SetLockdown(Item i, bool locked) - { - SetLockdown(i, locked, false); - } - - private void SetLockdown(Item i, bool locked, bool checkContains) + private void SetLockdown(Item i, bool locked, bool checkContains = false) { if (LockDowns == null) return; - #region Mondain's Legacy - if (i is BaseAddonContainer) i.Movable = false; else - - #endregion - i.Movable = !locked; + i.IsLockedDown = locked; if (locked) @@ -1976,12 +1948,9 @@ namespace Server.Multis { AggressorInfo info = m.Aggressed[i]; - Guild attackerGuild = m.Guild as Guild; - Guild defenderGuild = info.Defender.Guild as Guild; - if (info.Defender.Player && info.Defender.Alive && DateTime.UtcNow - info.LastCombatTime < HouseRegion.CombatHeatDelay && - (attackerGuild == null || defenderGuild == null || + (!(m.Guild is Guild attackerGuild) || !(info.Defender.Guild is Guild defenderGuild) || defenderGuild != attackerGuild && !defenderGuild.IsEnemy(attackerGuild))) return true; } @@ -2063,7 +2032,7 @@ namespace Server.Multis { Container c = info.Item; - if (!c.Deleted && c is StrongBox && ((StrongBox)c).Owner == from) + if (!c.Deleted && c is StrongBox box && box.Owner == from) { from.SendLocalizedMessage(502112); //You already have a strong box return; @@ -2086,10 +2055,7 @@ namespace Server.Multis } } - StrongBox sb = new StrongBox(from, this); - sb.Movable = false; - sb.IsLockedDown = false; - sb.IsSecure = true; + StrongBox sb = new StrongBox(from, this) { Movable = false, IsLockedDown = false, IsSecure = true }; Secures.Add(new SecureInfo(sb, SecureLevel.CoOwners)); sb.MoveToWorld(from.Location, from.Map); } @@ -2115,7 +2081,7 @@ namespace Server.Multis { from.SendLocalizedMessage(501352); // You may not eject someone who is not in your house! } - else if (targ is BaseCreature && ((BaseCreature)targ).NoHouseRestrictions) + else if (targ is BaseCreature creature && creature.NoHouseRestrictions) { from.SendLocalizedMessage(501347); // You cannot eject that from the house! } @@ -2196,7 +2162,7 @@ namespace Server.Multis from.SendLocalizedMessage( 1062521); // You cannot ban someone from a private house. Revoke their access instead. } - else if (targ is BaseCreature && ((BaseCreature)targ).NoHouseRestrictions) + else if (targ is BaseCreature bc && bc.NoHouseRestrictions) { from.SendLocalizedMessage(1062040); // You cannot ban that. } @@ -2296,12 +2262,12 @@ namespace Server.Multis { Container c = info.Item; - if (c is StrongBox && ((StrongBox)c).Owner == targ) + if (c is StrongBox box && box.Owner == targ) { - c.IsLockedDown = false; - c.IsSecure = false; + box.IsLockedDown = false; + box.IsSecure = false; Secures.Remove(info); - c.Destroy(); + box.Destroy(); break; } } @@ -2452,9 +2418,8 @@ namespace Server.Multis { Item item = (Item)LockDowns[i]; - if (item is Container && !(item is BaseBoard || item is Aquarium || item is FishBowl)) + if (item is Container cont && !(cont is BaseBoard || cont is Aquarium || cont is FishBowl)) { - Container cont = (Container)item; List children = cont.Items; for (int j = 0; j < children.Count; ++j) @@ -2640,9 +2605,7 @@ namespace Server.Multis for (int i = 0; i < items.Count; ++i) { - Container c = items[i] as Container; - - if (c != null) + if (items[i] is Container c) { c.IsSecure = true; Secures.Add(new SecureInfo(c, SecureLevel.CoOwners)); @@ -2888,16 +2851,15 @@ namespace Server.Multis if (item != null) { - if (!item.Deleted && item is IAddon) + if (!item.Deleted && item is IAddon addon) { - Item deed = ((IAddon)item).Deed; + Item deed = addon.Deed; bool retainDeedHue = false; //if the items aren't hued but the deed itself is int hue = 0; - if (item is BaseAddon && ((BaseAddon)item).RetainDeedHue + if (addon is BaseAddon ba && ba.RetainDeedHue ) //There are things that are IAddon which aren't BaseAddon { - BaseAddon ba = (BaseAddon)item; retainDeedHue = true; for (int j = 0; hue == 0 && j < ba.Components.Count; ++j) @@ -2959,9 +2921,7 @@ namespace Server.Multis public static bool HasAccountHouse(Mobile m) { - Account a = m.Account as Account; - - if (a == null) + if (!(m.Account is Account a)) return false; for (int i = 0; i < a.Length; ++i) @@ -3009,9 +2969,7 @@ namespace Server.Multis for (int i = 0; keyValue == 0 && i < Doors.Count; ++i) { - BaseDoor door = Doors[i] as BaseDoor; - - if (door != null) + if (Doors[i] is BaseDoor door) keyValue = door.KeyValue; } @@ -3026,9 +2984,7 @@ namespace Server.Multis if (Doors != null) for (int i = 0; i < Doors.Count; ++i) { - BaseDoor door = Doors[i] as BaseDoor; - - if (door != null) + if (Doors[i] is BaseDoor door) door.KeyValue = keyValue; } } @@ -3038,9 +2994,7 @@ namespace Server.Multis if (Doors != null) for (int i = 0; i < Doors.Count; ++i) { - BaseDoor door = Doors[i] as BaseDoor; - - if (door != null) + if (Doors[i] is BaseDoor door) { door.KeyValue = 0; door.Locked = false; @@ -3075,9 +3029,7 @@ namespace Server.Multis if (c == m) return true; - Account bannedAccount = c.Account as Account; - - if (bannedAccount != null && bannedAccount == theirAccount) + if (c.Account is Account bannedAccount && bannedAccount == theirAccount) return true; } @@ -3092,10 +3044,8 @@ namespace Server.Multis if (m.AccessLevel > AccessLevel.Player || IsFriend(m) || Access != null && Access.Contains(m)) return true; - if (m is BaseCreature) + if (m is BaseCreature bc) { - BaseCreature bc = (BaseCreature)m; - if (bc.NoHouseRestrictions) return true; @@ -3425,57 +3375,43 @@ namespace Server.Multis if (!from.Alive || m_House.Deleted || !m_House.IsCoOwner(from)) return; - if (targeted is Item) + if (targeted is Item item) { if (m_Release) { - #region Mondain's legacy - - if (targeted is AddonContainerComponent) + if (item is AddonContainerComponent component) { - AddonContainerComponent component = (AddonContainerComponent)targeted; - if (component.Addon != null) m_House.Release(from, component.Addon); } else - - #endregion - { - m_House.Release(from, (Item)targeted); + m_House.Release(from, item); } } else { - if (targeted is VendorRentalContract) + if (item is VendorRentalContract) { from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1062392); // You must double click the contract in your pack to lock it down. from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 501732); // I cannot lock this down! } - else if ((Item)targeted is AddonComponent) + else if (item is AddonComponent) { from.LocalOverheadMessage(MessageType.Regular, 0x3E9, 501727); // You cannot lock that down! from.LocalOverheadMessage(MessageType.Regular, 0x3E9, 501732); // I cannot lock this down! } else { - #region Mondain's legacy - - if (targeted is AddonContainerComponent) + if (item is AddonContainerComponent component) { - AddonContainerComponent component = (AddonContainerComponent)targeted; - if (component.Addon != null) m_House.LockDown(from, component.Addon); } else - - #endregion - { - m_House.LockDown(from, (Item)targeted); + m_House.LockDown(from, item); } } } @@ -3513,30 +3449,23 @@ namespace Server.Multis if (!from.Alive || m_House.Deleted || !m_House.IsCoOwner(from)) return; - if (targeted is Item) + if (targeted is Item item) { if (m_Release) { - #region Mondain's legacy - - if (targeted is AddonContainerComponent) + if (item is AddonContainerComponent component) { - AddonContainerComponent component = (AddonContainerComponent)targeted; - if (component.Addon != null) m_House.ReleaseSecure(from, component.Addon); } else - - #endregion - { - m_House.ReleaseSecure(from, (Item)targeted); + m_House.ReleaseSecure(from, item); } } else { - if (targeted is VendorRentalContract) + if (item is VendorRentalContract) { from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1062392); // You must double click the contract in your pack to lock it down. @@ -3544,21 +3473,14 @@ namespace Server.Multis } else { - #region Mondain's legacy - - if (targeted is AddonContainerComponent) + if (item is AddonContainerComponent component) { - AddonContainerComponent component = (AddonContainerComponent)targeted; - if (component.Addon != null) m_House.AddSecure(from, component.Addon); } else - - #endregion - { - m_House.AddSecure(from, (Item)targeted); + m_House.AddSecure(from, item); } } } @@ -3586,8 +3508,8 @@ namespace Server.Multis if (!from.Alive || m_House.Deleted || !m_House.IsFriend(from)) return; - if (targeted is Mobile) - m_House.Kick(from, (Mobile)targeted); + if (targeted is Mobile mobile) + m_House.Kick(from, mobile); else from.SendLocalizedMessage(501347); //You cannot eject that from the house! } @@ -3611,12 +3533,12 @@ namespace Server.Multis if (!from.Alive || m_House.Deleted || !m_House.IsFriend(from)) return; - if (targeted is Mobile) + if (targeted is Mobile mobile) { if (m_Banning) - m_House.Ban(from, (Mobile)targeted); + m_House.Ban(from, mobile); else - m_House.RemoveBan(from, (Mobile)targeted); + m_House.RemoveBan(from, mobile); } else { @@ -3641,8 +3563,8 @@ namespace Server.Multis if (!from.Alive || m_House.Deleted || !m_House.IsFriend(from)) return; - if (targeted is Mobile) - m_House.GrantAccess(from, (Mobile)targeted); + if (targeted is Mobile mobile) + m_House.GrantAccess(from, mobile); else from.SendLocalizedMessage(1060712); // That is not a player. } @@ -3666,12 +3588,12 @@ namespace Server.Multis if (!from.Alive || m_House.Deleted || !m_House.IsOwner(from)) return; - if (targeted is Mobile) + if (targeted is Mobile mobile) { if (m_Add) - m_House.AddCoOwner(from, (Mobile)targeted); + m_House.AddCoOwner(from, mobile); else - m_House.RemoveCoOwner(from, (Mobile)targeted); + m_House.RemoveCoOwner(from, mobile); } else { @@ -3698,12 +3620,12 @@ namespace Server.Multis if (!from.Alive || m_House.Deleted || !m_House.IsCoOwner(from)) return; - if (targeted is Mobile) + if (targeted is Mobile mobile) { if (m_Add) - m_House.AddFriend(from, (Mobile)targeted); + m_House.AddFriend(from, mobile); else - m_House.RemoveFriend(from, (Mobile)targeted); + m_House.RemoveFriend(from, mobile); } else { @@ -3725,8 +3647,8 @@ namespace Server.Multis protected override void OnTarget(Mobile from, object targeted) { - if (targeted is Mobile) - m_House.BeginConfirmTransfer(from, (Mobile)targeted); + if (targeted is Mobile mobile) + m_House.BeginConfirmTransfer(from, mobile); else from.SendLocalizedMessage(501384); // Only a player can own a house! } @@ -3759,7 +3681,7 @@ namespace Server.Multis bool isOwned = house.Doors.Contains(item); if (!isOwned) - isOwned = house is HouseFoundation && ((HouseFoundation)house).IsFixture(item); + isOwned = house is HouseFoundation foundation && foundation.IsFixture(item); if (!isOwned) isOwned = house.HasLockedDownItem(item); diff --git a/Scripts/Multis/Boats/BaseBoat.cs b/Scripts/Multis/Boats/BaseBoat.cs index 473ebbfd5..0abdd4d92 100644 --- a/Scripts/Multis/Boats/BaseBoat.cs +++ b/Scripts/Multis/Boats/BaseBoat.cs @@ -231,9 +231,7 @@ namespace Server.Multis for (int i = 0; i < sector.Multis.Count; i++) { - BaseBoat boat = sector.Multis[i] as BaseBoat; - - if (boat != null && boat.Contains(loc.X, loc.Y)) + if (sector.Multis[i] is BaseBoat boat && boat.Contains(loc.X, loc.Y)) return boat; } @@ -1521,19 +1519,15 @@ namespace Server.Multis } foreach (IEntity e in toMove) - if (e is Item) + if (e is Item item) { - Item item = (Item)e; - item.NoMoveHS = true; if (!(item is TillerMan || item is Hold || item is Plank)) item.Location = new Point3D(item.X + xOffset, item.Y + yOffset, item.Z); } - else if (e is Mobile) + else if (e is Mobile m) { - Mobile m = (Mobile)e; - m.NoMoveHS = true; m.Location = new Point3D(m.X + xOffset, m.Y + yOffset, m.Z); } @@ -1542,10 +1536,10 @@ namespace Server.Multis Location = new Point3D(X + xOffset, Y + yOffset, Z); foreach (IEntity e in toMove) - if (e is Item) - ((Item)e).NoMoveHS = false; - else if (e is Mobile) - ((Mobile)e).NoMoveHS = false; + if (e is Item item) + item.NoMoveHS = false; + else if (e is Mobile mobile) + mobile.NoMoveHS = false; NoMoveHS = false; } @@ -1567,16 +1561,12 @@ namespace Server.Multis { IEntity e = toMove[i]; - if (e is Item) + if (e is Item item) { - Item item = (Item)e; - item.Location = new Point3D(item.X + xOffset, item.Y + yOffset, item.Z + zOffset); } - else if (e is Mobile) + else if (e is Mobile m) { - Mobile m = (Mobile)e; - m.Location = new Point3D(m.X + xOffset, m.Y + yOffset, m.Z + zOffset); } } @@ -1595,23 +1585,19 @@ namespace Server.Multis MultiComponentList mcl = Components; - foreach (object o in map.GetObjectsInBounds(new Rectangle2D(X + mcl.Min.X, Y + mcl.Min.Y, mcl.Width, mcl.Height)) + foreach (IEntity o in map.GetObjectsInBounds(new Rectangle2D(X + mcl.Min.X, Y + mcl.Min.Y, mcl.Width, mcl.Height)) ) { if (o == this || o is TillerMan || o is Hold || o is Plank) continue; - if (o is Item) + if (o is Item item) { - Item item = (Item)o; - if (Contains(item) && item.Visible && item.Z >= Z) list.Add(item); } - else if (o is Mobile) + else if (o is Mobile m) { - Mobile m = (Mobile)o; - if (Contains(m)) list.Add(m); } @@ -1679,16 +1665,12 @@ namespace Server.Multis { IEntity e = toMove[i]; - if (e is Item) + if (e is Item item) { - Item item = (Item)e; - item.Location = Rotate(item.Location, count); } - else if (e is Mobile) + else if (e is Mobile m) { - Mobile m = (Mobile)e; - m.Direction = (m.Direction - old + facing) & Direction.Mask; m.Location = Rotate(m.Location, count); } @@ -1894,10 +1876,8 @@ namespace Server.Multis m_Stream.Write((byte)0xF3); m_Stream.Write((short)0x1); - if (ent is BaseMulti) + if (ent is BaseMulti bm) { - BaseMulti bm = (BaseMulti)ent; - m_Stream.Write((byte)0x02); m_Stream.Write(bm.Serial); // TODO: Mask no longer needed, merge with Item case? @@ -1915,10 +1895,8 @@ namespace Server.Multis m_Stream.Write((short)bm.Hue); m_Stream.Write((byte)bm.GetPacketFlags()); } - else if (ent is Mobile) + else if (ent is Mobile m) { - Mobile m = (Mobile)ent; - m_Stream.Write((byte)0x01); m_Stream.Write(m.Serial); m_Stream.Write((short)m.Body); @@ -1935,10 +1913,8 @@ namespace Server.Multis m_Stream.Write((short)m.Hue); m_Stream.Write((byte)m.GetPacketFlags()); } - else if (ent is Item) + else if (ent is Item item) { - Item item = (Item)ent; - m_Stream.Write((byte)0x00); m_Stream.Write(item.Serial); m_Stream.Write((ushort)(item.ItemID & 0xFFFF)); diff --git a/Scripts/Multis/Boats/BaseBoatDeed.cs b/Scripts/Multis/Boats/BaseBoatDeed.cs index 5171d8c27..5509ccf9b 100644 --- a/Scripts/Multis/Boats/BaseBoatDeed.cs +++ b/Scripts/Multis/Boats/BaseBoatDeed.cs @@ -153,12 +153,10 @@ namespace Server.Multis protected override void OnTarget(Mobile from, object o) { - IPoint3D ip = o as IPoint3D; - - if (ip != null) + if (o is IPoint3D ip) { - if (ip is Item) - ip = ((Item)ip).GetWorldTop(); + if (ip is Item item) + ip = item.GetWorldTop(); Point3D p = new Point3D(ip); diff --git a/Scripts/Multis/Boats/BaseDockedBoat.cs b/Scripts/Multis/Boats/BaseDockedBoat.cs index dbd03d0bc..3209e2061 100644 --- a/Scripts/Multis/Boats/BaseDockedBoat.cs +++ b/Scripts/Multis/Boats/BaseDockedBoat.cs @@ -172,12 +172,10 @@ namespace Server.Multis protected override void OnTarget(Mobile from, object o) { - IPoint3D ip = o as IPoint3D; - - if (ip != null) + if (o is IPoint3D ip) { - if (ip is Item) - ip = ((Item)ip).GetWorldTop(); + if (ip is Item item) + ip = item.GetWorldTop(); Point3D p = new Point3D(ip); diff --git a/Scripts/Multis/Boats/Strandedness.cs b/Scripts/Multis/Boats/Strandedness.cs index f01c4b3c0..5f818ecee 100644 --- a/Scripts/Multis/Boats/Strandedness.cs +++ b/Scripts/Multis/Boats/Strandedness.cs @@ -97,17 +97,17 @@ namespace Server.Misc object surface = map.GetTopSurface(from.Location); - if (surface is LandTile) + if (surface is LandTile tile) { - int id = ((LandTile)surface).ID; + int id = tile.ID; return id >= 168 && id <= 171 || id >= 310 && id <= 311; } - if (surface is StaticTile) + if (surface is StaticTile staticTile) { - int id = ((StaticTile)surface).ID; + int id = staticTile.ID; return id >= 0x1796 && id <= 0x17B2; } diff --git a/Scripts/Multis/Boats/TillerMan.cs b/Scripts/Multis/Boats/TillerMan.cs index 1e9cb3014..fb90fb9f9 100644 --- a/Scripts/Multis/Boats/TillerMan.cs +++ b/Scripts/Multis/Boats/TillerMan.cs @@ -79,8 +79,8 @@ namespace Server.Items public override bool OnDragDrop(Mobile from, Item dropped) { - if (dropped is MapItem && m_Boat != null && m_Boat.CanCommand(from) && m_Boat.Contains(from)) - m_Boat.AssociateMap((MapItem)dropped); + if (dropped is MapItem item && m_Boat != null && m_Boat.CanCommand(from) && m_Boat.Contains(from)) + m_Boat.AssociateMap(item); return false; } diff --git a/Scripts/Multis/Camps/BaseCamp.cs b/Scripts/Multis/Camps/BaseCamp.cs index 6a8b0a727..84963f3e6 100644 --- a/Scripts/Multis/Camps/BaseCamp.cs +++ b/Scripts/Multis/Camps/BaseCamp.cs @@ -80,15 +80,14 @@ namespace Server.Multis int zavg = Map.GetAverageZ(X + xOffset, Y + yOffset); Point3D loc = new Point3D(X + xOffset, Y + yOffset, zavg + zOffset); - BaseCreature bc = m as BaseCreature; - if (bc != null) + if (m is BaseCreature bc) { bc.RangeHome = wanderRange; bc.Home = loc; } - if (m is BaseVendor || m is Banker) + if (m is BaseVendor) m.Direction = Direction.South; m.MoveToWorld(loc, Map); diff --git a/Scripts/Multis/ComponentVerification.cs b/Scripts/Multis/ComponentVerification.cs index 8cb79395a..62a47d1ee 100644 --- a/Scripts/Multis/ComponentVerification.cs +++ b/Scripts/Multis/ComponentVerification.cs @@ -235,8 +235,8 @@ namespace Server.Multis public int GetInt32(object obj) { - if (obj is int) - return (int)obj; + if (obj is int i) + return i; return 0; } diff --git a/Scripts/Multis/Deeds.cs b/Scripts/Multis/Deeds.cs index 05e2dbf58..f79408640 100644 --- a/Scripts/Multis/Deeds.cs +++ b/Scripts/Multis/Deeds.cs @@ -15,12 +15,10 @@ namespace Server.Multis.Deeds protected override void OnTarget(Mobile from, object o) { - IPoint3D ip = o as IPoint3D; - - if (ip != null) + if (o is IPoint3D ip) { - if (ip is Item) - ip = ((Item)ip).GetWorldTop(); + if (ip is Item item) + ip = item.GetWorldTop(); Point3D p = new Point3D(ip); @@ -139,9 +137,8 @@ namespace Server.Multis.Deeds } else { - ArrayList toMove; Point3D center = new Point3D(p.X - Offset.X, p.Y - Offset.Y, p.Z - Offset.Z); - HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out toMove); + HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out ArrayList toMove); switch (res) { @@ -155,10 +152,10 @@ namespace Server.Multis.Deeds { object o = toMove[i]; - if (o is Mobile) - ((Mobile)o).Location = house.BanLocation; - else if (o is Item) - ((Item)o).Location = house.BanLocation; + if (o is Mobile mobile) + mobile.Location = house.BanLocation; + else if (o is Item item) + item.Location = house.BanLocation; } break; diff --git a/Scripts/Multis/HouseFoundation.cs b/Scripts/Multis/HouseFoundation.cs index 06bd4ede1..05ba2511c 100644 --- a/Scripts/Multis/HouseFoundation.cs +++ b/Scripts/Multis/HouseFoundation.cs @@ -538,25 +538,19 @@ namespace Server.Multis { Item fixture = Fixtures[i]; - if (fixture is HouseTeleporter) + if (fixture is HouseTeleporter tp) { - HouseTeleporter tp = (HouseTeleporter)fixture; - for (int j = 1; j <= Fixtures.Count; ++j) { - HouseTeleporter check = Fixtures[(i + j) % Fixtures.Count] as HouseTeleporter; - - if (check != null && check.ItemID == tp.ItemID) + if (Fixtures[(i + j) % Fixtures.Count] is HouseTeleporter check && check.ItemID == tp.ItemID) { tp.Target = check; break; } } } - else if (fixture is BaseHouseDoor) + else if (fixture is BaseHouseDoor door) { - BaseHouseDoor door = (BaseHouseDoor)fixture; - if (door.Link != null) continue; @@ -630,9 +624,7 @@ namespace Server.Multis for (int j = i + 1; j < Fixtures.Count; ++j) { - BaseHouseDoor check = Fixtures[j] as BaseHouseDoor; - - if (check != null && check.Link == null && check.Facing == linkFacing && + if (Fixtures[j] is BaseHouseDoor check && check.Link == null && check.Facing == linkFacing && check.X - door.X == xOffset && check.Y - door.Y == yOffset && check.Z == door.Z) { check.Link = door; @@ -725,9 +717,7 @@ namespace Server.Multis public static void ApplyFoundation(FoundationType type, MultiComponentList mcl) { - int east, south, post, corner; - - GetFoundationGraphics(type, out east, out south, out post, out corner); + GetFoundationGraphics(type, out int east, out int south, out int post, out int corner); int xCenter = mcl.Center.X; int yCenter = mcl.Center.Y; @@ -834,7 +824,8 @@ namespace Server.Multis public void BeginCustomize(Mobile m) { - if (!m.CheckAlive()) return; + if (!m.CheckAlive()) + return; if (SpellHelper.CheckCombat(m)) { @@ -1579,6 +1570,7 @@ namespace Server.Multis } catch { + // ignored } } @@ -1706,9 +1698,7 @@ namespace Server.Multis Mobile from = state.Mobile; DesignContext context = DesignContext.Find(from); - HouseFoundation foundation = World.FindItem(pvSrc.ReadInt32()) as HouseFoundation; - - if (foundation != null && from.Map == foundation.Map && from.InRange(foundation.GetWorldLocation(), 24) && + if (World.FindItem(pvSrc.ReadInt32()) is HouseFoundation foundation && from.Map == foundation.Map && from.InRange(foundation.GetWorldLocation(), 24) && from.CanSee(foundation)) { DesignState stateToSend; @@ -2139,8 +2129,8 @@ namespace Server.Multis Table[from] = c; - if (from is PlayerMobile) - ((PlayerMobile)from).DesignContext = c; + if (from is PlayerMobile pm) + pm.DesignContext = c; foundation.Customizer = from; @@ -2180,11 +2170,8 @@ namespace Server.Multis Table.Remove(from); - if (from is PlayerMobile) - ((PlayerMobile)from).DesignContext = null; - - if (context == null) - return; + if (from is PlayerMobile pm) + pm.DesignContext = null; context.Foundation.Customizer = null; @@ -2437,7 +2424,7 @@ namespace Server.Multis ++planeCount; - int size = 0; + int size; if (i == 0) size = width * height * 2; @@ -2573,7 +2560,7 @@ namespace Server.Multis while (count > 0) { - SendQueueEntry sqe = null; + SendQueueEntry sqe; lock (m_SendQueueSyncRoot) { @@ -2582,7 +2569,7 @@ namespace Server.Multis try { - Packet p = null; + Packet p; lock (sqe.m_Root) { diff --git a/Scripts/Multis/HousePlacementTool.cs b/Scripts/Multis/HousePlacementTool.cs index 168a9c114..728d897e7 100644 --- a/Scripts/Multis/HousePlacementTool.cs +++ b/Scripts/Multis/HousePlacementTool.cs @@ -234,12 +234,10 @@ namespace Server.Items if (!from.CheckAlive() || from.Backpack?.FindItemByType() == null) return; - IPoint3D ip = o as IPoint3D; - - if (ip != null) + if (o is IPoint3D ip) { - if (ip is Item) - ip = ((Item)ip).GetWorldTop(); + if (ip is Item item) + ip = item.GetWorldTop(); Point3D p = new Point3D(ip); diff --git a/Scripts/Skills/Inscribe.cs b/Scripts/Skills/Inscribe.cs index 99e32f605..14f6956e0 100644 --- a/Scripts/Skills/Inscribe.cs +++ b/Scripts/Skills/Inscribe.cs @@ -77,8 +77,7 @@ namespace Server.SkillHandlers protected override void OnTarget(Mobile from, object targeted) { - BaseBook book = targeted as BaseBook; - if (book == null) + if (!(targeted is BaseBook book)) { from.SendLocalizedMessage(1046296); // That is not a book } @@ -122,9 +121,7 @@ namespace Server.SkillHandlers if (m_BookSrc.Deleted) return; - BaseBook bookDst = targeted as BaseBook; - - if (bookDst == null) + if (!(targeted is BaseBook bookDst)) { from.SendLocalizedMessage(1046296); // That is not a book } diff --git a/Scripts/Skills/Provocation.cs b/Scripts/Skills/Provocation.cs index 68700b471..baca501ff 100644 --- a/Scripts/Skills/Provocation.cs +++ b/Scripts/Skills/Provocation.cs @@ -42,10 +42,8 @@ namespace Server.SkillHandlers { from.RevealingAction(); - if (targeted is BaseCreature && from.CanBeHarmful((Mobile)targeted, true)) + if (targeted is BaseCreature creature && from.CanBeHarmful(creature, true)) { - BaseCreature creature = (BaseCreature)targeted; - if (!m_Instrument.IsChildOf(from.Backpack)) { from.SendLocalizedMessage( @@ -91,10 +89,8 @@ namespace Server.SkillHandlers { from.RevealingAction(); - if (targeted is BaseCreature) + if (targeted is BaseCreature creature) { - BaseCreature creature = (BaseCreature)targeted; - if (!m_Instrument.IsChildOf(from.Backpack)) { from.SendLocalizedMessage( diff --git a/Scripts/Skills/RemoveTrap.cs b/Scripts/Skills/RemoveTrap.cs index e62b01d05..a8913dc5e 100644 --- a/Scripts/Skills/RemoveTrap.cs +++ b/Scripts/Skills/RemoveTrap.cs @@ -45,10 +45,8 @@ namespace Server.SkillHandlers { from.SendLocalizedMessage(502816); // You feel that such an action would be inappropriate } - else if (targeted is TrappableContainer) + else if (targeted is TrappableContainer targ) { - TrappableContainer targ = (TrappableContainer)targeted; - from.Direction = from.GetDirectionTo(targ); if (targ.TrapType == TrapType.None) diff --git a/Scripts/Skills/Snooping.cs b/Scripts/Skills/Snooping.cs index 174191e20..ed86a04ad 100644 --- a/Scripts/Skills/Snooping.cs +++ b/Scripts/Skills/Snooping.cs @@ -28,9 +28,7 @@ namespace Server.SkillHandlers if (reg == null || reg.IsDisabled()) return true; // not in town? we can snoop any npc - BaseCreature cret = to as BaseCreature; - - if (to.Body.IsHuman && (cret == null || !cret.AlwaysAttackable && !cret.AlwaysMurderer)) + if (to.Body.IsHuman && (!(to is BaseCreature cret) || !cret.AlwaysAttackable && !cret.AlwaysMurderer)) return false; // in town we cannot snoop blue human npcs return true; @@ -81,7 +79,7 @@ namespace Server.SkillHandlers if (from.AccessLevel > AccessLevel.Player || from.CheckTargetSkill(SkillName.Snooping, cont, 0.0, 100.0)) { - if (cont is TrappableContainer && ((TrappableContainer)cont).ExecuteTrap(from)) + if (cont is TrappableContainer container && container.ExecuteTrap(from)) return; cont.DisplayTo(from); diff --git a/Scripts/Skills/SpiritSpeak.cs b/Scripts/Skills/SpiritSpeak.cs index ffface8f7..4f2aaac63 100644 --- a/Scripts/Skills/SpiritSpeak.cs +++ b/Scripts/Skills/SpiritSpeak.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Server.Items; using Server.Network; using Server.Spells; @@ -134,14 +135,9 @@ namespace Server.SkillHandlers public override void OnCast() { - Corpse toChannel = null; - - foreach (Item item in Caster.GetItemsInRange(3)) - if (item is Corpse && !((Corpse)item).Channeled) - { - toChannel = (Corpse)item; - break; - } + IPooledEnumerable eable = Caster.GetItemsInRange(3); + Corpse toChannel = eable.ToList().Find(item => item is Corpse corpse && !corpse.Channeled); + eable.Free(); int max, min, mana, number; diff --git a/Scripts/Skills/Stealing.cs b/Scripts/Skills/Stealing.cs index 8977ddbc5..859e2b9c4 100644 --- a/Scripts/Skills/Stealing.cs +++ b/Scripts/Skills/Stealing.cs @@ -25,7 +25,7 @@ namespace Server.SkillHandlers public static bool IsInGuild(Mobile m) { - return m is PlayerMobile && ((PlayerMobile)m).NpcGuild == NpcGuild.ThievesGuild; + return m is PlayerMobile mobile && mobile.NpcGuild == NpcGuild.ThievesGuild; } public static bool IsInnocentTo(Mobile from, Mobile to) @@ -72,7 +72,6 @@ namespace Server.SkillHandlers public StealingTarget(Mobile thief) : base(1, false, TargetFlags.None) { m_Thief = thief; - AllowNonlocal = true; } @@ -81,6 +80,7 @@ namespace Server.SkillHandlers Item stolen = null; object root = toSteal.RootParent; + Mobile mobRoot = root as Mobile; StealableArtifactsSpawner.StealableInstance si = null; if (toSteal.Parent == null || !toSteal.Movable) @@ -94,16 +94,16 @@ namespace Server.SkillHandlers { m_Thief.SendMessage("You may not steal in this area."); } - else if (root is Mobile && ((Mobile)root).Player && !IsInGuild(m_Thief)) + else if (mobRoot?.Player == true && !IsInGuild(m_Thief)) { m_Thief.SendLocalizedMessage(1005596); // You must be in the thieves guild to steal from other players. } - else if (SuspendOnMurder && root is Mobile && ((Mobile)root).Player && IsInGuild(m_Thief) && + else if (SuspendOnMurder && mobRoot?.Player == true && IsInGuild(m_Thief) && m_Thief.Kills > 0) { m_Thief.SendLocalizedMessage(502706); // You are currently suspended from the thieves guild. } - else if (root is BaseVendor && ((BaseVendor)root).IsInvulnerable) + else if (root is BaseVendor vendor && vendor.IsInvulnerable) { m_Thief.SendLocalizedMessage(1005598); // You can't steal from shopkeepers. } @@ -122,14 +122,12 @@ namespace Server.SkillHandlers #region Sigils - else if (toSteal is Sigil) + else if (toSteal is Sigil sig) { PlayerState pl = PlayerState.Find(m_Thief); Faction faction = pl?.Faction; - Sigil sig = (Sigil)toSteal; - - if (!m_Thief.InRange(toSteal.GetWorldLocation(), 1)) + if (!m_Thief.InRange(sig.GetWorldLocation(), 1)) { m_Thief.SendLocalizedMessage(502703); // You must be standing next to an item to steal it. } @@ -242,11 +240,11 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(502704); // You catch yourself red-handed. } - else if (root is Mobile && ((Mobile)root).AccessLevel > AccessLevel.Player) + else if (mobRoot?.AccessLevel > AccessLevel.Player) { m_Thief.SendLocalizedMessage(502710); // You can't steal that! } - else if (root is Mobile && !m_Thief.CanBeHarmful((Mobile)root)) + else if (mobRoot != null && !m_Thief.CanBeHarmful((Mobile)root)) { } else if (root is Corpse) @@ -337,20 +335,20 @@ namespace Server.SkillHandlers object root = null; bool caught = false; - if (target is Item) + if (target is Item item) { - root = ((Item)target).RootParent; - stolen = TryStealItem((Item)target, ref caught); + root = item.RootParent; + stolen = TryStealItem(item, ref caught); } - else if (target is Mobile) + else if (target is Mobile mobile) { - Container pack = ((Mobile)target).Backpack; + Container pack = mobile.Backpack; if (pack != null && pack.Items.Count > 0) { int randomIndex = Utility.Random(pack.Items.Count); - root = target; + root = mobile; stolen = TryStealItem(pack.Items[randomIndex], ref caught); } } @@ -358,28 +356,27 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(502710); // You can't steal that! } + + Mobile mobRoot = root as Mobile; if (stolen != null) { from.AddToBackpack(stolen); - if (!(stolen is Container || stolen.Stackable)) StolenItem.Add(stolen, m_Thief, root as Mobile); + if (!(stolen is Container || stolen.Stackable)) + StolenItem.Add(stolen, m_Thief, mobRoot); } + Corpse corpse = root as Corpse; + if (caught) { - if (root == null) + if (root == null || corpse?.IsCriminalAction(m_Thief) == true) { m_Thief.CriminalAction(false); } - else if (root is Corpse && ((Corpse)root).IsCriminalAction(m_Thief)) + else if (mobRoot != null) { - m_Thief.CriminalAction(false); - } - else if (root is Mobile) - { - Mobile mobRoot = (Mobile)root; - if (!IsInGuild(mobRoot) && IsInnocentTo(m_Thief, mobRoot)) m_Thief.CriminalAction(false); @@ -390,16 +387,14 @@ namespace Server.SkillHandlers ns.Mobile.SendMessage(message); } } - else if (root is Corpse && ((Corpse)root).IsCriminalAction(m_Thief)) + else if (corpse?.IsCriminalAction(m_Thief) == true) { m_Thief.CriminalAction(false); } - if (root is Mobile && ((Mobile)root).Player && m_Thief is PlayerMobile && - IsInnocentTo(m_Thief, (Mobile)root) && !IsInGuild((Mobile)root)) + if (mobRoot?.Player == true && m_Thief is PlayerMobile pm && + IsInnocentTo(pm, mobRoot) && !IsInGuild(mobRoot)) { - PlayerMobile pm = (PlayerMobile)m_Thief; - pm.PermaFlags.Add((Mobile)root); pm.Delta(MobileDelta.Noto); } diff --git a/Scripts/Skills/Stealth.cs b/Scripts/Skills/Stealth.cs index 16f1494c9..e696af453 100644 --- a/Scripts/Skills/Stealth.cs +++ b/Scripts/Skills/Stealth.cs @@ -38,9 +38,7 @@ namespace Server.SkillHandlers for (int i = 0; i < m.Items.Count; i++) { - BaseArmor armor = m.Items[i] as BaseArmor; - - if (armor == null) + if (!(m.Items[i] is BaseArmor armor)) continue; int materialType = (int)armor.MaterialType; @@ -91,9 +89,7 @@ namespace Server.SkillHandlers m.AllowedStealthSteps = steps; - PlayerMobile pm = m as PlayerMobile; // IsStealthing should be moved to Server.Mobiles - - if (pm != null) + if (m is PlayerMobile pm) pm.IsStealthing = true; m.SendLocalizedMessage(502730); // You begin to move quietly. diff --git a/Scripts/Skills/TasteID.cs b/Scripts/Skills/TasteID.cs index 43b41d358..654b54924 100644 --- a/Scripts/Skills/TasteID.cs +++ b/Scripts/Skills/TasteID.cs @@ -35,10 +35,8 @@ namespace Server.SkillHandlers { from.SendLocalizedMessage(502816); // You feel that such an action would be inappropriate. } - else if (targeted is Food) + else if (targeted is Food food) { - Food food = (Food)targeted; - if (from.CheckTargetSkill(SkillName.TasteID, food, 0, 100)) { if (food.Poison != null) @@ -52,17 +50,13 @@ namespace Server.SkillHandlers food.SendLocalizedMessageTo(from, 502823); // You cannot discern anything about this substance. } } - else if (targeted is BasePotion) + else if (targeted is BasePotion potion) { - BasePotion potion = (BasePotion)targeted; - potion.SendLocalizedMessageTo(from, 502813); // You already know what kind of potion that is. potion.SendLocalizedMessageTo(from, potion.LabelNumber); } - else if (targeted is PotionKeg) + else if (targeted is PotionKeg keg) { - PotionKeg keg = (PotionKeg)targeted; - if (keg.Held <= 0) { keg.SendLocalizedMessageTo(from, 502228); // There is nothing in the keg to taste! diff --git a/Scripts/SpecialSystems/Engines/GiftGiving.cs b/Scripts/SpecialSystems/Engines/GiftGiving.cs index 21537afb8..728e2d0c5 100644 --- a/Scripts/SpecialSystems/Engines/GiftGiving.cs +++ b/Scripts/SpecialSystems/Engines/GiftGiving.cs @@ -26,9 +26,7 @@ namespace Server.Misc private static void EventSink_Login(LoginEventArgs e) { - Account acct = e.Mobile.Account as Account; - - if (acct == null) + if (!(e.Mobile.Account is Account acct)) return; DateTime now = DateTime.UtcNow; diff --git a/Scripts/Spells/Base/Spell.cs b/Scripts/Spells/Base/Spell.cs index e6ea8a6a8..5159d0fd3 100644 --- a/Scripts/Spells/Base/Spell.cs +++ b/Scripts/Spells/Base/Spell.cs @@ -90,13 +90,8 @@ namespace Server.Spells if (IsCasting) { object o = ProtectionSpell.Registry[Caster]; - bool disturb = true; - if (o is double) - if ((double)o > Utility.RandomDouble() * 100.0) - disturb = false; - - if (disturb) + if (!(o is double d) || d <= Utility.RandomDouble() * 100.0) Disturb(DisturbType.Hurt, false, true); } } @@ -205,8 +200,8 @@ namespace Server.Spells TransformContext context = TransformationSpellHelper.GetContext(Caster); - if (context?.Spell is ReaperFormSpell) - damageBonus += ((ReaperFormSpell)context.Spell).SpellDamageBonus; + if (context?.Spell is ReaperFormSpell spell) + damageBonus += spell.SpellDamageBonus; damage = AOS.Scale(damage, 100 + damageBonus); @@ -380,20 +375,12 @@ namespace Server.Spells } } - public void Disturb(DisturbType type) - { - Disturb(type, true, false); - } - public virtual bool CheckDisturb(DisturbType type, bool firstCircle, bool resistable) { - if (resistable && Scroll is BaseWand) - return false; - - return true; + return !(resistable && Scroll is BaseWand); } - public void Disturb(DisturbType type, bool firstCircle, bool resistable) + public void Disturb(DisturbType type, bool firstCircle = true, bool resistable = false) { if (!CheckDisturb(type, firstCircle, resistable)) return; @@ -456,7 +443,7 @@ namespace Server.Spells if (Scroll is BaseWand) return; - if (Info.Mantra != null && Info.Mantra.Length > 0 && Caster.Player) + if (!string.IsNullOrEmpty(Info.Mantra) && Caster.Player) Caster.PublicOverheadMessage(MessageType.Spell, Caster.SpeechHue, true, Info.Mantra, false); } @@ -464,8 +451,8 @@ namespace Server.Spells { StartCastTime = Core.TickCount; - if (Core.AOS && Caster.Spell is Spell && ((Spell)Caster.Spell).State == SpellState.Sequencing) - ((Spell)Caster.Spell).Disturb(DisturbType.NewCast); + if (Core.AOS && Caster.Spell is Spell spell && spell.State == SpellState.Sequencing) + spell.Disturb(DisturbType.NewCast); if (!Caster.CheckAlive()) return false; @@ -491,9 +478,9 @@ namespace Server.Spells { Caster.SendLocalizedMessage(502644); // You have not yet recovered from casting a spell. } - else if (Caster is PlayerMobile && ((PlayerMobile)Caster).PeacedUntil > DateTime.UtcNow) + else if (Caster is PlayerMobile mobile && mobile.PeacedUntil > DateTime.UtcNow) { - Caster.SendLocalizedMessage(1072060); // You cannot cast a spell while calmed. + mobile.SendLocalizedMessage(1072060); // You cannot cast a spell while calmed. } #region Dueling @@ -582,9 +569,7 @@ namespace Server.Spells if (Scroll is BaseWand) return true; - double minSkill, maxSkill; - - GetCastSkills(out minSkill, out maxSkill); + GetCastSkills(out double minSkill, out double maxSkill); if (DamageSkill != CastSkill) Caster.CheckSkill(DamageSkill, 0.0, Caster.Skills[DamageSkill].Cap); @@ -710,8 +695,8 @@ namespace Server.Spells DoFizzle(); } else if (Scroll != null && !(Scroll is Runebook) && - (Scroll.Amount <= 0 || Scroll.Deleted || Scroll.RootParent != Caster || Scroll is BaseWand && - (((BaseWand)Scroll).Charges <= 0 || Scroll.Parent != Caster))) + (Scroll.Amount <= 0 || Scroll.Deleted || Scroll.RootParent != Caster || Scroll is BaseWand baseWand && + (baseWand.Charges <= 0 || baseWand.Parent != Caster))) { DoFizzle(); } @@ -728,9 +713,9 @@ namespace Server.Spells Caster.SendLocalizedMessage(502646); // You cannot cast a spell while frozen. DoFizzle(); } - else if (Caster is PlayerMobile && ((PlayerMobile)Caster).PeacedUntil > DateTime.UtcNow) + else if (Caster is PlayerMobile mobile && mobile.PeacedUntil > DateTime.UtcNow) { - Caster.SendLocalizedMessage(1072060); // You cannot cast a spell while calmed. + mobile.SendLocalizedMessage(1072060); // You cannot cast a spell while calmed. DoFizzle(); } else if (CheckFizzle()) @@ -741,9 +726,9 @@ namespace Server.Spells { Scroll.Consume(); } - else if (Scroll is BaseWand) + else if (Scroll is BaseWand wand) { - ((BaseWand)Scroll).ConsumeCharge(Caster); + wand.ConsumeCharge(Caster); Caster.RevealingAction(); } diff --git a/Scripts/Spells/Base/SpellHelper.cs b/Scripts/Spells/Base/SpellHelper.cs index fbb88dda6..07dd3e4d1 100644 --- a/Scripts/Spells/Base/SpellHelper.cs +++ b/Scripts/Spells/Base/SpellHelper.cs @@ -102,6 +102,7 @@ namespace Server.Spells IsMLDungeon }; + // TODO: Find a better way private static bool[,] m_Rules = { /*T2A(Fel), Khaldun, Ilshenar, Wind(Tram), Wind(Fel), Dungeons(Fel), Solen(Tram), Solen(Fel), CrystalCave(Malas), Gauntlet(Malas), Gauntlet(Ferry), SafeZone, Stronghold, ChampionSpawn, Dungeons(Tokuno[Malas]), LampRoom(Doom), GuardianRoom(Doom), Heartwood, MLDungeons */ @@ -155,17 +156,7 @@ namespace Server.Spells return Core.AOS ? AosDamageDelay : OldDamageDelay; } - public static bool CheckMulti(Point3D p, Map map) - { - return CheckMulti(p, map, true, 0); - } - - public static bool CheckMulti(Point3D p, Map map, bool houses) - { - return CheckMulti(p, map, houses, 0); - } - - public static bool CheckMulti(Point3D p, Map map, bool houses, int housingrange) + public static bool CheckMulti(Point3D p, Map map, bool houses = true, int housingrange = 0) { if (map == null || map == Map.Internal) return false; @@ -176,10 +167,8 @@ namespace Server.Spells { BaseMulti multi = sector.Multis[i]; - if (multi is BaseHouse) + if (multi is BaseHouse bh) { - BaseHouse bh = (BaseHouse)multi; - if (houses && bh.IsInside(p, 16) || housingrange > 0 && bh.InRange(p, housingrange)) return true; } @@ -194,15 +183,11 @@ namespace Server.Spells public static void Turn(Mobile from, object to) { - IPoint3D target = to as IPoint3D; - - if (target == null) + if (!(to is IPoint3D target)) return; - if (target is Item) + if (target is Item item) { - Item item = (Item)target; - if (item.RootParent != from) from.Direction = from.GetDirectionTo(item.GetWorldLocation()); } @@ -258,26 +243,18 @@ namespace Server.Spells public static bool CanRevealCaster(Mobile m) { - if (m is BaseCreature) - { - BaseCreature c = (BaseCreature)m; - if (!c.Controlled) - return true; - } - - return false; + return m is BaseCreature c && !c.Controlled; } public static void GetSurfaceTop(ref IPoint3D p) { - if (p is Item) + if (p is Item item) { - p = ((Item)p).GetSurfaceTop(); + p = item.GetSurfaceTop(); } - else if (p is StaticTarget) + else if (p is StaticTarget t) { - StaticTarget t = (StaticTarget)p; int z = t.Z; if ((t.Flags & TileFlag.Surface) == 0) @@ -408,9 +385,8 @@ namespace Server.Spells { Guild g = m.Guild as Guild; - if (g == null && m is BaseCreature) + if (g == null && m is BaseCreature c) { - BaseCreature c = (BaseCreature)m; m = c.ControlMaster; if (m != null) @@ -436,26 +412,23 @@ namespace Server.Spells if (to.Hidden && to.AccessLevel > from.AccessLevel) return false; + BaseCreature bcFrom = from as BaseCreature; + BaseCreature bcTarg = to as BaseCreature; + #region Dueling - PlayerMobile pmFrom = from as PlayerMobile; - PlayerMobile pmTarg = to as PlayerMobile; + PlayerMobile pmFrom; + PlayerMobile pmTarg; - if (pmFrom == null && from is BaseCreature) - { - BaseCreature bcFrom = (BaseCreature)from; + if (bcFrom != null && bcFrom.Summoned) + pmFrom = bcFrom.SummonMaster as PlayerMobile; + else + pmFrom = from as PlayerMobile; - if (bcFrom.Summoned) - pmFrom = bcFrom.SummonMaster as PlayerMobile; - } - - if (pmTarg == null && to is BaseCreature) - { - BaseCreature bcTarg = (BaseCreature)to; - - if (bcTarg.Summoned) - pmTarg = bcTarg.SummonMaster as PlayerMobile; - } + if (bcTarg != null && bcTarg.Summoned) + pmTarg = bcTarg.SummonMaster as PlayerMobile; + else + pmTarg = to as PlayerMobile; if (pmFrom != null && pmTarg != null) if (pmFrom.DuelContext != null && pmFrom.DuelContext == pmTarg.DuelContext && pmFrom.DuelContext.Started && @@ -475,37 +448,27 @@ namespace Server.Spells if (p != null && p.Contains(to)) return false; - if (to is BaseCreature) + if (bcTarg != null && (bcTarg.Controlled || bcTarg.Summoned)) { - BaseCreature c = (BaseCreature)to; + if (bcTarg.ControlMaster == from || bcTarg.SummonMaster == from) + return false; - if (c.Controlled || c.Summoned) - { - if (c.ControlMaster == from || c.SummonMaster == from) - return false; - - if (p != null && (p.Contains(c.ControlMaster) || p.Contains(c.SummonMaster))) - return false; - } + if (p != null && (p.Contains(bcTarg.ControlMaster) || p.Contains(bcTarg.SummonMaster))) + return false; } - if (from is BaseCreature) + if (bcFrom != null && (bcFrom.Controlled || bcFrom.Summoned)) { - BaseCreature c = (BaseCreature)from; + if (bcFrom.ControlMaster == to || bcFrom.SummonMaster == to) + return false; - if (c.Controlled || c.Summoned) - { - if (c.ControlMaster == to || c.SummonMaster == to) - return false; + p = Party.Get(to); - p = Party.Get(to); - - if (p != null && (p.Contains(c.ControlMaster) || p.Contains(c.SummonMaster))) - return false; - } + if (p != null && (p.Contains(bcFrom.ControlMaster) || p.Contains(bcFrom.SummonMaster))) + return false; } - if (to is BaseCreature && !((BaseCreature)to).Controlled && ((BaseCreature)to).InitialInnocent) + if (bcTarg != null && !bcTarg.Controlled && bcTarg.InitialInnocent) return true; int noto = Notoriety.Compute(from, to); @@ -661,13 +624,8 @@ namespace Server.Spells } // Always allow monsters to teleport - if (caster is BaseCreature && (type == TravelCheckType.TeleportTo || type == TravelCheckType.TeleportFrom)) - { - BaseCreature bc = (BaseCreature)caster; - - if (!bc.Controlled && !bc.Summoned) + if (caster is BaseCreature bc && !bc.Controlled && !bc.Summoned && (type == TravelCheckType.TeleportTo || type == TravelCheckType.TeleportFrom)) return true; - } m_TravelCaster = caster; m_TravelType = type; @@ -883,12 +841,12 @@ namespace Server.Spells } //towns - public static bool IsTown(IPoint3D loc, Mobile caster) + public static bool IsTown(IPoint3D ip, Mobile caster) { - if (loc is Item) - loc = ((Item)loc).GetWorldLocation(); + if (ip is Item item) + ip = item.GetWorldLocation(); - return IsTown(new Point3D(loc), caster); + return IsTown(new Point3D(ip), caster); } public static bool IsTown(Point3D loc, Mobile caster) @@ -917,12 +875,12 @@ namespace Server.Spells return reg != null && !reg.IsDisabled(); } - public static bool CheckTown(IPoint3D loc, Mobile caster) + public static bool CheckTown(IPoint3D ip, Mobile caster) { - if (loc is Item) - loc = ((Item)loc).GetWorldLocation(); + if (ip is Item item) + ip = item.GetWorldLocation(); - return CheckTown(new Point3D(loc), caster); + return CheckTown(new Point3D(ip), caster); } public static bool CheckTown(Point3D loc, Mobile caster) @@ -971,18 +929,18 @@ namespace Server.Spells target = temp; } } - else if (target is BaseCreature) + else if (target is BaseCreature creature) { bool reflect = false; - ((BaseCreature)target).CheckReflect(caster, ref reflect); + creature.CheckReflect(caster, ref reflect); if (reflect) { - target.FixedEffect(0x37B9, 10, 5); + creature.FixedEffect(0x37B9, 10, 5); Mobile temp = caster; - caster = target; + caster = creature; target = temp; } } @@ -1022,63 +980,45 @@ namespace Server.Spells new SpellDamageTimer(spell, target, from, iDamage, delay).Start(); } - if (target is BaseCreature && from != null && delay == TimeSpan.Zero) + if (target is BaseCreature c && from != null && delay == TimeSpan.Zero) { - BaseCreature c = (BaseCreature)target; - c.OnHarmfulSpell(from); c.OnDamagedBySpell(from); } } public static void Damage(Spell spell, Mobile target, double damage, int phys, int fire, int cold, int pois, - int nrgy) + int nrgy, int chaos = 0, DFAlgorithm dfa = DFAlgorithm.Standard) { - TimeSpan ts = GetDamageDelayForSpell(spell); - - Damage(spell, ts, target, spell.Caster, damage, phys, fire, cold, pois, nrgy, DFAlgorithm.Standard); - } - - public static void Damage(Spell spell, Mobile target, double damage, int phys, int fire, int cold, int pois, - int nrgy, DFAlgorithm dfa) - { - TimeSpan ts = GetDamageDelayForSpell(spell); - - Damage(spell, ts, target, spell.Caster, damage, phys, fire, cold, pois, nrgy, dfa); + Damage(spell, GetDamageDelayForSpell(spell), target, spell.Caster, damage, phys, fire, cold, pois, nrgy, chaos, dfa); } public static void Damage(TimeSpan delay, Mobile target, double damage, int phys, int fire, int cold, int pois, - int nrgy) + int nrgy, int chaos = 0, DFAlgorithm dfa = DFAlgorithm.Standard) { - Damage(delay, target, null, damage, phys, fire, cold, pois, nrgy); + Damage(delay, target, null, damage, phys, fire, cold, pois, nrgy, chaos, dfa); } public static void Damage(TimeSpan delay, Mobile target, Mobile from, double damage, int phys, int fire, int cold, - int pois, int nrgy) + int pois, int nrgy, int chaos = 0, DFAlgorithm dfa = DFAlgorithm.Standard) { - Damage(delay, target, from, damage, phys, fire, cold, pois, nrgy, DFAlgorithm.Standard); - } - - public static void Damage(TimeSpan delay, Mobile target, Mobile from, double damage, int phys, int fire, int cold, - int pois, int nrgy, DFAlgorithm dfa) - { - Damage(null, delay, target, from, damage, phys, fire, cold, pois, nrgy, dfa); + Damage(null, delay, target, from, damage, phys, fire, cold, pois, nrgy, chaos, dfa); } public static void Damage(Spell spell, TimeSpan delay, Mobile target, Mobile from, double damage, int phys, int fire, - int cold, int pois, int nrgy, DFAlgorithm dfa) + int cold, int pois, int nrgy, int chaos = 0, DFAlgorithm dfa = DFAlgorithm.Standard) { - int iDamage = (int)damage; + int dmg = (int)damage; if (delay == TimeSpan.Zero) { - (from as BaseCreature)?.AlterSpellDamageTo(target, ref iDamage); + (from as BaseCreature)?.AlterSpellDamageTo(target, ref dmg); - (target as BaseCreature)?.AlterSpellDamageFrom(from, ref iDamage); + (target as BaseCreature)?.AlterSpellDamageFrom(from, ref dmg); WeightOverloading.DFA = dfa; - int damageGiven = AOS.Damage(target, from, iDamage, phys, fire, cold, pois, nrgy); + int damageGiven = AOS.Damage(target, from, dmg, phys, fire, cold, pois, nrgy, chaos); if (from != null) // sanity check DoLeech(damageGiven, from, target); @@ -1087,13 +1027,11 @@ namespace Server.Spells } else { - new SpellDamageTimerAOS(spell, target, from, iDamage, phys, fire, cold, pois, nrgy, delay, dfa).Start(); + new SpellDamageTimerAOS(spell, delay, target, from, dmg, phys, fire, cold, pois, nrgy, chaos, dfa).Start(); } - if (target is BaseCreature && from != null && delay == TimeSpan.Zero) + if (target is BaseCreature c && from != null && delay == TimeSpan.Zero) { - BaseCreature c = (BaseCreature)target; - c.OnHarmfulSpell(from); c.OnDamagedBySpell(from); } @@ -1103,25 +1041,25 @@ namespace Server.Spells { TransformContext context = TransformationSpellHelper.GetContext(from); - if (context != null) /* cleanup */ + if (context == null) /* cleanup */ + return; + + if (context.Type == typeof(WraithFormSpell)) { - if (context.Type == typeof(WraithFormSpell)) + int wraithLeech = + 5 + (int)(15 * from.Skills.SpiritSpeak.Value / 100); // Wraith form gives 5-20% mana leech + int manaLeech = AOS.Scale(damageGiven, wraithLeech); + if (manaLeech != 0) { - int wraithLeech = - 5 + (int)(15 * from.Skills.SpiritSpeak.Value / 100); // Wraith form gives 5-20% mana leech - int manaLeech = AOS.Scale(damageGiven, wraithLeech); - if (manaLeech != 0) - { - from.Mana += manaLeech; - from.PlaySound(0x44D); - } - } - else if (context.Type == typeof(VampiricEmbraceSpell)) - { - from.Hits += AOS.Scale(damageGiven, 20); + from.Mana += manaLeech; from.PlaySound(0x44D); } } + else if (context.Type == typeof(VampiricEmbraceSpell)) + { + from.Hits += AOS.Scale(damageGiven, 20); + from.PlaySound(0x44D); + } } public static void Heal(int amount, Mobile target, Mobile from) @@ -1172,12 +1110,12 @@ namespace Server.Spells { private int m_Damage; private DFAlgorithm m_DFA; - private int m_Phys, m_Fire, m_Cold, m_Pois, m_Nrgy; + private int m_Phys, m_Fire, m_Cold, m_Pois, m_Nrgy, m_Chaos; private Spell m_Spell; private Mobile m_Target, m_From; - public SpellDamageTimerAOS(Spell s, Mobile target, Mobile from, int damage, int phys, int fire, int cold, - int pois, int nrgy, TimeSpan delay, DFAlgorithm dfa) + public SpellDamageTimerAOS(Spell s, TimeSpan delay, Mobile target, Mobile from, int damage, int phys, int fire, int cold, + int pois, int nrgy, int chaos, DFAlgorithm dfa) : base(delay) { m_Target = target; @@ -1188,6 +1126,7 @@ namespace Server.Spells m_Cold = cold; m_Pois = pois; m_Nrgy = nrgy; + m_Chaos = chaos; m_DFA = dfa; m_Spell = s; if (m_Spell != null && m_Spell.DelayedDamage && !m_Spell.DelayedDamageStacking) @@ -1198,27 +1137,28 @@ namespace Server.Spells protected override void OnTick() { - if (m_From is BaseCreature && m_Target != null) - ((BaseCreature)m_From).AlterSpellDamageTo(m_Target, ref m_Damage); + BaseCreature bcFrom = m_From as BaseCreature; + BaseCreature bcTarg = m_Target as BaseCreature; + + if (bcFrom != null && m_Target != null) + bcFrom.AlterSpellDamageTo(m_Target, ref m_Damage); - if (m_Target is BaseCreature && m_From != null) - ((BaseCreature)m_Target).AlterSpellDamageFrom(m_From, ref m_Damage); + if (bcTarg != null && m_From != null) + bcTarg.AlterSpellDamageFrom(m_From, ref m_Damage); WeightOverloading.DFA = m_DFA; - int damageGiven = AOS.Damage(m_Target, m_From, m_Damage, m_Phys, m_Fire, m_Cold, m_Pois, m_Nrgy); + int damageGiven = AOS.Damage(m_Target, m_From, m_Damage, m_Phys, m_Fire, m_Cold, m_Pois, m_Nrgy, m_Chaos); if (m_From != null) // sanity check DoLeech(damageGiven, m_From, m_Target); WeightOverloading.DFA = DFAlgorithm.Standard; - if (m_Target is BaseCreature && m_From != null) + if (bcTarg != null && m_From != null) { - BaseCreature c = (BaseCreature)m_Target; - - c.OnHarmfulSpell(m_From); - c.OnDamagedBySpell(m_From); + bcTarg.OnHarmfulSpell(m_From); + bcTarg.OnDamagedBySpell(m_From); } m_Spell?.RemoveDelayedDamageContext(m_Target); @@ -1253,9 +1193,7 @@ namespace Server.Spells public static bool OnCast(Mobile caster, Spell spell) { - ITransformationSpell transformSpell = spell as ITransformationSpell; - - if (transformSpell == null) + if (!(spell is ITransformationSpell transformSpell)) return false; if (Sigil.ExistsOn(caster)) diff --git a/Scripts/Spells/Bushido/Evasion.cs b/Scripts/Spells/Bushido/Evasion.cs index e631140d0..6213eca09 100644 --- a/Scripts/Spells/Bushido/Evasion.cs +++ b/Scripts/Spells/Bushido/Evasion.cs @@ -37,9 +37,7 @@ namespace Server.Spells.Bushido if (Caster == null) // Sanity return false; - BaseWeapon weap = Caster.FindItemOnLayer(Layer.OneHanded) as BaseWeapon; - - if (weap == null) + if (!(Caster.FindItemOnLayer(Layer.OneHanded) is BaseWeapon weap)) weap = Caster.FindItemOnLayer(Layer.TwoHanded) as BaseWeapon; if (weap != null) @@ -70,9 +68,7 @@ namespace Server.Spells.Bushido public static bool CheckSpellEvasion(Mobile defender) { - BaseWeapon weap = defender.FindItemOnLayer(Layer.OneHanded) as BaseWeapon; - - if (weap == null) + if (!(defender.FindItemOnLayer(Layer.OneHanded) is BaseWeapon weap)) weap = defender.FindItemOnLayer(Layer.TwoHanded) as BaseWeapon; if (Core.ML) diff --git a/Scripts/Spells/Bushido/HonorableExecution.cs b/Scripts/Spells/Bushido/HonorableExecution.cs index 78f3cdd66..62c89abe4 100644 --- a/Scripts/Spells/Bushido/HonorableExecution.cs +++ b/Scripts/Spells/Bushido/HonorableExecution.cs @@ -28,9 +28,7 @@ namespace Server.Spells.Bushido ClearCurrentMove(attacker); - HonorableExecutionInfo info = m_Table[attacker] as HonorableExecutionInfo; - - if (info != null) + if (m_Table[attacker] is HonorableExecutionInfo info) { info.Clear(); @@ -54,14 +52,15 @@ namespace Server.Spells.Bushido } else { - ArrayList mods = new ArrayList(); - - mods.Add(new ResistanceMod(ResistanceType.Physical, -40)); - mods.Add(new ResistanceMod(ResistanceType.Fire, -40)); - mods.Add(new ResistanceMod(ResistanceType.Cold, -40)); - mods.Add(new ResistanceMod(ResistanceType.Poison, -40)); - mods.Add(new ResistanceMod(ResistanceType.Energy, -40)); - + ArrayList mods = new ArrayList + { + new ResistanceMod(ResistanceType.Physical, -40), + new ResistanceMod(ResistanceType.Fire, -40), + new ResistanceMod(ResistanceType.Cold, -40), + new ResistanceMod(ResistanceType.Poison, -40), + new ResistanceMod(ResistanceType.Energy, -40) + }; + double resSpells = attacker.Skills[SkillName.MagicResist].Value; if (resSpells > 0.0) @@ -78,9 +77,7 @@ namespace Server.Spells.Bushido public static int GetSwingBonus(Mobile target) { - HonorableExecutionInfo info = m_Table[target] as HonorableExecutionInfo; - - if (info == null) + if (!(m_Table[target] is HonorableExecutionInfo info)) return 0; return info.m_SwingBonus; @@ -88,9 +85,7 @@ namespace Server.Spells.Bushido public static bool IsUnderPenalty(Mobile target) { - HonorableExecutionInfo info = m_Table[target] as HonorableExecutionInfo; - - if (info == null) + if (!(m_Table[target] is HonorableExecutionInfo info)) return false; return info.m_Penalty; @@ -98,9 +93,7 @@ namespace Server.Spells.Bushido public static void RemovePenalty(Mobile target) { - HonorableExecutionInfo info = m_Table[target] as HonorableExecutionInfo; - - if (info == null || !info.m_Penalty) + if (!(m_Table[target] is HonorableExecutionInfo info) || !info.m_Penalty) return; info.Clear(); @@ -112,9 +105,7 @@ namespace Server.Spells.Bushido public void EndEffect(object state) { - HonorableExecutionInfo info = (HonorableExecutionInfo)state; - - RemovePenalty(info.m_Mobile); + RemovePenalty(((HonorableExecutionInfo)state).m_Mobile); } private class HonorableExecutionInfo @@ -125,15 +116,11 @@ namespace Server.Spells.Bushido public int m_SwingBonus; public Timer m_Timer; - public HonorableExecutionInfo(Mobile from, int swingBonus) : this(from, swingBonus, null, false) - { - } - public HonorableExecutionInfo(Mobile from, ArrayList mods) : this(from, 0, mods, true) { } - public HonorableExecutionInfo(Mobile from, int swingBonus, ArrayList mods, bool penalty) + public HonorableExecutionInfo(Mobile from, int swingBonus, ArrayList mods = null, bool penalty = false) { m_Mobile = from; m_SwingBonus = swingBonus; @@ -152,10 +139,10 @@ namespace Server.Spells.Bushido { object mod = m_Mods[i]; - if (mod is ResistanceMod) - m_Mobile.AddResistanceMod((ResistanceMod)mod); - else if (mod is SkillMod) - m_Mobile.AddSkillMod((SkillMod)mod); + if (mod is ResistanceMod resistanceMod) + m_Mobile.AddResistanceMod(resistanceMod); + else if (mod is SkillMod skillMod) + m_Mobile.AddSkillMod(skillMod); } } @@ -168,10 +155,10 @@ namespace Server.Spells.Bushido { object mod = m_Mods[i]; - if (mod is ResistanceMod) - m_Mobile.RemoveResistanceMod((ResistanceMod)mod); - else if (mod is SkillMod) - m_Mobile.RemoveSkillMod((SkillMod)mod); + if (mod is ResistanceMod resistanceMod) + m_Mobile.RemoveResistanceMod(resistanceMod); + else if (mod is SkillMod skillMod) + m_Mobile.RemoveSkillMod(skillMod); } } } diff --git a/Scripts/Spells/Chivalry/CleanseByFire.cs b/Scripts/Spells/Chivalry/CleanseByFire.cs index 85c49d26a..a12717909 100644 --- a/Scripts/Spells/Chivalry/CleanseByFire.cs +++ b/Scripts/Spells/Chivalry/CleanseByFire.cs @@ -113,8 +113,8 @@ namespace Server.Spells.Chivalry protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Chivalry/CloseWounds.cs b/Scripts/Spells/Chivalry/CloseWounds.cs index 6ebac1ee8..70972eacb 100644 --- a/Scripts/Spells/Chivalry/CloseWounds.cs +++ b/Scripts/Spells/Chivalry/CloseWounds.cs @@ -48,7 +48,7 @@ namespace Server.Spells.Chivalry { Caster.SendLocalizedMessage(1060178); // You are too far away to perform that action! } - else if (m is BaseCreature && ((BaseCreature)m).IsAnimatedDead) + else if (m is BaseCreature creature && creature.IsAnimatedDead) { Caster.SendLocalizedMessage(1061654); // You cannot heal that which is not alive. } @@ -72,19 +72,12 @@ namespace Server.Spells.Chivalry * The caster's Karma affects the amount of damage healed. */ - int toHeal = ComputePowerValue(6) + Utility.RandomMinMax(0, 2); - // TODO: Should caps be applied? - if (toHeal < 7) - toHeal = 7; - else if (toHeal > 39) - toHeal = 39; + int toHeal = Math.Min(Math.Max(ComputePowerValue(6) + Utility.RandomMinMax(0, 2), 7), 39); if (m.Hits + toHeal > m.HitsMax) toHeal = m.HitsMax - m.Hits; - //m.Hits += toHeal; //Was previously due to the message - //m.Heal( toHeal, Caster, false ); SpellHelper.Heal(toHeal, m, Caster, false); m.SendLocalizedMessage(1060203, @@ -109,8 +102,8 @@ namespace Server.Spells.Chivalry protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs index da8db66b4..dc5d2f8fb 100644 --- a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs +++ b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs @@ -28,9 +28,7 @@ namespace Server.Spells.Chivalry public override void OnCast() { - BaseWeapon weapon = Caster.Weapon as BaseWeapon; - - if (weapon == null || weapon is Fists) + if (!(Caster.Weapon is BaseWeapon weapon) || weapon is Fists) { Caster.SendLocalizedMessage(501078); // You must be holding a weapon. } diff --git a/Scripts/Spells/Chivalry/DispelEvil.cs b/Scripts/Spells/Chivalry/DispelEvil.cs index b5beb5624..ef9b2aeb2 100644 --- a/Scripts/Spells/Chivalry/DispelEvil.cs +++ b/Scripts/Spells/Chivalry/DispelEvil.cs @@ -54,13 +54,10 @@ namespace Server.Spells.Chivalry for (int i = 0; i < targets.Count; ++i) { Mobile m = targets[i]; - BaseCreature bc = m as BaseCreature; - if (bc != null) + if (m is BaseCreature bc) { - bool dispellable = bc.Summoned && !bc.IsAnimatedDead; - - if (dispellable) + if (bc.Summoned && !bc.IsAnimatedDead) { double dispelChance = (50.0 + 100 * (chiv - bc.DispelDifficulty) / (bc.DispelFocus * 2)) / 100; dispelChance *= dispelSkill / 100.0; diff --git a/Scripts/Spells/Chivalry/EnemyOfOne.cs b/Scripts/Spells/Chivalry/EnemyOfOne.cs index 1fe6fc28b..8382d357c 100644 --- a/Scripts/Spells/Chivalry/EnemyOfOne.cs +++ b/Scripts/Spells/Chivalry/EnemyOfOne.cs @@ -50,13 +50,13 @@ namespace Server.Spells.Chivalry m_Table[Caster] = Timer.DelayCall(TimeSpan.FromMinutes(delay), new TimerStateCallback(Expire_Callback), Caster); - if (Caster is PlayerMobile) + if (Caster is PlayerMobile mobile) { - ((PlayerMobile)Caster).EnemyOfOneType = null; - ((PlayerMobile)Caster).WaitingForEnemy = true; + mobile.EnemyOfOneType = null; + mobile.WaitingForEnemy = true; - BuffInfo.AddBuff(Caster, - new BuffInfo(BuffIcon.EnemyOfOne, 1075653, 1044111, TimeSpan.FromMinutes(delay), Caster)); + BuffInfo.AddBuff(mobile, + new BuffInfo(BuffIcon.EnemyOfOne, 1075653, 1044111, TimeSpan.FromMinutes(delay), mobile)); } } @@ -71,10 +71,10 @@ namespace Server.Spells.Chivalry m.PlaySound(0x1F8); - if (m is PlayerMobile) + if (m is PlayerMobile mobile) { - ((PlayerMobile)m).EnemyOfOneType = null; - ((PlayerMobile)m).WaitingForEnemy = false; + mobile.EnemyOfOneType = null; + mobile.WaitingForEnemy = false; } } } diff --git a/Scripts/Spells/Chivalry/NobleSacrifice.cs b/Scripts/Spells/Chivalry/NobleSacrifice.cs index d40189bb0..3591af33e 100644 --- a/Scripts/Spells/Chivalry/NobleSacrifice.cs +++ b/Scripts/Spells/Chivalry/NobleSacrifice.cs @@ -34,7 +34,7 @@ namespace Server.Spells.Chivalry foreach (Mobile m in Caster.GetMobilesInRange(3)) // TODO: Validate range { - if (m is BaseCreature && ((BaseCreature)m).IsAnimatedDead) + if (m is BaseCreature creature && creature.IsAnimatedDead) continue; if (Caster != m && m.InLOS(Caster) && Caster.CanBeBeneficial(m, false, true) && !(m is Golem)) @@ -54,7 +54,7 @@ namespace Server.Spells.Chivalry bool sacrifice = false; // TODO: Is there really a resurrection chance? - double resChance = 0.1 + 0.9 * ((double)Caster.Karma / 10000); + double resChance = 0.1 + 0.9 * Caster.Karma / 10000.0d; for (int i = 0; i < targets.Count; ++i) { diff --git a/Scripts/Spells/Chivalry/RemoveCurse.cs b/Scripts/Spells/Chivalry/RemoveCurse.cs index f7ac6fe21..7447a942e 100644 --- a/Scripts/Spells/Chivalry/RemoveCurse.cs +++ b/Scripts/Spells/Chivalry/RemoveCurse.cs @@ -76,9 +76,7 @@ namespace Server.Spells.Chivalry Effects.SendMovingParticles(from, to, 0x2255, 1, 0, false, false, 13, 3, 9501, 1, 0, EffectLayer.Head, 0x100); - StatMod mod; - - mod = m.GetStatMod("[Magic] Str Offset"); + StatMod mod = m.GetStatMod("[Magic] Str Offset"); if (mod != null && mod.Offset < 0) m.RemoveStatMod("[Magic] Str Offset"); @@ -130,8 +128,8 @@ namespace Server.Spells.Chivalry protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Chivalry/SacredJourney.cs b/Scripts/Spells/Chivalry/SacredJourney.cs index d4c6cf058..d4a1beedd 100644 --- a/Scripts/Spells/Chivalry/SacredJourney.cs +++ b/Scripts/Spells/Chivalry/SacredJourney.cs @@ -21,11 +21,7 @@ namespace Server.Spells.Chivalry private RunebookEntry m_Entry; - public SacredJourneySpell(Mobile caster, Item scroll) : this(caster, scroll, null, null) - { - } - - public SacredJourneySpell(Mobile caster, Item scroll, RunebookEntry entry, Runebook book) : base(caster, scroll, + public SacredJourneySpell(Mobile caster, Item scroll, RunebookEntry entry = null, Runebook book = null) : base(caster, scroll, m_Info) { m_Entry = entry; @@ -96,9 +92,9 @@ namespace Server.Spells.Chivalry else if (!SpellHelper.CheckTravel(Caster, map, loc, TravelCheckType.RecallTo)) { } - else if (map == Map.Felucca && Caster is PlayerMobile && ((PlayerMobile)Caster).Young) + else if (map == Map.Felucca && Caster is PlayerMobile mobile && mobile.Young) { - Caster.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 (Caster.Kills >= 5 && map != Map.Felucca) { @@ -157,38 +153,32 @@ namespace Server.Spells.Chivalry protected override void OnTarget(Mobile from, object o) { - if (o is RecallRune) + if (o is RecallRune rune) { - RecallRune rune = (RecallRune)o; - if (rune.Marked) m_Owner.Effect(rune.Target, rune.TargetMap, true); else from.SendLocalizedMessage(501805); // That rune is not yet marked. } - else if (o is Runebook) + else if (o is Runebook runebook) { - RunebookEntry e = ((Runebook)o).Default; + RunebookEntry e = runebook.Default; if (e != null) m_Owner.Effect(e.Location, e.Map, true); else from.SendLocalizedMessage(502354); // Target is not marked. } - else if (o is Key && ((Key)o).KeyValue != 0 && ((Key)o).Link is BaseBoat) + else if (o is Key key && key.KeyValue != 0 && key.Link is BaseBoat boat) { - BaseBoat boat = ((Key)o).Link as BaseBoat; - - if (!boat.Deleted && boat.CheckKey(((Key)o).KeyValue)) + if (!boat.Deleted && boat.CheckKey(key.KeyValue)) m_Owner.Effect(boat.GetMarkedLocation(), boat.Map, false); else from.Send(new MessageLocalized(from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 502357, from.Name, "")); // I can not recall from that object. } - else if (o is HouseRaffleDeed && ((HouseRaffleDeed)o).ValidLocation()) + else if (o is HouseRaffleDeed deed && deed.ValidLocation()) { - HouseRaffleDeed deed = (HouseRaffleDeed)o; - m_Owner.Effect(deed.PlotLocation, deed.PlotFacet, true); } else diff --git a/Scripts/Spells/Eighth/EnergyVortex.cs b/Scripts/Spells/Eighth/EnergyVortex.cs index 77075b338..86dbed550 100644 --- a/Scripts/Spells/Eighth/EnergyVortex.cs +++ b/Scripts/Spells/Eighth/EnergyVortex.cs @@ -78,8 +78,8 @@ namespace Server.Spells.Eighth protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetOutOfLOS(Mobile from, object o) diff --git a/Scripts/Spells/Eighth/Resurrection.cs b/Scripts/Spells/Eighth/Resurrection.cs index eb79f5642..34b350685 100644 --- a/Scripts/Spells/Eighth/Resurrection.cs +++ b/Scripts/Spells/Eighth/Resurrection.cs @@ -98,7 +98,8 @@ namespace Server.Spells.Eighth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fifth/BladeSpirits.cs b/Scripts/Spells/Fifth/BladeSpirits.cs index 6977c4196..a402371ed 100644 --- a/Scripts/Spells/Fifth/BladeSpirits.cs +++ b/Scripts/Spells/Fifth/BladeSpirits.cs @@ -85,8 +85,8 @@ namespace Server.Spells.Fifth protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetOutOfLOS(Mobile from, object o) diff --git a/Scripts/Spells/Fifth/DispelField.cs b/Scripts/Spells/Fifth/DispelField.cs index 679231614..3e8536a0b 100644 --- a/Scripts/Spells/Fifth/DispelField.cs +++ b/Scripts/Spells/Fifth/DispelField.cs @@ -40,7 +40,7 @@ namespace Server.Spells.Fifth { Caster.SendLocalizedMessage(1005049); // That cannot be dispelled. } - else if (item is Moongate && !((Moongate)item).Dispellable) + else if (item is Moongate moongate && !moongate.Dispellable) { Caster.SendLocalizedMessage(1005047); // That magic is too chaotic } @@ -69,8 +69,8 @@ namespace Server.Spells.Fifth protected override void OnTarget(Mobile from, object o) { - if (o is Item) - m_Owner.Target((Item)o); + if (o is Item item) + m_Owner.Target(item); else m_Owner.Caster.SendLocalizedMessage(1005049); // That cannot be dispelled. } diff --git a/Scripts/Spells/Fifth/MindBlast.cs b/Scripts/Spells/Fifth/MindBlast.cs index 55ebb2689..559fe882e 100644 --- a/Scripts/Spells/Fifth/MindBlast.cs +++ b/Scripts/Spells/Fifth/MindBlast.cs @@ -141,8 +141,8 @@ namespace Server.Spells.Fifth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fifth/Paralyze.cs b/Scripts/Spells/Fifth/Paralyze.cs index 253f1fe5e..56cf9727f 100644 --- a/Scripts/Spells/Fifth/Paralyze.cs +++ b/Scripts/Spells/Fifth/Paralyze.cs @@ -71,9 +71,9 @@ namespace Server.Spells.Fifth duration *= 0.75; } - if (m is PlagueBeastLord) + if (m is PlagueBeastLord lord) { - ((PlagueBeastLord)m).OnParalyzed(Caster); + lord.OnParalyzed(Caster); duration = 120; } @@ -99,8 +99,8 @@ namespace Server.Spells.Fifth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fifth/PoisonField.cs b/Scripts/Spells/Fifth/PoisonField.cs index b35c3dde7..941c92326 100644 --- a/Scripts/Spells/Fifth/PoisonField.cs +++ b/Scripts/Spells/Fifth/PoisonField.cs @@ -281,8 +281,8 @@ namespace Server.Spells.Fifth protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/First/Clumsy.cs b/Scripts/Spells/First/Clumsy.cs index e4bcea5a1..7310a5a67 100644 --- a/Scripts/Spells/First/Clumsy.cs +++ b/Scripts/Spells/First/Clumsy.cs @@ -67,7 +67,8 @@ namespace Server.Spells.First protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/First/Feeblemind.cs b/Scripts/Spells/First/Feeblemind.cs index 160d4008e..b8498ad78 100644 --- a/Scripts/Spells/First/Feeblemind.cs +++ b/Scripts/Spells/First/Feeblemind.cs @@ -67,7 +67,8 @@ namespace Server.Spells.First protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/First/Heal.cs b/Scripts/Spells/First/Heal.cs index 4e251300a..57dd26eff 100644 --- a/Scripts/Spells/First/Heal.cs +++ b/Scripts/Spells/First/Heal.cs @@ -49,7 +49,7 @@ namespace Server.Spells.First { Caster.SendLocalizedMessage(1060177); // You cannot heal a creature that is already dead! } - else if (m is BaseCreature && ((BaseCreature)m).IsAnimatedDead) + else if (m is BaseCreature creature && creature.IsAnimatedDead) { Caster.SendLocalizedMessage(1061654); // You cannot heal that which is not alive. } @@ -102,7 +102,8 @@ namespace Server.Spells.First protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/First/MagicArrow.cs b/Scripts/Spells/First/MagicArrow.cs index 793214eba..e19dc80d7 100644 --- a/Scripts/Spells/First/MagicArrow.cs +++ b/Scripts/Spells/First/MagicArrow.cs @@ -80,7 +80,8 @@ namespace Server.Spells.First protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/First/NightSight.cs b/Scripts/Spells/First/NightSight.cs index b1f796e27..79ba72b43 100644 --- a/Scripts/Spells/First/NightSight.cs +++ b/Scripts/Spells/First/NightSight.cs @@ -34,10 +34,8 @@ namespace Server.Spells.First protected override void OnTarget(Mobile from, object targeted) { - if (targeted is Mobile && m_Spell.CheckBSequence((Mobile)targeted)) + if (targeted is Mobile targ && m_Spell.CheckBSequence(targ)) { - Mobile targ = (Mobile)targeted; - SpellHelper.Turn(m_Spell.Caster, targ); if (targ.BeginAction(typeof(LightCycle))) diff --git a/Scripts/Spells/First/Weaken.cs b/Scripts/Spells/First/Weaken.cs index cd3acfb8f..d553639c4 100644 --- a/Scripts/Spells/First/Weaken.cs +++ b/Scripts/Spells/First/Weaken.cs @@ -67,7 +67,8 @@ namespace Server.Spells.First protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fourth/ArchCure.cs b/Scripts/Spells/Fourth/ArchCure.cs index 074666067..26faa81c2 100644 --- a/Scripts/Spells/Fourth/ArchCure.cs +++ b/Scripts/Spells/Fourth/ArchCure.cs @@ -170,9 +170,7 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Fourth/ArchProtection.cs b/Scripts/Spells/Fourth/ArchProtection.cs index 5bee6953d..56ad0133c 100644 --- a/Scripts/Spells/Fourth/ArchProtection.cs +++ b/Scripts/Spells/Fourth/ArchProtection.cs @@ -152,9 +152,7 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Fourth/Curse.cs b/Scripts/Spells/Fourth/Curse.cs index 7c5fd0587..12cb41452 100644 --- a/Scripts/Spells/Fourth/Curse.cs +++ b/Scripts/Spells/Fourth/Curse.cs @@ -66,7 +66,7 @@ namespace Server.Spells.Fourth ) //On OSI you CAN curse yourself and get this effect. { TimeSpan duration = SpellHelper.GetDuration(Caster, m); - m_UnderEffect[m] = t = Timer.DelayCall(duration, new TimerStateCallback(RemoveEffect), m); + m_UnderEffect[m] = Timer.DelayCall(duration, new TimerStateCallback(RemoveEffect), m); m.UpdateResistances(); } @@ -101,8 +101,8 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fourth/FireField.cs b/Scripts/Spells/Fourth/FireField.cs index 0a284d9b5..7f4278d78 100644 --- a/Scripts/Spells/Fourth/FireField.cs +++ b/Scripts/Spells/Fourth/FireField.cs @@ -246,36 +246,36 @@ namespace Server.Spells.Fourth Map map = m_Item.Map; Mobile caster = m_Item.m_Caster; - if (map != null && caster != null) + if (map == null || caster == null) + return; + + foreach (Mobile m in m_Item.GetMobilesInRange(0)) + if (m.Z + 16 > m_Item.Z && m_Item.Z + 12 > m.Z && (!Core.AOS || m != caster) && + SpellHelper.ValidIndirectTarget(caster, m) && caster.CanBeHarmful(m, false)) + m_Queue.Enqueue(m); + + while (m_Queue.Count > 0) { - foreach (Mobile m in m_Item.GetMobilesInRange(0)) - if (m.Z + 16 > m_Item.Z && m_Item.Z + 12 > m.Z && (!Core.AOS || m != caster) && - SpellHelper.ValidIndirectTarget(caster, m) && caster.CanBeHarmful(m, false)) - m_Queue.Enqueue(m); + Mobile m = (Mobile)m_Queue.Dequeue(); - while (m_Queue.Count > 0) + if (SpellHelper.CanRevealCaster(m)) + caster.RevealingAction(); + + caster.DoHarmful(m); + + int damage = m_Item.m_Damage; + + if (!Core.AOS && m.CheckSkill(SkillName.MagicResist, 0.0, 30.0)) { - Mobile m = (Mobile)m_Queue.Dequeue(); + damage = 1; - if (SpellHelper.CanRevealCaster(m)) - caster.RevealingAction(); - - caster.DoHarmful(m); - - int damage = m_Item.m_Damage; - - if (!Core.AOS && m.CheckSkill(SkillName.MagicResist, 0.0, 30.0)) - { - damage = 1; - - m.SendLocalizedMessage(501783); // You feel yourself resisting magical energy. - } - - AOS.Damage(m, caster, damage, 0, 100, 0, 0, 0); - m.PlaySound(0x208); - - (m as BaseCreature)?.OnHarmfulSpell(caster); + m.SendLocalizedMessage(501783); // You feel yourself resisting magical energy. } + + AOS.Damage(m, caster, damage, 0, 100, 0, 0, 0); + m.PlaySound(0x208); + + (m as BaseCreature)?.OnHarmfulSpell(caster); } } } @@ -293,8 +293,8 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fourth/GreaterHeal.cs b/Scripts/Spells/Fourth/GreaterHeal.cs index 5f2273545..f76cfeaa0 100644 --- a/Scripts/Spells/Fourth/GreaterHeal.cs +++ b/Scripts/Spells/Fourth/GreaterHeal.cs @@ -46,7 +46,7 @@ namespace Server.Spells.Fourth { Caster.SendLocalizedMessage(500237); // Target can not be seen. } - else if (m is BaseCreature && ((BaseCreature)m).IsAnimatedDead) + else if (m is BaseCreature creature && creature.IsAnimatedDead) { Caster.SendLocalizedMessage(1061654); // You cannot heal that which is not alive. } @@ -92,7 +92,8 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fourth/Lightning.cs b/Scripts/Spells/Fourth/Lightning.cs index ca2093cb3..163fcae79 100644 --- a/Scripts/Spells/Fourth/Lightning.cs +++ b/Scripts/Spells/Fourth/Lightning.cs @@ -76,8 +76,8 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fourth/ManaDrain.cs b/Scripts/Spells/Fourth/ManaDrain.cs index e66676a7e..355d617e0 100644 --- a/Scripts/Spells/Fourth/ManaDrain.cs +++ b/Scripts/Spells/Fourth/ManaDrain.cs @@ -120,8 +120,8 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Fourth/Recall.cs b/Scripts/Spells/Fourth/Recall.cs index 8bf37ed50..e3c86baa7 100644 --- a/Scripts/Spells/Fourth/Recall.cs +++ b/Scripts/Spells/Fourth/Recall.cs @@ -24,11 +24,7 @@ namespace Server.Spells.Fourth private RunebookEntry m_Entry; - public RecallSpell(Mobile caster, Item scroll) : this(caster, scroll, null, null) - { - } - - public RecallSpell(Mobile caster, Item scroll, RunebookEntry entry, Runebook book) : base(caster, scroll, m_Info) + public RecallSpell(Mobile caster, Item scroll, RunebookEntry entry = null, Runebook book = null) : base(caster, scroll, m_Info) { m_Entry = entry; m_Book = book; @@ -99,9 +95,9 @@ namespace Server.Spells.Fourth else if (!SpellHelper.CheckTravel(Caster, map, loc, TravelCheckType.RecallTo)) { } - else if (map == Map.Felucca && Caster is PlayerMobile && ((PlayerMobile)Caster).Young) + else if (map == Map.Felucca && Caster is PlayerMobile mobile && mobile.Young) { - Caster.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 (Caster.Kills >= 5 && map != Map.Felucca) { @@ -159,38 +155,32 @@ namespace Server.Spells.Fourth protected override void OnTarget(Mobile from, object o) { - if (o is RecallRune) + if (o is RecallRune rune) { - RecallRune rune = (RecallRune)o; - if (rune.Marked) m_Owner.Effect(rune.Target, rune.TargetMap, true); else from.SendLocalizedMessage(501805); // That rune is not yet marked. } - else if (o is Runebook) + else if (o is Runebook runebook) { - RunebookEntry e = ((Runebook)o).Default; + RunebookEntry e = runebook.Default; if (e != null) m_Owner.Effect(e.Location, e.Map, true); else from.SendLocalizedMessage(502354); // Target is not marked. } - else if (o is Key && ((Key)o).KeyValue != 0 && ((Key)o).Link is BaseBoat) + else if (o is Key key && key.KeyValue != 0 && key.Link is BaseBoat boat) { - BaseBoat boat = ((Key)o).Link as BaseBoat; - - if (!boat.Deleted && boat.CheckKey(((Key)o).KeyValue)) + if (!boat.Deleted && boat.CheckKey(key.KeyValue)) m_Owner.Effect(boat.GetMarkedLocation(), boat.Map, false); else from.Send(new MessageLocalized(from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 502357, from.Name, "")); // I can not recall from that object. } - else if (o is HouseRaffleDeed && ((HouseRaffleDeed)o).ValidLocation()) + else if (o is HouseRaffleDeed deed && deed.ValidLocation()) { - HouseRaffleDeed deed = (HouseRaffleDeed)o; - m_Owner.Effect(deed.PlotLocation, deed.PlotFacet, true); } else diff --git a/Scripts/Spells/Mysticism/AnimatedWeaponSpell.cs b/Scripts/Spells/Mysticism/AnimatedWeaponSpell.cs index 224b7ffaf..563cf0168 100644 --- a/Scripts/Spells/Mysticism/AnimatedWeaponSpell.cs +++ b/Scripts/Spells/Mysticism/AnimatedWeaponSpell.cs @@ -76,8 +76,8 @@ namespace Server.Spells.Mysticism protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Mysticism/EagleStrikeSpell.cs b/Scripts/Spells/Mysticism/EagleStrikeSpell.cs index 39941eb52..5872252c0 100644 --- a/Scripts/Spells/Mysticism/EagleStrikeSpell.cs +++ b/Scripts/Spells/Mysticism/EagleStrikeSpell.cs @@ -75,8 +75,8 @@ namespace Server.Spells.Mysticism protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Mysticism/HailStormSpell.cs b/Scripts/Spells/Mysticism/HailStormSpell.cs index 1838ef98f..ef5040d8c 100644 --- a/Scripts/Spells/Mysticism/HailStormSpell.cs +++ b/Scripts/Spells/Mysticism/HailStormSpell.cs @@ -43,8 +43,8 @@ namespace Server.Spells.Mysticism SpellHelper.Turn(Caster, p); - if (p is Item) - p = ((Item)p).GetWorldLocation(); + if (p is Item item) + p = item.GetWorldLocation(); List targets = new List(); @@ -131,9 +131,7 @@ namespace Server.Spells.Mysticism protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Mysticism/NetherCycloneSpell.cs b/Scripts/Spells/Mysticism/NetherCycloneSpell.cs index ac63b8e72..675b2ac98 100644 --- a/Scripts/Spells/Mysticism/NetherCycloneSpell.cs +++ b/Scripts/Spells/Mysticism/NetherCycloneSpell.cs @@ -46,8 +46,8 @@ namespace Server.Spells.Mysticism SpellHelper.Turn(Caster, p); - if (p is Item) - p = ((Item)p).GetWorldLocation(); + if (p is Item item) + p = item.GetWorldLocation(); List targets = new List(); @@ -83,11 +83,7 @@ namespace Server.Spells.Mysticism foreach (Mobile m in targets) { Caster.DoHarmful(m); - - int[] types = new int[4]; - types[Utility.Random(types.Length)] = 100; - - SpellHelper.Damage(this, m, damage, 0, types[0], types[1], types[2], types[3]); + SpellHelper.Damage(this, m, damage, 0, 0, 0, 0, 0, 100); double resistedReduction = reduction - m.Skills[SkillName.MagicResist].Value / 800.0; diff --git a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs index 397b167d1..e6e3fc4a9 100644 --- a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs +++ b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs @@ -63,11 +63,7 @@ namespace Server.Spells.Mysticism VisualEffect(targeted); int damage = GetNewAosDamage(33, 1, 5, targeted); - - int[] types = new int[4]; - types[Utility.Random(types.Length)] = 100; - - SpellHelper.Damage(this, targeted, damage, 0, types[0], types[1], types[2], types[3]); + SpellHelper.Damage(this, targeted, damage, 0, 0, 0, 0, 0); SpellPlagueContext context = new SpellPlagueContext(this, targeted); @@ -176,10 +172,7 @@ namespace Server.Spells.Mysticism m_Explosions++; m_LastExploded = DateTime.Now; - int[] types = new int[4]; - types[Utility.Random(types.Length)] = 100; - - SpellHelper.Damage(m_Owner, m_Target, damage, 0, types[0], types[1], types[2], types[3]); + SpellHelper.Damage(m_Owner, m_Target, damage, 0, 0, 0, 0, 0, 100); if (m_Explosions >= 3) EndPlague(); @@ -222,8 +215,8 @@ namespace Server.Spells.Mysticism protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs index 3b18ea952..fdedad3e1 100644 --- a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs +++ b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs @@ -132,9 +132,7 @@ namespace Server.Spells.Necromancy { MaabusCoffinComponent comp = obj as MaabusCoffinComponent; - MaabusCoffin addon = comp?.Addon as MaabusCoffin; - - if (addon != null) + if (comp?.Addon is MaabusCoffin addon) { PlayerMobile pm = Caster as PlayerMobile; @@ -154,9 +152,7 @@ namespace Server.Spells.Necromancy return; } - Corpse c = obj as Corpse; - - if (c == null) + if (!(obj is Corpse c)) { Caster.SendLocalizedMessage(1061084); // You cannot animate that. } @@ -167,8 +163,8 @@ namespace Server.Spells.Necromancy if (c.Owner != null) type = c.Owner.GetType(); if (c.ItemID != 0x2006 || c.Animated || type == typeof(PlayerMobile) || type == null || - c.Owner != null && c.Owner.Fame < 100 || c.Owner is BaseCreature && - (((BaseCreature)c.Owner).Summoned || ((BaseCreature)c.Owner).IsBonded)) + c.Owner != null && c.Owner.Fame < 100 || c.Owner is BaseCreature creature && + (creature.Summoned || creature.IsBonded)) { Caster.SendLocalizedMessage(1061085); // There's not enough life force there to animate. } @@ -326,25 +322,20 @@ namespace Server.Spells.Necromancy if (summoned == null) return; - if (summoned is BaseCreature) + if (summoned is BaseCreature bc) { - BaseCreature bc = (BaseCreature)summoned; - // to be sure bc.Tamable = false; - if (bc is BaseMount) - bc.ControlSlots = 1; - else - bc.ControlSlots = 0; + bc.ControlSlots = bc is BaseMount ? 1 : 0; Effects.PlaySound(loc, map, bc.GetAngerSound()); - BaseCreature.Summon((BaseCreature)summoned, false, caster, loc, 0x28, TimeSpan.FromDays(1.0)); + BaseCreature.Summon(bc, false, caster, loc, 0x28, TimeSpan.FromDays(1.0)); } - if (summoned is SkeletalDragon) - Scale((SkeletalDragon)summoned, 50); // lose 50% hp and strength + if (summoned is SkeletalDragon dragon) + Scale(dragon, 50); // lose 50% hp and strength summoned.Fame = 0; summoned.Karma = -1500; @@ -359,9 +350,7 @@ namespace Server.Spells.Necromancy public static void Scale(BaseCreature bc, int scalar) { - int toScale; - - toScale = bc.RawStr; + int toScale = bc.RawStr; bc.RawStr = AOS.Scale(toScale, scalar); toScale = bc.HitsMaxSeed; diff --git a/Scripts/Spells/Necromancy/BloodOathSpell.cs b/Scripts/Spells/Necromancy/BloodOathSpell.cs index 3a45af9db..0deee24ff 100644 --- a/Scripts/Spells/Necromancy/BloodOathSpell.cs +++ b/Scripts/Spells/Necromancy/BloodOathSpell.cs @@ -173,8 +173,8 @@ namespace Server.Spells.Necromancy protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); else from.SendLocalizedMessage(1060508); // You can't curse that. } diff --git a/Scripts/Spells/Necromancy/CorpseSkin.cs b/Scripts/Spells/Necromancy/CorpseSkin.cs index eb8b7cd2f..ff39fb6a0 100644 --- a/Scripts/Spells/Necromancy/CorpseSkin.cs +++ b/Scripts/Spells/Necromancy/CorpseSkin.cs @@ -141,8 +141,8 @@ namespace Server.Spells.Necromancy protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Necromancy/CurseWeapon.cs b/Scripts/Spells/Necromancy/CurseWeapon.cs index 45272f17a..9d550b85c 100644 --- a/Scripts/Spells/Necromancy/CurseWeapon.cs +++ b/Scripts/Spells/Necromancy/CurseWeapon.cs @@ -26,9 +26,7 @@ namespace Server.Spells.Necromancy public override void OnCast() { - BaseWeapon weapon = Caster.Weapon as BaseWeapon; - - if (weapon == null || weapon is Fists) + if (!(Caster.Weapon is BaseWeapon weapon) || weapon is Fists) { Caster.SendLocalizedMessage(501078); // You must be holding a weapon. } diff --git a/Scripts/Spells/Necromancy/EvilOmen.cs b/Scripts/Spells/Necromancy/EvilOmen.cs index acfc578dd..6caad743f 100644 --- a/Scripts/Spells/Necromancy/EvilOmen.cs +++ b/Scripts/Spells/Necromancy/EvilOmen.cs @@ -116,8 +116,8 @@ namespace Server.Spells.Necromancy protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); else from.SendLocalizedMessage(1060508); // You can't curse that. } diff --git a/Scripts/Spells/Necromancy/Exorcism.cs b/Scripts/Spells/Necromancy/Exorcism.cs index 462c72376..365dcd0b6 100644 --- a/Scripts/Spells/Necromancy/Exorcism.cs +++ b/Scripts/Spells/Necromancy/Exorcism.cs @@ -87,9 +87,7 @@ namespace Server.Spells.Necromancy public override void OnCast() { - ChampionSpawnRegion r = Caster.Region.GetRegion(typeof(ChampionSpawnRegion)) as ChampionSpawnRegion; - - if (r == null || !Caster.InRange(r.ChampionSpawn, Range)) + if (!(Caster.Region.GetRegion(typeof(ChampionSpawnRegion)) is ChampionSpawnRegion r) || !Caster.InRange(r.ChampionSpawn, Range)) { Caster.SendLocalizedMessage(1072111); // You are not in a valid exorcism region. } diff --git a/Scripts/Spells/Necromancy/MindRot.cs b/Scripts/Spells/Necromancy/MindRot.cs index bc4e271e7..b56963e93 100644 --- a/Scripts/Spells/Necromancy/MindRot.cs +++ b/Scripts/Spells/Necromancy/MindRot.cs @@ -120,8 +120,8 @@ namespace Server.Spells.Necromancy protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); else from.SendLocalizedMessage(1060508); // You can't curse that. } @@ -135,14 +135,12 @@ namespace Server.Spells.Necromancy public class MRExpireTimer : Timer { - private Mobile m_Caster; private DateTime m_End; private Mobile m_Target; public MRExpireTimer(Mobile caster, Mobile target, TimeSpan delay) : base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0)) { - m_Caster = caster; m_Target = target; m_End = DateTime.UtcNow + delay; Priority = TimerPriority.TwoFiftyMS; diff --git a/Scripts/Spells/Necromancy/PainSpike.cs b/Scripts/Spells/Necromancy/PainSpike.cs index bb90436a0..adeaefb0a 100644 --- a/Scripts/Spells/Necromancy/PainSpike.cs +++ b/Scripts/Spells/Necromancy/PainSpike.cs @@ -39,7 +39,7 @@ namespace Server.Spells.Necromancy { SpellHelper.Turn(Caster, m); - //SpellHelper.CheckReflect( (int)this.Circle, Caster, ref m ); //Irrelevent asfter AoS + //SpellHelper.CheckReflect( (int)this.Circle, Caster, ref m ); //Irrelevent after AoS /* Temporarily causes intense physical pain to the target, dealing direct damage. * After 10 seconds the spell wears off, and if the target is still alive, @@ -61,9 +61,8 @@ namespace Server.Spells.Necromancy if (m_Table.Contains(m)) { damage = Utility.RandomMinMax(3, 7); - Timer t = m_Table[m] as Timer; - if (t != null) + if (m_Table[m] is Timer t) { t.Delay += TimeSpan.FromSeconds(2.0); @@ -77,6 +76,7 @@ namespace Server.Spells.Necromancy BuffInfo.AddBuff(m, new BuffInfo(BuffIcon.PainSpike, 1075667, buffTime, m, Convert.ToString((int)damage))); + // TODO: Find a better way to do this WeightOverloading.DFA = DFAlgorithm.PainSpike; m.Damage((int)damage, Caster); SpellHelper.DoLeech((int)damage, Caster, m); @@ -126,8 +126,8 @@ namespace Server.Spells.Necromancy protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Necromancy/PoisonStrike.cs b/Scripts/Spells/Necromancy/PoisonStrike.cs index 4e170854a..47f085182 100644 --- a/Scripts/Spells/Necromancy/PoisonStrike.cs +++ b/Scripts/Spells/Necromancy/PoisonStrike.cs @@ -107,8 +107,8 @@ namespace Server.Spells.Necromancy protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Ninjitsu/KiAttack.cs b/Scripts/Spells/Ninjitsu/KiAttack.cs index 598ff3035..7a8b02cde 100644 --- a/Scripts/Spells/Ninjitsu/KiAttack.cs +++ b/Scripts/Spells/Ninjitsu/KiAttack.cs @@ -33,18 +33,12 @@ namespace Server.Spells.Ninjitsu return false; } - if (Core.ML) + if (Core.ML && @from.Weapon is BaseRanged) { - BaseRanged ranged = from.Weapon as BaseRanged; - - if (ranged != null) - { - from.SendLocalizedMessage(1075858); // You can only use this with melee attacks. - return false; - } + from.SendLocalizedMessage(1075858); // You can only use this with melee attacks. + return false; } - - + return base.Validate(from); } @@ -86,9 +80,7 @@ namespace Server.Spells.Ninjitsu public override void OnClearMove(Mobile from) { - KiAttackInfo info = m_Table[from] as KiAttackInfo; - - if (info != null) + if (m_Table[@from] is KiAttackInfo info) { info.m_Timer?.Stop(); @@ -98,9 +90,7 @@ namespace Server.Spells.Ninjitsu public static double GetBonus(Mobile from) { - KiAttackInfo info = m_Table[from] as KiAttackInfo; - - if (info == null) + if (!(m_Table[@from] is KiAttackInfo info)) return 0.0; int xDelta = info.m_Location.X - from.X; diff --git a/Scripts/Spells/Ninjitsu/ShadowJump.cs b/Scripts/Spells/Ninjitsu/ShadowJump.cs index 3adf25249..123c49f40 100644 --- a/Scripts/Spells/Ninjitsu/ShadowJump.cs +++ b/Scripts/Spells/Ninjitsu/ShadowJump.cs @@ -122,9 +122,7 @@ namespace Server.Spells.Ninjitsu protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs index e7854e830..3228aee88 100644 --- a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs +++ b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs @@ -86,9 +86,7 @@ namespace Server.Spells.Ninjitsu public static bool GetMalus(Mobile target, ref int malus) { - SurpriseAttackInfo info = m_Table[target] as SurpriseAttackInfo; - - if (info == null) + if (!(m_Table[target] is SurpriseAttackInfo info)) return false; malus = info.m_Malus; diff --git a/Scripts/Spells/Second/Agility.cs b/Scripts/Spells/Second/Agility.cs index 4a2941f6c..8966241df 100644 --- a/Scripts/Spells/Second/Agility.cs +++ b/Scripts/Spells/Second/Agility.cs @@ -71,7 +71,8 @@ namespace Server.Spells.Second protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Second/Cunning.cs b/Scripts/Spells/Second/Cunning.cs index 6b1659e09..465c8ae55 100644 --- a/Scripts/Spells/Second/Cunning.cs +++ b/Scripts/Spells/Second/Cunning.cs @@ -71,7 +71,8 @@ namespace Server.Spells.Second protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Second/Cure.cs b/Scripts/Spells/Second/Cure.cs index 56bd9aac5..ac336ed72 100644 --- a/Scripts/Spells/Second/Cure.cs +++ b/Scripts/Spells/Second/Cure.cs @@ -87,7 +87,8 @@ namespace Server.Spells.Second protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Second/Harm.cs b/Scripts/Spells/Second/Harm.cs index ef6db5836..b228e84a0 100644 --- a/Scripts/Spells/Second/Harm.cs +++ b/Scripts/Spells/Second/Harm.cs @@ -25,13 +25,11 @@ namespace Server.Spells.Second Caster.Target = new InternalTarget(this); } - public override double GetSlayerDamageScalar(Mobile target) { return 1.0; //This spell isn't affected by slayer spellbooks } - public void Target(Mobile m) { if (!Caster.CanSee(m)) @@ -97,7 +95,8 @@ namespace Server.Spells.Second protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Second/MagicTrap.cs b/Scripts/Spells/Second/MagicTrap.cs index 06a675ead..543288c9a 100644 --- a/Scripts/Spells/Second/MagicTrap.cs +++ b/Scripts/Spells/Second/MagicTrap.cs @@ -78,8 +78,8 @@ namespace Server.Spells.Second protected override void OnTarget(Mobile from, object o) { - if (o is TrappableContainer) - m_Owner.Target((TrappableContainer)o); + if (o is TrappableContainer container) + m_Owner.Target(container); else from.SendMessage("You can't trap that"); } diff --git a/Scripts/Spells/Second/RemoveTrap.cs b/Scripts/Spells/Second/RemoveTrap.cs index ff652357d..20651770f 100644 --- a/Scripts/Spells/Second/RemoveTrap.cs +++ b/Scripts/Spells/Second/RemoveTrap.cs @@ -64,8 +64,8 @@ namespace Server.Spells.Second protected override void OnTarget(Mobile from, object o) { - if (o is TrappableContainer) - m_Owner.Target((TrappableContainer)o); + if (o is TrappableContainer container) + m_Owner.Target(container); else from.SendMessage("You can't disarm that"); } diff --git a/Scripts/Spells/Second/Strength.cs b/Scripts/Spells/Second/Strength.cs index c6033bb97..0e36eef11 100644 --- a/Scripts/Spells/Second/Strength.cs +++ b/Scripts/Spells/Second/Strength.cs @@ -71,7 +71,8 @@ namespace Server.Spells.Second protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Seventh/ChainLightning.cs b/Scripts/Spells/Seventh/ChainLightning.cs index b82a66550..860431ffe 100644 --- a/Scripts/Spells/Seventh/ChainLightning.cs +++ b/Scripts/Spells/Seventh/ChainLightning.cs @@ -39,8 +39,8 @@ namespace Server.Spells.Seventh { SpellHelper.Turn(Caster, p); - if (p is Item) - p = ((Item)p).GetWorldLocation(); + if (p is Item item) + p = item.GetWorldLocation(); List targets = new List(); @@ -86,10 +86,9 @@ namespace Server.Spells.Seventh else if (!Core.AOS) damage /= targets.Count; - double toDeal; for (int i = 0; i < targets.Count; ++i) { - toDeal = damage; + double toDeal = damage; Mobile m = targets[i]; if (!Core.AOS && CheckResisted(m)) @@ -126,9 +125,7 @@ namespace Server.Spells.Seventh protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Seventh/EnergyField.cs b/Scripts/Spells/Seventh/EnergyField.cs index 71040c27e..0358c223d 100644 --- a/Scripts/Spells/Seventh/EnergyField.cs +++ b/Scripts/Spells/Seventh/EnergyField.cs @@ -188,8 +188,8 @@ namespace Server.Spells.Seventh protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Seventh/FlameStrike.cs b/Scripts/Spells/Seventh/FlameStrike.cs index ae41034e6..da64575f5 100644 --- a/Scripts/Spells/Seventh/FlameStrike.cs +++ b/Scripts/Spells/Seventh/FlameStrike.cs @@ -77,7 +77,8 @@ namespace Server.Spells.Seventh protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Seventh/GateTravel.cs b/Scripts/Spells/Seventh/GateTravel.cs index 79e33e82d..5f455055a 100644 --- a/Scripts/Spells/Seventh/GateTravel.cs +++ b/Scripts/Spells/Seventh/GateTravel.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Server.Factions; using Server.Items; using Server.Misc; @@ -65,19 +66,11 @@ namespace Server.Spells.Seventh private bool GateExistsAt(Map map, Point3D loc) { - bool _gateFound = false; - IPooledEnumerable eable = map.GetItemsInRange(loc, 0); - foreach (Item item in eable) - if (item is Moongate || item is PublicMoongate) - { - _gateFound = true; - break; - } - + bool gateFound = eable.Any(item => item is Moongate || item is PublicMoongate); eable.Free(); - return _gateFound; + return gateFound; } public void Effect(Point3D loc, Map map, bool checkMulti) @@ -96,9 +89,9 @@ namespace Server.Spells.Seventh else if (!SpellHelper.CheckTravel(Caster, map, loc, TravelCheckType.GateTo)) { } - else if (map == Map.Felucca && Caster is PlayerMobile && ((PlayerMobile)Caster).Young) + else if (map == Map.Felucca && Caster is PlayerMobile mobile && mobile.Young) { - Caster.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 (Caster.Kills >= 5 && map != Map.Felucca) { @@ -207,18 +200,16 @@ namespace Server.Spells.Seventh protected override void OnTarget(Mobile from, object o) { - if (o is RecallRune) + if (o is RecallRune rune) { - RecallRune rune = (RecallRune)o; - if (rune.Marked) m_Owner.Effect(rune.Target, rune.TargetMap, true); else from.SendLocalizedMessage(501803); // That rune is not yet marked. } - else if (o is Runebook) + else if (o is Runebook runebook) { - RunebookEntry e = ((Runebook)o).Default; + RunebookEntry e = runebook.Default; if (e != null) m_Owner.Effect(e.Location, e.Map, true); @@ -234,10 +225,8 @@ namespace Server.Spells.Seventh else from.Send( new MessageLocalized( from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 501030, from.Name, "" ) ); // I can not gate travel from that object. }*/ - else if (o is HouseRaffleDeed && ((HouseRaffleDeed)o).ValidLocation()) + else if (o is HouseRaffleDeed deed && deed.ValidLocation()) { - HouseRaffleDeed deed = (HouseRaffleDeed)o; - m_Owner.Effect(deed.PlotLocation, deed.PlotFacet, true); } else diff --git a/Scripts/Spells/Seventh/ManaVampire.cs b/Scripts/Spells/Seventh/ManaVampire.cs index 3b6043fdb..932111842 100644 --- a/Scripts/Spells/Seventh/ManaVampire.cs +++ b/Scripts/Spells/Seventh/ManaVampire.cs @@ -104,7 +104,7 @@ namespace Server.Spells.Seventh protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile)m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Seventh/MassDispel.cs b/Scripts/Spells/Seventh/MassDispel.cs index 016d5c9f4..513b7fd17 100644 --- a/Scripts/Spells/Seventh/MassDispel.cs +++ b/Scripts/Spells/Seventh/MassDispel.cs @@ -59,9 +59,7 @@ namespace Server.Spells.Seventh { Mobile m = targets[i]; - BaseCreature bc = m as BaseCreature; - - if (bc == null) + if (!(m is BaseCreature bc)) continue; double dispelChance = @@ -98,9 +96,7 @@ namespace Server.Spells.Seventh protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Seventh/MeteorSwarm.cs b/Scripts/Spells/Seventh/MeteorSwarm.cs index 8ded421b3..e75b9cc9a 100644 --- a/Scripts/Spells/Seventh/MeteorSwarm.cs +++ b/Scripts/Spells/Seventh/MeteorSwarm.cs @@ -39,8 +39,8 @@ namespace Server.Spells.Seventh { SpellHelper.Turn(Caster, p); - if (p is Item) - p = ((Item)p).GetWorldLocation(); + if (p is Item item) + p = item.GetWorldLocation(); List targets = new List(); @@ -120,9 +120,7 @@ namespace Server.Spells.Seventh protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Sixth/Dispel.cs b/Scripts/Spells/Sixth/Dispel.cs index bcb39619a..511a62614 100644 --- a/Scripts/Spells/Sixth/Dispel.cs +++ b/Scripts/Spells/Sixth/Dispel.cs @@ -37,9 +37,8 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) + if (o is Mobile m) { - Mobile m = (Mobile)o; BaseCreature bc = m as BaseCreature; if (!from.CanSee(m)) diff --git a/Scripts/Spells/Sixth/EnergyBolt.cs b/Scripts/Spells/Sixth/EnergyBolt.cs index b95b5a3d3..bfbd02fa9 100644 --- a/Scripts/Spells/Sixth/EnergyBolt.cs +++ b/Scripts/Spells/Sixth/EnergyBolt.cs @@ -82,8 +82,8 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Sixth/Explosion.cs b/Scripts/Spells/Sixth/Explosion.cs index b667bf028..4d27b9a14 100644 --- a/Scripts/Spells/Sixth/Explosion.cs +++ b/Scripts/Spells/Sixth/Explosion.cs @@ -115,8 +115,8 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Sixth/Invisibility.cs b/Scripts/Spells/Sixth/Invisibility.cs index 9f88a2c38..f5f5faf32 100644 --- a/Scripts/Spells/Sixth/Invisibility.cs +++ b/Scripts/Spells/Sixth/Invisibility.cs @@ -47,7 +47,7 @@ namespace Server.Spells.Sixth { Caster.SendLocalizedMessage(500237); // Target can not be seen. } - else if (m is BaseVendor || m is PlayerVendor || m is PlayerBarkeeper || m.AccessLevel > Caster.AccessLevel) + else if (m is BaseVendor || m is PlayerVendor || m.AccessLevel > Caster.AccessLevel) { Caster.SendLocalizedMessage(501857); // This spell won't work on that! } @@ -125,7 +125,8 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Sixth/Mark.cs b/Scripts/Spells/Sixth/Mark.cs index bd053ad10..0db750102 100644 --- a/Scripts/Spells/Sixth/Mark.cs +++ b/Scripts/Spells/Sixth/Mark.cs @@ -74,8 +74,8 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - if (o is RecallRune) - m_Owner.Target((RecallRune)o); + if (o is RecallRune rune) + m_Owner.Target(rune); else from.Send(new MessageLocalized(from.Serial, from.Body, MessageType.Regular, 0x3B2, 3, 501797, from.Name, "")); // I cannot mark that object. diff --git a/Scripts/Spells/Sixth/MassCurse.cs b/Scripts/Spells/Sixth/MassCurse.cs index 60042e493..20024e593 100644 --- a/Scripts/Spells/Sixth/MassCurse.cs +++ b/Scripts/Spells/Sixth/MassCurse.cs @@ -92,9 +92,7 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Sixth/ParalyzeField.cs b/Scripts/Spells/Sixth/ParalyzeField.cs index 8bab3ba6a..b40608937 100644 --- a/Scripts/Spells/Sixth/ParalyzeField.cs +++ b/Scripts/Spells/Sixth/ParalyzeField.cs @@ -224,8 +224,8 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Sixth/Reveal.cs b/Scripts/Spells/Sixth/Reveal.cs index 4b4faa593..18b05db09 100644 --- a/Scripts/Spells/Sixth/Reveal.cs +++ b/Scripts/Spells/Sixth/Reveal.cs @@ -107,9 +107,7 @@ namespace Server.Spells.Sixth protected override void OnTarget(Mobile from, object o) { - IPoint3D p = o as IPoint3D; - - if (p != null) + if (o is IPoint3D p) m_Owner.Target(p); } diff --git a/Scripts/Spells/Spellweaving/ArcaneCircle.cs b/Scripts/Spells/Spellweaving/ArcaneCircle.cs index 5837f47e7..b6c9cfb11 100644 --- a/Scripts/Spells/Spellweaving/ArcaneCircle.cs +++ b/Scripts/Spells/Spellweaving/ArcaneCircle.cs @@ -97,7 +97,7 @@ namespace Server.Spells.Spellweaving { ItemData id = item.ItemData; - if (item == null || item.Z + id.CalcHeight != location.Z) + if (item.Z + id.CalcHeight != location.Z) continue; if (IsValidTile(item.ItemID)) { @@ -120,14 +120,12 @@ namespace Server.Spells.Spellweaving private List GetArcanists() { - List weavers = new List(); - - weavers.Add(Caster); + List weavers = new List { Caster }; //OSI Verified: Even enemies/combatants count foreach (Mobile m in Caster.GetMobilesInRange(1)) //Range verified as 1 if (m != Caster && m is PlayerMobile && Caster.CanBeBeneficial(m, false) && - Math.Abs(Caster.Skills.Spellweaving.Value - m.Skills.Spellweaving.Value) <= 20 && !(m is Clone)) + Math.Abs(Caster.Skills.Spellweaving.Value - m.Skills.Spellweaving.Value) <= 20) weavers.Add(m); // Everyone gets the Arcane Focus, power capped elsewhere @@ -143,15 +141,15 @@ namespace Server.Spells.Spellweaving if (focus == null) { - ArcaneFocus f = new ArcaneFocus(duration, strengthBonus); - if (to.PlaceInBackpack(f)) + focus = new ArcaneFocus(duration, strengthBonus); + if (to.PlaceInBackpack(focus)) { - f.SendTimeRemainingMessage(to); + focus.SendTimeRemainingMessage(to); to.SendLocalizedMessage(1072740); // An arcane focus appears in your backpack. } else { - f.Delete(); + focus.Delete(); } } else //OSI renewal rules: the new one will override the old one, always. diff --git a/Scripts/Spells/Spellweaving/ArcanistSpell.cs b/Scripts/Spells/Spellweaving/ArcanistSpell.cs index ca12db952..46e133144 100644 --- a/Scripts/Spells/Spellweaving/ArcanistSpell.cs +++ b/Scripts/Spells/Spellweaving/ArcanistSpell.cs @@ -69,13 +69,13 @@ namespace Server.Spells.Spellweaving return false; } - if (caster is PlayerMobile) + if (caster is PlayerMobile mobile) { - MLQuestContext context = MLQuestSystem.GetContext((PlayerMobile)caster); + MLQuestContext context = MLQuestSystem.GetContext(mobile); if (context == null || !context.Spellweaving) { - caster.SendLocalizedMessage( + mobile.SendLocalizedMessage( 1073220); // You must have completed the epic arcanist quest to use this ability. return false; } @@ -93,7 +93,7 @@ namespace Server.Spells.Spellweaving if (caster.Skills[CastSkill].Value < RequiredSkill) { caster.SendLocalizedMessage(1063013, - $"{RequiredSkill.ToString("F1")}\t{"#1044114"}"); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability. + $"{RequiredSkill:F1}\t{"#1044114"}"); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability. return false; } diff --git a/Scripts/Spells/Spellweaving/GiftOfLife.cs b/Scripts/Spells/Spellweaving/GiftOfLife.cs index 04c506d1d..c16b6a7b5 100644 --- a/Scripts/Spells/Spellweaving/GiftOfLife.cs +++ b/Scripts/Spells/Spellweaving/GiftOfLife.cs @@ -39,8 +39,6 @@ namespace Server.Spells.Spellweaving public void Target(Mobile m) { - BaseCreature bc = m as BaseCreature; - if (!Caster.CanSee(m)) { Caster.SendLocalizedMessage(500237); // Target can not be seen. @@ -49,7 +47,7 @@ namespace Server.Spells.Spellweaving { // As per Osi: Nothing happens. } - else if (m != Caster && (bc == null || !bc.IsBonded || bc.ControlMaster != Caster)) + else if (m != Caster && !(m is BaseCreature bc && bc.IsBonded && bc.ControlMaster == Caster)) { Caster.SendLocalizedMessage(1072077); // You may only cast this spell on yourself or a bonded pet. } @@ -101,9 +99,8 @@ namespace Server.Spells.Spellweaving { double hitsScalar = timer.Spell.HitsScalar; - if (m is BaseCreature && m.IsDeadBondedPet) + if (m is BaseCreature pet && pet.IsDeadBondedPet) { - BaseCreature pet = (BaseCreature)m; Mobile master = pet.GetMaster(); if (master?.NetState != null && Utility.InUpdateRange(pet, master)) @@ -190,8 +187,8 @@ namespace Server.Spells.Spellweaving protected override void OnTarget(Mobile m, object o) { - if (o is Mobile) - m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); else m.SendLocalizedMessage(1072077); // You may only cast this spell on yourself or a bonded pet. } diff --git a/Scripts/Spells/Spellweaving/GiftOfRenewal.cs b/Scripts/Spells/Spellweaving/GiftOfRenewal.cs index fc2e24112..da03bc616 100644 --- a/Scripts/Spells/Spellweaving/GiftOfRenewal.cs +++ b/Scripts/Spells/Spellweaving/GiftOfRenewal.cs @@ -166,7 +166,8 @@ namespace Server.Spells.Spellweaving protected override void OnTarget(Mobile m, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile m) diff --git a/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs b/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs index b59770ab2..d797c9a6d 100644 --- a/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs +++ b/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs @@ -26,9 +26,7 @@ namespace Server.Spells.Spellweaving public override bool CheckCast() { - BaseWeapon weapon = Caster.Weapon as BaseWeapon; - - if (weapon == null || weapon is Fists || weapon is BaseRanged) + if (!(Caster.Weapon is BaseWeapon weapon) || weapon is Fists || weapon is BaseRanged) { Caster.SendLocalizedMessage(1060179); // You must be wielding a weapon to use this ability! return false; @@ -39,9 +37,7 @@ namespace Server.Spells.Spellweaving public override void OnCast() { - BaseWeapon weapon = Caster.Weapon as BaseWeapon; - - if (weapon == null || weapon is Fists || weapon is BaseRanged) + if (!(Caster.Weapon is BaseWeapon weapon) || weapon is Fists || weapon is BaseRanged) { Caster.SendLocalizedMessage(1060179); // You must be wielding a weapon to use this ability! } diff --git a/Scripts/Spells/Spellweaving/NatureFury.cs b/Scripts/Spells/Spellweaving/NatureFury.cs index 4cd54376e..6a226789f 100644 --- a/Scripts/Spells/Spellweaving/NatureFury.cs +++ b/Scripts/Spells/Spellweaving/NatureFury.cs @@ -84,8 +84,8 @@ namespace Server.Spells.Spellweaving protected override void OnTarget(Mobile from, object o) { - if (o is IPoint3D) - m_Owner.Target((IPoint3D)o); + if (o is IPoint3D d) + m_Owner.Target(d); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Spells/Spellweaving/SummonFey.cs b/Scripts/Spells/Spellweaving/SummonFey.cs index 4d0a660d1..d8eb77be8 100644 --- a/Scripts/Spells/Spellweaving/SummonFey.cs +++ b/Scripts/Spells/Spellweaving/SummonFey.cs @@ -28,13 +28,13 @@ namespace Server.Spells.Spellweaving Mobile caster = Caster; // This is done after casting completes - if (caster is PlayerMobile) + if (caster is PlayerMobile mobile) { - MLQuestContext context = MLQuestSystem.GetContext((PlayerMobile)caster); + MLQuestContext context = MLQuestSystem.GetContext(mobile); if (context == null || !context.SummonFey) { - caster.SendLocalizedMessage( + mobile.SendLocalizedMessage( 1074563); // You haven't forged a friendship with the fey and are unable to summon their aid. return false; } diff --git a/Scripts/Spells/Spellweaving/SummonFiend.cs b/Scripts/Spells/Spellweaving/SummonFiend.cs index e3619ca9b..5b8c0df37 100644 --- a/Scripts/Spells/Spellweaving/SummonFiend.cs +++ b/Scripts/Spells/Spellweaving/SummonFiend.cs @@ -28,13 +28,13 @@ namespace Server.Spells.Spellweaving Mobile caster = Caster; // This is done after casting completes - if (caster is PlayerMobile) + if (caster is PlayerMobile mobile) { - MLQuestContext context = MLQuestSystem.GetContext((PlayerMobile)caster); + MLQuestContext context = MLQuestSystem.GetContext(mobile); if (context == null || !context.SummonFiend) { - caster.SendLocalizedMessage(1074564); // You haven't demonstrated mastery to summon a fiend. + mobile.SendLocalizedMessage(1074564); // You haven't demonstrated mastery to summon a fiend. return false; } } diff --git a/Scripts/Spells/Spellweaving/WordOfDeath.cs b/Scripts/Spells/Spellweaving/WordOfDeath.cs index fa16a9760..4b696255e 100644 --- a/Scripts/Spells/Spellweaving/WordOfDeath.cs +++ b/Scripts/Spells/Spellweaving/WordOfDeath.cs @@ -58,11 +58,7 @@ namespace Server.Spells.Spellweaving damage /= 100; } - int[] types = new int[4]; - types[Utility.Random(types.Length)] = 100; - - SpellHelper.Damage(this, m, damage, 0, types[0], types[1], types[2], - types[3]); //Chaos damage. Random elemental damage + SpellHelper.Damage(this, m, damage, 0, 0, 0, 0, 0, 100); } FinishSequence(); @@ -79,7 +75,8 @@ namespace Server.Spells.Spellweaving protected override void OnTarget(Mobile m, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile m) diff --git a/Scripts/Spells/Third/Bless.cs b/Scripts/Spells/Third/Bless.cs index d0ee6aa6a..3e3f2cb82 100644 --- a/Scripts/Spells/Third/Bless.cs +++ b/Scripts/Spells/Third/Bless.cs @@ -77,7 +77,8 @@ namespace Server.Spells.Third protected override void OnTarget(Mobile from, object o) { - if (o is Mobile) m_Owner.Target((Mobile)o); + if (o is Mobile mobile) + m_Owner.Target(mobile); } protected override void OnTargetFinish(Mobile from) diff --git a/Scripts/Targets/MoveTarget.cs b/Scripts/Targets/MoveTarget.cs index b55765919..1057ec516 100644 --- a/Scripts/Targets/MoveTarget.cs +++ b/Scripts/Targets/MoveTarget.cs @@ -23,8 +23,8 @@ namespace Server.Targets return; } - if (p is Item) - p = ((Item)p).GetWorldTop(); + if (p is Item pItem) + p = pItem.GetWorldTop(); CommandLogging.WriteLine(from, "{0} {1} moving {2} to {3}", from.AccessLevel, CommandLogging.Format(from), CommandLogging.Format(m_Object), new Point3D(p)); diff --git a/Server/Map.cs b/Server/Map.cs index 5ccab07f7..fe03184f8 100644 --- a/Server/Map.cs +++ b/Server/Map.cs @@ -95,7 +95,7 @@ namespace Server { return s.Mobiles.OfType().Where(o => !o.Deleted && bounds.Contains(o)); } - + public static IEnumerable SelectItems(Sector s, Rectangle2D bounds) where T : Item { return s.Items.OfType() @@ -1081,23 +1081,13 @@ namespace Server return GetObjectsInRange(p, Core.GlobalMaxUpdateRange); } - public IPooledEnumerable GetObjectsInRange(Point3D p, int range) - { - return GetObjectsInRange(p, range, true, true); - } - - public IPooledEnumerable GetObjectsInRange(Point3D p, int range, bool items, bool mobiles) + public IPooledEnumerable GetObjectsInRange(Point3D p, int range, bool items = true, bool mobiles = true) { return GetObjectsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1), items, mobiles); } - public IPooledEnumerable GetObjectsInBounds(Rectangle2D bounds) - { - return GetObjectsInBounds(bounds, true, true); - } - - public IPooledEnumerable GetObjectsInBounds(Rectangle2D bounds, bool items, bool mobiles) + public IPooledEnumerable GetObjectsInBounds(Rectangle2D bounds, bool items = true, bool mobiles = true) { return PooledEnumeration.GetEntities(this, bounds, items, mobiles); } @@ -1353,13 +1343,7 @@ namespace Server dest = swap; } - double rise, run, zslp; - double sq3d; - double x, y, z; - int xd, yd, zd; - int ix, iy, iz; int height; - bool found; Point3D p; Point3DList path = new Point3DList(); TileFlag flags; @@ -1370,28 +1354,25 @@ namespace Server if (path.Count > 0) path.Clear(); - xd = dest.m_X - org.m_X; - yd = dest.m_Y - org.m_Y; - zd = dest.m_Z - org.m_Z; - zslp = Math.Sqrt(xd * xd + yd * yd); - if (zd != 0) - sq3d = Math.Sqrt(zslp * zslp + zd * zd); - else - sq3d = zslp; + int xd = dest.m_X - org.m_X; + int yd = dest.m_Y - org.m_Y; + int zd = dest.m_Z - org.m_Z; + double zslp = Math.Sqrt(xd * xd + yd * yd); + double sq3d = zd != 0 ? Math.Sqrt(zslp * zslp + zd * zd) : zslp; - rise = yd / sq3d; - run = xd / sq3d; + double rise = yd / sq3d; + double run = xd / sq3d; zslp = zd / sq3d; - y = org.m_Y; - z = org.m_Z; - x = org.m_X; + double y = org.m_Y; + double z = org.m_Z; + double x = org.m_X; while (Utility.NumberBetween(x, dest.m_X, org.m_X, 0.5) && Utility.NumberBetween(y, dest.m_Y, org.m_Y, 0.5) && Utility.NumberBetween(z, dest.m_Z, org.m_Z, 0.5)) { - ix = (int)Math.Round(x); - iy = (int)Math.Round(y); - iz = (int)Math.Round(z); + int ix = (int)Math.Round(x); + int iy = (int)Math.Round(y); + int iz = (int)Math.Round(z); if (path.Count > 0) { p = path.Last; @@ -1517,7 +1498,7 @@ namespace Server height = id.CalcHeight; - found = false; + bool found = false; int count = path.Count;