Ejemplo n.º 1
0
 public static void RemoveLevelBots(string level)
 {
     lock (locker) {
         for (int i = 0; i < SavedBots.Count; i++)
         {
             BotProperties props = SavedBots[i];
             if (level != props.Level)
             {
                 continue;
             }
             SavedBots.RemoveAt(i); i--;
         }
         Save();
     }
 }
Ejemplo n.º 2
0
 public static void RemoveBot(PlayerBot bot)
 {
     lock (locker) {
         for (int i = 0; i < SavedBots.Count; i++)
         {
             BotProperties props = SavedBots[i];
             if (bot.name != props.Name || bot.level.name != props.Level)
             {
                 continue;
             }
             SavedBots.RemoveAt(i);
             Save();
             return;
         }
     }
 }
Ejemplo n.º 3
0
        internal static void LoadAi(BotProperties props, PlayerBot bot)
        {
            if (String.IsNullOrEmpty(props.AI))
            {
                return;
            }
            try {
                ScriptFile.Parse(Player.Console, bot, props.AI);
            } catch (Exception ex) {
                Logger.LogError("Error loading bot AI " + props.AI, ex);
            }

            bot.cur = props.CurInstruction;
            if (bot.cur >= bot.Instructions.Count)
            {
                bot.cur = 0;
            }
        }
Ejemplo n.º 4
0
        static void LoadAi(BotProperties props, PlayerBot bot)
        {
            if (String.IsNullOrEmpty(props.AI))
            {
                return;
            }
            try {
                ScriptFile.Parse(null, bot, "bots/" + props.AI);
            } catch (Exception ex)  {
                Server.ErrorLog(ex);
            }

            bot.cur = props.CurInstruction;
            if (bot.cur >= bot.Instructions.Count)
            {
                bot.cur = 0;
            }
        }
Ejemplo n.º 5
0
        internal static List <BotProperties> ReadAll(string path)
        {
            List <BotProperties> props = new List <BotProperties>();

            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BotProperties));
            }
            string json = File.ReadAllText(path);

            JsonReader reader = new JsonReader(json);

            reader.OnMember = (obj, key, value) => {
                if (obj.Meta == null)
                {
                    obj.Meta = new BotProperties();
                }
                ConfigElement.Parse(elems, obj.Meta, key, (string)value);
            };

            JsonArray array = (JsonArray)reader.Parse();

            if (array == null)
            {
                return(props);
            }

            foreach (object raw in array)
            {
                JsonObject obj = (JsonObject)raw;
                if (obj == null || obj.Meta == null)
                {
                    continue;
                }

                BotProperties data = (BotProperties)obj.Meta;
                if (String.IsNullOrEmpty(data.DisplayName))
                {
                    data.DisplayName = data.Name;
                }
                props.Add(data);
            }
            return(props);
        }
Ejemplo n.º 6
0
 public static void MoveBots(string srcLevel, string dstLevel)
 {
     lock (locker) {
         int moved = 0;
         for (int i = 0; i < SavedBots.Count; i++)
         {
             BotProperties props = SavedBots[i];
             if (!props.Level.CaselessEq(srcLevel))
             {
                 continue;
             }
             props.Level = dstLevel; moved++;
         }
         if (moved > 0)
         {
             Save();
         }
     }
 }
Ejemplo n.º 7
0
        public static void DeleteBots(string level)
        {
            lock (locker) {
                int removed = 0;
                for (int i = 0; i < SavedBots.Count; i++)
                {
                    BotProperties props = SavedBots[i];
                    if (!props.Level.CaselessEq(level))
                    {
                        continue;
                    }

                    SavedBots.RemoveAt(i);
                    removed++; i--;
                }
                if (removed > 0)
                {
                    Save();
                }
            }
        }
Ejemplo n.º 8
0
        internal static List <BotProperties> ReadAll(string path)
        {
            List <BotProperties> props = new List <BotProperties>();

            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BotProperties));
            }
            string json = File.ReadAllText(path);

            bool      success;
            JsonArray array = (JsonArray)Json.Parse(json, out success);

            if (array == null)
            {
                return(props);
            }

            foreach (object raw in array)
            {
                JsonObject obj = (JsonObject)raw;
                if (obj == null)
                {
                    continue;
                }

                BotProperties data = new BotProperties();
                obj.Deserialise(elems, data);

                if (String.IsNullOrEmpty(data.DisplayName))
                {
                    data.DisplayName = data.Name;
                }
                props.Add(data);
            }
            return(props);
        }
Ejemplo n.º 9
0
        internal static List <BotProperties> ReadAll(string json)
        {
            List <BotProperties> props = new List <BotProperties>();

            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BotProperties));
            }

            JsonContext ctx   = new JsonContext(); ctx.Val = json;
            JsonArray   array = (JsonArray)Json.ParseStream(ctx);

            if (array == null)
            {
                return(props);
            }

            foreach (object raw in array)
            {
                JsonObject obj = (JsonObject)raw;
                if (obj == null)
                {
                    continue;
                }

                BotProperties data = new BotProperties();
                obj.Deserialise(elems, data);

                if (String.IsNullOrEmpty(data.DisplayName))
                {
                    data.DisplayName = data.Name;
                }
                props.Add(data);
            }
            return(props);
        }