refactor: Round 53 remove all legacy backward-compatibility code
- QuestSO: remove giverNpcId, prerequisiteQuests/Flags/FlagsLogic, failCondition, conditionFlags, npcDialogueKey fields; simplify GiverNpcId property to giverNpc?.npcId; clean ValidatePrerequisiteCycles/HasPrerequisiteCycle to use prerequisites.questDependencies; remove ValidateBranchDialogueKeys migration warning block; clean QuestPrerequisite doc - QuestManager: remove OnLoad DataVersion 1/2 migration paths (ProgressCounts, hasNewFormat/ useNewFormat); remove CheckQuestDepsAndFlags old-field fallback (prerequisiteQuests/Flags); remove UnlockBranches conditionFlags fallback; remove DispatchEvent failCondition fallback; fix ValidatePrerequisites DFS to scan prerequisites.questDependencies - SaveData: remove ProgressCounts (Obsolete), ObjectiveIndex (unused), GiverNpcId (never written) fields from QuestState; simplify DataVersion doc comment - QuestSOEditor: replace migration-only editor with minimal DrawDefaultInspector - QuestModule: update all prerequisiteQuests/conditionFlags/npcDialogueKey/failCondition references to canonical new fields; update ValidateBranchFlags check 10 - FlagAuditModule: replace conditionFlags/prerequisiteFlags scans with conditionFlagEntries/ prerequisites.flagCondition.flags - NpcSO: remove QuestSO.giverNpcId reference from npcId tooltip - NpcAffinityEvent/RewardSO: update doc comments to reference giverNpc instead of giverNpcId Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -16,21 +16,13 @@ namespace BaseGames.Quest
|
||||
[Tooltip("任务唯一 ID,如 \"Quest_FindMushroom\"。运行时由 QuestManager 以此为键索引,必须全局唯一。")]
|
||||
public string questId;
|
||||
|
||||
[Tooltip("发布/完成该任务的 NPC(直接引用 NpcSO 资产,推荐)。\n" +
|
||||
[Tooltip("发布/完成该任务的 NPC(直接引用 NpcSO 资产)。\n" +
|
||||
"用于完成任务后向该 NPC 应用 affinityBonus,及 CanAccept 好感度门槛检查。\n" +
|
||||
"留空时跳过好感度相关逻辑;与旧字段 giverNpcId 同时有值时以此 SO 为准。")]
|
||||
"留空时跳过好感度相关逻辑。")]
|
||||
public NpcSO giverNpc;
|
||||
|
||||
[System.Obsolete("已废弃,请改用 giverNpc(NpcSO 直接引用)。保留以兼容现有资产序列化。")]
|
||||
[HideInInspector]
|
||||
public string giverNpcId;
|
||||
|
||||
/// <summary>运行时使用的 NPC ID:giverNpc 优先,回退到旧字段 giverNpcId。</summary>
|
||||
public string GiverNpcId => (giverNpc != null && !string.IsNullOrEmpty(giverNpc.npcId))
|
||||
? giverNpc.npcId
|
||||
#pragma warning disable CS0618
|
||||
: giverNpcId;
|
||||
#pragma warning restore CS0618
|
||||
/// <summary>运行时使用的 NPC ID(来自 giverNpc.npcId)。</summary>
|
||||
public string GiverNpcId => giverNpc != null ? giverNpc.npcId : string.Empty;
|
||||
|
||||
[Tooltip("本地化 Key,格式如 \"Quest_FindMushroom_Name\"。通过 LocalizationManager.Get(displayNameKey, \"Quest\") 显示。")]
|
||||
public string displayNameKey;
|
||||
@@ -52,28 +44,9 @@ namespace BaseGames.Quest
|
||||
public QuestObjectiveSO[] objectives;
|
||||
|
||||
[Header("前置条件")]
|
||||
[Tooltip("任务前置条件(统一配置版)。将前置任务依赖和世界标志依赖合并为单一结构,便于 Inspector 管理。\n" +
|
||||
"如旧版字段(prerequisiteQuests / prerequisiteFlags)已有数据,运行时将自动回退使用旧版字段,无需手动迁移。")]
|
||||
[Tooltip("任务前置条件(前置任务依赖 + 世界标志依赖)。留空表示无前置限制。")]
|
||||
public QuestPrerequisite prerequisites = new QuestPrerequisite();
|
||||
|
||||
// ── 旧版前置字段(向后兼容,新配置请改用 prerequisites)────────────────
|
||||
[HideInInspector]
|
||||
[Tooltip("【已归入 prerequisites.questDependencies,此字段仅用于旧资产兼容】\n" +
|
||||
"所有前置任务必须处于 Completed 状态,本任务才能被接取。\n" +
|
||||
"⚠ 此字段计划在 v2.0 移除,请尽快通过 QuestSOEditor 迁移至 prerequisites。")]
|
||||
public QuestSO[] prerequisiteQuests;
|
||||
|
||||
[HideInInspector]
|
||||
[Tooltip("【已归入 prerequisites.flagCondition.logic,此字段仅用于旧资产兼容】\n" +
|
||||
"⚠ 此字段计划在 v2.0 移除,请尽快通过 QuestSOEditor 迁移至 prerequisites。")]
|
||||
public BaseGames.Core.WorldStateFlagLogic prerequisiteFlagsLogic = BaseGames.Core.WorldStateFlagLogic.And;
|
||||
|
||||
[HideInInspector]
|
||||
[Tooltip("【已归入 prerequisites.flagCondition.flags,此字段仅用于旧资产兼容】\n" +
|
||||
"⚠ 此字段计划在 v2.0 移除,请尽快通过 QuestSOEditor 迁移至 prerequisites。")]
|
||||
[BaseGames.Core.WorldStateFlag]
|
||||
public string[] prerequisiteFlags;
|
||||
|
||||
[Tooltip("接取本任务所需的 NPC 好感度下限(0 = 无限制)。由好感度系统提供实际数值。")]
|
||||
public int minAffinityToAccept;
|
||||
|
||||
@@ -88,10 +61,6 @@ namespace BaseGames.Quest
|
||||
[Tooltip("失败判定目标列表(任意一个达成即失败)。canFail=true 时有效。\n" +
|
||||
"支持多个失败条件(如「BOSS 在限时内未被击败」OR「关键 NPC 死亡」)。")]
|
||||
public QuestObjectiveSO[] failConditions;
|
||||
[System.Obsolete("已废弃,请改用 failConditions(数组,支持多个失败条件)。保留以兼容现有资产序列化。")]
|
||||
[HideInInspector]
|
||||
[Tooltip("(旧版单一失败条件,已被 failConditions 数组取代。保留以兼容现有资产。)")]
|
||||
public QuestObjectiveSO failCondition;
|
||||
|
||||
[Header("接取/完成对话")]
|
||||
[Tooltip("玩家接取任务时自动触发的 NPC 对话序列(如 NPC 委托台词)。\n" +
|
||||
@@ -182,10 +151,7 @@ namespace BaseGames.Quest
|
||||
var visited = new System.Collections.Generic.HashSet<string>(System.StringComparer.Ordinal);
|
||||
visited.Add(questId);
|
||||
|
||||
#pragma warning disable CS0618
|
||||
QuestSO[] deps = prerequisites.HasAny ? prerequisites.questDependencies : prerequisiteQuests;
|
||||
#pragma warning restore CS0618
|
||||
|
||||
QuestSO[] deps = prerequisites.questDependencies;
|
||||
if (deps == null) return;
|
||||
|
||||
foreach (var dep in deps)
|
||||
@@ -196,7 +162,7 @@ namespace BaseGames.Quest
|
||||
Debug.LogError(
|
||||
$"[QuestSO] '{name}'(questId='{questId}')的前置任务链存在循环依赖!" +
|
||||
$"前置任务 '{dep.name}' 最终指回自身或已访问任务," +
|
||||
"运行时将导致任务无法被接取。请检查 prerequisites/prerequisiteQuests 配置。", this);
|
||||
"运行时将导致任务无法被接取。请检查 prerequisites 配置。", this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -218,9 +184,7 @@ namespace BaseGames.Quest
|
||||
if (string.IsNullOrEmpty(quest.questId)) return false;
|
||||
if (!visited.Add(quest.questId)) return true; // 已在当前路径上 = 环路
|
||||
|
||||
#pragma warning disable CS0618
|
||||
QuestSO[] deps = quest.prerequisites.HasAny ? quest.prerequisites.questDependencies : quest.prerequisiteQuests;
|
||||
#pragma warning restore CS0618
|
||||
QuestSO[] deps = quest.prerequisites.questDependencies;
|
||||
|
||||
if (deps != null)
|
||||
{
|
||||
@@ -288,23 +252,7 @@ namespace BaseGames.Quest
|
||||
|
||||
private void ValidateBranchDialogueKeys()
|
||||
{
|
||||
if (branches == null || branches.Length == 0) return;
|
||||
|
||||
foreach (var branch in branches)
|
||||
{
|
||||
if (branch == null) continue;
|
||||
|
||||
// npcDialogueSequence 是 SO 直接引用,无需字符串校验。
|
||||
// 旧字段 npcDialogueKey(Obsolete)有值时提示迁移。
|
||||
#pragma warning disable CS0618
|
||||
if (!string.IsNullOrEmpty(branch.npcDialogueKey) && branch.npcDialogueSequence == null)
|
||||
{
|
||||
Debug.LogWarning(
|
||||
$"[QuestSO] '{name}' 分支仍使用旧字段 npcDialogueKey='{branch.npcDialogueKey}'," +
|
||||
"请迁移至 npcDialogueSequence(直接拖入 DialogueSequenceSO)。", this);
|
||||
}
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
// npcDialogueSequence 是 SO 直接引用;旧字符串字段已移除。
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -318,20 +266,12 @@ namespace BaseGames.Quest
|
||||
" And(默认)= 全部 conditionFlagEntries 均满足才走本分支\n" +
|
||||
" Or = 任意一个 conditionFlagEntry 满足即可走本分支")]
|
||||
public BaseGames.Core.WorldStateFlagLogic conditionFlagsLogic = BaseGames.Core.WorldStateFlagLogic.And;
|
||||
[Tooltip("世界状态标志条件(支持 invert 取反)。按 conditionFlagsLogic 逻辑与 conditionQuest 共同决定分支是否激活。\n" +
|
||||
"优先使用此字段;若为空则自动回退到旧版 conditionFlags 以保证兼容性。")]
|
||||
[Tooltip("世界状态标志条件(支持 invert 取反)。按 conditionFlagsLogic 逻辑与 conditionQuest 共同决定分支是否激活。")]
|
||||
public BranchFlagEntry[] conditionFlagEntries;
|
||||
[Tooltip("(旧版兼容字段,已被 conditionFlagEntries 取代。如 conditionFlagEntries 不为空则本字段被忽略。)")]
|
||||
[HideInInspector]
|
||||
public string[] conditionFlags;
|
||||
[Tooltip("本分支解锁的后续任务。满足所有条件后,此任务将被设为 Available。")]
|
||||
public QuestSO nextQuest;
|
||||
[Tooltip("完成本任务后触发的 NPC 对话序列(直接引用 DialogueSequenceSO 资产,无需手写 ID)。")]
|
||||
public DialogueSequenceSO npcDialogueSequence;
|
||||
|
||||
[System.Obsolete("已废弃,请改用 npcDialogueSequence(直接 SO 引用)。保留字段以兼容现有资产序列化。")]
|
||||
[HideInInspector]
|
||||
public string npcDialogueKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -365,10 +305,7 @@ namespace BaseGames.Quest
|
||||
// =========================================================================
|
||||
|
||||
/// <summary>
|
||||
/// 任务前置条件统一配置结构。
|
||||
/// 将旧版三个独立字段(prerequisiteQuests / prerequisiteFlags / prerequisiteFlagsLogic)
|
||||
/// 合并为单一可序列化类,便于 Inspector 统一管理与代码维护。
|
||||
/// 运行时通过 <see cref="HasAny"/> 判断是否启用新格式;若未配置则自动回退到旧版字段。
|
||||
/// 任务前置条件统一配置结构,将前置任务依赖和世界状态标志依赖合并为单一可序列化类。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class QuestPrerequisite
|
||||
@@ -379,7 +316,7 @@ namespace BaseGames.Quest
|
||||
[Tooltip("世界状态标志前置条件(支持 And / Or 逻辑)。")]
|
||||
public FlagCondition flagCondition;
|
||||
|
||||
/// <summary>此前置结构是否配置了任何条件(用于判断是否启用新格式,回退到旧字段)。</summary>
|
||||
/// <summary>此前置结构是否配置了任何条件。</summary>
|
||||
public bool HasAny =>
|
||||
(questDependencies != null && questDependencies.Length > 0) ||
|
||||
(flagCondition.flags != null && flagCondition.flags.Length > 0);
|
||||
|
||||
Reference in New Issue
Block a user