diff --git a/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs b/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs index 49dc2285e..9d3567516 100644 --- a/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs +++ b/Scripts/Engines/BulkOrders/Books/BulkOrderBook.cs @@ -142,7 +142,7 @@ namespace Server.Engines.BulkOrders } } - public void InvalidateContainers( object parent ) + public void InvalidateContainers(IEntity parent) { if ( parent is Container c ) { diff --git a/Scripts/Engines/ConPVP/Games/BombingRun.cs b/Scripts/Engines/ConPVP/Games/BombingRun.cs index 7adbe3b5d..9ca49e657 100644 --- a/Scripts/Engines/ConPVP/Games/BombingRun.cs +++ b/Scripts/Engines/ConPVP/Games/BombingRun.cs @@ -44,7 +44,7 @@ namespace Server.Engines.ConPVP public Mobile Thrower{ get; private set; } - private Mobile FindOwner(object parent) + private Mobile FindOwner(IEntity parent) { if (parent is Item item) return item.RootParent as Mobile; diff --git a/Scripts/Engines/ConPVP/Games/CTF.cs b/Scripts/Engines/ConPVP/Games/CTF.cs index abce7730b..526a4277a 100644 --- a/Scripts/Engines/ConPVP/Games/CTF.cs +++ b/Scripts/Engines/ConPVP/Games/CTF.cs @@ -455,7 +455,7 @@ namespace Server.Engines.ConPVP MoveToWorld(m_TeamInfo.Origin, m_TeamInfo.Game.Facet); } - private Mobile FindOwner(object parent) + private Mobile FindOwner(IEntity parent) { if (parent is Item item) return item.RootParent as Mobile; @@ -1199,4 +1199,4 @@ namespace Server.Engines.ConPVP m_FinishTimer = null; } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Factions/Items/Sigil.cs b/Scripts/Engines/Factions/Items/Sigil.cs index 916ab3be2..d18dde39a 100644 --- a/Scripts/Engines/Factions/Items/Sigil.cs +++ b/Scripts/Engines/Factions/Items/Sigil.cs @@ -181,7 +181,7 @@ namespace Server.Factions return false; } - private Mobile FindOwner(object parent) + private Mobile FindOwner(IEntity parent) { if (parent is Item item) return item.RootParent as Mobile; @@ -453,4 +453,4 @@ namespace Server.Factions base.Delete(); } } -} \ No newline at end of file +} diff --git a/Scripts/Gumps/ViewHousesGump.cs b/Scripts/Gumps/ViewHousesGump.cs index ccd70cf44..297ab58e9 100644 --- a/Scripts/Gumps/ViewHousesGump.cs +++ b/Scripts/Gumps/ViewHousesGump.cs @@ -234,9 +234,7 @@ namespace Server.Gumps public object FindHouseName(BaseHouse house) { int multiID = house.ItemID; - HousePlacementEntry[] entries; - - entries = HousePlacementEntry.ClassicHouses; + HousePlacementEntry[] entries = HousePlacementEntry.ClassicHouses; for (int i = 0; i < entries.Length; ++i) if (entries[i].MultiID == multiID) @@ -288,4 +286,4 @@ namespace Server.Gumps } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Games/BaseBoard.cs b/Scripts/Items/Games/BaseBoard.cs index 32a8dc5fe..b39aac3f6 100644 --- a/Scripts/Items/Games/BaseBoard.cs +++ b/Scripts/Items/Games/BaseBoard.cs @@ -114,7 +114,7 @@ namespace Server.Items if (board.IsChildOf(from.Backpack)) return true; - object root = board.RootParent; + IEntity root = board.RootParent; if (root is Mobile && root != from) return false; @@ -122,9 +122,7 @@ namespace Server.Items if (board.Deleted || board.Map != from.Map || !from.InRange(board.GetWorldLocation(), 1)) return false; - BaseHouse house = BaseHouse.FindHouseAt(board); - - return house != null && house.IsOwner(from); + return BaseHouse.FindHouseAt(board)?.IsOwner(from) == true; } public class DefaultEntry : ContextMenuEntry @@ -146,4 +144,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Maps/MapItem.cs b/Scripts/Items/Maps/MapItem.cs index 2930e9533..651b37ec3 100644 --- a/Scripts/Items/Maps/MapItem.cs +++ b/Scripts/Items/Maps/MapItem.cs @@ -174,12 +174,7 @@ namespace Server.Items if (!Movable || Protected || !from.InRange(GetWorldLocation(), 2)) return false; - object root = RootParent; - - if (root is Mobile && root != from) - return false; - - return true; + return !(RootParent is Mobile && RootParent != from); } public void ConvertToWorld(int x, int y, out int worldX, out int worldY) @@ -381,4 +376,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Misc/Scales.cs b/Scripts/Items/Misc/Scales.cs index f10c8cfef..9c33239e4 100644 --- a/Scripts/Items/Misc/Scales.cs +++ b/Scripts/Items/Misc/Scales.cs @@ -53,7 +53,7 @@ namespace Server.Items } else if (targeted is Item item) { - object root = item.RootParent; + IEntity root = item.RootParent; if (root != null && root != from || item.Parent == from) { @@ -61,10 +61,7 @@ namespace Server.Items } else if (item.Movable) { - if (item.Amount > 1) - message = "You place one item on the scale. "; - else - message = "You place that item on the scale. "; + message = item.Amount > 1 ? "You place one item on the scale. " : "You place that item on the scale. "; double weight = item.Weight; diff --git a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs index 11331c9ef..7c5771201 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs @@ -45,17 +45,13 @@ namespace Server.Items int version = reader.ReadInt(); } - public virtual object FindParent(Mobile from) + public virtual IEntity FindParent(Mobile from) { - Mobile m = HeldBy; + if (HeldBy?.Holding == this) + return HeldBy; - if (m != null && m.Holding == this) - return m; - - object obj = RootParent; - - if (obj != null) - return obj; + if (RootParent != null) + return RootParent; if (Map == Map.Internal) return from; @@ -74,7 +70,7 @@ namespace Server.Items ThrowTarget targ = from.Target as ThrowTarget; Stackable = false; // Scavenged explosion potions won't stack with those ones in backpack, and still will explode. - if (targ != null && targ.Potion == this) + if (targ?.Potion == this) return; from.RevealingAction(); @@ -107,7 +103,7 @@ namespace Server.Items if (Deleted) return; - object parent = FindParent(from); + IEntity parent = FindParent(from); if (timer == 0) { @@ -272,4 +268,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Suits/BaseSuit.cs b/Scripts/Items/Suits/BaseSuit.cs index 63ecdf70b..d824c571e 100644 --- a/Scripts/Items/Suits/BaseSuit.cs +++ b/Scripts/Items/Suits/BaseSuit.cs @@ -47,15 +47,12 @@ namespace Server.Items public bool Validate() { - object root = RootParent; + if (!(RootParent is Mobile mobile) || mobile.AccessLevel >= AccessLevel) + return true; - if (root is Mobile mobile && mobile.AccessLevel < AccessLevel) - { - Delete(); - return false; - } + Delete(); + return false; - return true; } public override void OnSingleClick(Mobile from) @@ -83,4 +80,4 @@ namespace Server.Items return from.AccessLevel >= AccessLevel; } } -} \ No newline at end of file +} diff --git a/Scripts/Misc/Cleanup.cs b/Scripts/Misc/Cleanup.cs index 6ba6d8fd8..407f1d0a0 100644 --- a/Scripts/Misc/Cleanup.cs +++ b/Scripts/Misc/Cleanup.cs @@ -66,9 +66,7 @@ namespace Server.Misc } else if (item.Layer == Layer.Hair || item.Layer == Layer.FacialHair) { - object rootParent = item.RootParent; - - if (rootParent is Mobile rootMobile) + if (item.RootParent is Mobile rootMobile) { if (item.Parent != rootMobile && rootMobile.AccessLevel == AccessLevel.Player) { @@ -164,4 +162,4 @@ namespace Server.Misc return false; } } -} \ No newline at end of file +} diff --git a/Scripts/Skills/Stealing.cs b/Scripts/Skills/Stealing.cs index 610e198ea..dbb03a2af 100644 --- a/Scripts/Skills/Stealing.cs +++ b/Scripts/Skills/Stealing.cs @@ -79,7 +79,7 @@ namespace Server.SkillHandlers { Item stolen = null; - object root = toSteal.RootParent; + IEntity root = toSteal.RootParent; Mobile mobRoot = root as Mobile; StealableArtifactsSpawner.StealableInstance si = null; @@ -215,7 +215,7 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(502710); // You can't steal that! } - else if (toSteal.LootType == LootType.Newbied || toSteal.CheckBlessed(root)) + else if (toSteal.LootType == LootType.Newbied || toSteal.CheckBlessed(mobRoot)) { m_Thief.SendLocalizedMessage(502710); // You can't steal that! } @@ -244,7 +244,7 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(502710); // You can't steal that! } - else if (mobRoot != null && !m_Thief.CanBeHarmful((Mobile)root)) + else if (mobRoot != null && !m_Thief.CanBeHarmful(mobRoot)) { } else if (root is Corpse) @@ -332,7 +332,7 @@ namespace Server.SkillHandlers from.RevealingAction(); Item stolen = null; - object root = null; + IEntity root = null; bool caught = false; if (target is Item item) @@ -356,7 +356,7 @@ namespace Server.SkillHandlers { m_Thief.SendLocalizedMessage(502710); // You can't steal that! } - + Mobile mobRoot = root as Mobile; if (stolen != null) @@ -395,7 +395,7 @@ namespace Server.SkillHandlers if (mobRoot?.Player == true && m_Thief is PlayerMobile pm && IsInnocentTo(pm, mobRoot) && !IsInGuild(mobRoot)) { - pm.PermaFlags.Add((Mobile)root); + pm.PermaFlags.Add(mobRoot); pm.Delta(MobileDelta.Noto); } } @@ -484,4 +484,4 @@ namespace Server.SkillHandlers } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Base/Spell.cs b/Scripts/Spells/Base/Spell.cs index eec45b17a..97606c81f 100644 --- a/Scripts/Spells/Base/Spell.cs +++ b/Scripts/Spells/Base/Spell.cs @@ -118,7 +118,7 @@ namespace Server.Spells return true; } - public virtual bool OnCasterUsingObject(object o) + public virtual bool OnCasterUsingObject(IEntity entity) { if (State == SpellState.Sequencing) Disturb(DisturbType.UseRequest); diff --git a/Scripts/Spells/Third/Telekinesis.cs b/Scripts/Spells/Third/Telekinesis.cs index 086682034..67b094a9c 100644 --- a/Scripts/Spells/Third/Telekinesis.cs +++ b/Scripts/Spells/Third/Telekinesis.cs @@ -42,8 +42,6 @@ namespace Server.Spells.Third { SpellHelper.Turn(Caster, item); - object root = item.RootParent; - if (!item.IsAccessibleTo(Caster)) { item.OnDoubleClickNotAccessible(Caster); @@ -51,7 +49,7 @@ namespace Server.Spells.Third else if (!item.CheckItemUse(Caster, item)) { } - else if (root is Mobile && root != Caster) + else if (item.RootParent is Mobile && item.RootParent != Caster) { item.OnSnoop(Caster); } @@ -104,4 +102,4 @@ namespace Server { void OnTelekinesis(Mobile from); } -} \ No newline at end of file +} diff --git a/Server/Interfaces.cs b/Server/Interfaces.cs index 24a855285..b1a06178b 100644 --- a/Server/Interfaces.cs +++ b/Server/Interfaces.cs @@ -84,7 +84,7 @@ namespace Server void OnConnectionChanged(); bool OnCasterMoving(Direction d); bool OnCasterEquipping(Item item); - bool OnCasterUsingObject(object o); + bool OnCasterUsingObject(IEntity entity); bool OnCastInTown(Region r); } @@ -111,4 +111,4 @@ namespace Server void OnBeforeSpawn(Point3D location, Map map); void OnAfterSpawn(); } -} \ No newline at end of file +} diff --git a/Server/Item.cs b/Server/Item.cs index 68edab5ee..6f975d680 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -3681,15 +3681,13 @@ namespace Server target.Map == null) return false; - object root = target.RootParent; - if (from.AccessLevel < AccessLevel.GameMaster && !from.InRange(target.GetWorldLocation(), 2)) return false; if (!from.CanSee(target) || !from.InLOS(target)) return false; if (!target.IsAccessibleTo(from)) return false; - if (root is Mobile mobile && !mobile.CheckNonlocalDrop(from, this, target)) + if (target.RootParent is Mobile mobile && !mobile.CheckNonlocalDrop(from, this, target)) return false; if (!from.OnDroppedItemToItem(this, target, p)) return false; @@ -4290,11 +4288,6 @@ namespace Server Delete(); } - public virtual bool CheckBlessed(object obj) - { - return CheckBlessed(obj as Mobile); - } - public virtual bool CheckBlessed(Mobile m) { if (m_LootType == LootType.Blessed || Mobile.InsuranceEnabled && Insured) diff --git a/Server/Items/Container.cs b/Server/Items/Container.cs index cb6a6c8e3..aaa0966cb 100644 --- a/Server/Items/Container.cs +++ b/Server/Items/Container.cs @@ -233,7 +233,7 @@ namespace Server.Items } } - object parent = Parent; + IEntity parent = Parent; while (parent != null) { @@ -627,15 +627,9 @@ namespace Server.Items public virtual bool CheckContentDisplay(Mobile from) { - if (DisplaysContent) - { - object root = RootParent; - - if (root == null || root is Item || root == from || from.AccessLevel > AccessLevel.Player) - return true; - } - - return false; + return DisplaysContent && RootParent == null || + RootParent is Item || RootParent == from || + from.AccessLevel > AccessLevel.Player; } public override void OnSingleClick(Mobile from) diff --git a/Server/Mobile.cs b/Server/Mobile.cs index ec94cccc1..44f434a62 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -4667,7 +4667,7 @@ namespace Server if (m_Spell != null && !m_Spell.OnCasterUsingObject(item)) return; - object root = item.RootParent; + IEntity root = item.RootParent; bool okay = false; if (!Utility.InUpdateRange(this, item.GetWorldLocation())) @@ -4789,7 +4789,7 @@ namespace Server } else { - object root = item.RootParent; + IEntity root = item.RootParent; if (root is Mobile mobile && !mobile.CheckNonlocalLift(from, item)) { @@ -4964,7 +4964,7 @@ namespace Server if (DragEffects && !item.Deleted) { Map map = m_Map; - object root = item.RootParent; + IEntity root = item.RootParent; if (map != null && (root == null || root is Item)) { diff --git a/Server/NativeReader.cs b/Server/NativeReader.cs index 788d9d951..d1d8ccf5d 100644 --- a/Server/NativeReader.cs +++ b/Server/NativeReader.cs @@ -56,7 +56,7 @@ namespace Server UnsafeNativeMethods.ReadFile(ptr, buffer, (uint)length, ref lpNumberOfBytesRead, null); } - internal class UnsafeNativeMethods + internal static class UnsafeNativeMethods { /*[DllImport("kernel32")] internal unsafe static extern int _lread(IntPtr hFile, void* lpBuffer, int wBytes);*/ @@ -74,10 +74,10 @@ namespace Server UnsafeNativeMethods.read(ptr, buffer, length); } - internal class UnsafeNativeMethods + internal static class UnsafeNativeMethods { [DllImport("libc")] internal static extern unsafe int read(IntPtr ptr, void* buffer, int length); } } -} \ No newline at end of file +} diff --git a/Server/Targeting/Target.cs b/Server/Targeting/Target.cs index 9df06fba1..64c209ada 100644 --- a/Server/Targeting/Target.cs +++ b/Server/Targeting/Target.cs @@ -165,9 +165,7 @@ namespace Server.Targeting return; } - object root = item.RootParent; - - if (!AllowNonlocal && root is Mobile && root != from && from.AccessLevel == AccessLevel.Player) + if (!AllowNonlocal && item.RootParent is Mobile && item.RootParent != from && from.AccessLevel == AccessLevel.Player) { OnNonlocalTarget(from, item); OnTargetFinish(from); @@ -290,4 +288,4 @@ namespace Server.Targeting } } } -} \ No newline at end of file +}