コード例 #1
0
        public static void GenerateInitData()
        {
            InitialSaveFileCreator i = new InitialSaveFileCreator();
            World world = new World(i.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);
            srb.CreateRoomWithSize("Eden", 5, 5);
            srb.CreateRoomWithSize("Hallway", 5, 5);
            srb.CreateRoomWithSize("Kitchen", 10, 5);
            srb.CreateRoomWithSize("Bedroom", 5, 5);

            world.tingRunner.CreateTing<Character>("Adam", new WorldCoordinate("Eden", new IntPoint(0, 0)));
            world.tingRunner.CreateTing<Character>("Eva", new WorldCoordinate("Eden", new IntPoint(4, 4)));

            MysticalCube c = world.tingRunner.CreateTing<MysticalCube>("PowerCube", new WorldCoordinate("Eden", new IntPoint(2, 2)));
            c.onInteractionSourceCodeName = "PowerCube";

            world.relay.SaveTableSubsetSeparately(Room.TABLE_NAME, INIT_DATA_PATH + "Rooms.json");
            RelayLib.RelayTwo tingSubset = new RelayLib.RelayTwo();

            foreach(string table in world.tingRunner.loadedTingTables)
                tingSubset.MergeWith(world.relay.Subset(table, (o) => { return true; }));

            tingSubset.SaveAll(INIT_DATA_PATH + "Tings.json");
        }
コード例 #2
0
ファイル: BedTests.cs プロジェクト: KarmaLaBelle/GameWorld2
 public void SetUp()
 {
     WorldTestHelper.GenerateInitData();
     InitialSaveFileCreator i = new InitialSaveFileCreator();
     _world = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));
     _room = _world.roomRunner.CreateRoom<Room>("Room");
 }
コード例 #3
0
 public void SetUp()
 {
     WorldTestHelper.GenerateInitData();
     InitialSaveFileCreator i = new InitialSaveFileCreator();
     _world = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));
     _eva = _world.tingRunner.GetTing("Eva") as Character;
 }
コード例 #4
0
 public static void PreloadWorld(World pWorld)
 {
     if(!pWorld.isReadyToPlay) {
         foreach (string s in pWorld.Preload())
         {
             //Console.WriteLine(s);
         }
     }
 }
コード例 #5
0
ファイル: SeatTests.cs プロジェクト: KarmaLaBelle/GameWorld2
 public void Setup()
 {
     D.onDLog += Console.WriteLine;
     WorldTestHelper.GenerateInitData();
     InitialSaveFileCreator i = new InitialSaveFileCreator();
     _world = new World(i.CreateRelay("../InitData1/"));
     _adam = _world.tingRunner.GetTing<Character>("Adam");
     _seat = _world.tingRunner.CreateTing<Seat>("Chair", new WorldCoordinate("Eden", 0, 3));
 }
コード例 #6
0
        public static void UpdateWorld(World pWorld, float pTime)
        {
            PreloadWorld(pWorld);

            const float stepSize = 1.0f / 30f;
            float time = 0f;
            while(time < pTime)
            {
                pWorld.Update(stepSize);
                time += stepSize;
            }
        }
コード例 #7
0
        public static void UpdateWorldUntilGameTime(World pWorld, GameTime pGameTime)
        {
            PreloadWorld(pWorld);

            const float stepSize = 1f;

            //Console.WriteLine("Total world time: " + pWorld.settings.gameTimeClock.totalSeconds);
            //Console.WriteLine("pGameTime.totalSeconds: " + pGameTime.totalSeconds);

            int i = 1000;

            while(pWorld.settings.gameTimeClock.totalSeconds < pGameTime.totalSeconds)
            {
                i--;
                //Console.WriteLine("Total world time: " + pWorld.settings.gameTimeClock.totalSeconds);
                pWorld.Update(stepSize);
            }
        }
