From f3ee7cb7fcb28d1c14862afb6cbafa4daab82175 Mon Sep 17 00:00:00 2001 From: HungDK <> Date: Sat, 18 Oct 2025 14:42:41 +0700 Subject: [PATCH] Add buy item --- Assets/Scripts/CECHostPlayer.cs | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 17b29f10d4..15af80692c 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -403,7 +403,39 @@ public class CECHostPlayer : CECPlayer switch (cmd) { case CommandID.HOST_OBTAIN_ITEM: - Debug.Log("Host OBTAIN_ITEM"); + { + // Parse cmd_host_obtain_item struct data + int type = BitConverter.ToInt32(data, 0); + int expire_date = BitConverter.ToInt32(data, 4); + uint amount = BitConverter.ToUInt32(data, 8); + uint slot_amount = BitConverter.ToUInt32(data, 12); + byte where = data[16]; // Package index + byte index = data[17]; // Slot index in that package + // Create new inventory item data + var newItem = new InventoryItemData + { + Package = where, + Slot = index, + TemplateId = type, + ExpireDate = expire_date, + State = 0, + Count = (int)amount, + Crc = 0, + Content = null + }; + + // Add item to inventory + EC_Inventory.SetItem(where, index, newItem); + + Debug.Log($"[HOST_OBTAIN_ITEM] Successfully added item {type} to package {where}, slot {index} with count {amount}"); + + // Trigger UI refresh if an EC_InventoryUI is present in scene + var ui = GameObject.FindFirstObjectByType(); + if (ui != null) + { + ui.RefreshAll(); + } + } break; case CommandID.PICKUP_ITEM: {