Ejemplo n.º 1
0
    private void enterNode(int nodeIndex, bool instantStep = false)
    {
        if (this.m_NodeEnteredCallback != null)
        {
            this.m_NodeEnteredCallback(nodeIndex);
        }

        this.m_CurrentNode    = nodeIndex;
        this.m_CurrentAction  = -1;
        this.m_ShowingAnswers = false;

        VerbalNode node = this.m_Data.getNode(nodeIndex);

        if (node.group || instantStep)
        {
            int[] nextNodes = getNextNodes(this.m_CurrentNode, true);
            if (nextNodes.Length > 0)
            {
                enterNode(nextNodes[0]);
            }
            else
            {
                onConversationEnded();
            }
            return;
        }

        nextAction();
    }
Ejemplo n.º 2
0
    private int[] getNextNodes(int nodeID, bool justOne = false)
    {
        List <int> nodes = new List <int>();
        VerbalNode node  = this.m_Data.getNode(nodeID);
        VerbalNode linkedNode;

        int[] linkedNodes;
        bool  condsValid;

        if (node.links != null)
        {
            foreach (int link in node.links)
            {
                linkedNode = this.m_Data.getNode(link);
                if (linkedNode == null)
                {
                    continue;
                }

                if (this.m_TestCondCallback != null && linkedNode.conds != null)
                {
                    condsValid = true;
                    foreach (string cond in linkedNode.conds)
                    {
                        if (!this.m_TestCondCallback(cond))
                        {
                            condsValid = false;
                            break;
                        }
                    }
                    if (!condsValid)
                    {
                        continue;
                    }
                }

                if (linkedNode.group)
                {
                    linkedNodes = getNextNodes(link, justOne);
                    nodes.AddRange(linkedNodes);
                }
                else
                {
                    nodes.Add(link);
                }
                if (justOne)
                {
                    break;
                }
            }
        }

        return(nodes.ToArray());
    }
Ejemplo n.º 3
0
    public VerbalData( VerbalNode[] data )
    {
        this.data = data;
        this.nodeMap = new Dictionary<int,VerbalNode>();
        List<VerbalNode> globalNodesList = new List<VerbalNode>();
        foreach (VerbalNode n in data)
		{
            this.nodeMap.Add(n.id, n);
            if (n.global)
            {
                globalNodesList.Add(n);
            }
		}
        this.globalNodes = globalNodesList.ToArray();
    }
Ejemplo n.º 4
0
    private void nextAction()
    {
        // process node
        this.m_CurrentAction++;
        Debug.Log("processing node " + this.m_CurrentNode + " action " + this.m_CurrentAction);
        VerbalNode    node    = this.m_Data.getNode(this.m_CurrentNode);
        List <string> answers = null;

        if (this.m_CurrentAction < node.actions.Count - 1)
        {
            // non-last actions
            this.m_NextLinks = null;
        }
        else
        {
            // last action in the node, fetch links
            int[] nextNodeIDs = getNextNodes(this.m_CurrentNode);

            Debug.Log("fetched links " + nextNodeIDs.Length + ", processing...");
            VerbalNode nextNode;
            answers = new List <string>();
            List <int> nextLinks = new List <int>();
            foreach (int nextNodeID in nextNodeIDs)
            {
                nextNode = this.m_Data.getNode(nextNodeID);
                if (nextNode.conds != null && nextNode.conds.Count > 0)
                {
                    answers.Add(nextNode.conds[0]);
                    nextLinks.Add(nextNodeID);
                }
            }
            if (answers.Count == 0)
            {
                // no answer links, simple continue hop
                if (nextNodeIDs.Length > 0)
                {
                    nextLinks = new List <int>()
                    {
                        nextNodeIDs[0]
                    };
                }
                else
                {
                    nextLinks = new List <int>()
                    {
                        -1
                    };                               // will end conversation
                }
                answers = null;
            }
            else
            {
                this.m_ShowingAnswers = true;
            }
            this.m_NextLinks = nextLinks.ToArray();
        }

        // action with continue
        string[] answersArray = null;
        if (answers != null)
        {
            answersArray = answers.ToArray();
        }
        this.m_ShowNodeCallback(node.actions[this.m_CurrentAction], answersArray);
    }