コード例 #8
0
ファイル: MainClass.cs プロジェクト: KarmaLaBelle/GameWorld2
        public static void Main( string[] args )
        {
            /*
            FlowerPotTest test = new FlowerPotTest();
            test.SetUp();
            test.RunWorld();
            Console.ReadLine();*/

            Console.WriteLine("Start");

            InitialSaveFileCreator i = new InitialSaveFileCreator();
            World world = new World(i.CreateRelay("../InitData2"));

            foreach(Room r in world.roomRunner.rooms)
            {
                Console.WriteLine("Got room " + r.name + " with " + r.points.Length.ToString() + " tile nodes");
            }

            Console.WriteLine("Done");
        }
コード例 #9
0
 public void TrySavingComputerMemory()
 {
     string saveName = "ComputerMemoryTest.json";
     {
         WorldTestHelper.GenerateInitData ();
         InitialSaveFileCreator i = new InitialSaveFileCreator ();
         World world = new World (i.CreateRelay (WorldTestHelper.INIT_DATA_PATH));
         Memory computerMemory = world.tingRunner.CreateTing<Memory> ("ComputerMemory1", new TingTing.WorldCoordinate ("Eden", 2, 3));
         computerMemory["a"] = 42;
         computerMemory["b"] = 100.5;
         world.Save (saveName);
     }
     {
         World world = new World (saveName);
         Memory computerMemory = world.tingRunner.GetTing<Memory> ("ComputerMemory1");
         Assert.AreEqual (2, computerMemory.data.Keys.Count);
         Assert.AreEqual (42, computerMemory["a"]);
         Assert.AreEqual (100.5, computerMemory["b"]);
     }
 }
コード例 #10
0
ファイル: DoorTests.cs プロジェクト: KarmaLaBelle/GameWorld2
        public void Setup()
        {
            D.onDLog += Console.WriteLine;
            SmartWalkBehaviour.s_logger.AddListener (s => Console.WriteLine ("Walk behaviour: " + s));

            WorldTestHelper.GenerateInitData();
            InitialSaveFileCreator i = new InitialSaveFileCreator();
            _world = new World(i.CreateRelay("../InitData1/"));
            foreach (string s in _world.Preload()) ;

            _d1 = _world.tingRunner.CreateTing<Door>("DoorOne", new TingTing.WorldCoordinate("Eden", new IntPoint(4, 4)), Direction.LEFT);
            _d2 = _world.tingRunner.CreateTing<Door>("DoorTwo", new TingTing.WorldCoordinate("Hallway", new IntPoint(0, 0)), Direction.RIGHT);
            _d1.targetDoorName = _d2.name;
            _d2.targetDoorName = _d1.name;

            _d3 = _world.tingRunner.CreateTing<Door>("DoorThree", new TingTing.WorldCoordinate("Hallway", new IntPoint(4, 2)), Direction.LEFT);
            _d4 = _world.tingRunner.CreateTing<Door>("DoorFour", new TingTing.WorldCoordinate("Kitchen", new IntPoint(0, 2)), Direction.RIGHT);
            _d3.targetDoorName = _d4.name;
            _d4.targetDoorName = _d3.name;

            _world.roomRunner.GetRoom("Hallway").worldPosition = new IntPoint(4, 4);
            _adam = _world.tingRunner.GetTing<Character>("Adam");
            _eve = _world.tingRunner.GetTing<Character>("Eva");
        }
コード例 #11
0
ファイル: Main.cs プロジェクト: eriksvedang/GameWorld2
        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;
            }
        }
