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]);
        }
Пример #2
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 CallAFunctionFromDialogueScript()
        {
            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

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

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

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

            dialogueRunner.StartConversation("conversation13");

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

            Assert.IsTrue(s_fooWasCalled);
        }
        public void CallAFunctionWithArguments()
        {
            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

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

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

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

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

            Assert.IsTrue(s_pooWasCalledCorrectly);
        }
        public void StartingOtherDialoguesAndStoryNodes()
        {
            _lines = new List<string>();

            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

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

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

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

            dialogueRunner.StartConversation("conversation11");

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

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

            Assert.AreEqual(6, _lines.Count);

            Assert.AreEqual("Hoho",  _lines[0]);
            Assert.AreEqual("", 	 _lines[1]);
            Assert.AreEqual("Hjälp!",_lines[2]);
            Assert.AreEqual("", 	 _lines[3]);
            Assert.AreEqual("Oh no", _lines[4]);
            Assert.AreEqual("", 	 _lines[5]);
        }
        public void ListeningDialogueNodeWithNoBranch()
        {
            _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/conversation21.dia");

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

            dialogueRunner.StartConversation("conversation21");

            Assert.AreEqual(0, _lines.Count);

            for(int i = 0; i < 500; i++)
            {
                if(i == 250) {
                    dialogueRunner.EventHappened("RainStarted");
                }
                dialogueRunner.Update(1.0f);
            }

            Assert.AreEqual(2, _lines.Count);
            Assert.AreEqual("Where is my umbrella?",  _lines[0]);
            Assert.AreEqual("",  _lines[1]);
        }
        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 Focus()
        {
            _lines = new List<string>();
            bool madeActive = false;

            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

            DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.DEFAULT);
            dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething);
            dialogueRunner.logger.AddListener(LogDialogueRunner);
            dialogueRunner.AddFocusConversationListener((string pConversation) => {
                if(pConversation == "conversation23") { madeActive = true; }
            });

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

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

            dialogueRunner.StartConversation("conversation23");

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

            Assert.IsTrue(madeActive);
        }
        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 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"));
        }
Пример #11
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"));
        }
