private void ProcessNode(ConversationElement element, IConversationReader reader) { Debug.Log("Processing Element " + element.type); currentElement = element; switch (element.type) { case ConversationElementType.Text: reader.DisplayText(reader.KeywordReplace(element.text)); break; case ConversationElementType.Set: conversationVariables.Add(element.setKey, element.setValue); break; case ConversationElementType.Choice: List <string> keywordedChoices = new List <string>(); foreach (string choice in element.choices) { keywordedChoices.Add(reader.KeywordReplace(choice)); } reader.DisplayChoice(keywordedChoices, GetChoiceResponse); waitingOnChoice = true; return; case ConversationElementType.Branch: for (int i = 0; i < element.branchVariables.Count; i++) { //i is the branch we're checking bool metCondtions = true; for (int j = 0; j < element.branchVariables[i].Count; j++) { //j is the condition of branch i that we're checking if (conversationVariables.ContainsKey(element.branchVariables[i][j])) { if (conversationVariables[element.branchVariables[i][j]] != element.branchConditions[i][j]) { metCondtions = false; } } } if (metCondtions) { nextElement = elements[element.branchResults[i]]; break; } } //no branch conditions met, so continue to use the next element break; } }
public void StartTree(ConversationElement element, IConversationReader reader) { currentReader = reader; ProcessNode(element, reader); if (currentElement.next <= -1) { Debug.Log("Tree is one node long"); currentReader.EndConversation(); } else if (currentElement.next >= elements.Count) { Debug.LogError("Out of range next element"); } else { nextElement = elements[currentElement.next]; } }