Exemple #1
0
        public void InstantiateDialoguesFromDatabase()
        {
            {
                RelayTwo relay = new RelayTwo();
                relay.CreateTable(DialogueNode.TABLE_NAME);
                DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);

                TimedDialogueNode d1 = runner.Create <TimedDialogueNode>("c", Language.SWEDISH, "d1") as TimedDialogueNode;
                d1.speaker = "A";

                TimedDialogueNode d2 = runner.Create <TimedDialogueNode>("c", Language.SWEDISH, "d2");
                d2.speaker = "B";

                relay.SaveAll("conversation.xml");
            }

            {
                RelayTwo relay = new RelayTwo();
                relay.LoadAll("conversation.xml");
                DialogueRunner runner = new DialogueRunner(relay, Language.SWEDISH);

                TimedDialogueNode d1 = runner.GetDialogueNode("c", "d1") as TimedDialogueNode;
                TimedDialogueNode d2 = runner.GetDialogueNode("c", "d2") as TimedDialogueNode;

                Assert.AreEqual("A", d1.speaker);
                Assert.AreEqual("B", d2.speaker);
            }
        }
Exemple #2
0
        public void CanNotStartDialogueNodeInAnotherConversation()
        {
            RelayTwo relay = new RelayTwo();

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

            TimedDialogueNode n1 = runner.Create <TimedDialogueNode>("Conversation1", Language.SWEDISH, "DialogueNode1");

            n1.nextNode = "DialogueNode2";
            n1.timer    = 1;

            runner.Create <TimedDialogueNode>("Conversation2", Language.SWEDISH, "DialogueNode2");
            n1.Start();

            string msg = null;

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

            runner.Update(1.0f);
            runner.Update(1.0f);
            Assert.NotNull(msg);
        }
Exemple #3
0
        public void CreateTimedDialogueNode()
        {
            RelayTwo relay = new RelayTwo();
            TableTwo table = relay.CreateTable(DialogueNode.TABLE_NAME);

            TimedDialogueNode t = new TimedDialogueNode();
            t.CreateNewRelayEntry(table, "TimedDialogueNode");
            t.timer = 100;
            t.Update(1.0f);

            Assert.AreEqual(99, t.timer, 0.001f);
        }
Exemple #4
0
        public void CreateTimedDialogueNode()
        {
            RelayTwo relay = new RelayTwo();
            TableTwo table = relay.CreateTable(DialogueNode.TABLE_NAME);

            TimedDialogueNode t = new TimedDialogueNode();

            t.CreateNewRelayEntry(table, "TimedDialogueNode");
            t.timer = 100;
            t.Update(1.0f);

            Assert.AreEqual(99, t.timer, 0.001f);
        }
Exemple #5
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);
        }
Exemple #6
0
        static void PrintBranchingNode()
        {
            BranchingDialogueNode branchingNode = _world.dialogueRunner.GetActiveBranchingDialogueNode(_focusedConversation);

            if (branchingNode != null)
            {
                int i = 1;
                Console.Write("\n");
                ConsoleColor previousColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Yellow;
                foreach (string optionNodeName in branchingNode.nextNodes)
                {
                    TimedDialogueNode optionNode = _world.dialogueRunner.GetDialogueNode(_focusedConversation, optionNodeName) as TimedDialogueNode;
                    Console.WriteLine("   " + i++ + ". " + _world.translator.Get(optionNode.line, _focusedConversation));
                }
                Console.ForegroundColor = previousColor;
                Console.Write("\n");
                if (_autoAnswer)
                {
                    ChooseOption(Randomizer.GetIntValue(0, branchingNode.nextNodes.Length));
                }
            }
        }
Exemple #7
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"
        }
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);
                }
            }
        }