MaximilianPs

Quest.cs

Sep 5th, 2022
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. public class Quest : ScriptableObject
  2.     {
  3.         [SerializeField] List<Objective> objectives = new List<Objective>();
  4.         [SerializeField] List<Reward> rewards = new List<Reward>();
  5.  
  6.  
  7.         [System.Serializable]
  8.         public class Reward
  9.         {
  10.             [Min(1)]
  11.             public int number;
  12.             public InventoryItem item;
  13.         }
  14.  
  15.         [System.Serializable]
  16.         public class Objective
  17.         {
  18.             public string reference;
  19.             public string description;
  20.             public bool usesCondition = false;
  21.             public Condition completionCondition;
  22.         }
  23.  
  24.         public string GetTitle()
  25.         {
  26.             return name;
  27.         }
  28.  
  29.         public int GetObjectiveCount()
  30.         {
  31.             return objectives.Count;
  32.         }
  33.  
  34.         public IEnumerable<Objective> GetObjectives()
  35.         {
  36.             return objectives;
  37.         }
  38.  
  39.         public IEnumerable<Reward> GetRewards()
  40.         {
  41.             return rewards;
  42.         }
  43.  
  44.         public bool HasObjective(string objectiveRef)
  45.         {
  46.             foreach (var objective in objectives)
  47.             {
  48.                 if(objective.reference == objectiveRef)
  49.                 {
  50.                     return true;
  51.                 }
  52.             }
  53.  
  54.             return false;
  55.         }
  56.  
  57.         private static Dictionary<string, Quest> masterQuestDictionary;
  58.         public static Quest GetByName(string questName)
  59.         {
  60.             if (masterQuestDictionary == null)
  61.             {
  62.                 masterQuestDictionary = new Dictionary<string, Quest>();
  63.                 foreach (Quest quest in Resources.LoadAll<Quest>(""))
  64.                 {
  65.                     if (masterQuestDictionary.ContainsKey(quest.name)) Debug.Log($"There are two {quest.name} quests in the system");
  66.                     else masterQuestDictionary.Add(quest.name, quest);
  67.                 }
  68.             }
  69.  
  70.             return masterQuestDictionary.ContainsKey(questName) ? masterQuestDictionary[questName] : null;
  71.         }
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment