Esempio n. 1
0
        public World LoadWorld(string worldName)
        {
            if (_worldManager.WorldExists(worldName))
            {
                WorldDirectory = _worldManager.GetWorldDirectory(worldName);
                GameServer.Instance.Worlds.CurrentWorldDirectory = WorldDirectory;
                WorldName = worldName;
                WorldConfigSave worldSave = FileManager.LoadObject <WorldConfigSave>(WorldDirectory + AppSettings.WorldSaveFile, false);
                WorldStartTime = worldSave.time;
                Terrain        = new TerrainBuilder(worldSave.terrain);
                GameServer.Instance.Users.LoadUsers(WorldDirectory + "Users" + GameServer.sepChar);
                GameServer.Instance.Alliances.Load(worldSave.alliances);
                GameServer.Instance.Structures.Load();

                Logger.Log("World \"{0}\" loaded.", worldName);
                GameServer.Instance.StartWorld(this);
            }
            else
            {
                Logger.LogWarning("Created world \"{0}\" as it does not exists.", worldName);
                CreateNewWorld(worldName);
            }

            return(this);
        }
Esempio n. 2
0
        public World CreateNewWorld(string worldName)
        {
            string stage = "stage1";

            try {
                Logger.Log("Creating new world '{0}'.", worldName);
                WorldDirectory = _worldManager.MainWorldDirectory + worldName + GameServer.sepChar;
                if (!Directory.Exists(WorldDirectory))
                {
                    Directory.CreateDirectory(WorldDirectory);
                }
                _worldManager.AddWorldDirectory(worldName, WorldDirectory);
                _worldManager.CurrentWorldDirectory = WorldDirectory;

                IModule module = new Perlin();
                ((Perlin)module).OctaveCount = 16;
                ((Perlin)module).Seed        = AppSettings.TerrainSeed;
                Terrain = new TerrainBuilder(AppSettings.TerrainWidth, AppSettings.TerrainHeight, AppSettings.TerrainSeed);
                Terrain.Generate(module, AppSettings.TerrainPreset);
                Terrain.Save(WorldDirectory + AppSettings.TerrainImageFile);
                Terrain.SaveModule(WorldDirectory + AppSettings.TerrainModuleFile);
                WorldName = worldName;
                WorldConfigSave worldSave = new WorldConfigSave();
                WorldStartTime      = new Time(0, 0, 0, 0, 0, 0, AppSettings.SecondsInTicks);
                worldSave.version   = GameServer.Instance.Version;
                worldSave.time      = WorldStartTime;
                worldSave.terrain   = Terrain.Settings;
                worldSave.alliances = GameServer.Instance.Alliances.Save();
                FileManager.SaveConfigFile(WorldDirectory + AppSettings.WorldSaveFile, worldSave, false);
                GameServer.Instance.Users.Save(WorldDirectory + "Users" + GameServer.sepChar);

                Logger.Log("World \"{0}\" created.", worldName);
                GameServer.Instance.StartWorld(this);
            }
            catch (JsonSerializationException e) {
                Logger.LogError("json serialization failed: {0}", stage);
                Logger.LogError(e.StackTrace);
            }
            catch (Exception e) {
                Logger.LogError("{0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
            }
            return(this);
        }
Esempio n. 3
0
        public World CreateNewWorld(string worldName)
        {
            string stage = "stage1";
            try {
                Logger.Log("Creating new world '{0}'.", worldName);
                WorldDirectory = _worldManager.MainWorldDirectory + worldName + GameServer.sepChar;
                if (!Directory.Exists (WorldDirectory))
                    Directory.CreateDirectory (WorldDirectory);
                _worldManager.AddWorldDirectory (worldName, WorldDirectory);
                _worldManager.CurrentWorldDirectory = WorldDirectory;

                IModule module = new Perlin ();
                ((Perlin)module).OctaveCount = 16;
                ((Perlin)module).Seed = AppSettings.TerrainSeed;
                Terrain = new TerrainBuilder (AppSettings.TerrainWidth, AppSettings.TerrainHeight, AppSettings.TerrainSeed);
                Terrain.Generate (module, AppSettings.TerrainPreset);
                Terrain.Save(WorldDirectory + AppSettings.TerrainImageFile);
                Terrain.SaveModule(WorldDirectory + AppSettings.TerrainModuleFile);
                WorldName = worldName;
                WorldConfigSave worldSave = new WorldConfigSave ();
                WorldStartTime = new Time (0, 0, 0, 0, 0, 0, AppSettings.SecondsInTicks);
                worldSave.version = GameServer.Instance.Version;
                worldSave.time = WorldStartTime;
                worldSave.terrain = Terrain.Settings;
                worldSave.alliances = GameServer.Instance.Alliances.Save();
                FileManager.SaveConfigFile(WorldDirectory + AppSettings.WorldSaveFile, worldSave, false);
                GameServer.Instance.Users.Save(WorldDirectory + "Users" + GameServer.sepChar);

                Logger.Log ("World \"{0}\" created.", worldName);
                GameServer.Instance.StartWorld (this);
            }
            catch (JsonSerializationException e){
                Logger.LogError("json serialization failed: {0}", stage);
                Logger.LogError(e.StackTrace);
            }
            catch (Exception e){
                Logger.LogError("{0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
            }
            return this;
        }
Esempio n. 4
0
        public World LoadWorld(string worldName)
        {
            if (_worldManager.WorldExists (worldName)) {
                WorldDirectory = _worldManager.GetWorldDirectory(worldName);
                GameServer.Instance.Worlds.CurrentWorldDirectory = WorldDirectory;
                WorldName = worldName;
                WorldConfigSave worldSave = FileManager.LoadObject<WorldConfigSave>(WorldDirectory + AppSettings.WorldSaveFile, false);
                WorldStartTime = worldSave.time;
                Terrain = new TerrainBuilder(worldSave.terrain);
                GameServer.Instance.Users.LoadUsers(WorldDirectory + "Users" + GameServer.sepChar);
                GameServer.Instance.Alliances.Load(worldSave.alliances);
                GameServer.Instance.Structures.Load();

                Logger.Log("World \"{0}\" loaded.", worldName);
                GameServer.Instance.StartWorld(this);

            } else {
                Logger.LogWarning ("Created world \"{0}\" as it does not exists.", worldName);
                CreateNewWorld(worldName);
            }

            return this;
        }
Esempio n. 5
0
        private object Preview_CMD(User caller, params string[] args)
        {
            int seed = 0;

            if (args.Length == 1)
            {
                seed = AppSettings.TerrainSeed;
            }
            else if (args.Length == 2 && args [1].Equals("-r"))
            {
                seed = new Random(GameTimer.GetEpoch()).Next(int.MinValue, int.MaxValue);
            }
            else if (args.Length == 2)
            {
                if (int.TryParse(args[1], out seed))
                {
                    ;
                }
            }
            TaskQueue.QeueAsync("terrain preview", () => {
                try {
                    List <GradientPresets.GradientKeyData> keys = new List <GradientPresets.GradientKeyData>();
                    keys.Add(new GradientPresets.GradientKeyData(new Color(255, 0, 0, 128), 0));
                    keys.Add(new GradientPresets.GradientKeyData(new Color(255, 32, 64, 128), 0.4f));
                    keys.Add(new GradientPresets.GradientKeyData(new Color(255, 64, 96, 191), 0.48f));
                    keys.Add(new GradientPresets.GradientKeyData(new List <string> {
                        "sand.png"
                    }, 0.5f));
                    keys.Add(new GradientPresets.GradientKeyData(new List <string> {
                        "trees1.png", "trees2.png"
                    }, 0.52f));
                    keys.Add(new GradientPresets.GradientKeyData(new List <string> {
                        "grass1.png", "trees2.png"
                    }, 0.55f));
                    keys.Add(new GradientPresets.GradientKeyData(new List <string> {
                        "grass1.png", "grass2.png", "trees2.png"
                    }, 0.60f));
                    keys.Add(new GradientPresets.GradientKeyData(new List <string> {
                        "grass1.png", "grass2.png"
                    }, 0.90f));
                    keys.Add(new GradientPresets.GradientKeyData(new List <string> {
                        "grass1.png", "grass2.png"
                    }, 1f));
                    //GradientPresets.CreateGradient(keys);
                    GradiantPresetLoader.PresetSerializer saveObj = new GradiantPresetLoader.PresetSerializer(AppSettings.TerrainPreset, keys);
                    FileManager.SaveConfigFile(GameServer.Instance.AppDirectory + "GradientPresets" + GameServer.sepChar + AppSettings.TerrainPreset + ".json", saveObj, false);
                    //return;
                    IModule module = new Perlin();
                    ((Perlin)module).OctaveCount = 16;
                    ((Perlin)module).Seed        = AppSettings.TerrainSeed;

                    TerrainBuilder builder = new TerrainBuilder(AppSettings.TerrainWidth, AppSettings.TerrainHeight, seed);
                    builder.Generate(module, AppSettings.TerrainPreset);
                    System.Drawing.Bitmap map = builder.GetBitmap();

                    /*System.Windows.Forms.Form imageForm = new System.Windows.Forms.Form();
                     *                  imageForm.Text = "Seed preview: " + seed;
                     *                  imageForm.Width = settings.TerrainWidth;
                     *                  imageForm.Height = settings.TerrainHeight;
                     *                  imageForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
                     *                  imageForm.Controls.Add (new System.Windows.Forms.PictureBox () {Image = map, Dock = System.Windows.Forms.DockStyle.Fill});
                     *                  imageForm.ShowDialog();
                     *                  Logger.Log("Preview closed.");
                     *                  imageForm.Close();
                     *                  imageForm.Dispose();*/
                }
                catch (Exception e) {
                    Logger.LogError("{0}\n{1}", e.Message, e.StackTrace);
                }
            });
            return("Seed: " + seed);
        }
        private object Preview_CMD(User caller, params string[] args)
        {
            int seed = 0;
            if (args.Length == 1)
                seed = AppSettings.TerrainSeed;
            else if (args.Length == 2 && args [1].Equals ("-r")) {
                seed = new Random (GameTimer.GetEpoch ()).Next (int.MinValue, int.MaxValue);
            } else if (args.Length == 2) {
                if (int.TryParse(args[1], out seed));
            }
            TaskQueue.QeueAsync("terrain preview", ()=>{
                try {
                    List<GradientPresets.GradientKeyData> keys = new List<GradientPresets.GradientKeyData>();
                    keys.Add(new GradientPresets.GradientKeyData(new Color(255, 0, 0, 128), 0));
                    keys.Add(new GradientPresets.GradientKeyData(new Color(255, 32, 64, 128), 0.4f));
                    keys.Add(new GradientPresets.GradientKeyData(new Color(255, 64, 96, 191), 0.48f));
                    keys.Add(new GradientPresets.GradientKeyData(new List<string> {"sand.png"}, 0.5f));
                    keys.Add(new GradientPresets.GradientKeyData(new List<string> {"trees1.png", "trees2.png" }, 0.52f));
                    keys.Add(new GradientPresets.GradientKeyData(new List<string> {"grass1.png", "trees2.png"}, 0.55f));
                    keys.Add(new GradientPresets.GradientKeyData(new List<string> {"grass1.png", "grass2.png", "trees2.png"}, 0.60f));
                    keys.Add(new GradientPresets.GradientKeyData(new List<string> {"grass1.png", "grass2.png"}, 0.90f));
                    keys.Add(new GradientPresets.GradientKeyData(new List<string> {"grass1.png", "grass2.png"}, 1f));
                    //GradientPresets.CreateGradient(keys);
                    GradiantPresetLoader.PresetSerializer saveObj = new GradiantPresetLoader.PresetSerializer(AppSettings.TerrainPreset, keys);
                    FileManager.SaveConfigFile(GameServer.Instance.AppDirectory + "GradientPresets" + GameServer.sepChar + AppSettings.TerrainPreset+".json", saveObj, false);
                    //return;
                    IModule module = new Perlin ();
                    ((Perlin)module).OctaveCount = 16;
                    ((Perlin)module).Seed = AppSettings.TerrainSeed;

                    TerrainBuilder builder = new TerrainBuilder(AppSettings.TerrainWidth, AppSettings.TerrainHeight, seed);
                    builder.Generate (module, AppSettings.TerrainPreset);
                    System.Drawing.Bitmap map = builder.GetBitmap();
                    /*System.Windows.Forms.Form imageForm = new System.Windows.Forms.Form();
                    imageForm.Text = "Seed preview: " + seed;
                    imageForm.Width = settings.TerrainWidth;
                    imageForm.Height = settings.TerrainHeight;
                    imageForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
                    imageForm.Controls.Add (new System.Windows.Forms.PictureBox () {Image = map, Dock = System.Windows.Forms.DockStyle.Fill});
                    imageForm.ShowDialog();
                    Logger.Log("Preview closed.");
                    imageForm.Close();
                    imageForm.Dispose();*/
                }
                catch(Exception e){
                    Logger.LogError("{0}\n{1}", e.Message, e.StackTrace);
                }
            });
            return "Seed: " + seed;
        }