mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-26 21:04:41 -05:00
Add IEquatable interface for items
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
namespace NHSE.Core
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = SIZE, Pack = 1)]
|
||||
public class Item : ICopyableItem<Item>
|
||||
public class Item : ICopyableItem<Item>, IEquatable<Item>
|
||||
{
|
||||
public static readonly Item NO_ITEM = new() {ItemId = NONE};
|
||||
public const ushort NONE = 0xFFFE;
|
||||
@@ -197,12 +197,7 @@ public void SetAsExtension(Item tile, byte x, byte y)
|
||||
public Item(ulong raw) => RawValue = raw;
|
||||
public Item(ushort itemId = NONE) => ItemId = itemId;
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
ItemId = NONE;
|
||||
SystemParam = AdditionalParam = 0;
|
||||
FreeParam = 0;
|
||||
}
|
||||
public void Delete() => RawValue = NONE; // clears & sets the two lowest byte as ItemID
|
||||
|
||||
public virtual int Size => SIZE;
|
||||
|
||||
@@ -227,5 +222,24 @@ public ushort GetWrappedItemName()
|
||||
_ => ItemId,
|
||||
};
|
||||
}
|
||||
|
||||
public bool Equals(Item? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return RawValue == other.RawValue;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != GetType()) return false;
|
||||
return Equals((Item) obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode() => RawValue.GetHashCode();
|
||||
public static bool operator ==(Item? left, Item? right) => Equals(left, right);
|
||||
public static bool operator !=(Item? left, Item? right) => !Equals(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user