diff --git a/Assets/PerfectWorld/Scripts/Common/DataProcess/globaldataman.cs b/Assets/PerfectWorld/Scripts/Common/DataProcess/globaldataman.cs index 8d8de22feb..a576716513 100644 --- a/Assets/PerfectWorld/Scripts/Common/DataProcess/globaldataman.cs +++ b/Assets/PerfectWorld/Scripts/Common/DataProcess/globaldataman.cs @@ -33,6 +33,7 @@ public struct GShopItem public uint giftTime; // Gift duration public uint logPrice; // Log price public uint[] ownerNpcs; // NPCs that own this item (8 max) + public int itemIndex; } [System.Serializable] diff --git a/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs b/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs index ca395265d2..d5a494b531 100644 --- a/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs +++ b/Assets/PerfectWorld/Scripts/GameData/GShopLoader.cs @@ -64,6 +64,7 @@ public class GShopLoader : MonoBehaviour for (int i = 0; i < itemCount; i++) { GShopItem item = ReadGShopItem(reader); + item.itemIndex = i; shopData.items.Add(item); } @@ -188,6 +189,7 @@ public class GShopLoader : MonoBehaviour Debug.Log($" Quantity: {item.num}"); Debug.Log($" Icon: {item.icon}"); Debug.Log($" Description: {item.desc}"); + Debug.Log($" Local ID: {item.localId}"); // Log buy options for (int j = 0; j < 4; j++) diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs index d5443fdb14..ca6c690a6f 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommand.cs @@ -633,6 +633,17 @@ namespace CSNetwork.C2SCommand public int serviceId; public byte[] data; // Variable length array } + public struct CMD_MallShopping + { + public uint count; + + public struct goods + { + public int goods_id; + public int goods_index; + public int goods_pos; + } + }; // Random mall shopping command public struct CMD_RandomMallShopping diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs index c6759f9d89..851c02e270 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs @@ -331,6 +331,29 @@ namespace CSNetwork.C2SCommand }; return SerializeCommand(CommandID.GET_IVTR_DETAIL, cmd); } + public static Octets CreateGetMallShopping(uint count, CMD_MallShopping.goods[] goodsArray) + { + var cmd = new CMD_MallShopping() + { + count = count + }; + + // Serialize the command structure first + var octets = SerializeCommand(CommandID.MALL_SHOPPING, cmd); + + // Append the goods array directly (matching C++ memcpy behavior) + if (goodsArray != null && goodsArray.Length > 0) + { + foreach (var goods in goodsArray) + { + WriteBasicValue(octets, goods.goods_id); + WriteBasicValue(octets, goods.goods_index); + WriteBasicValue(octets, goods.goods_pos); + } + } + + return octets; + } public static Octets CreateOwnItemInfo ( byte byPackage, diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs index bf7772adde..d296de067a 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs @@ -923,7 +923,16 @@ namespace CSNetwork.GPDataType { public info_matter Info; }; - + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_host_obtain_item + { + public int type; + public int expire_date; + public uint amount; + public uint slot_amount; + public byte where; //���ĸ���������0 ��׼��2 ����1 װ�� + public byte index; //��󲿷ַ����ĸ�λ�� + }; [StructLayout(LayoutKind.Sequential, Pack = 1)] struct cmd_pickup_item { diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs index 147f6f09bc..2e60be814c 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs @@ -214,6 +214,13 @@ namespace CSNetwork gamedatasendRequest.Data = CSNetwork.C2SCommand.C2SCommandFactory.CreateEquipItem(iIvtrIdx, iEquipIdx); SendProtocol(gamedatasendRequest, callback); } + + public void RequestMallShopping(uint count, CMD_MallShopping.goods[] goodsArray) + { + gamedatasend gamedatasendRequest = new gamedatasend(); + gamedatasendRequest.Data = CSNetwork.C2SCommand.C2SCommandFactory.CreateGetMallShopping(count, goodsArray); + SendProtocol(gamedatasendRequest); + } public void RequestOwnItemInfoAsync( byte byPackage, byte bySlot, @@ -389,7 +396,8 @@ namespace CSNetwork case CommandID.MATTER_ENTER_WORLD: EC_ManMessage.PostMessage(EC_MsgDef.MSG_MM_MATTERENTWORLD, (int)MANAGER_INDEX.MAN_MATTER, 0, pDataBuf, pCmdHeader); break; - case CommandID.PICKUP_ITEM: + case CommandID.PICKUP_ITEM: + case CommandID.HOST_OBTAIN_ITEM: EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_PICKUPITEM, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); break; case CommandID.HOST_CORRECT_POS: diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 2938b25ff1..debd9738c9 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -1,5 +1,6 @@ using BrewMonster; using CSNetwork; +using CSNetwork.C2SCommand; using CSNetwork.Protocols; using CSNetwork.Protocols.RPCData; using CSNetwork.Security; @@ -160,6 +161,20 @@ namespace BrewMonster.Network { Instance._gameSession.RequestCheckSecurityPassWd(password); } + + public void RequestMallShopping(uint count, int good_id, int good_index, int good_pos) + { + var goods = new CMD_MallShopping.goods[] + { + new CMD_MallShopping.goods + { + goods_id = good_id, + goods_index = good_index, + goods_pos = good_pos + } + }; + Instance._gameSession.RequestMallShopping(count, goods); + } public static void RequestAllInventoriesAsync(Action callback = null, params byte[] packages) { if (packages == null || packages.Length == 0) diff --git a/Assets/PerfectWorld/Scripts/UI/ShopDetailPanel.cs b/Assets/PerfectWorld/Scripts/UI/ShopDetailPanel.cs index e296ff7310..d74287a2f8 100644 --- a/Assets/PerfectWorld/Scripts/UI/ShopDetailPanel.cs +++ b/Assets/PerfectWorld/Scripts/UI/ShopDetailPanel.cs @@ -1,3 +1,5 @@ +using System; +using BrewMonster.Network; using UnityEngine; using UnityEngine.UI; using TMPro; @@ -311,8 +313,8 @@ public class ShopDetailPanel : MonoBehaviour void OnBuyClicked() { // TODO: Implement purchase logic - Debug.Log($"Attempting to buy item: {currentItem.name} (ID: {currentItem.id})"); - + Debug.Log($"Attempting to buy item: ID {currentItem.id} (Index: {currentItem.itemIndex})"); + UnityGameSession.Instance.RequestMallShopping(1, Convert.ToInt32(currentItem.id), currentItem.itemIndex, 0); // Close panel after purchase attempt OnCloseClicked(); } diff --git a/Assets/PerfectWorld/Scripts/UI/ShopUIManager.cs b/Assets/PerfectWorld/Scripts/UI/ShopUIManager.cs index 9711bef534..72effef336 100644 --- a/Assets/PerfectWorld/Scripts/UI/ShopUIManager.cs +++ b/Assets/PerfectWorld/Scripts/UI/ShopUIManager.cs @@ -247,7 +247,7 @@ public class ShopUIManager : MonoBehaviour public void ShowItemDetail(GShopItem item) { selectedItem = item; - + Debug.Log($"$ Local ID of selected item: {item.localId}"); if (shopDetailPanel != null) { shopDetailPanel.SetActive(true); diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index c6c63b92e0..17b29f10d4 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -402,6 +402,9 @@ public class CECHostPlayer : CECPlayer int cmd = Convert.ToInt32(Msg.dwParam2); switch (cmd) { + case CommandID.HOST_OBTAIN_ITEM: + Debug.Log("Host OBTAIN_ITEM"); + break; case CommandID.PICKUP_ITEM: { int tid = BitConverter.ToInt32(data, 0);