For some reason my quests wont complete

im pretty sure the scripts are correct if someone could dumb it down how to make them complete like equiping a weapon ive re watched multiple time and followed but its not working on my end here the quest stuff just incase

public class QuestList : MonoBehaviour, ISaveable, IPredicateEvaluator
{
    List<QuestStatus> statuses = new List<QuestStatus>();

    public event Action onUpdate;

    private void Update()
    {
        CompleteObjectivesByPredicate();
    }

    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 CompleteObjectivesByPredicate()
    {
        foreach (QuestStatus status in statuses)
        {
            if (status.IsComplete()) continue;
            Quest quest = status.GetQuest();
            foreach(var objective in status.GetQuest().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));
        }
    }

    //implement this whenever i use evaulate
    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;
    }

update to this the conditions are fine when i use the predicates and all that stuff it works in my dialogue with npcs but it wont show up or read that its completed in my UI or give me rewards ect if anyone know where i should look or a few steps i can take to check everything again that would be sick

Is this all Quest Completions, or just the ones using Conditions to complete the objective…
In other words, does the classic QuestCompletion component work for you with DialogueTriggers?

all of it seems to be having issues reading its complete and giving me rewards

i was pretty careful to make sure all the strings were spot on so idk whats going on with it

Ok, let’s try the obvious, and test things from the ground up… In CompleteObjective()

public void CompleteObjective(Quest quest, string objective)
{
    QuestStatus status = GetQuestStatus(quest);
    if(status==null)
    {
         Debug.Log($"Player does not have quest {quest.name}");
         return;
     }
     Debug.Log($"Attempting to complete [{objective}] on {quest.name}");
     if (status.IsComplete())
     {
          Debug.Log($"Giving reward for completing {quest.name}");
          GiveReward(quest);
      }
      onUpdate?.Invoke();
}

nothing is coming up in console but i havent touched the quesst stuff since way earlier in the tutorials besides towards the end of shops so i dont remeber how the old conditions were met i have all the debugs in place though

should achievmentounter be using the predicate evaluator

public class AchievementCounter : MonoBehaviour, ISaveable//, //IPredicateEvaluator
{
    private Dictionary<string, int> counts = new Dictionary<string, int>();

    public event System.Action onCountChanged;

    public int AddToCount(string token, int amount, bool onlyIfExists = false)
    {
        if (!counts.ContainsKey(token))
        {
            if (onlyIfExists) return 0;
            counts[token] = amount;
            onCountChanged?.Invoke();
            return amount;
        }
        counts[token] += amount;
        onCountChanged?.Invoke();
        return counts[token];
    }

    public int RegisterCounter(string token, bool overwrite = false)
    {
        if (!counts.ContainsKey(token) || overwrite)
        {
            counts[token] = 0;
            onCountChanged?.Invoke();
        }
        return counts[token];
    }

    public int GetCounterValue(string token)
    {
        if (!counts.ContainsKey(token)) return 0;
        return counts[token];
    }



    public object CaptureState()
    {
        return counts;
    }

    public void RestoreState(object state)
    {
        counts = (Dictionary<string, int>)state;
        onCountChanged?.Invoke();
    }

    public bool? Evaluate(IPredicateEvaluator predicate, string[] parameters)
    {
        //if (predicate == IPredicateEvaluator.HasKilled)
        {
            if (int.TryParse(parameters[1], out int intParameter))
            {
                RegisterCounter(parameters[0]);
                return counts[parameters[0]] >= intParameter;
            }
            return false;
        }
        return null;
    }
}

i dont remember commenting that stuff out but it looks like its just for confirming that you killed something so idk

yes, or Evaluate() will never be called.

that wouldn’t have anything to do with my quest though because its just for defeating something, another thing popped up after uncommenting those and has killed isnt working but ill worry about that once i can finish normal stuff

With the debugs, are you running a QuestCompletion? The Debugs won’t show up until you do something that should trigger a completed quest objective.

At this point, since nothing appears to be happening, I would set up a simple Dialogue with Trigger to give a quest, and another with a trigger to Complete it, throw it on a couple of NPCs and test. From there, we’ll work up to completions.

tried changeing stuff an getting somethin to trigger when i equip the weapon it will change the dialoge on the npc but in my list it wont show and i wont get the rewrads i noticed in my status script i have an un used variable i cant remeber what it was from maybe this is the issue public class QuestStatus
{
Quest quest;
List completedObjectives = new List();
private object objectState;

    [System.Serializable]
    class QuestStatusRecord
    {
        public string questName;
        public List<string> completedObjectives;
    }

    public QuestStatus(Quest quest)
    {
        this.quest = quest;
    }

    public QuestStatus(object objectState)
    {
        QuestStatusRecord state = objectState as QuestStatusRecord;
        quest = Quest.GetByName(state.questName);
        completedObjectives = state.completedObjectives;
    }

    public bool IsComplete()
    {
        foreach (var objective in quest.GetObjectives())
        {
            if (completedObjectives.Contains(objective.reference))
            {
                return false;
            }
        }
        return true;
    }

    public Quest GetQuest()
    {
        return quest;
    }

    public int GetCompletedCount()
    {
        return completedObjectives.Count;
    }

    public bool IsObjectiveComplete(string objective)
    {
        return completedObjectives.Contains(objective);
    }

    public void CompleteObjective(string objective)
    {
        if (quest.HasObjective(objective))
        {
            completedObjectives.Add(objective);
        }
    }

    public object CaptureState()
    {
        QuestStatusRecord state = new QuestStatusRecord();
        state.questName = quest.name;
        state.completedObjectives = completedObjectives;
        return state;
    }
}

just double checked in the rpg project the gave us and its not relevant i think it was from early in the quest series

I might suggest reviewing the Dialogues and Quests course to refresh your memory, and check your code against Ben’s original code…

so i got a reward however it isnt updating on my quest ui



i has 100 currency before getting the trigger the second time talking to him again but it still didnt give it to me upon equipping the weapon being that thats the only objective in the quest and still dosnt update on the ui

i just now did that thats how i got the reward just now i re watched the completion one but in the newer version of it he dosnt bring up the quest comepletion component

actually the weapon being equipped is irellevant it give the reward whenever i talk to the npc

I see you have both the quest assignment and quest completion on the same DialogueTrigger…
Create a second DialogueTrigger with something like GiveReward for the Completeobjective trigger action. Then you can test that with a different branch of the dialogue.

That being said, it does appear that the Quest reward system is working as intended.

Privacy & Terms