Exemple #1
0
        void SetBotText(Player p, string botName, string text)
        {
            PlayerBot bot = Matcher.FindBots(p, botName);

            if (bot == null)
            {
                return;
            }
            if (!bot.EditableBy(p, "set the text of"))
            {
                return;
            }
            if (text == null)
            {
                p.Message("Removed text shown when bot {0} %Sclicked on", bot.ColoredName);
                bot.ClickedOnText = null;
            }
            else
            {
                if (!MessageBlock.Validate(p, text, false))
                {
                    return;
                }
                p.Message("Set text shown when bot {0} %Sis clicked on to {1}", bot.ColoredName, text);
                bot.ClickedOnText = text;
            }
            BotsFile.Save(p.level);
        }
Exemple #2
0
        void RenameBot(Player p, string botName, string newName)
        {
            if (newName == null)
            {
                p.Message("New name of bot required."); return;
            }
            if (!Formatter.ValidName(p, newName, "bot"))
            {
                return;
            }

            PlayerBot bot = Matcher.FindBots(p, botName);

            if (bot == null)
            {
                return;
            }
            if (BotExists(p.level, newName, bot))
            {
                p.Message("A bot with the new name already exists."); return;
            }

            p.Message("Renamed bot {0}", bot.ColoredName);
            if (bot.DisplayName == bot.name)
            {
                bot.DisplayName = newName;
                bot.GlobalDespawn();
                bot.GlobalSpawn();
            }

            bot.name = newName;
            BotsFile.Save(p.level);
        }
Exemple #3
0
        void CopyBot(Player p, string botName, string newName)
        {
            if (newName == null)
            {
                p.Message("Name of new bot required."); return;
            }
            if (!Formatter.ValidName(p, newName, "bot"))
            {
                return;
            }

            PlayerBot bot = Matcher.FindBots(p, botName);

            if (bot == null)
            {
                return;
            }

            PlayerBot     clone = new PlayerBot(newName, p.level);
            BotProperties props = new BotProperties();

            props.FromBot(bot);
            props.ApplyTo(clone);
            clone.Owner = p.name;
            clone.SetModel(clone.Model);
            BotsFile.LoadAi(props, clone);
            // Preserve custom name tag
            if (bot.DisplayName == bot.name)
            {
                clone.DisplayName = newName;
            }
            TryAddBot(p, clone);
        }
Exemple #4
0
        /// <summary> Renames the .lvl (and related) files and database tables. Does not unload. </summary>
        public static void Rename(string src, string dst)
        {
            File.Move(LevelInfo.MapPath(src), LevelInfo.MapPath(dst));

            MoveIfExists(LevelInfo.MapPath(src) + ".backup",
                         LevelInfo.MapPath(dst) + ".backup");
            MoveIfExists("levels/level properties/" + src + ".properties",
                         "levels/level properties/" + dst + ".properties");
            MoveIfExists("levels/level properties/" + src,
                         "levels/level properties/" + dst + ".properties");
            MoveIfExists("blockdefs/lvl_" + src + ".json",
                         "blockdefs/lvl_" + dst + ".json");
            MoveIfExists("blockprops/lvl_" + src + ".txt",
                         "blockprops/lvl_" + dst + ".txt");
            MoveIfExists(BotsFile.BotsPath(src),
                         BotsFile.BotsPath(dst));

            // TODO: Should we move backups still
            try {
                //MoveBackups(src, dst);
            } catch {
            }

            RenameDatabaseTables(src, dst);
            BlockDBFile.MoveBackingFile(src, dst);
        }
Exemple #5
0
        void SetDeathMessage(Player p, string botName, string text)
        {
            PlayerBot bot = Matcher.FindBots(p, botName);

            if (bot == null)
            {
                return;
            }
            if (!bot.EditableBy(p, "set the death message of"))
            {
                return;
            }
            if (text == null)
            {
                p.Message("Reset shown when bot {0} %Skills someone", bot.ColoredName);
                bot.DeathMessage = null;
            }
            else
            {
                if (!MessageBlock.Validate(p, text, false))
                {
                    return;
                }
                p.Message("Set message shown when bot {0} %Skills someone to {1}", bot.ColoredName, text);
                bot.DeathMessage = text;
            }
            BotsFile.Save(p.level);
        }