コード例 #12
0
ファイル: Main.cs プロジェクト: eriksvedang/GameWorld2
        private static void SimplePathfinding()
        {
            D.onDLog += Console.WriteLine; // take care of the D.Log message from invalid path

            InitialSaveFileCreator isc = new InitialSaveFileCreator();
            World world = new World(isc.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);
            srb.CreateRoomWithSize("Eden", 10, 10);
            var middleRoom = srb.CreateRoomWithSize("MiddleRoom", 10, 10);
            var wrongRoom = srb.CreateRoomWithSize("WrongRoom", 10, 10);
            var distantRoom = srb.CreateRoomWithSize("DistantRoom", 10, 10);

            middleRoom.worldPosition = new IntPoint(10, 0);
            wrongRoom.worldPosition = new IntPoint(30, 0);
            distantRoom.worldPosition = new IntPoint(50, 0);

            var p1 = world.tingRunner.CreateTing<Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = world.tingRunner.CreateTing<Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            // Add doors
            var edenDoor = world.tingRunner.CreateTing<Door>("edenDoor", new WorldCoordinate("Eden", new IntPoint(4, 4)));
            var middleRoomDoor1 = world.tingRunner.CreateTing<Door>("middleRoomDoor1", new WorldCoordinate("MiddleRoom", new IntPoint(2, 4)));
            var middleRoomDoor2 = world.tingRunner.CreateTing<Door>("middleRoomDoor2", new WorldCoordinate("MiddleRoom", new IntPoint(7, 4)));
            var middleRoomDoor3 = world.tingRunner.CreateTing<Door>("middleRoomDoor3", new WorldCoordinate("MiddleRoom", new IntPoint(4, 4)));
            var wrongRoomDoor = world.tingRunner.CreateTing<Door>("wrongRoomDoor", new WorldCoordinate("WrongRoom", new IntPoint(4, 4)));
            var distantRoomDoor = world.tingRunner.CreateTing<Door>("distantRoomDoor", new WorldCoordinate("DistantRoom", new IntPoint(2, 4)));

            edenDoor.targetDoorName = "middleRoomDoor1";
            middleRoomDoor1.targetDoorName = "edenDoor";
            middleRoomDoor2.targetDoorName = "distantRoomDoor";
            middleRoomDoor3.targetDoorName = "wrongRoomDoor";
            wrongRoomDoor.targetDoorName = "middleRoomDoor3";
            distantRoomDoor.targetDoorName = "middleRoomDoor2";

            world.sourceCodeDispenser.CreateSourceCodeFromString ("OnDoorUsed", "");

            if(!world.isReadyToPlay) {
                foreach (string s in world.Preload()) {}
            }

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);

            var result = pathfinder.Search(p1, p2);
            Console.WriteLine("Result: " + result);
        }
コード例 #13
0
ファイル: Main.cs プロジェクト: eriksvedang/GameWorld2
        private static void TextView(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            DateTime startTime = DateTime.Now;
            D.onDLog += (pMessage) => Console.WriteLine ("" + pMessage);

            string macroFileName = "macro1.txt";
            string saveFileName = "";

            for (int i = 0; i < args.Length; i++) {
                string s = args [i];
                if (s == "-autopilot") {
                    _autoPilot = true;
                    _autoAnswer = true;
                    _timeLimit = Convert.ToSingle (args [++i]);
                } else if (s == "-macro") {
                    macroFileName = args [++i];
                } else if (s == "-load") {
                    saveFileName = args [++i];
                }
            }

            StreamReader macroFile = File.OpenText ("../" + macroFileName);
            while (!macroFile.EndOfStream) {
                string line = macroFile.ReadLine ();
                _macro.Add (line);
            }

            // Instantiate
            IEnumerable<float> loader = null;
            InitialSaveFileCreator saveCreator = new InitialSaveFileCreator ();

            if(saveFileName != "") {
                //IEnumerable<float> loader = saveCreator.LoadFromFile("../../../../../assembla/MimanUnity2/Saves/Quicksave.json");
                loader = saveCreator.LoadFromFile(saveFileName);
            } else {
                loader = saveCreator.LoadRelayFromDirectory ("../../../../../assembla/MimanUnity2/InitData/");
            }

            // Load files
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            foreach (float f in loader) {
                Console.Write (".");
            }
            Console.Write ("\n");

            // Setup world and its runners
            _world = new World (saveCreator.GetLoadedRelay ());
            SetupWorldListeners ();

            SmartWalkBehaviour.s_logger.AddListener (Console.WriteLine);

            LoadTranslationFiles();

            // Preload
            foreach (string s in _world.Preload()) {
                //Console.WriteLine(s);
            }

            Console.WriteLine ("Loading took " + (DateTime.Now - startTime).TotalSeconds + " seconds");
            Console.ForegroundColor = ConsoleColor.White;

            #if ONLY_STARTUP
            return;
            #endif

            // Run a few frames
            for (int i = 0; i < 30; i++) {
                _world.Update (NORMAL_DELTA_TIME);
            }

            if(saveFileName == "") {
                _world.dialogueRunner.StartConversation ("StoryStart");
            }

            // Run
            while (_run) {
                try {
                    PrintBranchingNode ();

                    if (_autoPilot) {
                        if (_macroPos < _macro.Count) {
                            Eval (new string[] { "macro" });
                        } else {
                            Eval (new string[] { "tick" });
                        }
                        if (_world.settings.totalWorldTime > _timeLimit) {
                            Eval (new string[] { "clock" });
                            Console.WriteLine ("Stopped by time limit (" + _timeLimit + " s.)");
                            break;
                        }
                    } else {
                        Console.ForegroundColor = ConsoleColor.White;
                        //Console.Write("\n> ");
                        Console.Write ("\n" + _world.settings.gameTimeClock + " => ");
                        string command = Console.ReadLine ();
                        Eval (Split (command));
                    }
                } catch (Exception e) {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine ("Error in World: " + e.Message + ", stack trace:\n" + e.StackTrace);
                    Console.ForegroundColor = ConsoleColor.White;
                    if (_autoPilot) {
                        _run = false;
                    }
                }
            }
        }
