using System; using System.Collections.Generic; [Serializable] public class QuestState { public QuestData questData; public QuestStatus status; public List goalProgress = new List(); public QuestState(QuestData quest) { questData = quest; status = QuestStatus.Active; int goalCount = quest != null && quest.goals != null ? quest.goals.Count : 0; for (int i = 0; i < goalCount; i++) { goalProgress.Add(0); } } public bool IsGoalComplete(int index) { if (questData == null || index < 0 || index >= questData.goals.Count) { return false; } return GetProgress(index) >= questData.goals[index].requiredAmount; } public int GetProgress(int index) { if (index < 0 || index >= goalProgress.Count) { return 0; } return goalProgress[index]; } public void AddProgress(int index, int amount) { if (questData == null || index < 0 || index >= questData.goals.Count || amount <= 0) { return; } while (goalProgress.Count < questData.goals.Count) { goalProgress.Add(0); } int required = questData.goals[index].requiredAmount; goalProgress[index] = Math.Min(required, goalProgress[index] + amount); } public bool AreAllGoalsComplete() { if (questData == null || questData.goals == null || questData.goals.Count == 0) { return false; } for (int i = 0; i < questData.goals.Count; i++) { if (!IsGoalComplete(i)) { return false; } } return true; } }