Exemple #6
0
        void SetBotText(Player p, string botName, string text, LevelPermission plRank)
        {
            PlayerBot bot = Matcher.FindBots(p, botName);

            if (bot == null)
            {
                return;
            }
            if (!bot.EditableBy(p, "set the text of"))
            {
                return;
            }

            if (text == null)
            {
                p.Message("Removed text shown when bot {0} &Sclicked on", bot.ColoredName);
                bot.ClickedOnText = null;
            }
            else
            {
                bool allCmds = HasExtraPerm(p, "MB", plRank, 1);
                if (!MessageBlock.Validate(p, text, allCmds))
                {
                    return;
                }

                p.Message("Set text shown when bot {0} &Sis clicked on to {1}", bot.ColoredName, text);
                bot.ClickedOnText = text;
            }
            BotsFile.Save(p.level);
        }
Exemple #7
0
        public static void MoveBots(Player p, int x, int y, int z)
        {
            // Convert from block positions into precise positions

            x *= 32;
            y *= 32;
            z *= 32;

            Position pos;
            byte     yaw, pitch;

            PlayerBot[] bots = p.level.Bots.Items;

            int count = 0;

            for (int i = 0; i < bots.Length; i++)
            {
                pos.X       = bots[i].Pos.X + x;
                pos.Y       = bots[i].Pos.Y + y;
                pos.Z       = bots[i].Pos.Z + z;
                yaw         = bots[i].Rot.RotY; pitch = bots[i].Rot.HeadX;
                bots[i].Pos = pos;
                bots[i].SetYawPitch(yaw, pitch);

                count++;
            }

            BotsFile.Save(p.level);
            p.Message("%SSuccessfully moved %b" + count + " %Sbots.");
        }
Exemple #8
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }
            if (p == null)
            {
                MessageInGameOnly(p); return;
            }

            if (!p.level.BuildAccess.CheckDetailed(p))
            {
                Player.Message(p, "Hence, you cannot summon bots on this map.");
                return;
            }

            PlayerBot bot = PlayerBot.FindMatchesPreferLevel(p, message);

            if (bot == null)
            {
                return;
            }
            if (!p.level.name.CaselessEq(bot.level.name))
            {
                Player.Message(p, bot.name + " is in a different level."); return;
            }
            bot.SetPos(p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]);
            BotsFile.UpdateBot(bot);
        }
Exemple #9
0
        protected override void SetBotData(Player p, PlayerBot bot, string nick)
        {
            if (!MessageCmd.CanSpeak(p, name))
            {
                return;
            }

            if (nick.Length == 0)
            {
                bot.DisplayName = bot.name;
                p.level.Message("Bot " + bot.ColoredName + " &Sreverted to their original name.");
            }
            else
            {
                string nameTag = nick.CaselessEq("empty") ? "" : nick;
                if (nick.Length > 62)
                {
                    p.Message("Name must be 62 or fewer letters."); return;
                }

                p.Message("You changed the name of bot " + bot.ColoredName + " &Sto &c" + nameTag);
                bot.DisplayName = Colors.Escape(nick);
            }

            bot.GlobalDespawn();
            bot.GlobalSpawn();
            BotsFile.Save(p.level);
        }
Exemple #10
0
        public static Level Load(string name, string path)
        {
            OnLevelLoadEvent.Call(name);
            if (cancelload)
            {
                cancelload = false; return(null);
            }

            if (!File.Exists(path))
            {
                Logger.Log(LogType.Warning, "Attempted to load {0}, but the level file does not exist.", name);
                return(null);
            }

            try {
                Level lvl = IMapImporter.Formats[0].Read(path, name, true);
                lvl.backedup = true;
                LoadMetadata(lvl);
                BotsFile.Load(lvl);

                object locker = ThreadSafeCache.DBCache.GetLocker(name);
                lock (locker) {
                    LevelDB.LoadZones(lvl, name);
                    LevelDB.LoadPortals(lvl, name);
                    LevelDB.LoadMessages(lvl, name);
                }

                Logger.Log(LogType.SystemActivity, "Level \"{0}\" loaded.", lvl.name);
                OnLevelLoadedEvent.Call(lvl);
                return(lvl);
            } catch (Exception ex) {
                Logger.LogError("Error loading map from " + path, ex);
                return(null);
            }
        }
