public static async Task <Dictionary <int, DB_Loot> > SelectAllLootsAsync()
 {
     try
     {
         using (var connection = await GetConnectionAsync())
         {
             using (var command = connection.CreateCommand())
             {
                 command.CommandText = $"SELECT * FROM {tb_09};";
                 using (var reader = await command.ExecuteReaderAsyncEx())
                 {
                     var result = new Dictionary <int, DB_Loot>();
                     if (reader.HasRows)
                     {
                         while (await reader.ReadAsyncEx())
                         {
                             var id = reader.GetInt32(0);
                             if (!result.TryGetValue(id, out var entry))
                             {
                                 result[id] = entry = new DB_Loot(id);
                             }
                             entry.Loot.Add((reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetFloat(4), reader.GetInt32(5), reader.GetInt32(6)));
                         }
                     }
                     return(result);
                 }
             }
         }
     }
     catch (Exception exp)
     {
         ServerLogger.LogException(exp);
         return(null);
     }
 }
Beispiel #2
0
 public WO_Loot(DB_Loot loot, WorldObject at, MapPlayer onwer, ObjectsMgr manager)
     : base(manager.GetNewGuid() | Constants.IDRObject, manager)
 {
     _onwer     = onwer;
     _position  = at.Position;
     _rotation  = at.Rotation;
     _loot      = loot;
     _resource  = DataMgr.SelectResource(Constants.LootResource);
     OnSpawn   += WO_Loot_OnSpawn;
     OnDespawn += WO_Loot_OnDespawn;
     OnDestroy += WO_Loot_OnDestroy;
     Spawn();
 }
Beispiel #3
0
        public static bool SelectAllLoots(out Dictionary <int, DB_Loot> data)
        {
            var locked = false;

            data = new Dictionary <int, DB_Loot>();
            if (!IsConnected)
            {
                return(false);
            }
            try
            {
                using (MySqlCommand _cmd = _connection.CreateCommand())
                {
                    _cmd.CommandText = $"SELECT * FROM {tb_09};";
                    Monitor.Enter(_connection, ref locked);
                    using (MySqlDataReader _result = _cmd.ExecuteReader())
                    {
                        DB_Loot entry; int id;
                        if (_result.HasRows)
                        {
                            while (_result.Read())
                            {
                                id = _result.GetInt32(0);
                                if (data.ContainsKey(id))
                                {
                                    data[id].Loot.Add(new Tuple <int, int, int, float, int, int>(_result.GetInt32(1), _result.GetInt32(2), _result.GetInt32(3),
                                                                                                 _result.GetFloat(4), _result.GetInt32(5), _result.GetInt32(6)));
                                }
                                else
                                {
                                    entry = new DB_Loot(id);
                                    entry.Loot.Add(new Tuple <int, int, int, float, int, int>(_result.GetInt32(1), _result.GetInt32(2), _result.GetInt32(3),
                                                                                              _result.GetFloat(4), _result.GetInt32(5), _result.GetInt32(6)));
                                    data[id] = entry;
                                }
                            }
                        }
                    }
                }
                return(true);
            }
            catch { return(false); }
            finally { if (locked)
                      {
                          Monitor.Exit(_connection);
                      }
            }
        }
Beispiel #4
0
 public static bool Select(int id, out DB_Loot entry)
 {
     return(m_loots.TryGetValue(id, out entry));
 }