Пример #1
0
        static void RunDialogue()
        {
            string conversationName = "meeting"; // "PixieMeeting1";

            RelayTwo relay;
            DialogueRunner dialogueRunner;

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

            dialogueRunner = new DialogueRunner(relay, Language.DEFAULT);
            dialogueRunner.AddExpression("CoinFlip", CoinFlip);
            dialogueRunner.AddOnSomeoneSaidSomethingListener(OnSpeech);
            dialogueRunner.logger.AddListener(Log);

            DialogueScriptLoader scriptLoader = new DialogueScriptLoader(dialogueRunner);
            scriptLoader.LoadDialogueNodesFromFile(conversationName + ".dia");

            DialogueScriptPrinter printer = new DialogueScriptPrinter(dialogueRunner);
            printer.PrintConversation(conversationName);

            Console.WriteLine(" - " + conversationName + " - ");
            dialogueRunner.StartConversation(conversationName);

            while(dialogueRunner.ConversationIsRunning(conversationName))
            {
                //printer.PrintConversation(conversationName);

                dialogueRunner.Update(1.0f);
                DialogueNode activeDialogueNode = dialogueRunner.GetActiveDialogueNode(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);
                }
            }
        }
Пример #2
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.GetActiveDialogueNode("Snack") as BranchingDialogueNode;

            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.GetActiveDialogueNode("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"
        }