Exemple #11
0
        void SetDeathMessage(Player p, string botName, string text)
        {
            PlayerBot bot = Matcher.FindBots(p, botName);

            if (bot == null)
            {
                return;
            }
            if (!LevelInfo.ValidateAction(p, p.level.name, "set kill message of that bot"))
            {
                return;
            }

            if (text == null)
            {
                Player.Message(p, "Reset shown when bot {0} %Skills someone", bot.ColoredName);
                bot.DeathMessage = null;
            }
            else
            {
                if (!MessageBlock.Validate(p, text, false))
                {
                    return;
                }
                Player.Message(p, "Set message shown when bot {0} %Skills someone to {1}", bot.ColoredName, text);
                bot.DeathMessage = text;
            }
            BotsFile.Save(bot.level);
        }
Exemple #12
0
        void SetBotText(Player p, string botName, string text)
        {
            PlayerBot bot = Matcher.FindBots(p, botName);

            if (bot == null)
            {
                return;
            }
            if (!LevelInfo.ValidateAction(p, p.level.name, "set bot text of that bot"))
            {
                return;
            }

            if (text == null)
            {
                Player.Message(p, "Removed text shown when bot {0} %Sclicked on", bot.ColoredName);
                bot.ClickedOnText = null;
            }
            else
            {
                if (!MessageBlock.Validate(p, text, false))
                {
                    return;
                }
                Player.Message(p, "Set text shown when bot {0} %Sis clicked on to {1}", bot.ColoredName, text);
                bot.ClickedOnText = text;
            }
            BotsFile.Save(bot.level);
        }
Exemple #13
0
        static Level ResizeLevel(Level lvl, int width, int height, int length)
        {
            Level res = new Level(lvl.name, (ushort)width, (ushort)height, (ushort)length);

            res.hasPortals       = lvl.hasPortals;
            res.hasMessageBlocks = lvl.hasMessageBlocks;
            byte[] src = lvl.blocks, dst = res.blocks;

            // Copy blocks in bulk
            width  = Math.Min(lvl.Width, res.Width);
            height = Math.Min(lvl.Height, res.Height);
            length = Math.Min(lvl.Length, res.Length);
            for (int y = 0; y < height; y++)
            {
                for (int z = 0; z < length; z++)
                {
                    int srcI = lvl.Width * (z + y * lvl.Length);
                    int dstI = res.Width * (z + y * res.Length);
                    Buffer.BlockCopy(src, srcI, dst, dstI, width);
                }
            }

            // Copy extended blocks in bulk
            width  = Math.Min(lvl.ChunksX, res.ChunksX);
            height = Math.Min(lvl.ChunksY, res.ChunksY);
            length = Math.Min(lvl.ChunksZ, res.ChunksZ);
            for (int cy = 0; cy < height; cy++)
            {
                for (int cz = 0; cz < length; cz++)
                {
                    for (int cx = 0; cx < width; cx++)
                    {
                        src = lvl.CustomBlocks[(cy * lvl.ChunksZ + cz) * lvl.ChunksX + cx];
                        if (src == null)
                        {
                            continue;
                        }

                        dst = new byte[16 * 16 * 16];
                        res.CustomBlocks[(cy * res.ChunksZ + cz) * res.ChunksX + cx] = dst;
                        Buffer.BlockCopy(src, 0, dst, 0, 16 * 16 * 16);
                    }
                }
            }

            res.spawnx = lvl.spawnx; res.spawny = lvl.spawny; res.spawnz = lvl.spawnz;
            res.rotx   = lvl.rotx; res.roty = lvl.roty;

            lock (lvl.saveLock) {
                lvl.Backup(true);
                IMapExporter.Formats[0].Write(LevelInfo.MapPath(lvl.name), res);
                lvl.SaveChanges = false;
            }

            res.backedup = true;
            Level.LoadMetadata(res);
            BotsFile.Load(res);
            return(res);
        }
 protected override void SetBotData(Player p, PlayerBot bot, string args)
 {
     if (!ParseArgs(p, args, bot))
     {
         return;
     }
     BotsFile.Save(p.level);
 }
Exemple #15
0
        protected override void SetBotData(Player p, PlayerBot bot, string model)
        {
            bool changedAxisScale;

            model = ParseModel(p, bot, model, out changedAxisScale);
            Entities.UpdateModel(bot, model);

            p.Message("You changed the model of bot " + bot.ColoredName + " %Sto a &c" + model);
            BotsFile.Save(p.level);
        }
