コード例 #1
0
 public static async Task <Character> CreateCharacterAsync(int user, PonyData pony, short level = 1)
 {
     try
     {
         using (var connection = await GetConnectionAsync())
         {
             using (var command = connection.CreateCommand())
             {
                 var data = CharsMgr.CreateCharacterData(pony, level);
                 command.CommandText = $"INSERT INTO {tb_02} (user, level, race, gender, name, vdata, gdata) VALUES (@user, {level}, @race, @gender, @name, @vdata, @gdata);";
                 command.Parameters.AddWithValue("user", user);
                 command.Parameters.AddWithValue("name", pony.Name);
                 command.Parameters.AddWithValue("race", pony.Race);
                 command.Parameters.AddWithValue("gender", pony.Gender);
                 command.Parameters.AddWithValue("vdata", pony.GetBytes());
                 command.Parameters.AddWithValue("gdata", data.GetBytes());
                 if (await command.ExecuteNonQueryAsyncEx() == 1)
                 {
                     return(new Character((int)command.LastInsertedId, user, level, 0, pony, data));
                 }
             }
         }
         return(null);
     }
     catch (Exception exp)
     {
         ServerLogger.LogException(exp);
         return(null);
     }
 }
コード例 #2
0
 public Character(PonyData pony)
 {
     ID    = -1;
     Level = 1;
     Pony  = pony;
     CharsMgr.CreateCharacterData(this);
 }