public void AssertCommando() { _lines = new List<string>(); s_pooWasCalledCorrectly = false; RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.AddExpression("Pass", Pass); dialogueRunner.AddExpression("Fail", Fail); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation16.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation16"); Assert.Throws<GrimmAssertException>(() => { dialogueRunner.StartConversation("conversation16"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(1.0f); } }); Assert.AreEqual(4, _lines.Count); Assert.AreEqual("hej1", _lines[0]); Assert.AreEqual("", _lines[1]); Assert.AreEqual("hej2", _lines[2]); Assert.AreEqual("", _lines[3]); }
static void RunDialogue() { string conversationName = "meeting"; // "PixieMeeting1"; RelayTwo relay; DialogueRunner dialogueRunner; relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddExpression("CoinFlip", CoinFlip); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSpeech); dialogueRunner.logger.AddListener(Log); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile(conversationName + ".dia"); DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner); printer.PrintConversation(conversationName); Console.WriteLine(" - " + conversationName + " - "); dialogueRunner.StartConversation(conversationName); while(dialogueRunner.ConversationIsRunning(conversationName)) { //printer.PrintConversation(conversationName); dialogueRunner.Update(1.0f); DialogueNode activeDialogueNode = dialogueRunner.GetActiveBranchingDialogueNode(conversationName); if(activeDialogueNode is BranchingDialogueNode) { BranchingDialogueNode branchingNode = activeDialogueNode as BranchingDialogueNode; //printer.PrintConversation(conversationName); int i = 1; Console.WriteLine("Choose an alternative:"); foreach(string optionNodeName in branchingNode.nextNodes) { TimedDialogueNode optionNode = dialogueRunner.GetDialogueNode(conversationName, optionNodeName) as TimedDialogueNode; Console.WriteLine(i++ + ". " + optionNode.line); } int choice = -1; while(choice < 0 || choice > branchingNode.nextNodes.Length - 1) { try { choice = 0; //Convert.ToInt32(Console.ReadLine()) - 1; } catch { choice = -1; } } branchingNode.Choose(choice); } } }
public void DontTriggerEventOnWaitingNodeUnlessEventHappensWhenExpressionIsTrue() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); runner.logger.AddListener (msg => Console.WriteLine ("Dialog runner log: " + msg)); bool sunny = false; runner.AddExpression ("IsSunny", new DialogueRunner.Expression (args => { return sunny; })); var expression = runner.Create<ExpressionDialogueNode>("Conversation1", Language.SWEDISH, "ExpressionNode"); expression.expression = "IsSunny"; expression.args = new string[] { }; var waitNode = runner.Create<WaitDialogueNode>("Conversation1", Language.SWEDISH, "WaitNode"); waitNode.eventName = "bam!"; waitNode.expressions = new ExpressionDialogueNode[] { expression }; var start = runner.Create<ConversationStartDialogueNode>("Conversation1", Language.SWEDISH, "Start"); var end = runner.Create<ConversationEndDialogueNode>("Conversation1", Language.SWEDISH, "End"); start.nextNode = waitNode.name; waitNode.nextNode = end.name; runner.StartConversation ("Conversation1"); runner.Update (0.1f); runner.Update (0.1f); runner.Update (0.1f); Assert.IsTrue (waitNode.isOn); Assert.IsTrue (runner.ConversationIsRunning("Conversation1")); // Event should not occur since it's not sunny yet runner.EventHappened("bam!"); runner.Update (0.1f); Assert.IsTrue (waitNode.isOn); Assert.IsTrue (runner.ConversationIsRunning("Conversation1")); sunny = true; // Now, even though it's sunny the event should still not happen since we're not bam!:ing runner.Update (0.1f); Assert.IsTrue (waitNode.isOn); Assert.IsTrue (runner.ConversationIsRunning("Conversation1")); // But if the bam! event happens while sunny, the conversation should end runner.EventHappened("bam!"); runner.Update (0.1f); runner.Update (0.1f); runner.Update (0.1f); Assert.IsFalse (waitNode.isOn); Assert.IsFalse (runner.ConversationIsRunning("Conversation1")); }
public void ShortIf() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); dialogueRunner.AddExpression("Foo", ((string[] args) => (true))); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation30.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation30"); }
public void IfNode() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.SWEDISH); dialogueRunner.logger.AddListener(LogDialogueRunner); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.AddExpression("TimeForSleep", TimeForSleep); dialogueRunner.AddExpression("TimeForDinner", TimeForDinner); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation7.dia"); DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner); printer.PrintConversation("conversation7"); dialogueRunner.StartConversation("conversation7"); for(int i = 0; i < 1000; i++) { dialogueRunner.Update(1.0f); } Console.WriteLine("Output:"); foreach(string s in _lines) { Console.WriteLine(s); } Assert.AreEqual(4, _lines.Count); Assert.AreEqual("Let's eat", _lines[0]); Assert.AreEqual("", _lines[1]); Assert.AreEqual("I'm hungry", _lines[2]); Assert.AreEqual("", _lines[3]); }
public void Elif() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); dialogueRunner.AddExpression("A", ((string[] args) => (false))); dialogueRunner.AddExpression("B", ((string[] args) => (false))); dialogueRunner.AddExpression("C", ((string[] args) => (true))); dialogueRunner.AddExpression("D", ((string[] args) => (false))); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation29.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation29"); dialogueRunner.StartConversation("conversation29"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.5f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("C", _lines[0]); }
public void WaitForEvents() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.logger.AddListener(Console.WriteLine); dialogueRunner.AddExpression("Whatever", ((string[] args) => (true))); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation35.dia"); //DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); //scriptPrinter.PrintConversation("conversation35"); dialogueRunner.StartConversation("conversation35"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.5f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("Yeah1", _lines[0]); dialogueRunner.EventHappened("Bam"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(0.5f); } Assert.AreEqual(4, _lines.Count); Assert.AreEqual("Yeah2", _lines[2]); }
public void WaitForConditionWithArguments() { _lines = new List<string>(); RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething); dialogueRunner.AddExpression("StateIs", StateIs); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation18.dia"); DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner); scriptPrinter.PrintConversation("conversation18"); dialogueRunner.StartConversation("conversation18"); for(int i = 0; i < 100; i++) { dialogueRunner.Update(1.0f); } Assert.AreEqual(0, _lines.Count); for(int i = 0; i < 100; i++) { if(i == 50) { s_monsterState = "Angry"; } dialogueRunner.Update(1.0f); } Assert.AreEqual(2, _lines.Count); Assert.AreEqual("Ahhhhh!", _lines[0]); Assert.AreEqual("", _lines[1]); }
public void DontTriggerEventOnWaitingNodeUnlessEventHappensWhenExpressionIsTrue() { RelayTwo relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH); runner.logger.AddListener(msg => Console.WriteLine("Dialog runner log: " + msg)); bool sunny = false; runner.AddExpression("IsSunny", new DialogueRunner.Expression(args => { return(sunny); })); var expression = runner.Create <ExpressionDialogueNode>("Conversation1", Language.SWEDISH, "ExpressionNode"); expression.expression = "IsSunny"; expression.args = new string[] { }; var waitNode = runner.Create <WaitDialogueNode>("Conversation1", Language.SWEDISH, "WaitNode"); waitNode.eventName = "bam!"; waitNode.expressions = new ExpressionDialogueNode[] { expression }; var start = runner.Create <ConversationStartDialogueNode>("Conversation1", Language.SWEDISH, "Start"); var end = runner.Create <ConversationEndDialogueNode>("Conversation1", Language.SWEDISH, "End"); start.nextNode = waitNode.name; waitNode.nextNode = end.name; runner.StartConversation("Conversation1"); runner.Update(0.1f); runner.Update(0.1f); runner.Update(0.1f); Assert.IsTrue(waitNode.isOn); Assert.IsTrue(runner.ConversationIsRunning("Conversation1")); // Event should not occur since it's not sunny yet runner.EventHappened("bam!"); runner.Update(0.1f); Assert.IsTrue(waitNode.isOn); Assert.IsTrue(runner.ConversationIsRunning("Conversation1")); sunny = true; // Now, even though it's sunny the event should still not happen since we're not bam!:ing runner.Update(0.1f); Assert.IsTrue(waitNode.isOn); Assert.IsTrue(runner.ConversationIsRunning("Conversation1")); // But if the bam! event happens while sunny, the conversation should end runner.EventHappened("bam!"); runner.Update(0.1f); runner.Update(0.1f); runner.Update(0.1f); Assert.IsFalse(waitNode.isOn); Assert.IsFalse(runner.ConversationIsRunning("Conversation1")); }
static void RunDialogue() { string conversationName = "meeting"; // "PixieMeeting1"; RelayTwo relay; DialogueRunner dialogueRunner; relay = new RelayTwo(); relay.CreateTable(DialogueNode.TABLE_NAME); dialogueRunner = new DialogueRunner(relay, Language.DEFAULT); dialogueRunner.AddExpression("CoinFlip", CoinFlip); dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSpeech); dialogueRunner.logger.AddListener(Log); DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner); scriptLoader.LoadDialogueNodesFromFile(conversationName + ".dia"); DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner); printer.PrintConversation(conversationName); Console.WriteLine(" - " + conversationName + " - "); dialogueRunner.StartConversation(conversationName); while (dialogueRunner.ConversationIsRunning(conversationName)) { //printer.PrintConversation(conversationName); dialogueRunner.Update(1.0f); DialogueNode activeDialogueNode = dialogueRunner.GetActiveBranchingDialogueNode(conversationName); if (activeDialogueNode is BranchingDialogueNode) { BranchingDialogueNode branchingNode = activeDialogueNode as BranchingDialogueNode; //printer.PrintConversation(conversationName); int i = 1; Console.WriteLine("Choose an alternative:"); foreach (string optionNodeName in branchingNode.nextNodes) { TimedDialogueNode optionNode = dialogueRunner.GetDialogueNode(conversationName, optionNodeName) as TimedDialogueNode; Console.WriteLine(i++ + ". " + optionNode.line); } int choice = -1; while (choice < 0 || choice > branchingNode.nextNodes.Length - 1) { try { choice = 0; //Convert.ToInt32(Console.ReadLine()) - 1; } catch { choice = -1; } } branchingNode.Choose(choice); } } }