Exemple #1
0
        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 EmptyLoop()
        {
            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

            DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT);

            DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
            scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation24.dia");

            DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner);
            scriptPrinter.PrintConversation("conversation24");

            dialogueRunner.StartConversation("conversation24");
            dialogueRunner.Update(1.0f);

            Assert.IsTrue(dialogueRunner.ConversationIsRunning("conversation24")); // never ends
        }
        public void ListeningForEventAndSaveInBetween()
        {
            _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(LogDialogueRunner);

                DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
                scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation19.dia");

                DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner);
                scriptPrinter.PrintConversation("conversation19");

                dialogueRunner.StartConversation("conversation19");

                for(int i = 0; i < 10; i++) {
                    dialogueRunner.Update(0.1f);
                }

                Assert.AreEqual(1, _lines.Count);
                Assert.AreEqual("Blah blah blah",  _lines[0]);
                relay.SaveAll("save.xml");
            }

            {
                RelayTwo relay = new RelayTwo("save.xml");
                DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT);
                dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething);
                dialogueRunner.logger.AddListener(LogDialogueRunner);

                dialogueRunner.EventHappened("TensionWentUp");

                for(int i = 0; i < 500; i++)
                {
                    dialogueRunner.Update(1.0f);
                }

                Assert.AreEqual(4, _lines.Count);
                Assert.AreEqual("Oh!",  _lines[1]);
                Assert.AreEqual("",  _lines[2]);
                Assert.AreEqual("",  _lines[3]);

                Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation19"));

                dialogueRunner.EventHappened("SomethingElse"); // this is not supposed to do anything since the story is over

                for(int i = 0; i < 500; i++)
                {
                    dialogueRunner.Update(1.0f);
                }

                Assert.AreEqual(4, _lines.Count);
            }
        }
        public void BreakOutOfLoop()
        {
            _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);

            DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
            scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation26.dia");

            DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner);
            scriptPrinter.PrintConversation("conversation26");

            Console.WriteLine("Starting...");
            dialogueRunner.StartConversation("conversation26");

            for(int i = 0; i < 10; i++) {
                Console.WriteLine("Update " + i);
                dialogueRunner.Update(0.3f);
            }

            foreach(string s in _lines) {
                Console.WriteLine(s);
            }

            Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation26"));
            Assert.AreEqual(2, _lines.Count);
            Assert.AreEqual("yo", _lines[0]);
            Assert.AreEqual("", _lines[1]);
        }
        public void StopAnotherConversation()
        {
            _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);

            DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
            scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation32.dia");
            scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation31.dia");

            dialogueRunner.StartConversation("conversation32");

            for(int i = 0; i < 100; i++)
            {
                dialogueRunner.Update(0.1f);
            }

            dialogueRunner.StartConversation("conversation31");

            for(int i = 0; i < 100; i++)
            {
                dialogueRunner.Update(0.1f);
            }

            Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation32"));
            Assert.IsFalse(dialogueRunner.ConversationIsRunning("conversation31"));
        }
Exemple #6
0
        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"));
        }
Exemple #7
0
        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);
            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);
            Assert.IsFalse (waitNode.isOn);
            Assert.IsFalse (runner.ConversationIsRunning("Conversation1"));
        }
Exemple #8
0
        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);
                }
            }
        }