Allow level presets to be any size

This commit is contained in:
UnknownShadow200 2018-07-25 19:55:12 +10:00
parent b489ce7cea
commit 13d7436189
8 changed files with 62 additions and 65 deletions

View File

@ -37,8 +37,8 @@ namespace MCGalaxy.Commands {
result = false; return true;
}
p.Message("\"{0}\" is not a valid boolean.", input);
p.Message("Value must be either 1/yes/on or 0/no/off");
p.Message("%W\"{0}\" is not a valid boolean.", input);
p.Message("%WValue must be either 1/yes/on or 0/no/off");
return false;
}
@ -82,17 +82,17 @@ namespace MCGalaxy.Commands {
int min = int.MinValue, int max = int.MaxValue) {
int value;
if (!int.TryParse(input, out value)) {
p.Message("\"{0}\" is not a valid integer.", input); return false;
p.Message("%W\"{0}\" is not a valid integer.", input); return false;
}
if (value < min || value > max) {
// Try to provide more helpful range messages
if (max == int.MaxValue) {
p.Message("{0} must be {1} or greater", argName, min);
p.Message("%W{0} must be {1} or greater", argName, min);
} else if (min == int.MinValue) {
p.Message("{0} must be {1} or less", argName, max);
p.Message("%W{0} must be {1} or less", argName, max);
} else {
p.Message("{0} must be between {1} and {2}", argName, min, max);
p.Message("%W{0} must be between {1} and {2}", argName, min, max);
}
return false;
}
@ -105,11 +105,11 @@ namespace MCGalaxy.Commands {
float min, float max) {
float value;
if (!Utils.TryParseDecimal(input, out value)) {
p.Message("\"{0}\" is not a valid number.", input); return false;
p.Message("%W\"{0}\" is not a valid number.", input); return false;
}
if (value < min || value > max) {
p.Message("{0} must be between {1} and {2}", argName,
p.Message("%W{0} must be between {1} and {2}", argName,
min.ToString("F4"), max.ToString("F4"));
return false;
}
@ -140,7 +140,7 @@ namespace MCGalaxy.Commands {
public static bool GetHex(Player p, string input, ref ColorDesc col) {
ColorDesc tmp;
if (!Colors.TryParseHex(input, out tmp)) {
p.Message("\"#{0}\" is not a valid HEX color.", input); return false;
p.Message("%W\"#{0}\" is not a valid HEX color.", input); return false;
}
col = tmp; return true;
}

View File

@ -61,10 +61,7 @@ namespace MCGalaxy.Commands.Fun {
}
ushort x = 0, y = 0, z = 0;
if (!CmdNewLvl.CheckMapAxis(p, args[1], "Width", ref x)) return;
if (!CmdNewLvl.CheckMapAxis(p, args[2], "Height", ref y)) return;
if (!CmdNewLvl.CheckMapAxis(p, args[3], "Length", ref z)) return;
if (!CmdNewLvl.CheckMapVolume(p, x, y, z)) return;
if (!CmdNewLvl.GetDimensions(p, args, 1, ref x, ref y, ref z)) return;
CountdownGame game = (CountdownGame)game_;
game.GenerateMap(p, x, y, z);

View File

@ -169,7 +169,7 @@ namespace MCGalaxy.Commands.Info {
p.Message("No custom texture pack set for this map.");
}
const string format = "Colors: Fog {0}, Sky {1}, Clouds {2}, Sunlight {3}, Shadowlight {4}";
const string format = "Colors: &eFog {0}, &eSky {1}, &eClouds {2}, &eSunlight {3}, &eShadowlight {4}";
p.Message(format, Color(cfg.FogColor), Color(cfg.SkyColor),
Color(cfg.CloudColor), Color(cfg.LightColor), Color(cfg.ShadowColor));
@ -227,7 +227,7 @@ namespace MCGalaxy.Commands.Info {
}
static string Color(string src) {
return (src == null || src.Length == 0 || src == "-1") ? "&bnone&e" : "&b" + src + "&e";
return (src == null || src.Length == 0 || src == "-1") ? "&bnone" : "&b" + src;
}
public override void Help(Player p) {

View File

@ -51,10 +51,7 @@ namespace MCGalaxy.Commands.World {
ushort x = 0, y = 0, z = 0;
string name = args[0].ToLower();
if (!CheckMapAxis(p, args[1], "Width", ref x)) return null;
if (!CheckMapAxis(p, args[2], "Height", ref y)) return null;
if (!CheckMapAxis(p, args[3], "Length", ref z)) return null;
if (!CheckMapVolume(p, x, y, z)) return null;
if (!GetDimensions(p, args, 1, ref x, ref y, ref z)) return null;
string seed = args.Length == 6 ? args[5] : "";
if (!Formatter.ValidName(p, name, "level")) return null;
@ -85,7 +82,15 @@ namespace MCGalaxy.Commands.World {
}
internal static bool CheckMapAxis(Player p, string input, string type, ref ushort len) {
internal static bool GetDimensions(Player p, string[] args, int i, ref ushort x, ref ushort y, ref ushort z) {
return
CheckMapAxis(p, args[i ], "Width", ref x) &&
CheckMapAxis(p, args[i + 1], "Height", ref y) &&
CheckMapAxis(p, args[i + 2], "Length", ref z) &&
CheckMapVolume(p, x, y, z);
}
static bool CheckMapAxis(Player p, string input, string type, ref ushort len) {
if (!CommandParser.GetUShort(p, input, type, ref len)) return false;
if (len == 0) { p.Message("%W{0} cannot be 0.", type); return false; }
if (len > 16384) { p.Message("%W{0} must be 16384 or less.", type); return false; }
@ -97,12 +102,12 @@ namespace MCGalaxy.Commands.World {
return true;
}
internal static bool CheckMapVolume(Player p, int x, int y, int z) {
static bool CheckMapVolume(Player p, int x, int y, int z) {
if (p.IsConsole) return true;
int limit = p.group.GenVolume;
if ((long)x * y * z <= limit) return true;
string text = "You cannot create a map with over ";
string text = "%WYou cannot create a map with over ";
if (limit > 1000 * 1000) text += (limit / (1000 * 1000)) + " million blocks";
else if (limit > 1000) text += (limit / 1000) + " thousand blocks";
else text += limit + " blocks";
@ -110,8 +115,6 @@ namespace MCGalaxy.Commands.World {
return false;
}
public override void Help(Player p) {
p.Message("%T/NewLvl [name] [width] [height] [length] [theme] <seed>");
p.Message("%HCreates/generates a new level.");

View File

@ -113,9 +113,12 @@ namespace MCGalaxy.Commands.World {
string[] args = value.SplitSpaces();
if (args.Length < 4) { Command.Find("ResizeLvl").Help(p); return; }
if (CmdResizeLvl.DoResize(p, args, p.DefaultCmdData)) return;
bool needConfirm;
if (CmdResizeLvl.DoResize(p, args, p.DefaultCmdData, out needConfirm)) return;
if (!needConfirm) return;
p.Message("Type %T/os map resize {0} {1} {2} confirm %Sif you're sure.",
args[1], args[2], args[3]);
args[1], args[2], args[3]);
} else if (cmd == "PERVISIT") {
// Older realm maps didn't put you on visit whitelist, so make sure we put the owner here
AccessController access = p.level.VisitAccess;

View File

@ -33,25 +33,28 @@ namespace MCGalaxy.Commands.World {
string[] args = message.SplitSpaces();
if (args.Length < 4) { Help(p); return; }
if (DoResize(p, args, data)) return;
bool needConfirm;
if (DoResize(p, args, data, out needConfirm)) return;
if (!needConfirm) return;
p.Message("Type %T/ResizeLvl {0} {1} {2} {3} confirm %Sif you're sure.",
args[0], args[1], args[2], args[3]);
args[0], args[1], args[2], args[3]);
}
public static bool DoResize(Player p, string[] args, CommandData data) {
public static bool DoResize(Player p, string[] args, CommandData data, out bool needConfirm) {
needConfirm = false;
Level lvl = Matcher.FindLevels(p, args[0]);
if (lvl == null) return true;
if (!LevelInfo.Check(p, data.Rank, lvl, "resize this level")) return false;
ushort x = 0, y = 0, z = 0;
if (!CmdNewLvl.CheckMapAxis(p, args[1], "Width", ref x)) return false;
if (!CmdNewLvl.CheckMapAxis(p, args[2], "Height", ref y)) return false;
if (!CmdNewLvl.CheckMapAxis(p, args[3], "Length", ref z)) return false;
if (!CmdNewLvl.CheckMapVolume(p, x, y, z)) return true;
if (!CmdNewLvl.GetDimensions(p, args, 1, ref x, ref y, ref z)) return false;
bool confirmed = args.Length > 4 && args[4].CaselessEq("confirm");
if (!confirmed && (x < lvl.Width || y < lvl.Height || z < lvl.Length)) {
p.Message("New level dimensions are smaller than the current dimensions, %Wyou will lose blocks%S.");
needConfirm = true;
return false;
}

View File

@ -51,11 +51,11 @@ namespace MCGalaxy.Eco {
}
switch (args[3]) {
case "price": preset.price = int.Parse(args[4]); break;
case "x": preset.x = args[4]; break;
case "y": preset.y = args[4]; break;
case "z": preset.z = args[4]; break;
case "type": preset.type = args[4]; break;
case "price": preset.price = int.Parse(args[4]); break;
case "x": preset.x = args[4]; break;
case "y": preset.y = args[4]; break;
case "z": preset.z = args[4]; break;
case "type": preset.type = args[4]; break;
}
}
@ -84,7 +84,7 @@ namespace MCGalaxy.Eco {
p.Message("&aCreating level: '&f" + name + "&a' . . .");
UseCommand(p, "NewLvl", name + " " + preset.x + " " + preset.y + " " + preset.z + " " + preset.type);
Level level = LevelActions.Load(Player.Console, name, true);
CmdOverseer.SetPerms(p, level);
Level.SaveSettings(level);
@ -114,11 +114,10 @@ namespace MCGalaxy.Eco {
preset = new LevelPreset();
preset.name = args[2];
if (OkayAxis(args[3]) && OkayAxis(args[4]) && OkayAxis(args[5])) {
preset.x = args[3]; preset.y = args[4]; preset.z = args[5];
} else {
p.Message("%WDimension must be a power of 2"); return;
}
ushort x = 0, y = 0, z = 0;
if (!CmdNewLvl.GetDimensions(p, args, 3, ref x, ref y, ref z)) return;
preset.x = args[3]; preset.y = args[4]; preset.z = args[5];
if (!MapGen.IsRecognisedTheme(args[6])) {
MapGen.PrintThemes(p); return;
@ -139,7 +138,7 @@ namespace MCGalaxy.Eco {
Presets.Remove(preset);
p.Message("&aSuccessfully removed preset: &f" + preset.name);
}
void EditPreset(Player p, string[] args, LevelPreset preset) {
if (preset == null) { p.Message("%WThat preset level doesn't exist"); return; }
@ -147,11 +146,15 @@ namespace MCGalaxy.Eco {
preset.name = args[4];
p.Message("&aSuccessfully changed preset name to &f" + preset.name);
} else if (args[3] == "x" || args[3] == "y" || args[3] == "z") {
if (!OkayAxis(args[4])) { p.Message("%WDimension was wrong, it must be a power of 2"); return; }
if (args[3] == "x") preset.x = args[4];
if (args[3] == "y") preset.y = args[4];
if (args[3] == "z") preset.z = args[4];
string[] dims = new string[] { preset.x, preset.y, preset.z };
if (args[3] == "x") dims[0] = args[4];
if (args[3] == "y") dims[1] = args[4];
if (args[3] == "z") dims[2] = args[4];
ushort x = 0, y = 0, z = 0;
if (!CmdNewLvl.GetDimensions(p, dims, 0, ref x, ref y, ref z)) return;
preset.x = dims[0]; preset.y = dims[1]; preset.z = dims[2];
p.Message("&aSuccessfully changed preset {0} size to &f{1}", args[3], args[4]);
} else if (args[3] == "type" || args[3] == "theme") {
if (!MapGen.IsRecognisedTheme(args[4])) { MapGen.PrintThemes(p); return; }
@ -189,8 +192,8 @@ namespace MCGalaxy.Eco {
foreach (LevelPreset preset in Presets) {
p.Message("&6{0} %S({1}, {2}, {3}) {4}: &a{5} %S{6}",
preset.name, preset.x, preset.y, preset.z,
preset.type, preset.price, ServerConfig.Currency);
preset.name, preset.x, preset.y, preset.z,
preset.type, preset.price, ServerConfig.Currency);
}
}
@ -200,11 +203,5 @@ namespace MCGalaxy.Eco {
}
return null;
}
static bool OkayAxis(string value) {
ushort length;
if (!ushort.TryParse(value, out length)) return false;
return MapGen.OkayAxis(length);
}
}
}

View File

@ -50,14 +50,8 @@ namespace MCGalaxy.Generator {
p.Message("Advanced themes: " + advGens.Keys.Join(", "));
}
public static IEnumerable<string> SimpleThemeNames { get { return simpleGens.Keys; } }
public static IEnumerable<string> SimpleThemeNames { get { return simpleGens.Keys; } }
public static IEnumerable<string> AdvancedThemeNames { get { return advGens.Keys; } }
public static bool OkayAxis(int len) {
return len >= 16 && len <= 8192 && (len % 16) == 0;
}
public static bool Generate(Level lvl, string theme, string seed, Player p) {
MapGenArgs genArgs = new MapGenArgs();