Retain item values not exposed for edits

Fixes pouch getting nuked
This commit is contained in:
Kurt 2025-11-07 02:38:39 -06:00
parent c218098f26
commit 9d719bdf06
3 changed files with 21 additions and 6 deletions

View File

@ -117,7 +117,7 @@ private static InventoryPouch9a MakePouch(InventoryType type)
return new InventoryPouch9a(type, info, max, GetPouchIndex(type));
}
private static uint GetPouchIndex(InventoryType type) => type switch
public static uint GetPouchIndex(InventoryType type) => type switch
{
InventoryType.Items => InventoryItem9a.PouchOther,
InventoryType.KeyItems => InventoryItem9a.PouchKey,

View File

@ -64,10 +64,6 @@ public static InventoryItem9a Read(ushort index, ReadOnlySpan<byte> data) => new
public void Write(Span<byte> data)
{
// Ensure the updated flag state is as expected.
if (Pouch == PouchNone)
Flags = DefaultFlagValue;
// Index is not saved.
WriteUInt32LittleEndian(data, Pouch);
WriteUInt32LittleEndian(data[4..], (uint)Count);

View File

@ -10,7 +10,16 @@ public sealed class InventoryPouch9a(InventoryType type, IItemStorage info, int
public bool SetNew { get; set; }
public uint PouchIndex { get; set; } = pouch;
public override InventoryItem9a GetEmpty(int itemID = 0, int count = 0) => new() { Index = itemID, Count = count, IsNew = count != 0 };
public override InventoryItem9a GetEmpty(int itemID = 0, int count = 0) => new()
{
Index = itemID,
Pouch = MyItem9a.GetPouchIndex(ItemStorage9ZA.GetInventoryPouch((ushort)itemID)),
Count = count,
IsNewShop = true,
IsNewNotify = true,
IsNew = true,
};
public static int GetItemOffset(ushort index) => InventoryItem9a.SIZE * index;
public static Span<byte> GetItemSpan(Span<byte> block, ushort index) => block.Slice(GetItemOffset(index), InventoryItem9a.SIZE);
@ -74,6 +83,11 @@ public override void SetPouch(Span<byte> block)
private void EnsureFlagsConsistent(InventoryItem9a item, InventoryItem9a original)
{
if (item.Index == 0x14)
{
}
item.Pouch = PouchIndex; // ensure the pouch is set
if (item.Count != 0)
{
// Ensure the flag is set; 0->X and Y->Z
@ -81,6 +95,11 @@ private void EnsureFlagsConsistent(InventoryItem9a item, InventoryItem9a origina
item.IsNew = true;
item.IsNewNotify = false;
}
else if (original.Count == 0)
{
item.Flags = original.Flags;
item.Pouch = original.Pouch;
}
}
public static void SetQuantityZero(Span<byte> block, ushort index)