68 lines
2.5 KiB
C#
68 lines
2.5 KiB
C#
using System;
|
||
using BaseGames.World;
|
||
using UnityEngine;
|
||
|
||
namespace BaseGames.Dialogue
|
||
{
|
||
/// <summary>
|
||
/// 条件对话 NPC(架构 14_NarrativeModule §7)。
|
||
/// 扩展 InteractableNPC,根据 WorldStateRegistry 标志动态选择对话版本。
|
||
/// 版本列表从高到低优先级排列;第一个满足条件的版本生效。
|
||
/// </summary>
|
||
public class NarrativeNPC : InteractableNPC
|
||
{
|
||
[Header("台词版本集(从高到低优先级排列)")]
|
||
[SerializeField] private DialogueVersion[] _dialogueVersions;
|
||
[SerializeField] private DialogueSequenceSO _fallbackDialogue; // 无条件满足时的兜底台词
|
||
[SerializeField] private WorldStateRegistry _worldState; // SO 注入
|
||
|
||
protected override DialogueSequenceSO GetCurrentDialogue()
|
||
{
|
||
if (_dialogueVersions == null) return _fallbackDialogue;
|
||
|
||
foreach (var version in _dialogueVersions)
|
||
{
|
||
if (version != null && version.CheckConditions(_worldState))
|
||
return version.dialogue;
|
||
}
|
||
|
||
return _fallbackDialogue;
|
||
}
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────
|
||
|
||
/// <summary>
|
||
/// 一个对话版本及其激活条件(架构 14_NarrativeModule §7)。
|
||
/// </summary>
|
||
[Serializable]
|
||
public class DialogueVersion
|
||
{
|
||
[Tooltip("编辑器显示名,如'森林 Boss 击败后'")]
|
||
public string versionLabel;
|
||
public DialogueSequenceSO dialogue;
|
||
|
||
[Tooltip("全部满足才激活此版本(AND 关系)")]
|
||
public string[] requiredFlags;
|
||
|
||
[Tooltip("有任意一个 = 此版本不激活(NOT 关系)")]
|
||
public string[] blockedByFlags;
|
||
|
||
/// <summary>检查此版本的激活条件(AND requiredFlags / NOT blockedByFlags)。</summary>
|
||
public bool CheckConditions(WorldStateRegistry registry)
|
||
{
|
||
if (registry == null) return false;
|
||
|
||
if (requiredFlags != null)
|
||
foreach (var f in requiredFlags)
|
||
if (!registry.HasFlag(f)) return false;
|
||
|
||
if (blockedByFlags != null)
|
||
foreach (var f in blockedByFlags)
|
||
if (registry.HasFlag(f)) return false;
|
||
|
||
return true;
|
||
}
|
||
}
|
||
}
|