using UnityEngine; using System.Collections.Generic; using System.Linq; using EasyTalk.Nodes; [CreateAssetMenu(fileName = "New Quest", menuName = "RPG/Quest")] public class Quest : ScriptableObject { [Header("Basic Info")] public string questId; public string questName; [TextArea(3, 5)] public string description; [TextArea(2, 4)] public string summary; [Header("Quest Properties")] public int level = 1; public bool isMainQuest = false; public bool isRepeatable = false; public Quest[] prerequisites; [Header("Objectives")] public List objectives = new List(); public string currentObjective; [Header("Rewards")] public int experienceReward = 100; public int goldReward = 50; public string[] itemRewards; // Runtime data (not serialized) [System.NonSerialized] public QuestStatus status = QuestStatus.NotStarted; /// /// Check if all required objectives are completed /// public bool AreRequiredObjectivesCompleted() { return objectives.Where(obj => !obj.isOptional).All(obj => obj.isCompleted); } /// /// Check if all objectives (including optional) are completed /// public bool AreAllObjectivesCompleted() { return objectives.All(obj => obj.isCompleted); } /// /// Get overall quest progress percentage (0-1) /// public float GetProgressPercentage() { if (objectives.Count == 0) return 0f; float totalProgress = objectives.Sum(obj => obj.GetProgressPercentage()); return totalProgress / objectives.Count; } /// /// Get specific objective by ID /// public QuestObjective GetObjective(string objectiveId) { return objectives.FirstOrDefault(obj => obj.objectiveId == objectiveId); } /// /// Reset all objectives /// public void ResetObjectives() { foreach (var objective in objectives) { objective.Reset(); } } /// /// Validate quest data /// public bool IsValid() { if (string.IsNullOrEmpty(questId) || string.IsNullOrEmpty(questName)) return false; if (objectives.Count == 0) return false; // Check for duplicate objective IDs var objectiveIds = objectives.Select(obj => obj.objectiveId).ToList(); return objectiveIds.Count == objectiveIds.Distinct().Count(); } public void GetCurrentObjective(out QuestObjective currentObjective, out int currentIndex) { currentObjective = null; currentIndex = -1; for (int i = 0; i < objectives.Count; i++) { if (!objectives[i].isCompleted) { currentObjective = objectives[i]; currentIndex = i; break; } } } }