Esempio n. 1
0
        public static SerializedWorld FromWorld(Internal.Model.World world)
        {
            var sWorld = new SerializedWorld();

            world.ForEach((v, p) => sWorld.Voxels.Add(SerializedVoxel.FromVoxel(v)));
            return(sWorld);
        }
Esempio n. 2
0
        /*public static GodGameOffline CreateGame()
         * {
         *  var world = new Internal.Model.World(100, 10);
         *  buildDemoWorld(world);
         *
         *
         *
         *
         *  var ret = new GodGameOffline(EngineFactory.CreateEngine(), world);
         *
         *  return ret;
         * }*/

        private static void buildDemoWorld(Internal.Model.World world, VoxelTypesFactory typesFactory)
        {
            world.ForEach((v, p) =>
            {
                if (Vector2.Distance(p, new Vector2(100, 100)) < 100)
                {
                    v.Data.Type = typesFactory.Get <LandType>();
                }
                else if (Vector2.Distance(p, new Vector2(8, 8)) < 7)
                {
                    v.Data.Type = typesFactory.Get <LandType>();
                }
                else if (Vector2.Distance(p, new Vector2(25, 25)) < 15)
                {
                    v.Data.Type = typesFactory.Get <LandType>();
                }
                //v.ChangeType(GameVoxelType.Infestation);
                else
                {
                    v.Data.Type = typesFactory.Get <LandType>();
                }
            });


            /*var worldPersister = new WorldPersister(getTypeFromName, getItemFromName);
             * var simpleWorldRenderer = new SimpleWorldRenderer(world);
             * var ret = new GodGameOffline(EngineFactory.CreateEngine(),
             *  world,
             *  new UserInputProcessingService(createPlayerInputs(world).ToArray(), world, worldPersister, simpleWorldRenderer),
             *  worldPersister,
             *  simpleWorldRenderer);
             *
             * return ret;*/
        }
        public AllCommandProvider(WorldPersisterService persister,
                                  Internal.Model.World world,
                                  VoxelTypesFactory typesFactory,
                                  ItemTypesFactory itemTypesFactory,
                                  UserInputProcessingService userInputProcessingService,
                                  GenericDatastore genericDatastore)
        {
            this.typesFactory     = typesFactory;
            this.itemTypesFactory = itemTypesFactory;
            this.genericDatastore = genericDatastore;
            addDummy();

            addPersistence(persister, world);

            addCommand("clearinfestation", () =>
            {
                world.ForEach((v, _) =>
                {
                    if (v.Type != typesFactory.Get <InfestationVoxelType>())
                    {
                        return;
                    }
                    typesFactory.Get <InfestationVoxelType>().CureInfestation(v);
                });

                return("Cleared all infestation!");
            });

            addCommand("helpall", () =>
            {
                return("All Commands: " + string.Join(", ", CommandNames.ToArray()));
            });
            addCommand("help", partialCommand =>
            {
                return("Commands containing '" + partialCommand + "': " + string.Join(", ", CommandNames.Where(c => c.Contains(partialCommand)).ToArray()));
            });
            addCommand("clearWorld", () =>
            {
                genericDatastore.ClearAll();
                world.ForEach((v, _) =>
                {
                    v.Data.Type = typesFactory.Get <LandType>();
                });
                return("World cleared!");
            });
            addCommand("listsaves", () =>
            {
                var saves        = TWDir.GameData.CreateChild("Saves\\GodGame").GetFiles().ToList();
                var outputstring = String.Join(", ", saves.Select(e => e.Name.Substring(0, e.Name.Length - 4)));     // Drop extension
                return("Saved games: \n" + outputstring);
            });

            addCommand("addresource", (typeStr, amountStr) =>
            {
                var itemType = itemTypesFactory.AllTypes.FirstOrDefault(t => t.Name.ToLower() == typeStr.ToLower());
                if (itemType == null)
                {
                    return("Item type not found: " + typeStr);
                }
                var amount = 0;
                if (!int.TryParse(amountStr, out amount))
                {
                    return("Invalid item amount: " + amountStr);
                }

                var target = userInputProcessingService.GetTargetedVoxel();
                if (target == null || target.Type != typesFactory.Get <WarehouseType>())
                {
                    return("Not targeting a warehouse");
                }

                target.Data.Inventory.AddNewItems(itemType, amount);

                return("Added items!");
            });
        }