Page 1 of 1

Activate next quest node

Posted: Sat Jun 10, 2023 7:05 pm
by shortestyard57
I am attempting to write a debug command that would allow me to step through a quest. Is there a method that progresses a quest one node? Looked on the forum and API but no luck so far.

Re: Activate next quest node

Posted: Sat Jun 10, 2023 9:54 pm
by Tony Li
Hi,

Yes, you can either:

1. Cause the conditions to be true -- for example, call MessageSystem.SendMessage() if the conditions are waiting for a message.

2. Or manually set a node's state by calling QuestMachine.SetQuestNodeState().

Re: Activate next quest node

Posted: Sun Jun 11, 2023 7:34 am
by shortestyard57
Is there a way to do it without having to specify the quest node ID? For example, I am hoping to create a debug function that will accept the quest ID as the input and then regardless which node it is on, progress to the next linked node. If the nodes are indexed then move from node n to node n + 1.

Re: Activate next quest node

Posted: Sun Jun 11, 2023 10:07 am
by Tony Li
Hi,

That would be fine if all quests were entirely linear. But Quest Machine is more flexible than that. Your quests can branch, or even loop back on themselves. To do it properly in these cases, make a list of all nodes that are active. Then set them true.

Code: Select all

public void AdvanceQuest(Quest quest)
{
    var activeNodes = quest.nodeList.FindAll(node => node.GetState() == QuestNodeState.Active);
    activeNodes.ForEach(node => node.SetState(QuestNodeState.True));
}

Re: Activate next quest node

Posted: Tue Jun 13, 2023 8:16 am
by shortestyard57
Is there a way to get the Quest class by its string name?

Re: Activate next quest node

Posted: Tue Jun 13, 2023 8:42 am
by Tony Li
Hi,

What do you mean by quest class?

Re: Activate next quest node

Posted: Tue Jun 13, 2023 3:53 pm
by shortestyard57
Sorry I mean the Quest asset by its quest ID.

This is the method I am working on.

Code: Select all

 public void AdvanceQuest(string questName)
    {
        string[] currentQuests = QuestLog.GetAllQuests();
        for (int i = 0; i < currentQuests.Length; i++)
        {
            if(questName == currentQuests[i])
            {                                
                Quest quest = //get Quest asset with the string name.
            }
        }

        var activeNodes = quest.nodeList.FindAll(node => node.GetState() == QuestNodeState.Active);
        activeNodes.ForEach(node => node.SetState(QuestNodeState.True));
    }

Re: Activate next quest node

Posted: Tue Jun 13, 2023 4:25 pm
by shortestyard57
I found GetQuestInstance() that should work if I understand it correctly.

Code: Select all

public void AdvanceQuest(string questName)
    {
        PixelCrushers.QuestMachine.Quest quest = null;

        string[] currentQuests = QuestLog.GetAllQuests();
        for (int i = 0; i < currentQuests.Length; i++)
        {
            if (questName == currentQuests[i])
            {
                quest = QuestMachine.GetQuestInstance(currentQuests[i]);
            }
        }
        
        if (quest == null) { return; }

        var activeNodes = quest.nodeList.FindAll(node => node.GetState() == QuestNodeState.Active);
        activeNodes.ForEach(node => node.SetState(QuestNodeState.True));
    }

Re: Activate next quest node

Posted: Tue Jun 13, 2023 4:36 pm
by Tony Li
Hi,

Yes, that's correct. You can control most Quest Machine things using the QuestMachine class.