Esempio n. 1
0
        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 (!MapGen.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);
            }

            Level resized = ResizeLevel(lvl, x, y, z);

            LevelActions.Replace(lvl, resized);
            return(true);
        }
Esempio n. 2
0
        public void GenerateMap(Player p, int width, int height, int length)
        {
            Level lvl = CountdownMapGen.Generate(width, height, length);
            Level cur = LevelInfo.FindExact("countdown");

            if (cur != null)
            {
                LevelActions.Replace(cur, lvl);
            }
            else
            {
                LevelInfo.Add(lvl);
            }

            lvl.Save();
            Map = lvl;

            const string format = "Generated map ({0}x{1}x{2}), sending you to it..";

            p.Message(format, width, height, length);
            PlayerActions.ChangeMap(p, "countdown");

            Position pos = Position.FromFeetBlockCoords(8, 23, 17);

            p.SendPos(Entities.SelfID, pos, p.Rot);
        }
Esempio n. 3
0
        public void GenerateMap(Player p, int width, int height, int length)
        {
            Level lvl = CountdownMapGen.Generate(width, height, length);
            Level cur = LevelInfo.FindExact("countdown");

            if (cur != null)
            {
                LevelActions.Replace(cur, lvl);
            }
            else
            {
                LevelInfo.Loaded.Add(lvl);
            }

            lvl.Save();
            Map = lvl;

            const string format = "Generated map ({0}x{1}x{2}), sending you to it..";

            Player.Message(p, format, width, height, length);
            PlayerActions.ChangeMap(p, "countdown");

            Position pos = new Position(16 + 8 * 32, 32 + 23 * 32, 16 + 17 * 32);

            p.SendPos(Entities.SelfID, pos, p.Rot);
        }
Esempio n. 4
0
        void HandleGenerate(Player p, string arg1, string arg2, string arg3)
        {
            int width, height, length;

            if (!int.TryParse(arg1, out width) || !int.TryParse(arg2, out height) || !int.TryParse(arg3, out length))
            {
                width = 32; height = 32; length = 32;
            }
            if (width < 32 || !MapGen.OkayAxis(width))
            {
                width = 32;
            }
            if (height < 32 || !MapGen.OkayAxis(height))
            {
                height = 32;
            }
            if (length < 32 || !MapGen.OkayAxis(length))
            {
                length = 32;
            }
            if (!CmdNewLvl.CheckMapSize(p, width, height, length))
            {
                return;
            }

            Level lvl = CountdownMapGen.Generate(width, height, length);

            lvl.Deletable       = false;
            lvl.Buildable       = false;
            lvl.permissionbuild = LevelPermission.Nobody;
            lvl.motd            = "Welcome to the Countdown map! -hax";

            Level oldLvl = LevelInfo.FindExact("countdown");

            if (oldLvl != null)
            {
                LevelActions.Replace(oldLvl, lvl);
            }
            else
            {
                LevelInfo.Loaded.Add(lvl);
            }

            lvl.Save();
            if (Server.Countdown.gamestatus != CountdownGameStatus.Disabled)
            {
                Server.Countdown.mapon = lvl;
            }

            const string format = "Generated map ({0}x{1}x{2}), sending you to it..";

            Player.Message(p, format, width, height, length);
            PlayerActions.ChangeMap(p, "countdown");

            const ushort x = 8 * 32 + 16;
            const ushort y = 23 * 32 + 32;
            const ushort z = 17 * 32 + 16;

            p.SendPos(Entities.SelfID, x, y, z, p.rot[0], p.rot[1]);
        }
