fix EC_Game: get GameRun, cache TaskData before playmode

This commit is contained in:
MinhHai
2025-11-22 10:04:50 +07:00
parent f2eee71c9e
commit 7ba8ca49ba
12 changed files with 75 additions and 27 deletions
@@ -17,7 +17,7 @@ namespace BrewMonster.Network
public static bool g_bEnableFortressDeclareWar = false;
private static ATaskTemplMan m_pTaskMan; // Task template manager
private static elementdataman m_pElementDataMan; // global element templates manager
private static CECGameRun m_pGameRun; // Game running object
private static CECGameRun m_pGameRun => CECGameRun.Instance; // Game running object
private static CECGFXCaster m_pGFXCaster; // GFX caster
private static BrewMonster.CECStringTab m_FixedMsgs; // Fixed message table
@@ -92,6 +92,13 @@ namespace BrewMonster.Network
{
m_pElementDataMan = ElementDataManProvider.GetElementDataMan();
#if UNITY_EDITOR
if (TaskTest.Instance &&
TaskTest.Instance.m_pTaskMan != null)
{
m_pTaskMan = TaskTest.Instance.m_pTaskMan;
}
#endif
// Load task templates
if (m_pTaskMan == null) m_pTaskMan = new ATaskTemplMan();
@@ -99,14 +106,14 @@ namespace BrewMonster.Network
if (!m_pTaskMan.InitStorageTask())
{
BMLogger.LogError("[Dat]- CECGame::Init, Storage task Init Failed!");
return false;
// return false;
}
// Create GFX caster
if (m_pGFXCaster == null)
{
m_pGFXCaster = new CECGFXCaster();
return false;
// return false;
}
// Initialize string tables
@@ -114,7 +121,7 @@ namespace BrewMonster.Network
// m_pGameRun = new CECGameRun();
// m_pGameRun.Init();
m_pGameRun = CECGameRun.Instance;
// m_pGameRun = CECGameRun.Instance;
return true;
}
@@ -13,6 +13,8 @@ namespace BrewMonster.Scripts.Task
/// </summary>
public class ATaskTemplMan
{
public int TaskLoadedCount => m_TaskTemplMap.Count;
public const ulong TASK_PACK_MAGIC = 0x93858361;
public const ulong _task_templ_cur_version = 121;
@@ -341,11 +343,11 @@ namespace BrewMonster.Scripts.Task
log += $"Task ID {pTempl.m_FixedData.m_ID} Fail : {failCode} \n";
}
if (i % 1000 == 0)
{
Debug.Log($"--- {i % 1000} Find Available Task --- \n {log}");
log = "";
}
// if (i % 1000 == 0)
// {
// Debug.Log($"--- {i % 1000} Find Available Task --- \n {log}");
// log = "";
// }
}
@@ -403,9 +403,23 @@ namespace BrewMonster.Scripts.Task
ATaskTemplMan pTaskMan = GetTaskTemplMan();
pTaskMan.Release();
#if UNITY_EDITOR
if (TaskTest.Instance &&
TaskTest.Instance.WasLoadTaskData &&
pTaskMan.TaskLoadedCount > 100)
{
Debug.Log($" [TaskInterface] Using TaskTest loaded data with {pTaskMan.TaskLoadedCount} tasks.");
}
else
{
string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
pTaskMan.LoadTasksFromPack(task_data_path, true);
}
#else
string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
pTaskMan.LoadTasksFromPack(task_data_path, true);
#endif
pTaskMan.LoadNPCInfoFromPack("data\\task_npc.data");
pTaskMan.VerifyDynTasksPack("userdata\\dyn_tasks.data");
@@ -469,7 +483,7 @@ namespace BrewMonster.Scripts.Task
return inv != null ? inv.GetItemTotalNum((int)ulTaskItem) : 0;
}
private ATaskTemplMan GetTaskTemplMan()
public ATaskTemplMan GetTaskTemplMan()
{
return EC_Game.GetTaskTemplateMan();
}
@@ -296,7 +296,7 @@ namespace BrewMonster.Scripts.Task
public static void OnServerNotify(TaskInterface pTask, byte[] pBuf, uint sz)
{
// Check version validity
// TODO: CheckVersion not exposed on TaskInterface; skipping version check
// CheckVersion not exposed on TaskInterface; skipping version check
if (!pTask.CheckVersion())
return;
@@ -490,7 +490,7 @@ namespace BrewMonster.Scripts.Task
// Clear valid count and process server notification
pTempl.ClearValidCount();
// TODO: OnServerNotify method signature may need adjustment for C# (ref/out parameters)
// OnServerNotify method signature may need adjustment for C# (ref/out parameters)
pTempl.OnServerNotify(pTask, pEntry, ref pNotify, sz);
}
@@ -101,5 +101,6 @@ namespace BrewMonster.Scripts.Task
void TakeAwayFactionConsumeContrib(int ulNum);
void TakeAwayFactionExpContrib(int ulNum){}
void OnGiveupTask(int iTaskID);
ATaskTemplMan GetTaskTemplMan();
}
}
+4 -3
View File
@@ -9,9 +9,10 @@ using UnityEngine;
namespace BrewMonster.Scripts.Task
{
public class TaskTest : MonoBehaviour
public class TaskTest : MonoSingleton<TaskTest>
{
ATaskTemplMan m_pTaskMan;
public ATaskTemplMan m_pTaskMan;
public bool WasLoadTaskData = false;
[ContextMenu("Load Data")]
void LoadTaskData()
@@ -22,7 +23,7 @@ namespace BrewMonster.Scripts.Task
}
string path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
m_pTaskMan.LoadTasksFromPack(path, true);
WasLoadTaskData = m_pTaskMan.LoadTasksFromPack(path, true);
}
[ContextMenu("Test Size")]
+13 -1
View File
@@ -14,7 +14,7 @@ using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace BrewMonster.PerfectWorld.Scripts.Task.UI
namespace BrewMonster.Scripts.Task.UI
{
/// <summary>
/// This is DlgTask.cpp
@@ -678,6 +678,18 @@ namespace BrewMonster.PerfectWorld.Scripts.Task.UI
public CECHostPlayer GetHostPlayer()
{
if(EC_Game.GetGameRun() == null)
{
BMLogger.LogError("EC_Game.GetGameRun() is null !!!");
return null;
}
if (EC_Game.GetGameRun().GetHostPlayer() == null)
{
BMLogger.LogError("EC_Game.GetHostPlayer() is null !!!");
return null;
}
return EC_Game.GetGameRun().GetHostPlayer();
}
//
@@ -0,0 +1,7 @@
namespace BrewMonster.Scripts.Task.UI
{
public interface IRefreshLayout
{
void RefreshLayout();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab060868fe9f4611adda010fcadfd23d
timeCreated: 1763778954
@@ -2,9 +2,9 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster.PerfectWorld.Scripts.Task.UI
namespace BrewMonster.Scripts.Task.UI
{
public class TaskTreeView : MonoBehaviour
public class TaskTreeView : MonoBehaviour, IRefreshLayout
{
[SerializeField] private TaskTreeViewItem m_pTreeViewItemPrefab;
@@ -5,9 +5,9 @@ using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace BrewMonster.PerfectWorld.Scripts.Task.UI
namespace BrewMonster.Scripts.Task.UI
{
public class TaskTreeViewItem : MonoBehaviour
public class TaskTreeViewItem : MonoBehaviour, IRefreshLayout
{
[SerializeField] private TMP_Text m_text;
[SerializeField] private Button m_Button;
@@ -124,8 +124,12 @@ namespace BrewMonster.PerfectWorld.Scripts.Task.UI
// Force Unity to rebuild layout immediately
rectTransform.ForceUpdateRectTransforms();
LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
transform.parent.SendMessage("RefreshLayout");
if (transform.parent &&
transform.parent.TryGetComponent<IRefreshLayout>(out var refreshLayout))
{
refreshLayout.RefreshLayout();
}
}
void OnBtnClick()
+1 -4
View File
@@ -67,8 +67,6 @@ public partial class CECHostPlayer
if (header == CommandID.TASK_DATA)
{
#if LOAD_TASK_TEMPL // only load on developer project
// Parse aggregated task buffers
cmd_task_data pCmd = cmd_task_data.FromBuffer(pDataBuf);
// cmd_task_data pCmd = GPDataTypeHelper.FromBytes<cmd_task_data>(pDataBuf);
@@ -89,8 +87,6 @@ public partial class CECHostPlayer
}
m_pTaskInterface.CheckPQEnterWorldInit();
#endif
// check if player has equipped goblin (not yet implemented in C#)
// TODO: implement goblin initialization when equipment system is ready
@@ -101,6 +97,7 @@ public partial class CECHostPlayer
}
else if (header == CommandID.TASK_VAR_DATA)
{
Debug.Log($" OnMsgHstTaskData: Received TASK_VAR_DATA, size: {pDataBuf.Length} bytes");
// Minimal forwarding; original code passes inner data pointer and size
if (m_pTaskInterface != null)
{