コード例 #14
0
        public void CheckBalance()
        {
            WorldCoordinate testDefaultCoordinate = new WorldCoordinate("Eden", IntPoint.Zero);

            WorldTestHelper.GenerateInitData ();
            InitialSaveFileCreator i = new InitialSaveFileCreator ();
            World world = new World (i.CreateRelay (WorldTestHelper.INIT_DATA_PATH));

            D.onDLog += o => Console.WriteLine("D.Log: " + o);
            world.dialogueRunner.AddOnSomeoneSaidSomethingListener(o => Console.WriteLine("Dialogue: " + o));

            CreditCard card = world.tingRunner.CreateTing<CreditCard> ("Visa", testDefaultCoordinate);
            card.logger.AddListener (o => Console.WriteLine ("Card log: " + o));
            card.AddDataListener ("dialogueLine", (string oldValue, string newValue) => {
                Console.WriteLine ("Card said: " + newValue);
            });
            card.nameOfOwner = "Eva";
            card.masterProgramName = "EvasCard";

            Computer financeComputer = world.tingRunner.CreateTing<Computer>("FinanceComputer", testDefaultCoordinate);
            financeComputer.masterProgramName = "FinanceComputer";
            financeComputer.hasMemoryAPI = true;
            financeComputer.masterProgram.Start();

            WorldTestHelper.UpdateWorld (world, 3f);
            card.RunMakeTransactionFunction (100.0f);
            WorldTestHelper.UpdateWorld (world, 3f);

            Console.WriteLine ("Evas card errors: ");
            foreach (var error in card.masterProgram.GetErrors()) {
                Console.WriteLine (error.ToString ());
            }

            Console.WriteLine ("Finance computer errors: ");
            foreach (var error in financeComputer.masterProgram.GetErrors()) {
                Console.WriteLine (error.ToString ());
            }

            Console.WriteLine ("Finance computer output: ");
            PrintOutput(financeComputer);

            Assert.IsNotNull(financeComputer.memory);
            Assert.IsNotNull(financeComputer.memory.data);

            object cashAmount = null;
            bool gotIt = financeComputer.memory.data.TryGetValue("Eva", out cashAmount);

            Assert.IsTrue(gotIt);
            Assert.AreEqual(typeof(float), cashAmount.GetType());
            Assert.AreEqual(100.0f, (float)cashAmount);

            card.RunMakeTransactionFunction(-20.0f);
            WorldTestHelper.UpdateWorld (world, 1.0f);

            Assert.IsNotNull(financeComputer.memory);
            Assert.IsNotNull(financeComputer.memory.data);

            object cashAmount2 = null;
            bool gotIt2 = financeComputer.memory.data.TryGetValue("Eva", out cashAmount2);

            Assert.IsTrue(gotIt2);
            Assert.AreEqual(80.0f, (float)cashAmount2);
        }
