public static void Start(Player player) { Map map = MapGeneratorOld.GenerateEmpty(64, 128, 16); map.Save("maps/minefield.fcm"); if (_world != null) { WorldManager.RemoveWorld(_world); } WorldManager.AddWorld(Player.Console, "Minefield", map, true); _map = map; _world = WorldManager.FindWorldExact("Minefield"); SetUpRed(); SetUpMiddleWater(); SetUpGreen(); SetUpMines(); _map.Spawn = new Position(_map.Width / 2, 5, _ground + 3).ToVector3I().ToPlayerCoords(); _world.LoadMap(); _world.gameMode = GameMode.MineField; _world.EnableTNTPhysics(Player.Console, false); Server.Message("{0}&S started a game of MineField on world Minefield!", player.ClassyName); WorldManager.SaveWorldList(); Server.RequestGC(); }
internal static bool LoadWorldList() { World newMainWorld = null; Worlds = new World[0]; if (File.Exists(Paths.WorldListFileName)) { try { XDocument doc = XDocument.Load(Paths.WorldListFileName); XElement root = doc.Root; if (root != null) { foreach (XElement el in root.Elements("World")) { #if !DEBUG try { #endif LoadWorldListEntry(el); #if !DEBUG } catch (Exception ex) { Logger.LogAndReportCrash("An error occured while trying to parse one of the entries on the world list", "800Craft", ex, false); } #endif } XAttribute temp; if ((temp = root.Attribute("main")) != null) { World suggestedMainWorld = FindWorldExact(temp.Value); if (suggestedMainWorld != null) { newMainWorld = suggestedMainWorld; } else if (firstWorld != null) { // if specified main world does not exist, use first-defined world Logger.Log(LogType.Warning, "The specified main world \"{0}\" does not exist. " + "\"{1}\" was designated main instead. You can use /WMain to change it.", temp.Value, firstWorld.Name); newMainWorld = firstWorld; } // if firstWorld was also null, LoadWorldList() should try creating a new mainWorld } else if (firstWorld != null) { newMainWorld = firstWorld; } } } catch (Exception ex) { Logger.LogAndReportCrash("Error occured while trying to load the world list.", "800Craft", ex, true); return(false); } if (newMainWorld == null) { Logger.Log(LogType.Error, "Server.Start: Could not load any of the specified worlds, or no worlds were specified. " + "Creating default \"main\" world."); newMainWorld = AddWorld(null, "main", MapGeneratorOld.GenerateFlatgrass(128, 128, 64), true); } } else { Logger.Log(LogType.SystemActivity, "Server.Start: No world list found. Creating default \"main\" world."); newMainWorld = AddWorld(null, "main", MapGeneratorOld.GenerateFlatgrass(128, 128, 64), true); } // if there is no default world still, die. if (newMainWorld == null) { throw new Exception("Could not create any worlds."); } else if (newMainWorld.AccessSecurity.HasRestrictions) { Logger.Log(LogType.Warning, "Server.LoadWorldList: Main world cannot have any access restrictions. " + "Access permission for \"{0}\" has been reset.", newMainWorld.Name); newMainWorld.AccessSecurity.Reset(); } MainWorld = newMainWorld; return(true); }
public static void RealmCreate(Player player, Command cmd, string themeName, string templateName) { MapGenTemplate template; MapGenTheme theme; int wx, wy, height = 128; if (!(cmd.NextInt(out wx) && cmd.NextInt(out wy) && cmd.NextInt(out height))) { if (player.World != null) { wx = 128; wy = 128; height = 128; } else { player.Message("When used from console, /gen requires map dimensions."); return; } cmd.Rewind(); cmd.Next(); cmd.Next(); } if (!Map.IsValidDimension(wx)) { player.Message("Cannot make map with width {0}: dimensions must be multiples of 16.", wx); return; } else if (!Map.IsValidDimension(wy)) { player.Message("Cannot make map with length {0}: dimensions must be multiples of 16.", wy); return; } else if (!Map.IsValidDimension(height)) { player.Message("Cannot make map with height {0}: dimensions must be multiples of 16.", height); return; } string fileName = player.Name.Replace(".", "-"); string fullFileName = null; if (fileName == null) { if (player.World == null) { player.Message("When used from console, /gen requires FileName."); return; } if (!cmd.IsConfirmed) { player.Confirm(cmd, "Replace this realm's map with a generated one?"); return; } } else { fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!fileName.EndsWith(".fcm", StringComparison.OrdinalIgnoreCase)) { fileName += ".fcm"; } fullFileName = Path.Combine(Paths.MapPath, fileName); if (!Paths.IsValidPath(fullFileName)) { player.Message("Invalid filename."); return; } if (!Paths.Contains(Paths.MapPath, fullFileName)) { player.MessageUnsafePath(); return; } string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar)); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } if (!cmd.IsConfirmed && File.Exists(fullFileName)) { player.Confirm(cmd, "The mapfile \"{0}\" already exists. Overwrite?", fileName); return; } } bool noTrees; if (themeName.Equals("grass", StringComparison.OrdinalIgnoreCase)) { theme = MapGenTheme.Forest; noTrees = true; } else { try { theme = ( MapGenTheme )Enum.Parse(typeof(MapGenTheme), themeName, true); noTrees = (theme != MapGenTheme.Forest); } catch (Exception) { player.MessageNow("Unrecognized theme \"{0}\". Available themes are: Grass, {1}", themeName, String.Join(", ", Enum.GetNames(typeof(MapGenTheme)))); return; } } try { template = ( MapGenTemplate )Enum.Parse(typeof(MapGenTemplate), templateName, true); } catch (Exception) { player.Message("Unrecognized template \"{0}\". Available templates are: {1}", templateName, String.Join(", ", Enum.GetNames(typeof(MapGenTemplate)))); return; } if (!Enum.IsDefined(typeof(MapGenTheme), theme) || !Enum.IsDefined(typeof(MapGenTemplate), template)) { return; } MapGeneratorArgs args = MapGeneratorOld.MakeTemplate(template); args.MapWidth = wx; args.MapLength = wy; args.MapHeight = height; args.MaxHeight = ( int )(args.MaxHeight / 80d * height); args.MaxDepth = ( int )(args.MaxDepth / 80d * height); args.Theme = theme; args.AddTrees = !noTrees; Map map; try { if (theme == MapGenTheme.Forest && noTrees) { player.MessageNow("Generating Grass {0}...", template); } else { player.MessageNow("Generating {0} {1}...", theme, template); } if (theme == MapGenTheme.Forest && noTrees && template == MapGenTemplate.Flat) { map = MapGeneratorOld.GenerateFlatgrass(args.MapWidth, args.MapLength, args.MapHeight); } else { MapGeneratorOld generator = new MapGeneratorOld(args); map = generator.Generate(); } } catch (Exception ex) { Logger.Log(LogType.Error, "MapGenerator: Generation failed: {0}", ex); player.MessageNow("&WAn error occured while generating the map."); return; } if (fileName != null) { if (map.Save(fullFileName)) { player.MessageNow("Generation done. Saved to {0}", fileName); } else { player.Message("&WAn error occured while saving generated map to {0}", fileName); } } else { player.MessageNow("Generation done. Changing map..."); player.World.ChangeMap(map); } }