fix: Adds FindItemOnLayer generic (#1223)
This commit is contained in:
parent
053dbcbad0
commit
fd6f4239e2
20 changed files with 112 additions and 169 deletions
|
|
@ -68,8 +68,7 @@ public struct Point2D
|
|||
|
||||
public bool Equals(Point2D other) => m_X == other.m_X && m_Y == other.m_Y;
|
||||
|
||||
public bool Equals(IPoint2D other) =>
|
||||
m_X == other?.X && m_Y == other.Y;
|
||||
public bool Equals(IPoint2D other) => m_X == other?.X && m_Y == other.Y;
|
||||
|
||||
public override bool Equals(object obj) => obj is Point2D other && Equals(other);
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public static class OutgoingVendorBuyPackets
|
|||
var writer = new SpanWriter(stackalloc byte[length]);
|
||||
writer.Write((byte)0x74); // Packet ID
|
||||
writer.Write((ushort)length);
|
||||
writer.Write((vendor.FindItemOnLayer(Layer.ShopBuy) as Container)?.Serial ?? Serial.MinusOne);
|
||||
writer.Write(vendor.FindItemOnLayer<Container>(Layer.ShopBuy)?.Serial ?? Serial.MinusOne);
|
||||
writer.Write((byte)list.Count);
|
||||
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue