private static void ChooseOption(int pOptionNr) { BranchingDialogueNode branchingNode = _world.dialogueRunner.GetActiveBranchingDialogueNode(_focusedConversation); if (branchingNode != null) { if (pOptionNr < 0 || pOptionNr > branchingNode.nextNodes.Length - 1) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(pOptionNr.ToString() + " is not a valid option on this branching node with " + branchingNode.nextNodes.Length.ToString() + " options"); } else { branchingNode.Choose(pOptionNr); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Is not at a branching node"); } Eval(new string[] { "ff", "7" }); Eval(new string[] { "ff", "7" }); }
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)); } } }
string GetTextFromOption(BranchingDialogueNode branchingNode, int nr) { string conversationName = branchingNode.conversation; TimedDialogueNode option = _dialogueRunner.GetDialogueNode(conversationName, branchingNode.nextNodes[nr]) as TimedDialogueNode; return option.line; }
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" }
private static void Eval(string[] pCommand) { Console.ForegroundColor = ConsoleColor.White; if (pCommand.Length == 0) { pCommand = new string[] { "m" }; } int nrOfUpdates = 1; switch (pCommand[0]) { case "q": case "quit": _run = false; break; case "1": ChooseOption(0); break; case "2": ChooseOption(1); break; case "3": ChooseOption(2); break; case "4": ChooseOption(3); break; case "5": ChooseOption(4); break; case "6": ChooseOption(5); break; case "7": ChooseOption(6); break; case "PATH": var pathfinder = new MimanPathfinder2(_world.tingRunner, _world.roomRunner); Ting sebastian = _world.tingRunner.GetTing("Sebastian"); Ting wellspringer = _world.tingRunner.GetTing("Wellspringer"); for (int i = 0; i < 100; i++) { D.Log(" - " + i + " - "); D.Log(pathfinder.Search(sebastian, wellspringer).ToString()); } D.Log("Did 100 searches."); break; case "clock": PrintClock(); break; case "bn": BranchingDialogueNode branchingNode = _world.dialogueRunner.GetActiveBranchingDialogueNode(_focusedConversation); if (branchingNode != null) { Console.WriteLine("On branching node " + branchingNode.name + " in conversation " + branchingNode.conversation); } else { Console.WriteLine("Not on a branching node"); } break; case "occupants": Room r = _world.roomRunner.GetRoom(pCommand [1]); foreach (var tile in r.tiles) { D.Log(tile.ToString() + ": " + tile.GetOccupantsAsString()); } break; case "t": case "tick": nrOfUpdates = 1; if (pCommand.Length > 1) { nrOfUpdates = Convert.ToInt32(pCommand[1]); } for (int i = 0; i < nrOfUpdates; i++) { _world.Update(NORMAL_DELTA_TIME); if (!_autoPilot) { PrintTotalWorldTime(); } } break; case "ff": // fast forward DateTime startTime = DateTime.Now; nrOfUpdates = (int)FPS; if (pCommand.Length > 1) { nrOfUpdates = Convert.ToInt32(pCommand[1]) * (int)FPS; } for (int i = 0; i < nrOfUpdates; i++) { _world.Update(NORMAL_DELTA_TIME); } PrintTotalWorldTime(); double totalLength = (DateTime.Now - startTime).TotalSeconds; float secsPerUpdate = (float)(totalLength / (double)nrOfUpdates); float updatesPerSec = 1f / secsPerUpdate; Console.WriteLine("ff took " + (float)totalLength + "s. (" + secsPerUpdate + " s/update, " + updatesPerSec + " updates/s)"); break; case "->": // smart fast forward SmartFastForward(pCommand); break; case "!": case "run": // run Grimm script RunGrimmScript(pCommand, 1); break; case "dump": Console.WriteLine(_world.tingRunner.ToString()); Console.WriteLine(_world.roomRunner.ToString()); Console.WriteLine(_world.dialogueRunner.ToString()); Console.WriteLine(_world.programRunner.ToString()); Console.WriteLine(_world.sourceCodeDispenser.ToString()); Console.WriteLine(_world.timetableRunner.ToString()); break; case "book": // turn all the dialogue into a file called book.txt string text = _world.dialogueRunner.GetAllDialogueAsString(); var file = File.CreateText("book.txt"); file.Write(text); file.Close(); Console.WriteLine("Saved all dialogue to book.txt"); break; case "i": case "info": string tingName = "Sebastian"; if (pCommand.Length > 1) { tingName = pCommand[1]; } MimanTing ting = _world.tingRunner.GetTing <MimanTing>(tingName); PrintTingInfo(ting); break; case "pp": string tingName2 = "Sebastian"; if (pCommand.Length > 1) { tingName2 = pCommand [1]; } Character character = _world.tingRunner.GetTing <Character> (tingName2); if (character != null) { Console.WriteLine(character.PrettyPrintableInfo()); } else { Console.WriteLine("Not a character"); } break; case "ppall": foreach (var c in _world.tingRunner.GetTingsOfType <Character>()) { Console.WriteLine(c.name + "\t" + c.PrettyPrintableInfo()); } break; case "m": case "macro": ExecuteMacro(); break; case "progs": foreach (var prog in _world.programRunner.GetAllPrograms()) { Console.WriteLine("- " + prog); } break; case "h": case "help": Console.WriteLine("q / quit \ni / info [TING] \ndump (prints runners) \n! / run [GRIMM COMMANDO] \nclock (prints in game clock) \nt / tick [N] (ticks N steps) \nff [N] (fast forwards N seconds, does not print time stamp) \nauto_answer [ON | OFF] (choose answers automatically in conversations) \nload/save \nlog [TING]\nconvos (list all active conversations) \nbook save a book.txt file with all dialogue \nroom [TING (optional)] list all chracters in the same room as the ting, no arg means avatar \n@ [TING] translates to avatarName.Interact(TING) and ff until the interaction event\npp [character] pretty print info about character\nppall pretty print info about all characters\n\nprogs print all program names"); break; case "save": _world.Save("save.json"); break; case "load": Reset(); _world = new World("save.json"); LoadTranslationFiles(); foreach (string s in _world.Preload()) { //Console.WriteLine(s); } SetupWorldListeners(); break; case "log": Ting t = _world.tingRunner.GetTing(pCommand[1]); t.logger.AddListener(Console.WriteLine); break; case "convos": var activeConversations = _world.dialogueRunner.GetActiveConversations(); foreach (var convo in activeConversations) { Console.WriteLine(" " + convo); } break; case "room": PrintRoomTings(pCommand); break; case "@": FastInteract(pCommand); break; case "auto_answer": _autoAnswer = true; if (pCommand.Length > 1) { if (pCommand[1].ToString().ToLower() == "off") { _autoAnswer = false; } } Console.WriteLine("Auto answer: " + (_autoAnswer ? "ON" : "OFF")); break; case "stop": Console.WriteLine("Stopped by command 'stop'"); _run = false; break; default: //Console.WriteLine("Can't understand command '" + pCommand[0] + "'"); RunGrimmScript(pCommand, 0); break; } }
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); } } }