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]);
        }
Beispiel #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);
                }
            }
        }
Beispiel #3
0
        public MimanTingRunner(
            RelayTwo pRelay,
            DialogueRunner pDialogueRunner,
            ProgramRunner pProgramRunner,
            SourceCodeDispenser pSourceCodeDispenser,
            RoomRunner pRoomRunner,
            TimetableRunner pTimetableRunner,
            WorldSettings pWorldSettings
            )
            : base(pRelay, pRoomRunner)
        {
            _dialogueRunner = pDialogueRunner;
            _dialogueRunner.AddOnSomeoneSaidSomethingListener(this.OnSomeoneSaidSomething);
            _programRunner       = pProgramRunner;
            _sourceCodeDispenser = pSourceCodeDispenser;
            _timetableRunner     = pTimetableRunner;
            _worldSettings       = pWorldSettings;

            foreach (Ting ting in _tings.Values)
            {
                if (ting is MimanTing)
                {
                    (ting as MimanTing).SetMimanRunners(_programRunner, _sourceCodeDispenser, _dialogueRunner, _worldSettings);
                }
                if (ting is Character)
                {
                    (ting as Character).SetTimetableRunner(_timetableRunner);
                }
            }

            foreach (Ting ting in _tings.Values)
            {
                if (ting is MimanTing)
                {
                    var mimanTing = ting as MimanTing;
                    mimanTing.Init();
                    if (mimanTing.autoUnregisterFromUpdate && mimanTing.dialogueLine != "")
                    {
                        Unregister(mimanTing);
                    }
                }
            }
        }
Beispiel #4
0
        public void UsingTheDialogueRunner()
        {
            RelayTwo relay = new RelayTwo();

            relay.CreateTable(DialogueNode.TABLE_NAME);
            DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);

            runner.AddOnSomeoneSaidSomethingListener(LogDialogue);
            _dialogueLog = new List <string>();

            TimedDialogueNode d1 = runner.Create <TimedDialogueNode>("FirstConverstation", Language.SWEDISH, "DialogueNode1");

            d1.nextNode = "DialogueNode2";
            d1.timer    = 0.5f;
            d1.speaker  = "Helan";
            d1.line     = "Hi, what's up?";

            TimedDialogueNode d2 = runner.Create <TimedDialogueNode>("FirstConverstation", Language.SWEDISH, "DialogueNode2");

            d2.speaker = "Halvan";
            d2.line    = "I'm fine, thanks";

            // Frame 0
            d1.Start();

            Assert.IsTrue(d1.isOn);
            Assert.IsFalse(d2.isOn);

            runner.LogNodesThatAreOn();

            // Frame 1
            runner.Update(0.2f);
            runner.Update(0.2f);
            runner.Update(0.2f);
            runner.Update(0.2f);

            runner.LogNodesThatAreOn();

            Assert.IsFalse(d1.isOn);
            Assert.IsTrue(d2.isOn);
        }
        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 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 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 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"));
        }
Beispiel #11
0
        public void PlayerIsPresentedWithDialogueOptions()
        {
            RelayTwo relay = new RelayTwo();

            relay.CreateTable(DialogueNode.TABLE_NAME);
            DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.SWEDISH);

            dialogueRunner.logger.AddListener(LogDialogueRunner);

            DialogueNode start = dialogueRunner.Create <ConversationStartDialogueNode>("Snack", Language.SWEDISH, "Start");

            start.nextNode = "choice";

            BranchingDialogueNode choice = dialogueRunner.Create <BranchingDialogueNode>("Snack", Language.SWEDISH, "choice");

            choice.nextNodes = new string[] { "a", "b", "c" };

            TimedDialogueNode a = dialogueRunner.Create <TimedDialogueNode>("Snack", Language.SWEDISH, "a");
            TimedDialogueNode b = dialogueRunner.Create <TimedDialogueNode>("Snack", Language.SWEDISH, "b");
            TimedDialogueNode c = dialogueRunner.Create <TimedDialogueNode>("Snack", Language.SWEDISH, "c");

            DialogueNode end = dialogueRunner.Create <ConversationEndDialogueNode>("Snack", Language.SWEDISH, "End");

            a.line = "Yo";
            b.line = "Howdy";
            c.line = "Hola";

            a.nextNode = "End";
            b.nextNode = "End";
            c.nextNode = "End";
            a.timer    = b.timer = c.timer = 1;

            start.Start();
            start.Update(0.1f);

            BranchingDialogueNode branchingNode = dialogueRunner.GetActiveBranchingDialogueNode("Snack");

            List <string> options = new List <string>();

            foreach (string nextNodeName in branchingNode.nextNodes)
            {
                options.Add(nextNodeName);
            }

            Assert.AreEqual(3, options.Count);
            Assert.AreEqual("a", options[0]);
            Assert.AreEqual("b", options[1]);
            Assert.AreEqual("c", options[2]);

            DialogueNode activeDialogueNode = dialogueRunner.GetActiveBranchingDialogueNode("Snack");

            Assert.AreEqual("choice", activeDialogueNode.name);

            dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething);
            _lines = new List <string>();

            branchingNode.nextNode = "b";

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

            Assert.IsFalse(start.isOn);
            Assert.IsFalse(choice.isOn);
            Assert.IsFalse(a.isOn);
            Assert.IsFalse(b.isOn);
            Assert.IsFalse(c.isOn);
            Assert.IsFalse(end.isOn);
            Assert.AreEqual(2, _lines.Count);
            Assert.AreEqual("Howdy", _lines[0]);
            Assert.AreEqual("", _lines[1]);             // = the "shut up message"
        }