コード例 #15
0
ファイル: Main.cs プロジェクト: eriksvedang/GameWorld2
        private static void ProfileMimanPathfinding(int worldSize)
        {
            D.onDLog += Console.WriteLine;

            InitialSaveFileCreator isc = new InitialSaveFileCreator();
            World world = new World(isc.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);

            int worldWidth = worldSize;
            int worldHeight = worldSize;
            int roomSize = 10;

            int tingCounter = 0;

            for (int x = 0; x <= worldWidth; x++) {
                for (int y = 0; y <= worldHeight; y++) {
                    Room r = srb.CreateRoomWithSize("Room_" + x + "_" + y, roomSize, roomSize);

                    Door door1 = world.tingRunner.CreateTing<Door> (r.name + "_Door1", new WorldCoordinate (r.name, new IntPoint (0, 0)));
                    Door door2 = world.tingRunner.CreateTing<Door> (r.name + "_Door2", new WorldCoordinate (r.name, new IntPoint (roomSize - 1, roomSize - 1)));
                    door1.direction = Direction.DOWN;
                    door2.direction = Direction.UP;

                    // Randomizer.GetIntValue (0, roomSize);

                    int rx1 = (x + 1) % worldWidth;
                    int ry1 = y;
                    door1.targetDoorName = "Room_" + rx1 + "_" + ry1 + "_Door2";

                    int rx2 = x;
                    int ry2 = (y + 1) % worldHeight;
                    door2.targetDoorName = "Room_" + rx2 + "_" + ry2 + "_Door1";

                    world.tingRunner.CreateTing<Point> ("Point_" + (tingCounter++), new WorldCoordinate (r.name, new IntPoint (roomSize / 2, roomSize / 2)));

                    r.worldPosition = new IntPoint(x * roomSize + Randomizer.GetIntValue(-3, 3),
                                                   y * roomSize + Randomizer.GetIntValue(-3, 3));
                }
            }

            world.sourceCodeDispenser.CreateSourceCodeFromString ("OnDoorUsed", "");

            if(!world.isReadyToPlay) {
                foreach (string s in world.Preload())
                {
                    //Console.WriteLine(s);
                }
            }

            Console.WriteLine ("Room runner stats: " + world.roomRunner.ToString ());

            var pathfinder = new MimanPathfinder2 (world.tingRunner, world.roomRunner);

            for (int i = 0; i < 100; i++) {
                Point start = world.tingRunner.GetTing<Point> ("Point_" + Randomizer.GetIntValue (0, tingCounter));
                Point goal = world.tingRunner.GetTing<Point> ("Point_" + Randomizer.GetIntValue (0, tingCounter));
                var result = pathfinder.Search (start, goal);
                Console.WriteLine (result.status);
            }
        }
コード例 #16
0
        public void LoadAndSaveDialogueDuplicationBug()
        {
            string saveName = "../Saves/step1_save.json";
            var outputDialogue = new List<string>();

            Console.WriteLine("STEP 1");

            // Step 1
            {
                InitialSaveFileCreator i = new InitialSaveFileCreator();
                var world1 = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));
                WorldTestHelper.PreloadWorld(world1);

                GameTypes.D.onDLog += Console.WriteLine;
                world1.dialogueRunner.logger.AddListener(Console.WriteLine);

                world1.dialogueRunner.AddOnSomeoneSaidSomethingListener(o => {
                    Console.WriteLine(o.speaker + ": " + o.line);
                    outputDialogue.Add(o.line);
                });

                WorldTestHelper.UpdateWorld(world1, 1f);
                PrintActiveStuff(world1);
                world1.dialogueRunner.RunStringAsFunction("Story(BeforeFirst)");
                WorldTestHelper.UpdateWorld(world1, 1f);
                PrintActiveStuff(world1);

                world1.dialogueRunner.RunStringAsFunction("Story(First)");
                WorldTestHelper.UpdateWorld(world1, 0.5f);
                PrintActiveStuff(world1);

                world1.dialogueRunner.EventHappened("DO_IT_REAL_GOOD");
                PrintActiveStuff(world1);
                WorldTestHelper.UpdateWorld(world1, 3f);

                world1.Save(saveName);

                GameTypes.D.onDLog -= Console.WriteLine;
            }

            Console.WriteLine("\n\nSTEP 2");

            // Step 2
            {
                var world2 = new World(saveName);
                WorldTestHelper.PreloadWorld(world2);

                world2.dialogueRunner.logger.AddListener(Console.WriteLine);
                GameTypes.D.onDLog += Console.WriteLine;

                world2.dialogueRunner.AddOnSomeoneSaidSomethingListener(o => {
                    Console.WriteLine(o.speaker + ": " + o.line);
                    outputDialogue.Add(o.line);
                });

                PrintActiveStuff(world2);
                WorldTestHelper.UpdateWorld(world2, 3f);
                PrintActiveStuff(world2);

                world2.dialogueRunner.RunStringAsFunction("Story(Second)");
                WorldTestHelper.UpdateWorld(world2, 3.0f);

                PrintActiveStuff(world2);

                world2.dialogueRunner.EventHappened("DO_IT_REAL_GOOD");
                WorldTestHelper.UpdateWorld(world2, 3f);

            }
        }
