Fixing wrong command to send to server
This commit is contained in:
@@ -688,6 +688,14 @@ namespace CSNetwork.C2SCommand
|
||||
public bool agree;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct npc_trade_item
|
||||
{
|
||||
public int tid;
|
||||
public uint index;
|
||||
public uint count;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct npc_sell_item
|
||||
{
|
||||
@@ -697,6 +705,18 @@ namespace CSNetwork.C2SCommand
|
||||
public int price;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct NPCSevBuyCONTENT
|
||||
{
|
||||
public uint money; // Not use now
|
||||
public int consume_contrib;
|
||||
public int cumulate_contrib;
|
||||
public int force_id;
|
||||
public int force_repu;
|
||||
public int force_contrib;
|
||||
public uint item_count;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct NPCSevSellCONTENT
|
||||
{
|
||||
|
||||
@@ -583,6 +583,44 @@ namespace CSNetwork.C2SCommand
|
||||
return SerializeCommand(CommandID.SEVNPC_SERVE, cmd, content);
|
||||
}
|
||||
|
||||
public static Octets CreateNPCSevBuyCmd(int itemNum, CSNetwork.C2SCommand.npc_trade_item[] items)
|
||||
{
|
||||
if (itemNum <= 0 || items == null || items.Length < itemNum)
|
||||
throw new ArgumentException("Invalid itemNum or items array");
|
||||
|
||||
uint contentSize = (uint)Marshal.SizeOf<NPCSevBuyCONTENT>();
|
||||
uint itemSize = (uint)Marshal.SizeOf<CSNetwork.C2SCommand.npc_trade_item>();
|
||||
uint totalLen = contentSize + (uint)itemNum * itemSize;
|
||||
|
||||
var cmd = new cmd_sevnpc_serve
|
||||
{
|
||||
service_type = NPC_service_type.GP_NPCSEV_SELL, // NPC sells to player = player buys
|
||||
len = totalLen
|
||||
};
|
||||
|
||||
NPCSevBuyCONTENT content = new NPCSevBuyCONTENT()
|
||||
{
|
||||
money = 0, // Not use now
|
||||
consume_contrib = 0,
|
||||
cumulate_contrib = 0,
|
||||
force_id = 0,
|
||||
force_repu = 0,
|
||||
force_contrib = 0,
|
||||
item_count = (uint)itemNum
|
||||
};
|
||||
|
||||
// Serialize command + content
|
||||
var octets = SerializeCommand(CommandID.SEVNPC_SERVE, cmd, content);
|
||||
|
||||
// Append items array
|
||||
for (int i = 0; i < itemNum; i++)
|
||||
{
|
||||
WriteStruct(octets, items[i]);
|
||||
}
|
||||
|
||||
return octets;
|
||||
}
|
||||
|
||||
public static Octets CreateNPCSevSellCmd(int itemNum, npc_sell_item[] items)
|
||||
{
|
||||
if (itemNum <= 0 || items == null || items.Length < itemNum)
|
||||
@@ -594,7 +632,7 @@ namespace CSNetwork.C2SCommand
|
||||
|
||||
var cmd = new cmd_sevnpc_serve
|
||||
{
|
||||
service_type = NPC_service_type.GP_NPCSEV_BUY,
|
||||
service_type = NPC_service_type.GP_NPCSEV_BUY, // NPC buys from player = player sells
|
||||
len = totalLen
|
||||
};
|
||||
|
||||
|
||||
@@ -1224,6 +1224,16 @@ namespace CSNetwork
|
||||
SendProtocol(gamedatasend);
|
||||
}
|
||||
|
||||
public void c2s_SendCmdNPCSevBuy(int itemNum, C2SCommand.npc_trade_item[] items)
|
||||
{
|
||||
if (itemNum <= 0 || items == null || items.Length < itemNum)
|
||||
return;
|
||||
|
||||
gamedatasend gamedatasend = new gamedatasend();
|
||||
gamedatasend.Data = C2SCommandFactory.CreateNPCSevBuyCmd(itemNum, items);
|
||||
SendProtocol(gamedatasend);
|
||||
}
|
||||
|
||||
public void c2s_SendCmdNPCSevSell(int itemNum, C2SCommand.npc_sell_item[] items)
|
||||
{
|
||||
if (itemNum <= 0 || items == null || items.Length < itemNum)
|
||||
|
||||
@@ -305,6 +305,13 @@ namespace BrewMonster.Network
|
||||
Instance._gameSession.c2s_SendCmdNPCSevTaskMatter(idTask);
|
||||
}
|
||||
|
||||
public static void c2s_CmdNPCSevBuy(int itemNum, npc_trade_item[] items)
|
||||
{
|
||||
if (items == null || itemNum <= 0)
|
||||
return;
|
||||
Instance._gameSession.c2s_SendCmdNPCSevBuy(itemNum, items);
|
||||
}
|
||||
|
||||
public static void c2s_CmdNPCSevSell(int itemNum, npc_sell_item[] items)
|
||||
{
|
||||
if (items == null || itemNum <= 0)
|
||||
|
||||
@@ -168,22 +168,20 @@ public class NPCShopDetailPanel : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Create npc_sell_item array
|
||||
// Note: This function is for selling items TO NPC, but called on buy button click
|
||||
// The tid is the item template ID, index is inventory slot (0 for now), count is 1, price is from shop
|
||||
npc_sell_item[] items = new npc_sell_item[1];
|
||||
items[0] = new npc_sell_item
|
||||
// Create npc_trade_item array for buying from NPC
|
||||
// The tid is the item template ID, index is shop item index (0 for now), count is quantity to buy
|
||||
npc_trade_item[] items = new npc_trade_item[1];
|
||||
items[0] = new npc_trade_item
|
||||
{
|
||||
tid = (int)currentItem.id,
|
||||
index = 0, // Inventory slot index - may need to be determined from actual inventory
|
||||
count = 1, // Quantity to buy/sell
|
||||
price = (int)price
|
||||
index = 0, // Shop item index - may need to be determined from shop item position
|
||||
count = 1 // Quantity to buy
|
||||
};
|
||||
|
||||
// Send the command
|
||||
UnityGameSession.c2s_CmdNPCSevSell(1, items);
|
||||
// Send the buy command
|
||||
UnityGameSession.c2s_CmdNPCSevBuy(1, items);
|
||||
|
||||
Debug.Log($"[NPCShopDetailPanel] Sent sell command for item {currentItem.id}, price {price}");
|
||||
Debug.Log($"[NPCShopDetailPanel] Sent buy command for item {currentItem.id}, price {price}");
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
|
||||
@@ -2008,7 +2008,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 009ffcf832a02b545a5cce71d5e32877, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
npcShopMainPanel: {fileID: 239632690013192579}
|
||||
npcShopMainPanel: {fileID: 8237288432181259026}
|
||||
npcShopDetailPanel: {fileID: 4704784074983072622}
|
||||
tabButtonContainer: {fileID: 412875348489889375}
|
||||
tabButtonPrefab: {fileID: 532136160345846687, guid: 548ae6ac061bc9648b093c9f9d203615, type: 3}
|
||||
|
||||
Reference in New Issue
Block a user