Merge remote-tracking branch 'origin/develop' into feature/add-vfx

This commit is contained in:
NguyenVanDat
2025-11-13 09:13:15 +07:00
86 changed files with 16387 additions and 500 deletions
+7 -2
View File
@@ -4,10 +4,12 @@ using BrewMonster.Scripts.World;
using CSNetwork.GPDataType;
using CSNetwork.Protocols.RPCData;
using System.Data;
using BrewMonster.Network;
using CSNetwork;
using Unity.Cinemachine;
using UnityEngine;
public partial class CECGameRun : MonoBehaviour
public partial class CECGameRun : MonoBehaviour, IMsgHandler
{
private static CECGameRun instance;
@@ -18,7 +20,7 @@ public partial class CECGameRun : MonoBehaviour
[SerializeField] private GameObject _testVfxPrefab;
//[SerializeField] private Transform ground;
CECHostPlayer hostPlayer;
public CinemachineFreeLook freeLookCam;
public float rotateSpeedX = 300f; // tốc độ xoay ngang
public float rotateSpeedY = 2f; // tốc độ xoay dọc
@@ -56,6 +58,8 @@ public partial class CECGameRun : MonoBehaviour
{
instance = this;
}
EC_ManMessage.RegisterHandler(this);
}
public void Log(string s)
@@ -117,6 +121,7 @@ public partial class CECGameRun : MonoBehaviour
GameObject character = Instantiate(characterPrefab, transform);
return character.gameObject;
}
private void OnDestroy()
{
instance = null;
+38
View File
@@ -0,0 +1,38 @@
using System.Collections.Generic;
using BrewMonster.Network;
using CSNetwork;
using CSNetwork.GPDataType;
// Game runtime partial class
partial class CECGameRun : IMsgHandler
{
private readonly Dictionary<int, int> m_CommonDataTab = new Dictionary<int, int>();
public int GetCommonData(int key)
{
// Lookup a common data value by key
// 按键查找通用数据值
if (m_CommonDataTab != null && m_CommonDataTab.TryGetValue(key, out var value))
return value;
else
return 0;
}
private CECCounter l_QueryServerTime = new CECCounter(); // ѯǰʱ
public int HandlerId => -1;
public bool ProcessMessage(ECMSG Msg)
{
switch (Msg.dwMsg)
{
case CommandID.SERVER_TIME:
EC_Game.SetServerTime((int)Msg.dwParam1, (int)Msg.dwParam2);
l_QueryServerTime.Reset();
break;
}
return true;
}
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 598459b2399743b5ba1eb55fd1d9611e
timeCreated: 1762861835
+121
View File
@@ -0,0 +1,121 @@
using System;
using BrewMonster.Scripts.Task;
using CSNetwork;
using CSNetwork.GPDataType;
using UnityEngine;
using System.Runtime.InteropServices;
// ׶ // Contribution info
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CONTRIB_INFO
{
public int consume_contrib; // ѵ // Consume contribution
public int exp_contrib; // ɶһɾ // Experience contribution
public int cumulate_contrib; // ۻֵ // Cumulative contribution
// public CONTRIB_INFO()
// {
// consume_contrib = 0;
// exp_contrib = 0;
// cumulate_contrib = 0;
// }
}
public partial class CECHostPlayer
{
private int m_idTradePlayer; // ID of player who is trading with us
private CECTaskInterface m_pTaskInterface;
private int m_iBoothState; // Booth state. 0, none; 1, prepare; 2, open booth; 3, visite other's booth
private CONTRIB_INFO m_contribInfo;
public CECTaskInterface GetTaskInterface()
{
return m_pTaskInterface;
}
// Is host player trading ?
public bool IsTrading() { return m_idTradePlayer != 0; }
public CONTRIB_INFO GetContribInfo()
{
return m_contribInfo;
}
public int GetBoothState()
{
return m_iBoothState;
}
private void OnMsgHstTaskData(ECMSG Msg)
{
// decode header to distinguish TASK_DATA vs TASK_VAR_DATA
// if (!(Msg.dwParam2 is cmd_header header))
// {
// Debug.LogError("OnMsgHstTaskData: invalid header");
// return;
// }
int header = Convert.ToInt32(Msg.dwParam2);
byte[] pDataBuf = Msg.dwParam1 as byte[];
if (pDataBuf == null)
{
Debug.LogError("OnMsgHstTaskData: missing payload buffer");
return;
}
if (header == CommandID.TASK_DATA)
{
#if !LOAD_TASK_TEMPL
return; // Task templates loading not implemented in C#
#endif
// Parse aggregated task buffers
cmd_task_data pCmd = cmd_task_data.FromBuffer(pDataBuf);
// cmd_task_data pCmd = GPDataTypeHelper.FromBytes<cmd_task_data>(pDataBuf);
// Release and recreate task interface
m_pTaskInterface = null;
m_pTaskInterface = new CECTaskInterface(this);
if (!m_pTaskInterface.Init(
pCmd.active_list, (int)pCmd.active_list_size,
pCmd.finished_list, (int)pCmd.finished_list_size,
pCmd.finished_time_list, (int)pCmd.finished_time_list_size,
pCmd.finished_count, (int)pCmd.finished_count_size,
pCmd.storage_task, (int)pCmd.storage_task_size))
{
Debug.LogError("CECHostPlayer::OnMsgHstTaskData, failed to initialize task interface");
return;
}
m_pTaskInterface.CheckPQEnterWorldInit();
// check if player has equipped goblin (not yet implemented in C#)
// TODO: implement goblin initialization when equipment system is ready
// GET_ALL_DATA end flag tasks were here in C++ (LoadConfigData), omitted in C#
// if (UpdateEquipSkills()) UpdateEquipSkillCoolDown(); // methods not ported yet
}
else if (header == CommandID.TASK_VAR_DATA)
{
// Minimal forwarding; original code passes inner data pointer and size
if (m_pTaskInterface != null)
{
OnServerNotify(m_pTaskInterface, pDataBuf, pDataBuf.Length);
}
else
{
Debug.LogError("OnMsgHstTaskData: m_pTaskInterface is null on TASK_VAR_DATA");
}
}
}
private void OnServerNotify(CECTaskInterface pInterface, byte[] data, int size)
{
// TODO: Implement server notify handling for task var data
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c3d2b8f770fdd49619648d2a7aace2f4
+1 -75
View File
@@ -1171,81 +1171,7 @@ public partial class CECHostPlayer : CECPlayer
#region Task
public void OnMsgHstTaskData(ECMSG Msg)
{
int cmd = Convert.ToInt32(Msg.dwParam2);
if (cmd == CommandID.TASK_DATA)
{
//Debug.Log("[Dat]- OnMsgHstTaskData- TASK_DATA");
//a_LogOutput(1, "[Dat]- EC_HostMsg- OnMsgHstTaskData- TASK_DATA");
//cmd_task_data* pCmd = (cmd_task_data*)Msg.dwParam1;
//ASSERT(pCmd);
//int iActiveListSize = (int)pCmd.active_list_size;
//BYTE* pData = (BYTE*)pCmd + sizeof(size_t);
//void* pActiveListbuf = pData;
//pData += iActiveListSize;
//int iFinishedListSize = *(int*)pData;
//pData += sizeof(int);
//void* pFinishedListBuf = pData;
//pData += iFinishedListSize;
//int iFinishTimeListSize = *(int*)pData;
//pData += sizeof(int);
//void* pFinishTimeListBuf = pData;
//pData += iFinishTimeListSize;
//int iFinishedCountListSize = *(int*)pData;
//pData += sizeof(int);
//void* pFinishedCountListBuf = pData;
//pData += iFinishedCountListSize;
//int iStorageTasksListSize = *(int*)pData;
//pData += sizeof(int);
//void* pStorageTaskListBuf = pData;
//pData += iStorageTasksListSize;
//A3DRELEASE(m_pTaskInterface);
//todo
//var m_pTaskInterface = new CECTaskInterface(this);
//if (!m_pTaskInterface.Init(null, 0, null, 0,
// null, 0, null, 0, null, 0))
//{
// //a_LogOutput(1, "CECHostPlayer::OnMsgHstTaskData, failed to initialize task interface");
// return;
//}
//m_pTaskInterface.CheckPQEnterWorldInit();
//// check if player has equipped goblin
//if (m_pEquipPack.GetItem(EQUIPIVTR_GOBLIN) != NULL)
//{
// CECIvtrGoblin* pIvtrGoblin = (CECIvtrGoblin*)m_pEquipPack.GetItem(EQUIPIVTR_GOBLIN);
// m_pGoblin = new CECHostGoblin();
// m_pGoblin.Init(pIvtrGoblin.GetTemplateID(), pIvtrGoblin, this);
//}
//// Note: this command now is also used as the end flag of responding
//// for GET_ALL_DATA request
//g_pGame.GetGameSession().LoadConfigData();
//// ¸ù¾Ý×°±¸°ü¹ü¸üÐÂ×°±¸¼¼Äܵ½¼¼ÄÜÁбí
//if (UpdateEquipSkills())
// UpdateEquipSkillCoolDown();
}
else if (cmd == CommandID.TASK_VAR_DATA)
{
//cmd_task_var_data* pCmd = (cmd_task_var_data*)Msg.dwParam1;
//ASSERT(pCmd);
//if (m_pTaskInterface)
// OnServerNotify(m_pTaskInterface, pCmd.data, pCmd.size);
//else
// ASSERT(m_pTaskInterface);
}
}
#endregion
+8 -3
View File
@@ -33,18 +33,23 @@ struct cmd_notify_hostpos
struct cmd_task_data
{
public uint active_list_size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] active_list;
public uint finished_list_size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] finished_list;
public uint finished_time_list_size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] finished_time_list;
public uint finished_count_size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] finished_count;
public uint storage_task_size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] storage_task;
public static cmd_task_data FromPointer(IntPtr ptr)
@@ -62,7 +67,7 @@ struct cmd_task_data
cmd_task_data result = new cmd_task_data();
int offset = 0;
result.active_list_size = (uint)ReadULong(buffer, ref offset);
result.active_list_size = (uint)ReadULong(buffer, ref offset, 4);
result.active_list = ReadBytes(buffer, ref offset, (int)result.active_list_size);
result.finished_list_size = (uint)ReadULong(buffer, ref offset);
@@ -80,10 +85,10 @@ struct cmd_task_data
return result;
}
private static ulong ReadULong(byte[] buffer, ref int offset)
private static ulong ReadULong(byte[] buffer, ref int offset, int plusOffset = 4)
{
ulong value = BitConverter.ToUInt64(buffer, offset);
offset += 8;
offset += plusOffset;
return value;
}