Esempio n. 1
0
        public static void LoadMonsters()
        {
            var sqlText    = "SELECT * FROM creatures";
            var sqlCommand = new MySqlCommand(sqlText, Program.DBHelper.Use());

            var sqlReader = sqlCommand.ExecuteReader();

            while (sqlReader.Read())
            {
                var newMonsters = new Models.Monsters.MonsterModel()
                {
                    ID    = sqlReader.GetInt32("ID"),
                    Name  = sqlReader.GetString("Name"),
                    GfxID = sqlReader.GetInt32("GfxId"),
                    Align = sqlReader.GetInt32("Alignement"),

                    Color  = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[0]),
                    Color2 = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[1]),
                    Color3 = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[2]),

                    IA = sqlReader.GetInt16("AI_Type"),

                    Min_kamas = (sqlReader.GetString("Kamas_Dropped").Split(';')[0] == "" ? 0 : int.Parse(sqlReader.GetString("Kamas_Dropped").Split(';')[0])),
                    Max_kamas = (sqlReader.GetString("Kamas_Dropped").Split(';').Length <= 1 ||
                                 sqlReader.GetString("Kamas_Dropped").Split(';')[1] == "" ? 0 : int.Parse(sqlReader.GetString("Kamas_Dropped").Split(';')[0])),
                };

                foreach (var newItem in sqlReader.GetString("Items_Dropped").Split('|'))
                {
                    if (newItem == "")
                    {
                        continue;
                    }

                    var infos = newItem.Split(';');

                    if (infos.Length < 3)
                    {
                        continue;
                    }

                    newMonsters.Items.Add(new Models.Monsters.MonsterModel.MonsterItem(int.Parse(infos[0]),
                                                                                       double.Parse(infos[1]), int.Parse(infos[2])));
                }

                MonstersList.Add(newMonsters);
            }

            sqlReader.Close();

            Utilities.Loggers.Status.Write(string.Format("Loaded '{0}' monsters from the database !", MonstersList.Count));
        }
Esempio n. 2
0
        public static void LoadMonsters()
        {
            lock (DatabaseProvider.Locker)
            {
                var sqlText = "SELECT * FROM creatures";
                var sqlCommand = new MySqlCommand(sqlText, DatabaseProvider.Connection);

                var sqlReader = sqlCommand.ExecuteReader();

                while (sqlReader.Read())
                {
                    var newMonsters = new Models.Monsters.MonsterModel()
                    {
                        ID = sqlReader.GetInt32("ID"),
                        Name = sqlReader.GetString("Name"),
                        GfxID = sqlReader.GetInt32("GfxId"),
                        Align = sqlReader.GetInt32("Alignement"),

                        Color = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[0]),
                        Color2 = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[1]),
                        Color3 = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[2]),

                        IA = sqlReader.GetInt16("AI_Type"),

                        Min_kamas = (sqlReader.GetString("Kamas_Dropped").Split(';')[0] == "" ? 0 : int.Parse(sqlReader.GetString("Kamas_Dropped").Split(';')[0])),
                        Max_kamas = (sqlReader.GetString("Kamas_Dropped").Split(';').Length <= 1 ||
                            sqlReader.GetString("Kamas_Dropped").Split(';')[1] == "" ? 0 : int.Parse(sqlReader.GetString("Kamas_Dropped").Split(';')[0])),
                    };

                    foreach (var newItem in sqlReader.GetString("Items_Dropped").Split('|'))
                    {
                        if (newItem == "")
                            continue;

                        var infos = newItem.Split(';');

                        if (infos.Length < 3)
                            continue;

                        newMonsters.Items.Add(new Models.Monsters.MonsterModel.MonsterItem(int.Parse(infos[0]),
                            double.Parse(infos[1]), int.Parse(infos[2])));
                    }

                    MonstersList.Add(newMonsters);
                }

                sqlReader.Close();
            }

            Utilities.Loggers.Status.Write(string.Format("Loaded '{0}' monsters from the database !", MonstersList.Count));
        }
Esempio n. 3
0
        public static void LoadMonsters()
        {
            lock (DatabaseHandler.ConnectionLocker)
            {
                var sqlText = "SELECT * FROM datas_creatures";
                var sqlCommand = new MySqlCommand(sqlText, DatabaseHandler.Connection);

                var sqlReader = sqlCommand.ExecuteReader();

                while (sqlReader.Read())
                {
                    var newMonsters = new Models.Monsters.MonsterModel();
                    {
                        newMonsters.ID = sqlReader.GetInt32("ID");
                        newMonsters.Name = sqlReader.GetString("Name");
                        newMonsters.GfxID = sqlReader.GetInt32("GfxId");
                        newMonsters.Align = sqlReader.GetInt32("Alignement");

                        newMonsters.Color = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[0]);
                        newMonsters.Color2 = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[1]);
                        newMonsters.Color3 = SunDofus.Utilities.Basic.HexToDeci(sqlReader.GetString("Colors").Split(',')[2]);

                        newMonsters.IA = sqlReader.GetInt16("AI_Type");

                        if (sqlReader.GetString("Kamas_Dropped") == "" || sqlReader.GetString("Kamas_Dropped").Split(';').Length <= 1)
                        {
                            newMonsters.Min_kamas = 0;
                            newMonsters.Min_kamas = 0;
                        }
                        else
                        {
                            newMonsters.Min_kamas = int.Parse(sqlReader.GetString("Kamas_Dropped").Split(';')[0]);
                            newMonsters.Max_kamas = int.Parse(sqlReader.GetString("Kamas_Dropped").Split(';')[1]);
                        }

                        foreach (var newItem in sqlReader.GetString("Items_Dropped").Split('|'))
                        {
                            if (newItem == "")
                                continue;

                            var infos = newItem.Split(';');

                            if (infos.Length < 3)
                                continue;

                            try
                            {
                                lock (newMonsters.Items)
                                {
                                    newMonsters.Items.Add(new Models.Monsters.MonsterModel.MonsterItem(int.Parse(infos[0]),
                                        double.Parse(infos[1]), int.Parse(infos[2])));
                                }
                            }
                            catch
                            {
                                Utilities.Loggers.ErrorsLogger.Write(string.Format("Error on MonstersLoad() : {0}", newItem));
                            }
                        }
                    }

                    lock(MonstersList)
                        MonstersList.Add(newMonsters);
                }

                sqlReader.Close();
            }

            Utilities.Loggers.StatusLogger.Write(string.Format("Loaded @'{0}' monsters@ from the database !", MonstersList.Count));
        }