Exemple #16
0
        protected override void SetBotData(Player p, PlayerBot bot, string skin)
        {
            skin         = GetSkin(skin, bot.name);
            bot.SkinName = skin;
            p.Message("You changed the skin of bot " + bot.ColoredName + " %Sto &c" + skin);

            bot.GlobalDespawn();
            bot.GlobalSpawn();
            BotsFile.Save(p.level);
        }
Exemple #17
0
        protected override void SetBotData(Player p, PlayerBot bot, string[] args)
        {
            string model = GetModel(p, args, 2);

            bot.model = model;
            Entities.UpdateModel(bot.id, model, bot.level, null);

            Chat.MessageLevel(bot.level, "Bot " + bot.ColoredName + "'s %Smodel was changed to a &c" + model);
            BotsFile.UpdateBot(bot);
        }
Exemple #18
0
 public static void Remove(PlayerBot bot, bool save = true)
 {
     bot.level.Bots.Remove(bot);
     bot.GlobalDespawn();
     bot.curJump = 0;
     if (save)
     {
         BotsFile.Save(bot.level);
     }
 }
        protected override void SetBotData(Player p, PlayerBot bot, string model)
        {
            model = ParseModel(p, bot, model);
            if (model == null)
            {
                return;
            }
            bot.UpdateModel(model);

            BotsFile.Save(p.level);
        }
Exemple #20
0
        public bool Unload(bool silent = false, bool save = true)
        {
            if (Server.mainLevel == this)
            {
                return(false);
            }
            // Still cleanup resources, even if this is not a true level
            if (IsMuseum)
            {
                Cleanup(); return(true);
            }

            bool cancel = false;

            OnLevelUnloadEvent.Call(this, ref cancel);
            if (cancel)
            {
                Logger.Log(LogType.SystemActivity, "Unload canceled by Plugin! (Map: {0})", name);
                return(false);
            }
            MovePlayersToMain();

            if (save && SaveChanges && Changed)
            {
                Save();
            }
            if (save && SaveChanges)
            {
                SaveBlockDBChanges();
            }

            MovePlayersToMain();
            LevelInfo.Remove(this);

            try {
                if (!unloadedBots)
                {
                    unloadedBots = true;
                    BotsFile.Save(this);
                    PlayerBot.RemoveLoadedBots(this, false);
                }
            } catch (Exception ex) {
                Logger.LogError("Error saving bots", ex);
            }

            Cleanup();
            if (!silent)
            {
                Chat.MessageOps(ColoredName + " &Swas unloaded.");
            }
            Logger.Log(LogType.SystemActivity, name + " was unloaded.");
            return(true);
        }
Exemple #21
0
        protected override void SetBotData(Player p, PlayerBot bot, string model)
        {
            model = ParseModel(p, bot, model);
            if (model == null)
            {
                return;
            }
            bot.UpdateModel(model);

            p.Message("You changed the model of bot {0} %Sto a &c{1}", bot.ColoredName, model);
            BotsFile.Save(p.level);
        }
Exemple #22
0
        public bool Unload(bool silent = false, bool save = true)
        {
            if (Server.mainLevel == this || IsMuseum)
            {
                return(false);
            }
            OnLevelUnloadEvent.Call(this);
            if (cancelunload)
            {
                Logger.Log(LogType.SystemActivity, "Unload canceled by Plugin! (Map: {0})", name);
                cancelunload = false; return(false);
            }
            MovePlayersToMain();

            if (save && SaveChanges && Changed)
            {
                Save(false, true);
            }
            if (save && SaveChanges)
            {
                SaveBlockDBChanges();
            }

            MovePlayersToMain();
            LevelInfo.Remove(this);

            try {
                if (!unloadedBots)
                {
                    unloadedBots = true;
                    BotsFile.Save(this);
                    PlayerBot.RemoveLoadedBots(this, false);
                }
            } catch (Exception ex) {
                Logger.LogError("Error saving bots", ex);
            }

            try {
                physThread.Abort();
                physThread.Join();
            } catch {
            }

            Dispose();
            Server.DoGC();

            if (!silent)
            {
                Chat.MessageOps(ColoredName + " %Swas unloaded.");
            }
            Logger.Log(LogType.SystemActivity, name + " was unloaded.");
            return(true);
        }
