Example #1
0
    /// <summary>
    /// Determines how many branches a node has given the active quest state
    /// </summary>
    private int CountNumActiveChildren()
    {
        int children = 0;

        // Get the active quest and its current state if they exist
        Quest currentQuest = GameManager.instance.GetActiveQuest();

        Quest.QuestState state = Quest.QuestState.inactive;

        if (currentQuest != null)
        {
            state = currentQuest.GetCurrentState();
        }

        foreach (DialogueNode.DialogueBranchCondition dbc in currentNode.childNodes)
        {
            // If the condition matches the current quest state, then it is a possible condition
            if ((dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.cleared) && state.Equals(Quest.QuestState.completed)) ||
                (dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.failed) && state.Equals(Quest.QuestState.failed)) ||
                (dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.active) && state.Equals(Quest.QuestState.active)) ||
                dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.none))
            {
                children++;
            }
        }

        return(children);
    }
Example #2
0
    /// <summary>
    /// Advances to the next node. It also contains behavior for ending a dialogue
    /// </summary>
    public void Next()
    {
        // This button does nothing if the text is automatically being displayed.
        if (currentNode.auto.isAuto && !forceNext)
        {
            return;
        }

        // If the player attempts to advance while text is printing, abort the printing and return.
        if (isPrinting)
        {
            textBox.text = currentNode.dialogueText.Replace("[PLAYER]", "name");
            StopCoroutine(textPrint);
            isPrinting = false;
            return;
        }

        // Last one in the list
        if ((CountNumActiveChildren() == 0) || currentNode == null)
        {
            // Enables the player's movement, and allows the quest giver to be interacted with again
            dialogueUI.SetActive(false);
            GameManager.instance.EnablePlayerMovement();
            GameManager.instance.EndQuestFirstEncounter();
            GameManager.instance.ToggleQuestInteractivity(true);
            return;
        }

        // Get the active quest and its current state if they exist
        Quest currentQuest = GameManager.instance.GetActiveQuest();

        Quest.QuestState state = Quest.QuestState.inactive;

        if (currentQuest != null)
        {
            state = currentQuest.GetCurrentState();
        }

        // Which child do we advance to?
        foreach (DialogueNode.DialogueBranchCondition dbc in currentNode.childNodes)
        {
            // If the quest is cleared, use the child with that condition
            if (dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.cleared) && state.Equals(Quest.QuestState.completed))
            {
                currentNode = currentTree.GetNode(dbc.targetID);
                break;
            }

            // If the quest is failed, use the child with that condition
            else if (dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.failed) && state.Equals(Quest.QuestState.failed))
            {
                currentNode = currentTree.GetNode(dbc.targetID);
                break;
            }

            // If the quest is active, use the child with that condition
            else if (dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.active) && state.Equals(Quest.QuestState.active))
            {
                currentNode = currentTree.GetNode(dbc.targetID);
                break;
            }

            // Otherwise, just use the default condition. This one must always be last.
            else if (dbc.condition.Equals(DialogueNode.DialogueBranchCondition.Condition.none))
            {
                currentNode = currentTree.GetNode(dbc.targetID);
                break;
            }
        }

        firstLine = false;

        // Processes the node
        ProcessCurrentNode();

        forceNext = false;
    }