Пример #12
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"));
        }
        public void SwitchLanguageInTheMiddleOfConversation()
        {
            _lines = new List<string>();

            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

            DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.ENGLISH);
            dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething);

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

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

            dialogueRunner.StartConversation("conversation10");
            while(_lines.Count < 1)
            {
                dialogueRunner.Update(1.0f);
            }

            dialogueRunner.language = Language.SWEDISH;

            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("Hi", _lines[0]);
            Assert.AreEqual("", _lines[1]);
            Assert.AreEqual("Hej!", _lines[2]);
            Assert.AreEqual("", _lines[3]);
        }
        public void SaySomethingEachFrameUsingLoop()
        {
            _lines = new List<string>();

            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

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

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

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

            dialogueRunner.StartConversation("conversation25");
            for(int i = 0; i < 10; i++) {
                dialogueRunner.Update(5.0f);
            }

            Assert.AreEqual(20, _lines.Count);

            for(int i = 0; i < 10; i++) {
                Assert.AreEqual("hej", _lines[i * 2]);
                Assert.AreEqual("", _lines[i * 2 + 1]);
            }
        }
        public void CallAFunctionWithDotOperator()
        {
            s_pooWasCalledCorrectly = false;

            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);

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

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

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

            dialogueRunner.StartConversation("conversation15");

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

            Assert.IsTrue(s_pooWasCalledCorrectly);
        }
        public void CancelNested()
        {
            _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/conversation22b.dia");

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

            dialogueRunner.StartConversation("conversation22b");

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

            Assert.AreEqual(2, _lines.Count);
            Assert.AreEqual("Yup", _lines[0]);
            Assert.AreEqual("", _lines[1]);
        }
        public void StopCommando()
        {
            _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);

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

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

            dialogueRunner.StartConversation("conversation17");
            for(int i = 0; i < 100; i++)
            {
                dialogueRunner.Update(1.0f);
            }

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

            Assert.AreEqual(2, _lines.Count);
            Assert.AreEqual("hej1", _lines[0]);
            Assert.AreEqual("", _lines[1]);
        }
        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 WaitAndLoop()
        {
            var log = 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/conversation39.dia");

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

            dialogueRunner.AddFunction("Log", (args) => log.Add(args[0]));
            dialogueRunner.logger.AddListener(s => Console.WriteLine("LOG: " + s));

            dialogueRunner.StartConversation("conversation39");

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

            Assert.AreEqual(7, log.Count);
            Assert.AreEqual("boom", log[0]);
            Assert.AreEqual("boom", log[1]);
            Assert.AreEqual("boom", log[2]);
            Assert.AreEqual("boom", log[3]);
            Assert.AreEqual("boom", log[4]);
            Assert.AreEqual("boom", log[5]);
            Assert.AreEqual("boom", log[6]);
        }
 public void GotoNodes()
 {
     RelayTwo relay = new RelayTwo();
     relay.CreateTable(DialogueNode.TABLE_NAME);
     DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.SWEDISH);
     dialogueRunner.logger.AddListener(LogDialogueRunner);
     dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething);
     _lines = new List<string>();
     DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
     scriptLoader.LoadDialogueNodesFromFile("../conversations/conversation6.dia");
     DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner);
     printer.PrintConversation("conversation6");
     dialogueRunner.StartConversation("conversation6");
     for(int i = 0; i < 1000; i++)
     {
         dialogueRunner.Update(1.0f);
     }
     Console.WriteLine("Output:");
     foreach(string s in _lines)
     {
         Console.WriteLine(s);
     }
     Assert.AreEqual(6, _lines.Count);
     Assert.AreEqual("a", _lines[0]);
     Assert.AreEqual("", _lines[1]);
     Assert.AreEqual("b", _lines[2]);
     Assert.AreEqual("", _lines[3]);
     Assert.AreEqual("c", _lines[4]);
     Assert.AreEqual("", _lines[5]);
 }
        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 InterruptCommando()
        {
            _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);

            D.onDLog += (pMessage) => { Console.WriteLine("DLog: " + pMessage); };

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

            dialogueRunner.StartConversation("conversation33");

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

            Assert.AreEqual(10, _lines.Count);

            Assert.AreEqual("before", 	_lines[0]);
            Assert.AreEqual("", 		_lines[1]);
            Assert.AreEqual("Hoho", 	_lines[2]);
            Assert.AreEqual("", 		_lines[3]);
            Assert.AreEqual("Hjälp!", 	_lines[4]);
            Assert.AreEqual("",	 		_lines[5]);
            Assert.AreEqual("Oh no", 	_lines[6]);
            Assert.AreEqual("", 		_lines[7]);
            Assert.AreEqual("after", 	_lines[8]);
            Assert.AreEqual("",			_lines[9]);
        }
        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 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 WaitSpecifiedTime()
        {
            _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/conversation36.dia");

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

            dialogueRunner.StartConversation("conversation36");

            dialogueRunner.Update(1.0f);
            Assert.AreEqual(0, _lines.Count);

            dialogueRunner.Update(0.01f);
            dialogueRunner.Update(0.01f);
            dialogueRunner.Update(0.01f);
            dialogueRunner.Update(0.01f);
            dialogueRunner.Update(3.0f);
            dialogueRunner.Update(1.0f);
            dialogueRunner.Update(1.0f);
            dialogueRunner.Update(1.0f);

            // TODO: had to hack this a bit (with multiple updates) to make it work, hope it's OK...

            Assert.AreEqual(2, _lines.Count);
            Assert.AreEqual("Woo!", _lines[0]);
        }
        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]);
        }
Пример #27
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);
                }
            }
        }