fix: Adds FindItemOnLayer generic (#1223)

This commit is contained in:
Kamron Batman 2022-11-01 00:49:20 -07:00 • committed by GitHub
parent 053dbcbad0
commit fd6f4239e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 112 additions and 169 deletions

View file

@ -1568,7 +1568,7 @@ public class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPropertyLis
return m_BankBox;
}
m_BankBox = FindItemOnLayer(Layer.Bank) as BankBox;
m_BankBox = FindItemOnLayer<BankBox>(Layer.Bank);
if (m_BankBox == null)
{
@ -1586,7 +1586,7 @@ public class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPropertyLis
{
if (m_Backpack?.Deleted != false || m_Backpack.Parent != this)
{
m_Backpack = FindItemOnLayer(Layer.Backpack) as Container;
m_Backpack = FindItemOnLayer<Container>(Layer.Backpack);
}
return m_Backpack;
@ -7405,12 +7405,15 @@ public class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPropertyLis
{
if (m_BankBox?.Deleted != false || m_BankBox.Parent != this)
{
m_BankBox = FindItemOnLayer(Layer.Bank) as BankBox;
m_BankBox = FindItemOnLayer<BankBox>(Layer.Bank);
}
return m_BankBox;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T FindItemOnLayer<T>(Layer layer) where T : Item => FindItemOnLayer(layer) as T;
public Item FindItemOnLayer(Layer layer)
{
var eq = Items;
@ -7420,6 +7423,7 @@ public class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPropertyLis
{
var item = eq[i];
// TODO: We only allow 1 item per layer. It's an implicit contract.
if (!item.Deleted && item.Layer == layer)
{
return item;
@ -7463,15 +7467,8 @@ public class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPropertyLis
eable.Free();
}
public bool PlaceInBackpack(Item item)
{
if (item.Deleted)
{
return false;
}
return Backpack?.TryDropItem(this, item, false) == true;
}
public bool PlaceInBackpack(Item item) =>
!item.Deleted && Backpack?.TryDropItem(this, item, false) == true;
public bool AddToBackpack(Item item)
{
@ -7504,10 +7501,8 @@ public class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPropertyLis
from == this || from.AccessLevel > AccessLevel && from.AccessLevel >= AccessLevel.GameMaster;
public virtual bool CheckTrade(
Mobile to, Item item, SecureTradeContainer cont, bool message, bool checkItems,
int plusItems, int plusWeight
) =>
true;
Mobile to, Item item, SecureTradeContainer cont, bool message, bool checkItems, int plusItems, int plusWeight
) => true;
public virtual bool OpenTrade(Mobile from, Item offer = null)
{