コード例 #17
0
        public void LoadTimeTablesFromSave()
        {
            string saveName = "TimeTableSaveTest.json";

            _eva.timetableName = "Timetable1";
            _world.Save(saveName);

            World newWorld = new World(saveName);
            foreach(string s in newWorld.Preload()) {}

            Character newEva = newWorld.tingRunner.GetTing<Character>("Eva");
            Timetable newTimetable = newWorld.timetableRunner.GetTimetable("Timetable1");

            Assert.IsNotNull(newTimetable);
            Assert.AreEqual(newTimetable, newEva.timetable);
            Assert.AreEqual(2, newEva.timetable.timetableSpans.Length);
        }
コード例 #18
0
        public void PrintActiveStuff(World pWorld)
        {
            var activeConversations = pWorld.dialogueRunner.GetActiveConversations();
            var activeConversationsList = new List<string>();
            foreach(var s in activeConversations) {
                activeConversationsList.Add(s);
            }
            Console.WriteLine("Active conversations: " + string.Join(", ", activeConversationsList.ToArray()));

            var registeredNodes = pWorld.dialogueRunner.GetRegisteredDialogueNodes();
            var registeredNodeNames = new List<string>();
            foreach(var node in registeredNodes) {
                registeredNodeNames.Add("[" + node.name + " in conversation" + node.conversation + " " + (node.isListening ? "LISTENING" : "NOT listening") + "]");
            }
            Console.WriteLine("Registered nodes: " + string.Join(", ", registeredNodeNames.ToArray()));
        }
コード例 #19
0
 public void SetUp()
 {
     WorldTestHelper.GenerateInitData();
     InitialSaveFileCreator i = new InitialSaveFileCreator();
     _world = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));
     _adam = _world.tingRunner.GetTing("Adam") as Character;
     _eva = _world.tingRunner.GetTing("Eva") as Character;
     _cube = _world.tingRunner.GetTing("PowerCube") as MysticalCube;
 }
コード例 #20
0
 public void SetUp()
 {
     WorldTestHelper.GenerateInitData();
     InitialSaveFileCreator i = new InitialSaveFileCreator();
     _world = new World(i.CreateRelay(WorldTestHelper.INIT_DATA_PATH));
     _adam = _world.tingRunner.GetTing("Adam") as Character;
     _eva = _world.tingRunner.GetTing("Eva") as Character;
     D.onDLog += (pMessage) => Console.WriteLine(pMessage);
 }
