feat: Round 49 narrative systems improvements
QuestManager: extract CheckQuestDepsAndFlags shared method, simplify GetQuestLockInfo/CanAccept/MeetsPrerequisites; add GetQuestsInState+FilterQuests implementations; fix extra brace compile bug; add _pauseTimestamps logging; use actualDelta in ApplyAffinity event. QuestSO: add depth>32 guard to HasPrerequisiteCycle and HasBranchCycle to prevent editor freeze on deep chains. EventChainModule: replace FindObjectOfType with ServiceLocator.GetOrDefault in ForceExecute; add self-trigger flag detection (check 6) in ValidateAllChains using reflection. DialogueVariantPreviewWindow: add matrix analysis section enumerating all 2^N flag combinations (N<=10) with table showing winning variant per combination. WorldStateRegistry: LoadFromSave null guard on data.World sub-collections (P0 fix). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -200,10 +200,16 @@ namespace BaseGames.Quest
|
||||
/// <summary>
|
||||
/// 深度优先遍历前置链,检测是否存在环路。
|
||||
/// <para>已访问节点集 <paramref name="visited"/> 在回溯时移除,保证同一链条中不误报平行分支。</para>
|
||||
/// <para><paramref name="depth"/> 超过 32 层时停止递归并输出警告,防止编辑器因超深嵌套卡顿。</para>
|
||||
/// </summary>
|
||||
private static bool HasPrerequisiteCycle(QuestSO quest,
|
||||
System.Collections.Generic.HashSet<string> visited)
|
||||
System.Collections.Generic.HashSet<string> visited, int depth = 0)
|
||||
{
|
||||
if (depth > 32)
|
||||
{
|
||||
Debug.LogWarning($"[QuestSO] 前置链深度超过 32 层(路径末端:'{quest.name}'),已停止检测。请减少任务链深度。");
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(quest.questId)) return false;
|
||||
if (!visited.Add(quest.questId)) return true; // 已在当前路径上 = 环路
|
||||
|
||||
@@ -215,7 +221,7 @@ namespace BaseGames.Quest
|
||||
{
|
||||
foreach (var dep in deps)
|
||||
{
|
||||
if (dep != null && HasPrerequisiteCycle(dep, visited))
|
||||
if (dep != null && HasPrerequisiteCycle(dep, visited, depth + 1))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -250,10 +256,16 @@ namespace BaseGames.Quest
|
||||
|
||||
/// <summary>
|
||||
/// 深度优先遍历 branches[].nextQuest 链,检测是否存在环路(DFS 回溯)。
|
||||
/// <para><paramref name="depth"/> 超过 32 层时停止递归并输出警告,防止编辑器因超深嵌套卡顿。</para>
|
||||
/// </summary>
|
||||
private static bool HasBranchCycle(QuestSO quest,
|
||||
System.Collections.Generic.HashSet<string> visited)
|
||||
System.Collections.Generic.HashSet<string> visited, int depth = 0)
|
||||
{
|
||||
if (depth > 32)
|
||||
{
|
||||
Debug.LogWarning($"[QuestSO] 分支链深度超过 32 层(路径末端:'{quest.name}'),已停止检测。请减少分支链深度。");
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(quest.questId)) return false;
|
||||
if (!visited.Add(quest.questId)) return true; // 已在路径上 = 环路
|
||||
|
||||
@@ -261,7 +273,7 @@ namespace BaseGames.Quest
|
||||
{
|
||||
foreach (var branch in quest.branches)
|
||||
{
|
||||
if (branch?.nextQuest != null && HasBranchCycle(branch.nextQuest, visited))
|
||||
if (branch?.nextQuest != null && HasBranchCycle(branch.nextQuest, visited, depth + 1))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user