diff --git a/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll b/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll index c7689acd39..368d4eb1fc 100644 Binary files a/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll and b/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll differ diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 336a934e2d..6451a0935a 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -81,12 +81,12 @@ namespace BrewMonster.Network byte byDir, ushort wStamp, int iTime) { Debug.LogWarning("HoangDev : c2s_SendCmdStopMove"); - Instance._gameSession.c2s_SendCmdStopMove(EC_Utility.ToNumerics( vDest),fSpeed,iMoveMode,byDir,wStamp,iTime); + Instance._gameSession.c2s_SendCmdStopMove(EC_Utility.ToNumerics(vDest), fSpeed, iMoveMode, byDir, wStamp, iTime); } public void c2s_CmdPlayerMove(in Vector3 vCurPos, in Vector3 vDest, int iTime, float fSpeed, int iMoveMode, ushort wStamp) { - Instance._gameSession.c2s_CmdPlayerMove(EC_Utility.ToNumerics(vCurPos),EC_Utility.ToNumerics( vDest),iTime,fSpeed,iMoveMode,wStamp); + Instance._gameSession.c2s_CmdPlayerMove(EC_Utility.ToNumerics(vCurPos), EC_Utility.ToNumerics(vDest), iTime, fSpeed, iMoveMode, wStamp); } protected override void Initialize() { @@ -161,7 +161,15 @@ namespace BrewMonster.Network RequestInventoryAsync(p, onOneDone); } } - + + #region Task + public static void c2s_CmdGetAllData(bool byPack, bool byEquip, bool byTask) + { + Debug.Log("[Dat]- SendCmdGetAllData"); + Instance._gameSession.c2s_SendCmdGetAllData(byPack, byEquip, byTask); + } + #endregion + public void LoadScene(string sceneName, LoadSceneMode mode, Action actDone) { StartCoroutine(LoadSceneCoroutine(sceneName, mode, actDone)); diff --git a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs index 6efe193374..f2dc05e6cb 100644 --- a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs +++ b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs @@ -45,6 +45,14 @@ namespace BrewMonster.UI _selectCharacterScreen.InitScreen(_roleInfos, OnClickSelectCharacter); _roleInfos = null; } + +#if UNITY_EDITOR + if (Input.GetKeyUp(KeyCode.LeftAlt)) + { + _usernameInputField.text = "test025"; + _passwordInputField.text = "123456"; + } +#endif } public async void OnLoginButtonClicked() @@ -125,6 +133,7 @@ namespace BrewMonster.UI await Task.Delay(2000); // Request all known packages: 0=Inventory,1=Equipment,2=Task UnityGameSession.RequestAllInventoriesAsync(() => { Logger.Log("Sent Inventory Detail Requests (all packs)"); }, 0, 1, 2); + UnityGameSession.c2s_CmdGetAllData(true, true, false); } //private void OnInventoryReceived(List inventoryData) diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index b225ab1c2e..09c65f7239 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -3,18 +3,19 @@ using CSNetwork; using CSNetwork.GPDataType; using CSNetwork.Protocols; using CSNetwork.Protocols.RPCData; +using PerfectWorld.Scripts.Managers; +using PerfectWorld.Scripts.Task; using System; using System.IO; +using System.Runtime.InteropServices; using System.Text; using TMPro; +using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; using UnityEngine.UI; using Scene = UnityEngine.SceneManagement.Scene; -using System.Runtime.InteropServices; -using Unity.VisualScripting; -using PerfectWorld.Scripts.Managers; public class CECHostPlayer : EC_Player { @@ -196,7 +197,8 @@ public class CECHostPlayer : EC_Player public void ProcessMessage(in ECMSG Msg) { Debug.LogWarning("HoangDev : ProcessMessageProcessMessageProcessMessage"); - switch ((int)Msg.dwMsg) + var msg = (int)Msg.dwMsg; + switch (msg) { case int value when value == EC_MsgDef.MSG_HST_CORRECTPOS: OnMsgHstCorrectPos(Msg); break; case int value when value == EC_MsgDef.MSG_HST_GOTO: OnMsgHstGoto(Msg); break; @@ -210,6 +212,12 @@ public class CECHostPlayer : EC_Player OnMsgHstOwnItemInfo(Msg); break; } + case int value when value == EC_MsgDef.MSG_HST_TASKDATA: + { + OnMsgHstTaskData(Msg); + Debug.LogError("[Dat]- OnMsgHstTaskData"); + break; + } case int value when value == EC_MsgDef.MSG_HST_ITEMOPERATION: OnMsgHstItemOperation(Msg); break; @@ -377,6 +385,83 @@ public class CECHostPlayer : EC_Player SetModelHostPlayer(); Debug.LogError("Pos Character = " + pos); } + + #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); + + 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 } public enum StateAnim diff --git a/Assets/Scripts/EC_GPDataType.cs b/Assets/Scripts/EC_GPDataType.cs index 8b43195bdb..7e0de4b22d 100644 --- a/Assets/Scripts/EC_GPDataType.cs +++ b/Assets/Scripts/EC_GPDataType.cs @@ -1,6 +1,15 @@ using CSNetwork.GPDataType; +using System; +using System.Runtime.InteropServices; using UnityEngine; +struct cmd_get_all_data +{ + byte byPack; // Get detail info. flag + byte byEquip; + byte byTask; +}; + struct cmd_player_move { Vector3 vCurPos; @@ -17,7 +26,78 @@ struct cmd_host_correct_pos }; struct cmd_notify_hostpos { - public Vector3 vPos; - public int tag; - public int line; + public Vector3 vPos; + public int tag; + public int line; +}; +struct cmd_task_data +{ + public uint active_list_size; + public byte[] active_list; + + public uint finished_list_size; + public byte[] finished_list; + + public uint finished_time_list_size; + public byte[] finished_time_list; + + public uint finished_count_size; + public byte[] finished_count; + + public uint storage_task_size; + public byte[] storage_task; + + public static cmd_task_data FromPointer(IntPtr ptr) + { + // Copy enough memory into managed buffer (you can optimize this later) + int maxExpectedSize = 1024 * 10; + byte[] buffer = new byte[maxExpectedSize]; + Marshal.Copy(ptr, buffer, 0, buffer.Length); + + return FromBuffer(buffer); + } + + public static cmd_task_data FromBuffer(byte[] buffer) + { + cmd_task_data result = new cmd_task_data(); + int offset = 0; + + result.active_list_size = (uint)ReadULong(buffer, ref offset); + result.active_list = ReadBytes(buffer, ref offset, (int)result.active_list_size); + + result.finished_list_size = (uint)ReadULong(buffer, ref offset); + result.finished_list = ReadBytes(buffer, ref offset, (int)result.finished_list_size); + + result.finished_time_list_size = (uint)ReadULong(buffer, ref offset); + result.finished_time_list = ReadBytes(buffer, ref offset, (int)result.finished_time_list_size); + + result.finished_count_size = (uint)ReadULong(buffer, ref offset); + result.finished_count = ReadBytes(buffer, ref offset, (int)result.finished_count_size); + + result.storage_task_size = (uint)ReadULong(buffer, ref offset); + result.storage_task = ReadBytes(buffer, ref offset, (int)result.storage_task_size); + + return result; + } + + private static ulong ReadULong(byte[] buffer, ref int offset) + { + ulong value = BitConverter.ToUInt64(buffer, offset); + offset += 8; + return value; + } + + private static byte[] ReadBytes(byte[] buffer, ref int offset, int count) + { + byte[] result = new byte[count]; + Buffer.BlockCopy(buffer, offset, result, 0, count); + offset += count; + return result; + } +}; + +struct cmd_task_var_data +{ + public uint size; + public byte[] data; }; diff --git a/Assets/Scripts/Task.meta b/Assets/Scripts/Task.meta new file mode 100644 index 0000000000..7e7e1064ca --- /dev/null +++ b/Assets/Scripts/Task.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b7b3600ea9146f345883726da0f9c37e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Task/ATaskTemplMan.cs b/Assets/Scripts/Task/ATaskTemplMan.cs new file mode 100644 index 0000000000..363c3d3fa1 --- /dev/null +++ b/Assets/Scripts/Task/ATaskTemplMan.cs @@ -0,0 +1,217 @@ +using ModelRenderer.Scripts.GameData; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace PerfectWorld.Scripts.Task +{ + public struct TASK_PACK_HEADER + { + public ulong magic; + public ulong version; + public ulong item_count; + }; + public class ATaskTemplMan + { + public const ulong TASK_PACK_MAGIC = 0x93858361; + public const ulong _task_templ_cur_version = 121; + + + private ulong g_ulNewCount = 0;// do we need this? + private Dictionary m_TaskTemplMap = new Dictionary(); + private Dictionary m_AllTemplMap = new Dictionary(); + private Dictionary m_DynTaskMap = new Dictionary(); + private Dictionary m_TitleTaskMap = new Dictionary(); + private Dictionary m_ExlusiveAwardTaskMap = new Dictionary(); + private Dictionary m_ProtectNPCMap = new Dictionary(); + private Dictionary m_AutoDelvMap = new Dictionary(); + private Dictionary m_DeathTrigMap = new Dictionary(); + private Dictionary m_PQTemplMap = new Dictionary(); + + private List m_SkillTaskLst = new List(); + private List m_TmLmtChkLst = new List(); + + private elementdataman m_pEleDataMan; + + public void Release() + { + + } + public void Init(elementdataman pMan) + { + m_pEleDataMan = pMan; + } + public bool LoadTasksFromPack(string szPackPath, bool bLoadDescript) + { + //TaskInterface::WriteLog(0, 0, 2, "LoadPack begin"); + FileStream fs = new FileStream(szPackPath, FileMode.Open, FileAccess.Read); + + if (fs == null) return false; + + TASK_PACK_HEADER tph; + + // fread(&tph, sizeof(tph), 1, fp); + tph = ReadStruct(fs); + + if (tph.magic != TASK_PACK_MAGIC + || tph.version != _task_templ_cur_version) + return false; + + if (tph.item_count == 0) return true; + + long[] pOffs = new long[tph.item_count]; + g_ulNewCount++; + + // fread(pOffs, sizeof(long), tph.item_count, fp); + // Convert fread(pOffs, sizeof(long), tph.item_count, fp); to C# + // Read tph.item_count 8-byte integers (long) from the FileStream fs into pOffs array + + byte[] offsBuffer = new byte[tph.item_count * sizeof(long)]; + int bytesRead = fs.Read(offsBuffer, 0, offsBuffer.Length); + if (bytesRead != offsBuffer.Length) + throw new EndOfStreamException("Could not read enough bytes for offsets"); + + for (ulong i = 0; i < tph.item_count; i++) + { + pOffs[i] = System.BitConverter.ToInt64(offsBuffer, (int)(i * sizeof(long))); + } + + + for (ulong i = 0; i < tph.item_count; i++) + { + // if (fseek(fp, pOffs[i], SEEK_SET) != 0) + // continue; + if (fs.Seek(pOffs[i], SeekOrigin.Begin) != 0) + continue; + + ATaskTempl pTempl = new ATaskTempl(); + g_ulNewCount++; + + if (!pTempl.LoadFromBinFile(fs)) + { + CECTaskInterface.WriteLog(0, (int)pTempl.m_ID, 0, "Cant Load Task"); + // LOG_DELETE(pTempl); + continue; + } + + AddOneTaskTempl(pTempl); + // TaskInterface::WriteLog(0, pTempl->m_ID, 2, "LoadTask"); + } + + // char log[1024]; + // sprintf(log, "LoadTask, Count = %d", m_TaskTemplMap.size()); + // TaskInterface::WriteLog(0, 0, 2, log); + + //todo: check + // LOG_DELETE_ARR(pOffs); + fs.Close(); + UpdateTimeLimitCheckList(); + +#if _ELEMENTCLIENT + _task_err.Release(); + _task_err.Init("Configs\\task_err.txt", true); +#endif + + return true; + } + + // General method to read a struct from a FileStream + private T ReadStruct(FileStream stream) where T : struct + { + int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)); + byte[] buffer = new byte[size]; + int bytesRead = stream.Read(buffer, 0, size); + if (bytesRead != size) + throw new EndOfStreamException("Could not read enough bytes for struct"); + var handle = System.Runtime.InteropServices.GCHandle.Alloc(buffer, System.Runtime.InteropServices.GCHandleType.Pinned); + try + { + return (T)System.Runtime.InteropServices.Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); + } + finally + { + handle.Free(); + } + } + public bool LoadNPCInfoFromPack(string szPath) + { + return true; + } + public void VerifyDynTasksPack(string szPath) + { + + } + + private void AddOneTaskTempl(ATaskTempl pTask) + { + //todo: recheck - wrong logic + if (m_AllTemplMap.ContainsKey(pTask.m_ID)) + { + CECTaskInterface.WriteLog(0, (int)pTask.m_ID, 0, "Dup Task Found"); + // Optionally log duplicate task found, e.g.: + // Debug.LogWarning($"Duplicate Task Found: {pTempl.m_ID}"); + return; + } + + m_TaskTemplMap[pTask.m_ID] = pTask; + + if (pTask.m_bDeathTrig) m_DeathTrigMap[pTask.m_ID] = pTask; + else if (pTask.m_bAutoDeliver) m_AutoDelvMap[pTask.m_ID] = pTask; + + if (pTask.m_bPQTask) m_PQTemplMap[pTask.m_ID] = pTask; + + if (pTask.m_bSkillTask) m_SkillTaskLst.Add(pTask); + + //todo: recheck m_DynTaskType type + if (!string.IsNullOrEmpty(pTask.m_DynTaskType)) + { + if (m_DynTaskMap.TryGetValue(pTask.m_ID, out ATaskTempl task)) + { + CECTaskInterface.WriteLog(0, (int)pTask.m_ID, 0, "Dup Dyn Task Found"); + } + + m_DynTaskMap[pTask.m_ID] = pTask; + } + if (pTask.m_bDisplayInTitleTaskUI) + m_TitleTaskMap[pTask.m_ID] = pTask; + if (pTask.m_bAutoDeliver && pTask.m_bDisplayInExclusiveUI) + m_ExlusiveAwardTaskMap[pTask.m_ID] = pTask; + +//#if _TASK_CLIENT +// if (pTask.m_ulDelvNPC != 0 && pTask.m_bCanSeekOut) +// m_TasksCanSeekOut.Add(pTask); +//#endif + + AddTaskToMap(pTask); + } + + private void AddTaskToMap(ATaskTempl pTempl) + { + if (pTempl.m_enumMethod == (ulong)TaskMethod.enumTMProtectNPC && pTempl.m_ulNPCToProtect > 0) + m_ProtectNPCMap[pTempl.m_ulNPCToProtect] = pTempl; + + m_AllTemplMap[pTempl.m_ID] = pTempl; + ATaskTempl pChild = pTempl.m_pFirstChild; + + while (pChild != null) + { + AddTaskToMap(pChild); + pChild = pChild.m_pNextSibling; + } + } + + void UpdateTimeLimitCheckList() + { + m_TmLmtChkLst.Clear(); + + foreach (var entry in m_TaskTemplMap) + { + if (entry.Value.m_ulMaxReceiver != 0) + { + m_TmLmtChkLst.Add(entry.Value); + } + } + + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Task/ATaskTemplMan.cs.meta b/Assets/Scripts/Task/ATaskTemplMan.cs.meta new file mode 100644 index 0000000000..bfd63cb493 --- /dev/null +++ b/Assets/Scripts/Task/ATaskTemplMan.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: fb2a99ced76b6c847810e2eadf598724 \ No newline at end of file diff --git a/Assets/Scripts/Task/CECTaskInterface.cs b/Assets/Scripts/Task/CECTaskInterface.cs new file mode 100644 index 0000000000..57ddc357e8 --- /dev/null +++ b/Assets/Scripts/Task/CECTaskInterface.cs @@ -0,0 +1,118 @@ +using System.Collections.Generic; + +namespace PerfectWorld.Scripts.Task +{ + public class CECTaskInterface : TaskInterface + { + CECHostPlayer m_pHost; + object[] m_pActiveListBuf; // Active task list buffer + object[] m_pFinishedListBuf; // Finished task list buffer + object[] m_pFinishedTimeListBuf; // Finished time list buffer + object[] m_pFinishedCountListBuf;// Finished count list buffer + object[] m_pStorageTaskListBuf; // Storage tasks list buffer + private Dictionary m_TasksToConfirm = new Dictionary(); + + public CECTaskInterface() + { + + } + public CECTaskInterface(CECHostPlayer pHost) + { + m_pHost = pHost; + + m_pActiveListBuf = null; + m_pFinishedListBuf = null; + m_pFinishedTimeListBuf = null; + m_pFinishedCountListBuf = null; + m_pStorageTaskListBuf = null; + } + + public bool Init(object[] pActiveListBuf, int iActiveListLen, object[] pFinishedListBuf, int iFinishedListLen, object[] pFinishedTimeListBuf, int iFinishedTimeListLen, object[] pFinishedCountListBuf, int iFinishedCountListLen, object[] pStorageTaskListBuf, int iStorageTaskListLen) + { + //if (!(m_pActiveListBuf = a_malloc(TASK_ACTIVE_LIST_BUF_SIZE))) + //{ + // glb_ErrorOutput(ECERR_NOTENOUGHMEMORY, "CECTaskInterface::Init", __LINE__); + // return false; + //} + + //if (!(m_pFinishedListBuf = a_malloc(TASK_FINISHED_LIST_BUF_SIZE))) + //{ + // a_free(m_pActiveListBuf); + // m_pFinishedListBuf = NULL; + // glb_ErrorOutput(ECERR_NOTENOUGHMEMORY, "CECTaskInterface::Init", __LINE__); + // return false; + //} + + //if (!(m_pFinishedTimeListBuf = a_malloc(TASK_FINISH_TIME_LIST_BUF_SIZE))) + //{ + // a_free(m_pActiveListBuf); + // a_free(m_pFinishedListBuf); + // glb_ErrorOutput(ECERR_NOTENOUGHMEMORY, "CECTaskInterface::Init", __LINE__); + // return false; + //} + + //if (!(m_pFinishedCountListBuf = a_malloc(TASK_FINISH_COUNT_LIST_BUF_SIZE))) + //{ + // a_free(m_pActiveListBuf); + // a_free(m_pFinishedListBuf); + // a_free(m_pFinishedCountListBuf); + // glb_ErrorOutput(ECERR_NOTENOUGHMEMORY, "CECTaskInterface::Init", __LINE__); + // return false; + //} + + //if (!(m_pStorageTaskListBuf = a_malloc(TASK_STORAGE_LIST_BUF_SIZE))) + //{ + // a_free(m_pActiveListBuf); + // a_free(m_pFinishedListBuf); + // a_free(m_pFinishedCountListBuf); + // a_free(m_pStorageTaskListBuf); + // glb_ErrorOutput(ECERR_NOTENOUGHMEMORY, "CECTaskInterface::Init", __LINE__); + // return false; + //} + //ASSERT(pActiveListBuf && pFinishedListBuf && pFinishedTimeListBuf && pFinishedCountListBuf); + //memcpy(m_pActiveListBuf, pActiveListBuf, iActiveListLen); + //memcpy(m_pFinishedListBuf, pFinishedListBuf, iFinishedListLen); + //memcpy(m_pFinishedTimeListBuf, pFinishedTimeListBuf, iFinishedTimeListLen); + //memcpy(m_pFinishedCountListBuf, pFinishedCountListBuf, iFinishedCountListLen); + //memcpy(m_pStorageTaskListBuf, pStorageTaskListBuf, iStorageTaskListLen); + + //// Clear rest buffer + //if (iActiveListLen < TASK_ACTIVE_LIST_BUF_SIZE) + // memset((BYTE*)m_pActiveListBuf + iActiveListLen, 0, TASK_ACTIVE_LIST_BUF_SIZE - iActiveListLen); + + //if (iFinishedListLen < TASK_FINISHED_LIST_BUF_SIZE) + // memset((BYTE*)m_pFinishedListBuf + iFinishedListLen, 0, TASK_FINISHED_LIST_BUF_SIZE - iFinishedListLen); + + //if (iFinishedTimeListLen < TASK_FINISH_TIME_LIST_BUF_SIZE) + // memset((BYTE*)m_pFinishedTimeListBuf + iFinishedTimeListLen, 0, TASK_FINISH_TIME_LIST_BUF_SIZE - iFinishedTimeListLen); + + //if (iFinishedCountListLen < TASK_FINISH_COUNT_LIST_BUF_SIZE) + // memset((BYTE*)m_pFinishedCountListBuf + iFinishedCountListLen, 0, TASK_FINISH_COUNT_LIST_BUF_SIZE - iFinishedCountListLen); + + //if (iStorageTaskListLen < TASK_STORAGE_LIST_BUF_SIZE) + // memset((BYTE*)m_pStorageTaskListBuf + iStorageTaskListLen, 0, TASK_STORAGE_LIST_BUF_SIZE - iStorageTaskListLen); + + ATaskTemplMan pTaskMan = GetTaskTemplMan(); + pTaskMan.Release(); + pTaskMan.LoadTasksFromPack("data\\tasks.data", true); + pTaskMan.LoadNPCInfoFromPack("data\\task_npc.data"); + pTaskMan.VerifyDynTasksPack("userdata\\dyn_tasks.data"); + //InitActiveTaskList(); + + //m_bForceNavigateFinish = false; + + return true; + } + + public static void WriteLog(int nPlayerId, int nTaskId, int nType, string szLog) + { + //do something? + } + + private ATaskTemplMan GetTaskTemplMan() + { + //return g_pGame->GetTaskTemplateMan(); + return null; + } + } +} diff --git a/Assets/Scripts/Task/CECTaskInterface.cs.meta b/Assets/Scripts/Task/CECTaskInterface.cs.meta new file mode 100644 index 0000000000..4a321dc53c --- /dev/null +++ b/Assets/Scripts/Task/CECTaskInterface.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: fb2c49d4eb415e343b0b312e215a2d00 \ No newline at end of file diff --git a/Assets/Scripts/Task/TaskInterface.cs b/Assets/Scripts/Task/TaskInterface.cs new file mode 100644 index 0000000000..242ccd320f --- /dev/null +++ b/Assets/Scripts/Task/TaskInterface.cs @@ -0,0 +1,7 @@ +namespace PerfectWorld.Scripts.Task +{ + public interface TaskInterface + { + bool Init(object[] pActiveListBuf, int iActiveListLen, object[] pFinishedListBuf, int iFinishedListLen, object[] pFinishedTimeListBuf, int iFinishedTimeListLen, object[] pFinishedCountListBuf, int iFinishedCountListLen, object[] pStorageTaskListBuf, int iStorageTaskListLen); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Task/TaskInterface.cs.meta b/Assets/Scripts/Task/TaskInterface.cs.meta new file mode 100644 index 0000000000..d9cc56d7d4 --- /dev/null +++ b/Assets/Scripts/Task/TaskInterface.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 1247ada478ebf564e9086d6142776d50 \ No newline at end of file diff --git a/Assets/Scripts/Task/TaskTempl.cs b/Assets/Scripts/Task/TaskTempl.cs new file mode 100644 index 0000000000..a631b54d15 --- /dev/null +++ b/Assets/Scripts/Task/TaskTempl.cs @@ -0,0 +1,538 @@ +using UnityEngine; +using System.IO; +namespace PerfectWorld.Scripts.Task +{ + /// + /// Completion Method + /// + public enum TaskMethod + { + enumTMNone = 0, // None + enumTMKillNumMonster, // Kill a number of monsters + enumTMCollectNumArticle, // Collect a number of items + enumTMTalkToNPC, // Talk to a specific NPC + enumTMReachSite, // Reach a specific location + enumTMWaitTime, // Wait for a specified time + enumTMAnswerQuestion, // Answer a question + enumTMTinyGame, // Mini-game + enumTMProtectNPC, // Protect a specific NPC + enumTMNPCReachSite, // NPC reaches a specific location + enumTMGlobalValOK, // Global variable condition satisfied + enumTMLeaveSite, // Leave a specific location + enumTMReachTreasureZone, // Reach the treasure area + enumTMKillPlayer, // Kill another player + enumTMTransform, // Transform state + enumTMReachLevel, // Check level: normal level, rebirth count, realm level + enumTMSimpleClientTask, // Simple client task (only client-side validation, currently just checks UI triggers) + enumTMSimpleClientTaskForceNavi // Force navigation + } + + public class ATaskTemplFixedData + { + public ulong m_ID; + public ulong m_ulNPCToProtect; + public ulong m_ulProtectTimeLen; + public ulong m_enumMethod; + public ulong m_enumFinishType; + + //Hierarchy + public ATaskTempl m_pParent; + public ATaskTempl m_pPrevSibling; + public ATaskTempl m_pNextSibling; + public ATaskTempl m_pFirstChild; + + // Required items + public ulong m_ulPremItems; + // public ItemWanted[] m_PremItems; // [MAX_ITEM_WANTED] + public bool m_bShowByItems; + public bool m_bPremItemsAnyOne; + + // Level condition + public ulong m_ulPremise_Lev_Min; + public ulong m_ulPremise_Lev_Max; + public ulong m_bPremCheckMaxHistoryLevel; + public bool m_bShowByLev; + + // Monster controller + public long m_lMonsCtrl; + public bool m_bTrigCtrl; + + // Auto trigger when conditions are met + public bool m_bAutoDeliver; + + // Whether to display in exclusive UI + public bool m_bDisplayInExclusiveUI; + public bool m_bReadyToNotifyServer; + + // Whether used in token shop + public bool m_bUsedInTokenShop; + + // Trigger on death + public bool m_bDeathTrig; + + // Whether clear all acquired items + public bool m_bClearAcquired; + + // Recommended level + public ulong m_ulSuitableLevel; + + // Whether to show prompt + public bool m_bShowPrompt; + + // Whether it is a key task + public bool m_bKeyTask; + + // Deliver NPC + public ulong m_ulDelvNPC; + + // Award NPC + public ulong m_ulAwardNPC; + + // Whether it is a skill task + public bool m_bSkillTask; + + // Can be sought out + public bool m_bCanSeekOut; + + // Whether to show direction + public bool m_bShowDirection; + + // Marriage + public bool m_bMarriage; + + // Change global key/value + public ulong m_ulChangeKeyCnt; + public long[] m_plChangeKey; // [TASK_AWARD_MAX_CHANGE_VALUE] + public long[] m_plChangeKeyValue; + public bool[] m_pbChangeType; + + // Switch scene fail + public bool m_bSwitchSceneFail; + + // Hidden task + public bool m_bHidden; + + // Whether to deliver skill [Yongdong, 2010-1-6] + public bool m_bDeliverySkill; + public int m_iDeliveredSkillID; + public int m_iDeliveredSkillLevel; + + // Whether to show task finished effect [Yongdong, 2010-1-21] + public bool m_bShowGfxFinished; // Show effect when task is completed + + // Whether change PQ ranking + public bool m_bChangePQRanking; + + // Compare items with player inventory before delivery + public bool m_bCompareItemAndInventory; + public ulong m_ulInventorySlotNum; // Required number of inventory slots + + // Whether it is a PQ task + public bool m_bPQTask; + + // PQ task global variable display + public ulong m_ulPQExpCnt; + // Dynamic task type + public string m_DynTaskType; + + // Special award ID, used for events + public ulong m_ulSpecialAward; + // Whether to display in the title task UI + public bool m_bDisplayInTitleTaskUI; + + // Maximum number of receivers + public ulong m_ulMaxReceiver; + } + public class ATaskTempl : ATaskTemplFixedData + { + const int MAX_TASK_NAME_LEN = 30; + public bool LoadFromBinFile(FileStream fp) + { + LoadBinary(fp); + // CheckDepth(); + return true; + } + private void LoadBinary(FileStream fp) + { + LoadFixedDataFromBinFile(fp); +// LoadDescriptionBin(fp); +// LoadTributeBin(fp); + +//# ifndef _TASK_CLIENT +// CheckMask(); +//#else +// SyncTaskType(); +//#endif + + +// namechar code = (namechar)m_ID; + +// m_DelvTaskTalk.load(fp); +// convert_talk_text(&m_DelvTaskTalk, code); + +// m_UnqualifiedTalk.load(fp); +// convert_talk_text(&m_UnqualifiedTalk, code); + +// m_DelvItemTalk.load(fp); +// convert_talk_text(&m_DelvItemTalk, code); + +// m_ExeTalk.load(fp); +// convert_talk_text(&m_ExeTalk, code); + +// m_AwardTalk.load(fp); +// convert_talk_text(&m_AwardTalk, code); + +// fread(&m_nSubCount, sizeof(m_nSubCount), 1, fp); + +// for (int i = 0; i < m_nSubCount; i++) +// { +// ATaskTempl* pSub = new ATaskTempl; +// g_ulNewCount++; +// AddSubTaskTempl(pSub); +// pSub->LoadBinary(fp); +// } + +// SynchID(); + //return true; + } + private bool LoadFixedDataFromBinFile(FileStream fp) + { + // LOG_DELETE(m_Award_S); + // LOG_DELETE(m_Award_F); + // LOG_DELETE(m_AwByRatio_S); + // LOG_DELETE(m_AwByRatio_F); + // LOG_DELETE(m_AwByItems_S); + // LOG_DELETE(m_AwByItems_F); + // LOG_DELETE_ARR(m_tmStart); + // LOG_DELETE_ARR(m_tmEnd); + // LOG_DELETE_ARR(m_plChangeKey); + // LOG_DELETE_ARR(m_plChangeKeyValue); + // LOG_DELETE_ARR(m_pbChangeType); + // LOG_DELETE_ARR(m_PremItems); + // LOG_DELETE_ARR(m_GivenItems); + // LOG_DELETE_ARR(m_TeamMemsWanted); + // LOG_DELETE_ARR(m_ItemsWanted); + // LOG_DELETE_ARR(m_PlayerWanted); + // LOG_DELETE_ARR(m_MonsterWanted); + // LOG_DELETE_ARR(m_pszSignature); + // LOG_DELETE_ARR(m_pszExp); + // LOG_DELETE_ARR(m_pExpArr); + // LOG_DELETE_ARR(m_pTaskChar); + // LOG_DELETE_ARR(m_pszPQExp); + // LOG_DELETE_ARR(m_pPQExpArr); + // LOG_DELETE_ARR(m_MonstersContrib); + + // LOG_DELETE_ARR(m_pDelvRegion); + // LOG_DELETE_ARR(m_pEnterRegion); + // LOG_DELETE_ARR(m_pLeaveRegion); + // LOG_DELETE_ARR(m_pReachSite); + // LOG_DELETE_ARR(m_pLeaveSite); + // LOG_DELETE_ARR(m_PremTitles); + + ulong i; + //write method FRead convert this to c# + //fread(this, sizeof(*this), 1, fp); + + //convert_txt(m_szName, MAX_TASK_NAME_LEN, (namechar)m_ID); + + // m_Award_S = new AWARD_DATA; + // g_ulNewCount++; + // m_Award_F = new AWARD_DATA; + // g_ulNewCount++; + // m_AwByRatio_S = new AWARD_RATIO_SCALE; + // g_ulNewCount++; + // m_AwByRatio_F = new AWARD_RATIO_SCALE; + // g_ulNewCount++; + // m_AwByItems_S = new AWARD_ITEMS_SCALE; + // g_ulNewCount++; + // m_AwByItems_F = new AWARD_ITEMS_SCALE; + // g_ulNewCount++; + // m_tmStart = NULL; + // m_tmEnd = NULL; + // m_plChangeKey = NULL; + // m_plChangeKeyValue = NULL; + // m_pbChangeType = NULL; + // m_PremItems = NULL; + // m_GivenItems = NULL; + // m_TeamMemsWanted= NULL; + // m_ItemsWanted = NULL; + // m_PlayerWanted = NULL; + // m_MonsterWanted = NULL; + // m_pszSignature = NULL; + // m_pszExp = NULL; + // m_pExpArr = NULL; + // m_pTaskChar = NULL; + // m_pszPQExp = NULL; + // m_pPQExpArr = NULL; + // m_MonstersContrib = NULL; + // m_PremTitles = NULL; + + // if (m_bHasSign) + // { + // m_pszSignature = new task_char[MAX_TASK_NAME_LEN]; + // g_ulNewCount++; + // fread(m_pszSignature, sizeof(task_char), MAX_TASK_NAME_LEN, fp); + // convert_txt(m_pszSignature, MAX_TASK_NAME_LEN, (namechar)m_ID); + // } + + // if (m_ulTimetable) + // { + // m_tmStart = new task_tm[m_ulTimetable]; + // g_ulNewCount++; + // m_tmEnd = new task_tm[m_ulTimetable]; + // g_ulNewCount++; + // } + + // for (i = 0; i < m_ulTimetable; i++) + // { + // fread(&m_tmStart[i], sizeof(task_tm), 1, fp); + // fread(&m_tmEnd[i], sizeof(task_tm), 1, fp); + // } + + // if (m_ulChangeKeyCnt) + // { + // m_plChangeKey = new long[m_ulChangeKeyCnt]; + // m_plChangeKeyValue = new long[m_ulChangeKeyCnt]; + // m_pbChangeType = new bool[m_ulChangeKeyCnt]; + // } + + // for (i=0; i0) + // { + // m_pDelvRegion = new Task_Region[m_ulDelvRegionCnt]; + // g_ulNewCount++; + // } + // else m_pDelvRegion = NULL; + + // for (i=0;i0) + // { + // m_pEnterRegion = new Task_Region[m_ulEnterRegionCnt]; + // g_ulNewCount++; + // } + // else m_pEnterRegion = NULL; + + // for (i=0;i0) + // { + // m_pLeaveRegion = new Task_Region[m_ulLeaveRegionCnt]; + // g_ulNewCount++; + // } + // else m_pLeaveRegion = NULL; + + // for (i=0;i0) + // { + // m_pReachSite = new Task_Region[m_ulReachSiteCnt]; + // g_ulNewCount++; + // } + // else m_pReachSite = NULL; + + // for (i=0;i0) + // { + // m_pLeaveSite = new Task_Region[m_ulLeaveSiteCnt]; + // g_ulNewCount++; + // } + // else m_pLeaveSite = NULL; + + // for (i=0;i