complete cache task into SO

This commit is contained in:
MinhHai
2025-12-20 11:52:13 +07:00
parent 807fbdf6b0
commit 6c9388325f
11 changed files with 111 additions and 60 deletions
Binary file not shown.
+1 -1
View File
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0930e07b267dc93d54fbc4de6bfaac5a9bf1aa7ea5ff239a58e5a8a7a25cf6c7
oid sha256:adee80de40d18d133b32acbac1cf5cf624f39c542fea1003f3604af4f0211219
size 10723
@@ -91,15 +91,7 @@ namespace BrewMonster.Network
public static bool Init()
{
m_pElementDataMan = ElementDataManProvider.GetElementDataMan();
#if UNITY_EDITOR
if (TaskTest.Instance &&
TaskTest.m_pTaskMan != null &&
TaskTest.Instance.WasLoadTaskData)
{
m_pTaskMan = TaskTest.m_pTaskMan;
}
#endif
// Load task templates
// if (m_pTaskMan == null) m_pTaskMan = new ATaskTemplMan();
m_pTaskMan = new ATaskTemplMan();
@@ -105,6 +105,7 @@ namespace BrewMonster.Network
return;
}
BMLogger.Log( $"Connecting to {Instance._ip} {Instance._port}...");
await Instance.ConnectAsync(Instance._ip, Instance._port);
if (!Instance._gameSession.IsConnected)
@@ -246,10 +246,10 @@ namespace PerfectWorld.Scripts.Task
[MarshalAs(UnmanagedType.U1)]
public bool m_bPQTask; // Whether it is a PQ task // 是否是PQ任务
public uint m_ulPQExpCnt; // PQ task global variable display // PQ任务全局变量显示
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0)]
public byte[,] m_pszPQExp; // PQ expressions
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0)]
public byte[] m_pszPQExp_Seri; // Use to save m_pszPQExp into SO
public TASK_EXPRESSION[,] m_pPQExpArr; // PQ expression arrays
public TASK_EXPRESSION[] m_pPQExpArr_Seri; // Use to save m_pPQExpArr into SO
[MarshalAs(UnmanagedType.U1)]
public bool m_bPQSubTask; // Whether it is a PQ subtask // 是否PQ子任务
@@ -571,15 +571,17 @@ namespace PerfectWorld.Scripts.Task
// 需显示的全局变量表达式 // Global variable expressions to display
public uint m_ulExpCnt;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[,] m_pszExp;
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public TASK_EXPRESSION[,] m_pExpArr;
public byte[] m_pszExp_Seri; // Use to save m_pszExp into SO
public TASK_EXPRESSION[] m_pExpArr_Seri; // Use to save m_pExpArr into SO
// 需显示的全局变量表达式提示字符串 // Global variable expression prompt strings
public uint m_ulTaskCharCnt;
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public ushort[,] m_pTaskChar;
public ushort[] m_pTaskChar_Seri; // Use to save m_pTaskChar into SO
// 变身状态 // Transformation state
public byte m_ucTransformedForm;
@@ -604,14 +606,12 @@ namespace PerfectWorld.Scripts.Task
/* 时间比例方式 */ /* Time ratio method */
//TODO: Revert
public AWARD_RATIO_SCALE m_AwByRatio_S;
//public uint m_AwByRatio_S_ptr;
public AWARD_RATIO_SCALE m_AwByRatio_F;
// public uint m_AwByRatio_F_ptr;
/* 按获得物比例方式 */ /* Item ratio method */
//TODO: Revert
public AWARD_ITEMS_SCALE m_AwByItems_S;
public uint m_AwByItems_S_ptr;
public AWARD_ITEMS_SCALE m_AwByItems_F;
@@ -669,7 +669,7 @@ namespace BrewMonster.Scripts.Task
// fill unserialize data when play game
if (_taskTemplContainerSO != null && _taskTemplContainerSO.LoadAllTasksFromSO)
{
pTempl.FillUnserializeDatasWhenPlayGame(_taskTemplContainerSO);
pTempl.FillUnserializableDataWhenPlayGame(_taskTemplContainerSO);
}
if (pTempl.m_FixedData.m_enumMethod == (ulong)TaskCompletionMethod.enumTMProtectNPC && pTempl.m_FixedData.m_ulNPCToProtect > 0)
@@ -14,6 +14,7 @@ using System;
namespace BrewMonster.Scripts.Task
{
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class Kill_Player_Requirements
{
@@ -431,24 +432,7 @@ namespace BrewMonster.Scripts.Task
LoadingSceneController.Instance.ShowLoadingScene(true);
LoadingSceneController.Instance.UpdateUI(0f);
LoadingSceneController.Instance.SetLoadingText("Loading Tasks From Pack");
#if UNITY_EDITOR
if (TaskTest.Instance &&
TaskTest.Instance.WasLoadTaskData &&
pTaskMan.TaskLoadedCount > 100)
{
Debug.Log($" [TaskInterface] Using TaskTest loaded data with {pTaskMan.TaskLoadedCount} tasks.");
LoadingSceneController.Instance.ShowLoadingScene(false);
}
else
{
string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
await pTaskMan.LoadTasksFromPack(task_data_path, true, (x) =>
{
LoadingSceneController.Instance.SetProgress(x);
}, _cts.Token);
}
#else
bool result = await MoveShopDataToPersistentPath("data/tasks.data");
if (!result)
{
@@ -460,7 +444,7 @@ namespace BrewMonster.Scripts.Task
{
LoadingSceneController.Instance.SetProgress(x);
}, _cts.Token);
#endif
#if UNITY_ANDROID && !UNITY_EDITOR
result = await MoveShopDataToPersistentPath("data/tasks.data");
@@ -1176,7 +1176,7 @@ namespace BrewMonster.Scripts.Task
{
// Debug: Log why task is blocked
string taskName = GetTaskName(pTopTempl ?? this);
UnityEngine.Debug.Log($"[CheckFnshLst] Task {taskIdToCheck} '{taskName}' blocked: nRet={nRet}, bCanRedo={bCanRedo}, bCanRedoAfterFailure={bCanRedoAfterFailure}");
// BMLogger.Log($"[CheckFnshLst] Task {taskIdToCheck} '{taskName}' blocked: nRet={nRet}, bCanRedo={bCanRedo}, bCanRedoAfterFailure={bCanRedoAfterFailure}");
return (uint)TaskInterfaceConstants.TASK_PREREQU_FAIL_CANT_REDO;
}
+83 -7
View File
@@ -430,6 +430,7 @@ namespace BrewMonster.Scripts.Task
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PLAYER_WANTED
{
@@ -454,6 +455,7 @@ namespace BrewMonster.Scripts.Task
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MONSTER_WANTED
{
@@ -481,6 +483,7 @@ namespace BrewMonster.Scripts.Task
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct ITEM_WANTED
{
@@ -524,6 +527,7 @@ namespace BrewMonster.Scripts.Task
public uint m_ulItemNum;
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MONSTERS_SUMMONED
{
@@ -541,6 +545,7 @@ namespace BrewMonster.Scripts.Task
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MONSTERS_CONTRIB
{
@@ -558,6 +563,7 @@ namespace BrewMonster.Scripts.Task
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct RANKING_AWARD
{
@@ -863,7 +869,7 @@ namespace BrewMonster.Scripts.Task
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct task_tm
{
@@ -1022,6 +1028,7 @@ namespace BrewMonster.Scripts.Task
public static readonly uint[] _race_occ_map = new uint[TaskTemplConstants.MAX_OCCUPATIONS];
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct TEAM_MEM_WANTED
{
@@ -1156,7 +1163,7 @@ namespace BrewMonster.Scripts.Task
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct AWARD_RATIO_SCALE
{
@@ -1416,6 +1423,7 @@ namespace BrewMonster.Scripts.Task
// enumTMSimpleClientTaskForceNavi // Force navigation
// }
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct COMPARE_KEY_VALUE
{
@@ -1451,6 +1459,7 @@ namespace BrewMonster.Scripts.Task
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Task_Region
{
@@ -3146,6 +3155,10 @@ namespace BrewMonster.Scripts.Task
fixedData.m_pszPQExp = new byte[rowCount, colCount];
fixedData.m_pPQExpArr = new TASK_EXPRESSION[rowCount, colCount];
// serialize m_pszPQExp and m_pPQExpArr
fixedData.m_pszPQExp_Seri = new byte[rowCount * colCount];
fixedData.m_pPQExpArr_Seri = new TASK_EXPRESSION[rowCount * colCount];
for (int i = 0; i < rowCount; i++)
{
@@ -3154,12 +3167,14 @@ namespace BrewMonster.Scripts.Task
for (int j = 0; j < colCount; j++)
{
fixedData.m_pszPQExp[i, j] = expBytes[j];
fixedData.m_pszPQExp_Seri[i * colCount + j] = expBytes[j];
}
// Read TASK_EXPRESSION array (length TASK_AWARD_MAX_DISPLAY_CHAR_LEN)
for (int j = 0; j < colCount; j++)
{
fixedData.m_pPQExpArr[i, j] = AAssit.ReadFromBinaryOf<TASK_EXPRESSION>(fp, ref readBytes);
fixedData.m_pPQExpArr_Seri[i * colCount + j] = fixedData.m_pPQExpArr[i, j];
}
}
@@ -3387,6 +3402,9 @@ namespace BrewMonster.Scripts.Task
fixedData.m_pszExp = new byte[rowCount, colCount];
fixedData.m_pExpArr = new TASK_EXPRESSION[rowCount, colCount];
fixedData.m_pszExp_Seri = new byte[rowCount * colCount];
fixedData.m_pExpArr_Seri = new TASK_EXPRESSION[rowCount * colCount];
for (int i = 0; i < rowCount; i++)
{
@@ -3394,11 +3412,10 @@ namespace BrewMonster.Scripts.Task
for (int j = 0; j < colCount; j++)
{
fixedData.m_pszExp[i, j] = expBytes[j];
}
for (int j = 0; j < colCount; j++)
{
fixedData.m_pszExp_Seri[i * colCount + j] = expBytes[j];
fixedData.m_pExpArr[i, j] = AAssit.ReadFromBinaryOf<TASK_EXPRESSION>(fp, ref readBytes);
fixedData.m_pExpArr_Seri[i * colCount + j] = fixedData.m_pExpArr[i, j];
}
}
logContent += $"m_pszExp and m_pExpArr loaded, count: {fixedData.m_ulExpCnt} (each {TaskTemplConstants.TASK_AWARD_MAX_DISPLAY_CHAR_LEN})\n";
@@ -3415,6 +3432,8 @@ namespace BrewMonster.Scripts.Task
int rowCount = (int)fixedData.m_ulTaskCharCnt;
int colCount = TaskTemplConstants.TASK_AWARD_MAX_DISPLAY_CHAR_LEN;
fixedData.m_pTaskChar = new ushort[rowCount, colCount];
fixedData.m_pTaskChar_Seri = new ushort[rowCount * colCount];
string tcLog = "";
for (int i = 0; i < rowCount; i++)
@@ -3423,6 +3442,8 @@ namespace BrewMonster.Scripts.Task
for (int j = 0; j < colCount; j++)
{
fixedData.m_pTaskChar[i, j] = row[j];
fixedData.m_pTaskChar_Seri[i * colCount + j] = row[j];
}
tcLog += $" {i} = (...{colCount} chars) || ";
}
@@ -5350,12 +5371,67 @@ namespace BrewMonster.Scripts.Task
return m_FixedData.m_bDeathTrig || m_FixedData.m_bAutoDeliver;
}
public void FillUnserializeDatasWhenPlayGame(TaskTemplContainerSO container)
public void FillUnserializableDataWhenPlayGame(TaskTemplContainerSO container)
{
m_pParent = container.GetTaskTemplate(ParentID);
m_pPrevSibling = container.GetTaskTemplate( PrevSiblingID );
m_pNextSibling = container.GetTaskTemplate( NextSiblingID );
m_pFirstChild = container.GetTaskTemplate( FirstChildID );
// Unserialize m_pszPQExp and m_pPQExpArr
if (m_FixedData.m_ulPQExpCnt > 0)
{
int rowCount = (int)m_FixedData.m_ulPQExpCnt;
int colCount = TaskTemplConstants.TASK_AWARD_MAX_DISPLAY_CHAR_LEN;
m_FixedData.m_pszPQExp = new byte[rowCount, colCount];
m_FixedData.m_pPQExpArr = new TASK_EXPRESSION[rowCount, colCount];
for (int i = 0; i < rowCount; i++)
{
for (int j = 0; j < colCount; j++)
{
m_FixedData.m_pszPQExp[i, j] = m_FixedData.m_pszPQExp_Seri[ i * colCount + j ];
m_FixedData.m_pPQExpArr[i, j] = m_FixedData.m_pPQExpArr_Seri[ i * colCount + j ];
}
}
}
// Unserialize m_pszExp and m_pExpArr
if (m_FixedData.m_ulExpCnt > 0)
{
int rowCount = (int)m_FixedData.m_ulExpCnt;
int colCount = TaskTemplConstants.TASK_AWARD_MAX_DISPLAY_CHAR_LEN;
m_FixedData.m_pszExp = new byte[rowCount, colCount];
m_FixedData.m_pExpArr = new TASK_EXPRESSION[rowCount, colCount];
for (int i = 0; i < rowCount; i++)
{
for (int j = 0; j < colCount; j++)
{
m_FixedData.m_pszExp[i, j] = m_FixedData.m_pszExp_Seri[ i * colCount + j ];
m_FixedData.m_pExpArr[i, j] = m_FixedData.m_pExpArr_Seri[ i * colCount + j ];
}
}
}
// Unserialize m_pTaskChar
if (m_FixedData.m_ulTaskCharCnt > 0)
{
int rowCount = (int)m_FixedData.m_ulTaskCharCnt;
int colCount = TaskTemplConstants.TASK_AWARD_MAX_DISPLAY_CHAR_LEN;
m_FixedData.m_pTaskChar = new ushort[rowCount, colCount];
for (int i = 0; i < rowCount; i++)
{
for (int j = 0; j < colCount; j++)
{
m_FixedData.m_pTaskChar[i, j] = m_FixedData.m_pTaskChar_Seri[ i * colCount + j ];
}
}
}
}
public void SyncSerializableDataAfterLoaded()
@@ -10,7 +10,6 @@ namespace BrewMonster.Scripts.Task
[ CreateAssetMenu(fileName = "TaskTemplContainerSO", menuName = "BrewMonster/Task/TaskTemplContainerSO")]
public class TaskTemplContainerSO : ScriptableObject
{
public const ulong TASK_PACK_MAGIC = 0x93858361;
public const ulong _task_templ_cur_version = 121;
@@ -21,7 +20,7 @@ namespace BrewMonster.Scripts.Task
[Header("DEBUG")]
[SerializeField] private int _taskDemoIndex = 100;
[SerializeField] private ATaskTempl _taskDemo ;
// /*[SerializeField]*/ private ATaskTempl _taskDemo ;
private Dictionary<uint, ATaskTempl> _allTaskTemplMap = new Dictionary<uint, ATaskTempl>();
@@ -34,10 +33,10 @@ namespace BrewMonster.Scripts.Task
{
TaskLoadedCount = _topTaskTemplates == null ? 0 : _topTaskTemplates.Count;
if (TaskLoadedCount > _taskDemoIndex)
{
_taskDemo = _topTaskTemplates[_taskDemoIndex];
}
// if (TaskLoadedCount > _taskDemoIndex)
// {
// _taskDemo = _topTaskTemplates[_taskDemoIndex];
// }
}
public ATaskTempl GetTaskTemplate(uint id)
@@ -73,6 +72,8 @@ namespace BrewMonster.Scripts.Task
public void ClearDatas()
{
_topTaskTemplates.Clear();
_allTaskTemplates.Clear();
_allTaskTemplMap.Clear();
Debug.Log($"[TaskTemplContainerSO] Cleared all loaded task templates.");
}
+7 -10
View File
@@ -12,7 +12,7 @@ using UnityEngine;
namespace BrewMonster.Scripts.Task
{
public class TaskTest : MonoSingleton<TaskTest>
public class TaskTest : MonoBehaviour
{
public static ATaskTemplMan m_pTaskMan; // use static to store loaded data across instances
public bool WasLoadTaskData = false;
@@ -23,21 +23,18 @@ namespace BrewMonster.Scripts.Task
[SerializeField] private KeyCode _awardkey = KeyCode.A;
private CancellationTokenSource _cts;
protected override void Awake()
private void Awake()
{
base.Awake();
_cts = new CancellationTokenSource();
}
private void OnValidate()
{
WasLoadTaskData = m_pTaskMan != null && m_pTaskMan.TaskLoadedCount > 0;
if (!WasLoadTaskData && AutoLoadData)
{
LoadTaskData();
}
// if (!WasLoadTaskData && AutoLoadData)
// {
// LoadTaskData();
// }
}
private void OnDestroy()