using System; using System.Collections.Generic; using System.Linq; using UnityEngine; public class QuestRegistry : MonoBehaviour { // This will keep a register of all quest data and status public static QuestRegistry Instance { get; private set; } public Dictionary QuestBoolMap; public List CompletedQuests; public List ActiveQuests; private void Awake() { // If there is an instance, and it's not me, delete myself. if (Instance != null && Instance != this) { Destroy(this); } else { Instance = this; Instance.QuestBoolMap = PopulateQuestData(); PopulateQuestData(); DontDestroyOnLoad(gameObject); } } private Dictionary PopulateQuestData() { Dictionary questBoolMap = new Dictionary(); // Quest Bool Structure: QID__ // Example: QID11_4_landBurgerGreaseCleared #region 1 - Sam's Plea QuestBool[] QID1_List = new QuestBool[2]; // QID1_1_hasEnoughStarshards QID1_List[0] = new QuestBool(() => { return GameManager.Instance.StarShards > 2; }); // QID1_2_hasHelpedSam QID1_List[1] = new QuestBool(() => { return GameManager.Instance.Storybools.hasHelpedSam; }); questBoolMap.Add(1, QID1_List); #endregion return questBoolMap; } // Save completed quests to disk public void SaveQuestData(ref QuestSaveData data) { data.ActiveQuests = Instance.ActiveQuests; data.CompletedQuests = Instance.CompletedQuests; } public void LoadQuestData(QuestSaveData data) { if (data.ActiveQuests != null) { Instance.ActiveQuests = data.ActiveQuests; } else { Instance.ActiveQuests = new List(); } if (data.CompletedQuests != null) { Instance.CompletedQuests = data.CompletedQuests; } else { Instance.CompletedQuests = new List(); } } } public class QuestBool { // This let's us define complex behavior for quests. We can also store // raw booleans for this if we have story beats we want to keep track of. public Func getValue; public QuestBool(Func getValue) { this.getValue = getValue; } } [System.Serializable] public struct QuestSaveData { public List CompletedQuests; public List ActiveQuests; }