Add buy item

This commit is contained in:
HungDK
2025-10-18 14:42:41 +07:00
parent f22fe3d70f
commit f3ee7cb7fc
+33 -1
View File
@@ -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<EC_InventoryUI>();
if (ui != null)
{
ui.RefreshAll();
}
}
break;
case CommandID.PICKUP_ITEM:
{