Search Unity

Add active quests to a quest log

Discussion in 'Scripting' started by Calmax, Sep 12, 2019.

  1. Calmax

    Calmax

    Joined:
    Aug 8, 2017
    Posts:
    26
    Hi all,

    I am creating an RPG which has a working quest assign system. However, I am confused with how to add the quests name and description to the UI and end up running into errors.

    The quests assign correctly and complete under the correct conditions. I have a quest log that appears then the user presses the "Q" key.

    Any advice on how to tackle this would be greatly appreciated!

    The quest manager code:

    Code (CSharp):
    1.  
    2. public class Quest: MonoBehaviour
    3.  
    4.     public List<Quest> Quests { get; set; }
    5.     public List<Goal> Goals { get; set; } = new List<Goal>();
    6.     public string QuestName { get; set; }
    7.     public string Description { get; set; }
    8.     public int ExperienceReward { get; set; }
    9.  
    10.     public bool Completed { get; set; }
    11.  
    12.     public void CheckGoals()
    13.     {
    14.         Completed = Goals.All(g => g.Completed);
    15.         if (Completed) GiveReward();
    16.     }
    17.  
    18.     void GiveReward()
    19.     {
    20.         Debug.Log("Player given reward.");
    21.     }
    22. }
    23.  
    And the quest giver code:

    Code (CSharp):
    1. public class QuestGiver : NPC
    2. {
    3.     public List<Quest> Quests { get; set; } = new List<Quest>();
    4.     public bool AssignedQuest { get; set; }
    5.     public bool Helped { get; set; }
    6.  
    7.     [SerializeField]
    8.     private GameObject quests;
    9.  
    10.     [SerializeField]
    11.     private string questType;
    12.  
    13.     private Quest Quest { get; set; }
    14.  
    15.     public override void Interact()
    16.     {
    17.        
    18.         if (!AssignedQuest && !Helped)
    19.         {
    20.             base.Interact();
    21.             AssignQuest();
    22.         }
    23.         else if (AssignedQuest && !Helped)
    24.         {
    25.             CheckQuest();
    26.         }
    27.         else
    28.         {
    29.             DialogueSystem.Instance.AddNewDialogue(new string[] { "Appreciate you helping me out, adventurer!" }, name);
    30.         }
    31.     }
    32.  
    33.     void AssignQuest()
    34.     {
    35.         AssignedQuest = true;
    36.         Quest = (Quest)quests.AddComponent(System.Type.GetType(questType));
    37.         //Quest.Quests.Add(Quest);
    38.         AddToQuestLog();
    39.     }
    40.  
    41.     void CheckQuest()
    42.     {
    43.         if (Quest.Completed)
    44.         {
    45.             Helped = true;
    46.             AssignedQuest = false;
    47.             DialogueSystem.Instance.AddNewDialogue(new string[] { "Thanks! Here's your reward!", "You're the best" }, name );
    48.         }
    49.         else
    50.         {
    51.             DialogueSystem.Instance.AddNewDialogue(new string[] { "Did you get that task done for me?"}, name);
    52.         }
    53.     }
    54.  
    55.     void AddToQuestLog()
    56.     {
    57.         Debug.Log("Quest added to log!");
    58.         //questName.text = Quests[0].QuestName;
    59.         //questDescription.text = Quests[0].Description;
    60.     }
    61.  
    62. }
     
    Last edited: Sep 12, 2019
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    I suggest not to coouple log tightly to quest system. Create a LogEntry class and a UI to display list of such entries. After that you may create game events like quest given / quest completed and when such events appears in game add new LogEntry to the log