Esempio n. 5
0
        public override void Use(Player p, string message)
        {
            string[] args = message.Split(' ');
            if (args.Length < 4)
            {
                Help(p); return;
            }
            Level lvl = LevelInfo.FindMatches(p, args[0]);

            if (lvl == null)
            {
                return;
            }

            ushort x, y, z;

            if (!UInt16.TryParse(args[1], out x) || !UInt16.TryParse(args[2], out y) || !UInt16.TryParse(args[3], out z))
            {
                Player.Message(p, "Invalid dimensions."); return;
            }

            if (!MapGen.OkayAxis(x))
            {
                Player.Message(p, "width must be divisible by 16, and >= 16"); return;
            }
            if (!MapGen.OkayAxis(y))
            {
                Player.Message(p, "height must be divisible by 16, and >= 16"); return;
            }
            if (!MapGen.OkayAxis(z))
            {
                Player.Message(p, "length must be divisible by 16, and >= 16."); return;
            }
            if (!CmdNewLvl.CheckMapSize(p, x, y, z))
            {
                return;
            }

            bool confirmed = args.Length > 4 && args[4].CaselessEq("confirm");

            if (!confirmed && (x < lvl.Width || y < lvl.Height || z < lvl.Length))
            {
                Player.Message(p, "New level dimensions are smaller than the current dimensions, &cyou will lose blocks%S.");
                Player.Message(p, "Type %T/resizelvl {0} {1} {2} {3} confirm %Sif you're sure.", args[0], x, y, z);
                return;
            }

            Level newLvl = ResizeLevel(lvl, x, y, z);

            LevelActions.Replace(lvl, newLvl);
        }
Esempio n. 6
0
        public static bool DoResize(Player p, string[] args)
        {
            Level lvl = Matcher.FindLevels(p, args[0]);

            if (lvl == null)
            {
                return(true);
            }
            if (!LevelInfo.ValidateAction(p, lvl.name, "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);
            }

            bool confirmed = args.Length > 4 && args[4].CaselessEq("confirm");

            if (!confirmed && (x < lvl.Width || y < lvl.Height || z < lvl.Length))
            {
                Player.Message(p, "New level dimensions are smaller than the current dimensions, &cyou will lose blocks%S.");
                return(false);
            }

            Level newLvl = ResizeLevel(lvl, x, y, z);

            LevelActions.Replace(lvl, newLvl);
            return(true);
        }
Esempio n. 7
0
        static void DoRestore(Level lvl, string backup)
        {
            lock (lvl.saveLock) {
                File.Copy(LevelInfo.BackupFilePath(lvl.name, backup), LevelInfo.MapPath(lvl.name), true);
                lvl.SaveChanges = false;
            }

            Level restore = Level.Load(lvl.name);

            if (restore != null)
            {
                LevelActions.Replace(lvl, restore);
            }
            else
            {
                Logger.Log(LogType.Warning, "Restore nulled");
                File.Copy(LevelInfo.MapPath(lvl.name) + ".backup", LevelInfo.MapPath(lvl.name), true);
            }
        }
Esempio n. 8
0
        static void DoRestore(Level lvl, string backup)
        {
            lock (lvl.saveLock) {
                File.Copy(LevelInfo.BackupPath(lvl.name, backup), LevelInfo.LevelPath(lvl.name), true);
                lvl.saveLevel = false;
            }

            Level restore = Level.Load(lvl.name);

            if (restore != null)
            {
                LevelActions.Replace(lvl, restore);
            }
            else
            {
                Server.s.Log("Restore nulled");
                File.Copy(LevelInfo.LevelPath(lvl.name) + ".backup", LevelInfo.LevelPath(lvl.name), true);
            }
        }
Esempio n. 9
0
        public void GenerateMap(Player p, int width, int height, int length)
        {
            Level lvl = CountdownMapGen.Generate(width, height, length);
            Level cur = LevelInfo.FindExact("countdown");

            if (cur != null)
            {
                LevelActions.Replace(cur, lvl);
            }
            else
            {
                LevelInfo.Add(lvl);
            }

            lvl.Save();
            Map = lvl;

            const string format = "Generated map ({0}x{1}x{2}), sending you to it..";

            p.Message(format, width, height, length);
            PlayerActions.ChangeMap(p, "countdown");
        }