Conditional Quest dialogues not working

I cannot figure out why the conditional quest objectives don’t seem to work. When I activate a quest, I still get the first dialogue option that is only supposed to activate if I don’t have the quest.

The conditions work for the other conditional objectives (equipped item, stat requirements), but for the life of me I cannot figure out why this one won’t. I have quadruple checked names, copied and pasted, checked all the code and redone the lecture 3 times but no luck. Is there anything that is likely to be causing this?

Let’s start by looking in your QuestList.cs at your Evaluate method. Actually, just so we can be sure, include your entire QuestList.cs script.

using System;
using System.Collections;
using System.Collections.Generic;
using GameDevTV.Inventories;
using GameDevTV.Saving;
using GameDevTV.Utils;
using UnityEngine;
namespace RPG.Quests
{
    public class QuestList : MonoBehaviour, ISaveable, IPredicateEvaluator
    {
        List<QuestStatus> statuses = new List<QuestStatus>();

        public event Action onUpdate;

        private void Update()
        {
            CompleteObjectivesByPredicates();
        }

        public void AddQuest(Quest quest)
        {
            if (HasQuest(quest)) return;
            QuestStatus newStatus = new QuestStatus(quest);
            statuses.Add(newStatus);
            if (onUpdate != null)
            {
                onUpdate();
            }
        }
        public void CompleteObjective(Quest quest, string objective)
        {
            QuestStatus status = GetQuestStatus(quest);
            status.CompleteObjective(objective);
            if (status.IsComplete())
            {
                GiveReward(quest);
            }
            if (onUpdate != null)
            {
                onUpdate();
            }
        }
        public bool HasQuest(Quest quest)
        {
            return GetQuestStatus(quest) != null;
        }
        public IEnumerable<QuestStatus> GetStatuses()
        {
            return statuses;
        }
        private QuestStatus GetQuestStatus(Quest quest)
        {
            foreach (QuestStatus status in statuses)
            {
                if (status.GetQuest() == quest)
                {
                    return status;
                }
            }
            return null;
        }
        private void GiveReward(Quest quest)
        {
            foreach (var reward in quest.GetRewards())
            {
                bool success = GetComponent<Inventory>().AddToFirstEmptySlot(reward.item, reward.number);
                if (!success)
                {
                    GetComponent<ItemDropper>().DropItem(reward.item, reward.number);
                }
            }
        }

        private void CompleteObjectivesByPredicates()
        {
            foreach (QuestStatus status in statuses)
            {
                if (status.IsComplete()) continue;
                Quest quest = status.GetQuest();
                foreach (var objective in quest.GetObjectives())
                {
                    if (status.IsObjectiveComplete(objective.reference)) continue;
                    if (!objective.usesCondition) continue;
                    if (objective.completionCondition.Check(GetComponents<IPredicateEvaluator>()))
                    {
                        CompleteObjective(quest, objective.reference);
                    }
                }
            }
        }

        public object CaptureState()
        {
            List<object> state = new List<object>();
            foreach (QuestStatus status in statuses)
            {
                state.Add(status.CaptureState());
            }
            return state;
        }
        public void RestoreState(object state)
        {
            List<object> stateList = state as List<object>;
            if (stateList == null) return;
            statuses.Clear();
            foreach (object objectState in stateList)
            {
                statuses.Add(new QuestStatus(objectState));
            }
        }
        public bool? Evaluate(string predicate, string[] parameters)
        {
            switch (predicate)
            {
                case "HasQuest":
                    return HasQuest(Quest.GetByName(parameters[0]));
                case "CompletedQuest":
                    return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();
            }
            return null;
        }
    }
}

Ok, now let’s make sure that we’re getting the Quests when we do Quest.GetByName(parameters[0])

        public bool? Evaluate(string predicate, string[] parameters)
        {
            switch (predicate)
            {
                case "HasQuest":
                    Debug.Log($"Testing Predicate HasQuest({parameters[0]})");
                    return HasQuest(Quest.GetByName(parameters[0]));
                case "CompletedQuest":
                    return GetQuestStatus(Quest.GetByName(parameters[0])).IsComplete();
            }
            return null;
        }

Now… you’re looking to see if you’re getting that test of HasQuest, and that the Quest name is correct.
If those are correct, make sure that your Quest is in a folder named Resources (or a subfolder of a folder named Resources. Case is extremely important here. It must be Resources, not resources, and the name of the Quest must match exactly.

Thank you so so much! The “Resources” got me. You are a legend!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms