/// <summary> /// Adds the new item. /// </summary> /// <param name="id">The identifier.</param> /// <param name="baseItem">The base item.</param> /// <param name="extraData">The extra data.</param> /// <param name="group">The group.</param> /// <param name="insert">if set to <c>true</c> [insert].</param> /// <param name="fromRoom">if set to <c>true</c> [from room].</param> /// <param name="limno">The limno.</param> /// <param name="limtot">The limtot.</param> /// <param name="songCode">The song code.</param> /// <returns>UserItem.</returns> internal UserItem AddNewItem(uint id, uint baseItem, string extraData, int group, bool insert, bool fromRoom, int limno, int limtot, string songCode = "") { _isUpdated = false; if (insert) { if (fromRoom) { using (var queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor()) { queryReactor.RunFastQuery("UPDATE items_rooms SET user_id = '" + UserId + "', room_id= '0' WHERE (id='" + id + "')"); } } else { using (var queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery( string.Format( "INSERT INTO items_rooms (base_item, user_id, group_id) VALUES ('{0}', '{1}', '{2}');", baseItem, UserId, group)); if (id == 0) id = ((uint)queryReactor.InsertQuery()); SendNewItems(id); if (!string.IsNullOrEmpty(extraData)) { queryReactor.SetQuery("UPDATE items_rooms SET extra_data = @extraData WHERE id = " + id); queryReactor.AddParameter("extraData", extraData); queryReactor.RunQuery(); } if (limno > 0) queryReactor.RunFastQuery( string.Format("INSERT INTO items_limited VALUES ('{0}', '{1}', '{2}');", id, limno, limtot)); if (!string.IsNullOrEmpty(songCode)) { queryReactor.SetQuery( string.Format("UPDATE items_rooms SET songcode='{0}' WHERE id='{1}' LIMIT 1", songCode, id)); queryReactor.RunQuery(); } } } } if (id == 0) return null; var userItem = new UserItem(id, baseItem, extraData, @group, songCode); if (UserHoldsItem(id)) RemoveItem(id, false); if (userItem.BaseItem.InteractionType == Interaction.MusicDisc) SongDisks.Add(userItem.Id, userItem); if (userItem.IsWallItem) _wallItems.Add(userItem.Id, userItem); else _floorItems.Add(userItem.Id, userItem); if (_mRemovedItems.Contains(id)) _mRemovedItems.Remove(id); if (!_mAddedItems.Contains(id)) _mAddedItems.Add(id, userItem); return userItem; }
/// <summary> /// Loads the inventory. /// </summary> internal void LoadInventory() { _floorItems.Clear(); _wallItems.Clear(); DataTable table; using (var queryReactor = AzureEmulator.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery("SELECT * FROM items_rooms WHERE user_id=@userid AND room_id='0' LIMIT 8000;"); queryReactor.AddParameter("userid", ((int)UserId)); table = queryReactor.GetTable(); } foreach (DataRow dataRow in table.Rows) { var id = Convert.ToUInt32(dataRow[0]); var itemId = Convert.ToUInt32(dataRow[3]); if (!AzureEmulator.GetGame().GetItemManager().ContainsItem(itemId)) continue; string extraData; if (!DBNull.Value.Equals(dataRow[4])) extraData = (string)dataRow[4]; else extraData = string.Empty; var group = Convert.ToInt32(dataRow["group_id"]); string songCode; if (!DBNull.Value.Equals(dataRow["songcode"])) songCode = (string)dataRow["songcode"]; else songCode = string.Empty; var userItem = new UserItem(id, itemId, extraData, group, songCode); if (userItem.BaseItem.InteractionType == Interaction.MusicDisc && !SongDisks.Contains(id)) SongDisks.Add(id, userItem); if (userItem.IsWallItem) { if (!_wallItems.Contains(id)) _wallItems.Add(id, userItem); } else if (!_floorItems.Contains(id)) _floorItems.Add(id, userItem); } SongDisks.Clear(); _inventoryPets.Clear(); _inventoryBots.Clear(); using (var queryReactor2 = AzureEmulator.GetDatabaseManager().GetQueryReactor()) { queryReactor2.SetQuery( string.Format("SELECT * FROM bots WHERE user_id = {0} AND room_id = 0", UserId)); var table2 = queryReactor2.GetTable(); if (table2 == null) return; foreach (DataRow botRow in table2.Rows) switch ((string)botRow["ai_type"]) { case "pet": { queryReactor2.SetQuery(string.Format("SELECT * FROM pets_data WHERE id={0} LIMIT 1", botRow[0])); var row = queryReactor2.GetRow(); if (row == null) continue; var pet = Catalog.GeneratePetFromRow(botRow, row); if (_inventoryPets.Contains(pet.PetId)) _inventoryPets.Remove(pet.PetId); _inventoryPets.Add(pet.PetId, pet); } break; case "generic": AddBot(BotManager.GenerateBotFromRow(botRow)); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="SongItem"/> class. /// </summary> /// <param name="item">The item.</param> public SongItem(UserItem item) { ItemId = item.Id; SongId = SongManager.GetSongId(item.SongCode); BaseItem = item.BaseItem; }