diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index be0f3f2f5a..f56e42332b 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -221,9 +221,72 @@ public class CECHostPlayer : EC_Player case int value when value == EC_MsgDef.MSG_HST_ITEMOPERATION: OnMsgHstItemOperation(Msg); break; + case int value when value == EC_MsgDef.MSG_HST_PICKUPITEM: + OnMsgHstPickupItem(Msg); + break; } } + public void OnMsgHstPickupItem(in ECMSG Msg) + { + var data = Msg.dwParam1 as byte[]; + int cmd = Convert.ToInt32(Msg.dwParam2); + switch (cmd) + { + case CommandID.PICKUP_ITEM: + { + // Parse the pickup item data from the server response + if (data != null && data.Length >= 16) + { + int tid = BitConverter.ToInt32(data, 0); + int expire_date = BitConverter.ToInt32(data, 4); + uint iAmount = BitConverter.ToUInt32(data, 8); + uint iSlotAmount = BitConverter.ToUInt32(data, 12); + byte byPackage = data[16]; + byte bySlot = data[17]; + + Debug.Log($"[Inventory] PICKUP_ITEM: tid={tid}, expire_date={expire_date}, iAmount={iAmount}, iSlotAmount={iSlotAmount}, byPackage={byPackage}, bySlot={bySlot}"); + + // Notify pickupItem script about successful pickup + pickupItem pickupScript = UnityEngine.Object.FindFirstObjectByType(); + if (pickupScript != null) + { + pickupScript.OnPickupSuccess(tid); + } + + // Create new inventory item data + var newItem = new InventoryItemData + { + Package = byPackage, + Slot = bySlot, + TemplateId = tid, + ExpireDate = expire_date, + State = 0, + Count = (int)iAmount, + Crc = 0, + Content = null + }; + + // Add item to inventory + EC_Inventory.SetItem(byPackage, bySlot, newItem); + + Debug.Log($"[Inventory] Successfully added item {tid} to package {byPackage}, slot {bySlot} with count {iAmount}"); + + // Trigger UI refresh if an EC_InventoryUI is present in scene + var ui = GameObject.FindFirstObjectByType(); + if (ui != null) + { + ui.RefreshAll(); + } + } + else + { + Debug.LogWarning("[Inventory] PICKUP_ITEM: Invalid data length"); + } + break; + } + } + } public void OnMsgHstItemOperation(ECMSG Msg) { var data = Msg.dwParam1 as byte[];