Exemple #23
0
        public static void Add(PlayerBot bot, bool save = true)
        {
            Bots.Add(bot);
            bot.GlobalSpawn();

            Player[] players = PlayerInfo.Online.Items;
            Chat.MessageLevel(bot.level, bot.ColoredName + "%S, the bot, has been added.");
            if (save)
            {
                BotsFile.UpdateBot(bot);
            }
        }
Exemple #24
0
        public static void Remove(PlayerBot bot, bool save = true)
        {
            Bots.Remove(bot);
            bot.GlobalDespawn();

            bot.botTimer.Stop();
            bot.jumping = false;
            if (save)
            {
                BotsFile.RemoveBot(bot);
            }
        }
Exemple #25
0
 public static void Add(PlayerBot bot, bool save = true)
 {
     // Lock to ensure that no two bots can end up with the same playerid
     lock (bot.level.Bots.locker) {
         bot.id = NextFreeId(bot);
         bot.level.Bots.Add(bot);
     }
     bot.GlobalSpawn();
     if (save)
     {
         BotsFile.Save(bot.level);
     }
 }
Exemple #26
0
        protected override void SetBotData(Player p, PlayerBot bot, string args)
        {
            string axis;

            if (!ParseArgs(p, bot, args, out axis))
            {
                return;
            }
            bot.UpdateModel(bot.Model);

            p.Message("You changed the {1} scale of bot {0} %S", bot.ColoredName, axis);
            BotsFile.Save(p.level);
        }
Exemple #27
0
        protected override void SetBotData(Player p, PlayerBot bot, string[] args)
        {
            string skin = GetSkin(p, args, 2, bot.name);

            if (skin == null)
            {
                return;
            }
            bot.SkinName = skin;
            Chat.MessageLevel(bot.level, "Bot " + bot.ColoredName + "'s %Sskin was changed to &c" + skin);

            bot.GlobalDespawn();
            bot.GlobalSpawn();
            BotsFile.UpdateBot(bot);
        }
Exemple #28
0
        protected override void SetBotData(Player p, PlayerBot bot, string skin)
        {
            skin = GetSkin(skin, bot.name);
            if (skin.Length > NetUtils.StringSize)
            {
                p.Message("The skin must be " + NetUtils.StringSize + " characters or less."); return;
            }

            bot.SkinName = skin;
            p.Message("You changed the skin of bot " + bot.ColoredName + " %Sto &c" + skin);

            bot.GlobalDespawn();
            bot.GlobalSpawn();
            BotsFile.Save(p.level);
        }
Exemple #29
0
 static void DoAll(string src, string dst, byte action)
 {
     DoAction(LevelInfo.MapPath(src) + ".backup",
              LevelInfo.MapPath(dst) + ".backup", action);
     DoAction(LevelInfo.PropsPath(src),
              LevelInfo.PropsPath(dst), action);
     DoAction("levels/level properties/" + src,
              LevelInfo.PropsPath(dst), action);
     DoAction(BlockDefsPath(src),
              BlockDefsPath(dst), action);
     DoAction(BlockPropsOldPath(src),
              BlockPropsOldPath(dst), action);
     DoAction(BlockPropsLvlPath(src),
              BlockPropsLvlPath(dst), action);
     DoAction(BotsFile.BotsPath(src),
              BotsFile.BotsPath(dst), action);
 }
Exemple #30
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                Help(p); return;
            }
            if (!LevelInfo.Check(p, data.Rank, p.level, "summon that bot"))
            {
                return;
            }

            string[]  args = message.SplitSpaces(2);
            PlayerBot bot  = Matcher.FindBots(p, args[0]);

            if (bot == null)
            {
                return;
            }
            if (!bot.EditableBy(p, "summon"))
            {
                return;
            }

            Position pos; byte yaw, pitch;

            if (args.Length == 1)
            {
                pos = p.Pos; yaw = p.Rot.RotY; pitch = p.Rot.HeadX;
            }
            else
            {
                args = args[1].SplitSpaces();

                if (args.Length < 3)
                {
                    Help(p); return;
                }
                if (!CmdTp.GetTeleportCoords(p, bot, args, false, out pos, out yaw, out pitch))
                {
                    return;
                }
            }

            bot.Pos = pos; bot.SetYawPitch(yaw, pitch);
            BotsFile.Save(p.level);
        }