Fixes parent references. (#15)

This commit is contained in:
Kamron Batman 2019-03-03 15:40:17 -08:00 committed by GitHub
parent 01d0fb75b8
commit 90ffe0ea3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 55 additions and 93 deletions

View file

@ -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
}
}
}
}
}

View file

@ -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
}
}
}
}
}

View file

@ -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;

View file

@ -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
}
}
}
}
}

View file

@ -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;
}
}
}
}