using System;
using System.Buffers.Binary;
namespace AcDream.Core.Net.Messages;
///
/// Inbound PrivateUpdatePropertyInt (0x02CD) — the server updates one
/// PropertyInt on the player's OWN object. Unlike the sibling
/// (0x02CE), this carries NO guid (it
/// implicitly targets the local player). Burden (EncumbranceVal, PropertyInt 5)
/// changes ride this opcode on every pick-up / drop.
///
/// Wire layout (ACE GameMessagePrivateUpdatePropertyInt):
///
/// u32 opcode = 0x02CD
/// u8 sequence // single byte (ByteSequence) — not honored, latest-wins (DR-4)
/// u32 property // PropertyInt enum
/// i32 value
///
///
public static class PrivateUpdatePropertyInt
{
public const uint Opcode = 0x02CDu;
public readonly record struct Parsed(uint Property, int Value);
/// Parse a raw 0x02CD body. Returns null on opcode mismatch / truncation.
public static Parsed? TryParse(ReadOnlySpan body)
{
if (body.Length < 13) return null; // 4 + 1 + 4 + 4
if (BinaryPrimitives.ReadUInt32LittleEndian(body) != Opcode) return null;
int pos = 4;
pos += 1; // sequence byte (not honored)
uint prop = BinaryPrimitives.ReadUInt32LittleEndian(body[pos..]); pos += 4;
int value = BinaryPrimitives.ReadInt32LittleEndian(body[pos..]);
return new Parsed(prop, value);
}
}