Пример #1
0
        public void LoadCharacters()
        {
            using (var con = new MySqlConnection(MasterServer.Instance.SqlConnection.mConnectionString))
                using (var cmd = con.CreateCommand())
                {
                    con.Open();
                    cmd.CommandText = "SELECT * FROM chars WHERE ownerID = " + aID + " LIMIT 5";
                    using (var reader = cmd.ExecuteReader())
                    {
                        List <int> ids = new List <int>();

                        for (int i = 0; i < 5; i++)
                        {
                            if (!reader.Read())
                            {
                                break;
                            }

                            ids.Add(reader.GetInt32(0));
                        }

                        foreach (int id in ids)
                        {
                            Character chr = new Character();
                            chr.setcID(id);

                            if (chr.Load(this) == 0)
                            {
                                Logger.WriteLog(Logger.LogTypes.Error, "Could not load character with ID {0}.", chr.getuID());
                                continue;
                            }

                            chr.setAccount(this);
                            MySQLTool.loadEq(chr);
                            MySQLTool.loadInv(chr);
                            MySQLTool.loadCargo(chr);
                            MySQLTool.loadSkills(chr);
                            MySQLTool.loadSkillBar(chr);
                            MySQLTool.loadCommunities(chr);
                            CharacterFunctions.calculateCharacterStatistics(chr);
                            this.appendToCharacters(chr);
                        }
                    }
                }
        }