Beispiel #12
0
        public void UsingTheDialogueRunner()
        {
            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);
            DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);
            runner.AddOnSomeoneSaidSomethingListener(LogDialogue);
            _dialogueLog = new List<string>();

            TimedDialogueNode d1 = runner.Create<TimedDialogueNode>("FirstConverstation", Language.SWEDISH, "DialogueNode1");
            d1.nextNode = "DialogueNode2";
            d1.timer = 0.5f;
            d1.speaker = "Helan";
            d1.line = "Hi, what's up?";

            TimedDialogueNode d2 = runner.Create<TimedDialogueNode>("FirstConverstation", Language.SWEDISH, "DialogueNode2");
            d2.speaker = "Halvan";
            d2.line = "I'm fine, thanks";

            // Frame 0
            d1.Start();

            Assert.IsTrue(d1.isOn);
            Assert.IsFalse(d2.isOn);

            // Frame 1
            runner.Update(0.8f);

            Assert.IsFalse(d1.isOn);
            Assert.IsTrue(d2.isOn);
        }
Beispiel #13
0
        public void PlayerIsPresentedWithDialogueOptions()
        {
            RelayTwo relay = new RelayTwo();
            relay.CreateTable(DialogueNode.TABLE_NAME);
            DialogueRunner dialogueRunner = new DialogueRunner(relay, Language.SWEDISH);
            dialogueRunner.logger.AddListener(LogDialogueRunner);

            DialogueNode start = dialogueRunner.Create<ConversationStartDialogueNode>("Snack", Language.SWEDISH, "Start");
            start.nextNode = "choice";

            BranchingDialogueNode choice = dialogueRunner.Create<BranchingDialogueNode>("Snack", Language.SWEDISH, "choice");
            choice.nextNodes = new string[] { "a", "b", "c" };

            TimedDialogueNode a = dialogueRunner.Create<TimedDialogueNode>("Snack", Language.SWEDISH, "a");
            TimedDialogueNode b = dialogueRunner.Create<TimedDialogueNode>("Snack", Language.SWEDISH, "b");
            TimedDialogueNode c = dialogueRunner.Create<TimedDialogueNode>("Snack", Language.SWEDISH, "c");

            DialogueNode end = dialogueRunner.Create<ConversationEndDialogueNode>("Snack", Language.SWEDISH, "End");

            a.line = "Yo";
            b.line = "Howdy";
            c.line = "Hola";

            a.nextNode = "End";
            b.nextNode = "End";
            c.nextNode = "End";
            a.timer = b.timer = c.timer = 1;

            start.Start();

            BranchingDialogueNode branchingNode = dialogueRunner.GetActiveBranchingDialogueNode("Snack");

            List<string> options = new List<string>();
            foreach(string nextNodeName in branchingNode.nextNodes)
            {
                options.Add(nextNodeName);
            }

            Assert.AreEqual(3, options.Count);
            Assert.AreEqual("a", options[0]);
            Assert.AreEqual("b", options[1]);
            Assert.AreEqual("c", options[2]);

            DialogueNode activeDialogueNode = dialogueRunner.GetActiveBranchingDialogueNode("Snack");

            Assert.AreEqual("choice", activeDialogueNode.name);

            dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSomeoneSaidSomething);
            _lines = new List<string>();

            branchingNode.nextNode = "b";
            dialogueRunner.Update(1.0f);
            dialogueRunner.Update(1.0f);

            Assert.IsFalse(start.isOn);
            Assert.IsFalse(choice.isOn);
            Assert.IsFalse(a.isOn);
            Assert.IsFalse(b.isOn);
            Assert.IsFalse(c.isOn);
            Assert.IsFalse(end.isOn);
            Assert.AreEqual(2, _lines.Count);
            Assert.AreEqual("Howdy", _lines[0]);
            Assert.AreEqual("", _lines[1]); // = the "shut up message"
        }
        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 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 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 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 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 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 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 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 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 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 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 WaitForMultipleConditions()
        {
            _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/conversation28.dia");

            DialogueScriptPrinter scriptPrinter = new DialogueScriptPrinter(dialogueRunner);
            scriptPrinter.PrintConversation("conversation28");
        }
        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]);
        }
Beispiel #28
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);
                }
            }
        }