コード例 #21
0
        World CreateWorldWithSomeRooms()
        {
            InitialSaveFileCreator isc = new InitialSaveFileCreator();
            World world = new World(isc.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);
            srb.CreateRoomWithSize("Eden", 10, 10);
            var middleRoom = srb.CreateRoomWithSize("MiddleRoom", 10, 10);
            var wrongRoom = srb.CreateRoomWithSize("WrongRoom", 10, 10);
            var distantRoom = srb.CreateRoomWithSize("DistantRoom", 10, 10);

            middleRoom.worldPosition = new IntPoint(10, 0);
            wrongRoom.worldPosition = new IntPoint(30, 0);
            distantRoom.worldPosition = new IntPoint(50, 0);

            // Add doors
            var edenDoor = world.tingRunner.CreateTing<Door>("edenDoor", new WorldCoordinate("Eden", new IntPoint(4, 4)));
            var middleRoomDoor1 = world.tingRunner.CreateTing<Door>("middleRoomDoor1", new WorldCoordinate("MiddleRoom", new IntPoint(2, 4)));
            var middleRoomDoor2 = world.tingRunner.CreateTing<Door>("middleRoomDoor2", new WorldCoordinate("MiddleRoom", new IntPoint(7, 4)));
            var middleRoomDoor3 = world.tingRunner.CreateTing<Door>("middleRoomDoor3", new WorldCoordinate("MiddleRoom", new IntPoint(4, 4)));
            var wrongRoomDoor = world.tingRunner.CreateTing<Door>("wrongRoomDoor", new WorldCoordinate("WrongRoom", new IntPoint(4, 4)));
            var distantRoomDoor = world.tingRunner.CreateTing<Door>("distantRoomDoor", new WorldCoordinate("DistantRoom", new IntPoint(2, 4)));

            edenDoor.targetDoorName = "middleRoomDoor1";
            middleRoomDoor1.targetDoorName = "edenDoor";
            middleRoomDoor2.targetDoorName = "distantRoomDoor";
            middleRoomDoor3.targetDoorName = "wrongRoomDoor";
            wrongRoomDoor.targetDoorName = "middleRoomDoor3";
            distantRoomDoor.targetDoorName = "middleRoomDoor2";

            var distantTile = new PointTileNode(new IntPoint(200, 200), wrongRoom);
            distantTile.group = 1;
            wrongRoom.AddTile(distantTile);

            var wrongRoomUnattachedDoor = world.tingRunner.CreateTing<Door>("wrongRoomUnattachedDoor", new WorldCoordinate("WrongRoom", new IntPoint(200, 200)));
            wrongRoomUnattachedDoor.targetDoorName = "edenDoor";

            world.sourceCodeDispenser.CreateSourceCodeFromString ("OnDoorUsed", "");

            if(!world.isReadyToPlay) {
                foreach (string s in world.Preload()) {}
            }

            return world;
        }
コード例 #22
0
        public void EvaWalksWithSaveInTheMiddle()
        {
            const string saveName = "EvaWalksWithSaveInTheMiddle.json";

            // These variables are for checking that everything stays the same after loading the save
            IntPoint midPoint = new IntPoint(-1, -1);
            float walkTimerWhenSaving;
            int walkIteratorWhenSaving;

            {
                _eva.position = new WorldCoordinate("Hallway", IntPoint.Zero);
                _eva.walkSpeed = 1.0f; // 1 tile per second
                _eva.WalkTo(new WorldCoordinate("Hallway", new IntPoint(4, 4)));

                WorldTestHelper.UpdateWorld(_world, 1f);
                Assert.AreEqual("Walking", _eva.actionName);

                WorldTestHelper.UpdateWorld(_world, 2.5f);

                midPoint = _eva.localPoint;
                walkTimerWhenSaving = _eva.walkTimer;
                walkIteratorWhenSaving = _eva.walkIterator;

                _world.Save(saveName);
                _world = null;
            }

            {
                World freshWorld = new World(saveName);

                _eva = freshWorld.tingRunner.GetTing("Eva") as Character;
                Assert.AreEqual(midPoint, _eva.localPoint);
                Assert.AreEqual(walkTimerWhenSaving, _eva.walkTimer);
                Assert.AreEqual(walkIteratorWhenSaving, _eva.walkIterator);

                WorldTestHelper.UpdateWorld(freshWorld, 5.0f);
                Assert.AreEqual(new IntPoint(4, 4), _eva.localPoint);
                Assert.AreEqual("", _eva.actionName);
            }
        }