static void PrintTingInfo(MimanTing pTing) { foreach (PropertyInfo p in pTing.GetType().GetProperties()) { foreach (Attribute a in p.GetCustomAttributes(true)) { if (a.Match(EDITABLE_IN_EDITOR) || a.Match(SHOW_IN_EDITOR)) { object o = p.GetValue(pTing, null); string line = ""; if (o == null) { line = "null"; } else if (o is string) { line = "\"" + o.ToString() + "\""; } else { line = o.ToString(); } Console.WriteLine(p.Name + ": " + line); } } } }
public void AddProgramsToProgramsArray() { MimanTing mimanTing = _world.tingRunner.CreateTing <MimanTingConcrete>("Miman Ting", new WorldCoordinate("Kitchen", IntPoint.Zero)); SourceCode dummyCode = new SourceCode(); dummyCode.CreateNewRelayEntry(_world.relay.GetTable(SourceCode.TABLE_NAME), typeof(SourceCode).Name); WorldTestHelper.PreloadWorld(_world); Program p1 = _world.programRunner.CreateProgram(dummyCode); Program p2 = _world.programRunner.CreateProgram(dummyCode); _world.Update(0.1f); // the programs are added to the program runner at the end of the frame Assert.AreEqual(0, mimanTing.programs.Length); mimanTing.AddProgramToProgramsArray(p1); Assert.AreEqual(1, mimanTing.programs.Length); mimanTing.AddProgramToProgramsArray(p2); Assert.AreEqual(2, mimanTing.programs.Length); }
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; } }