/// <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 = SoundMachineSongManager.GetSongId(item.SongCode); BaseItem = item.BaseItem; ExtraData = item.ExtraData; SongCode = item.SongCode; }
/// <summary> /// Adds the new item. /// </summary> /// <param name="id">The identifier.</param> /// <param name="baseName">The base item.</param> /// <param name="extraData">The extra data.</param> /// <param name="thGroup">The thGroup.</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, string baseName, string extraData, uint thGroup, bool insert, bool fromRoom, uint limno, uint limtot, string songCode = "") { _isUpdated = false; if (insert) { if (fromRoom) { using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) queryReactor.RunFastQuery("UPDATE items_rooms SET user_id = '" + UserId + "', room_id= '0' WHERE (id='" + id + "')"); } else { using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery($"INSERT INTO items_rooms (item_name, user_id, group_id) VALUES ('{baseName}', '{UserId}', '{thGroup}');"); 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($"INSERT INTO items_limited VALUES ('{id}', '{limno}', '{limtot}');"); if (!string.IsNullOrEmpty(songCode)) queryReactor.RunFastQuery($"UPDATE items_rooms SET songcode='{songCode}' WHERE id='{id}' LIMIT 1"); } } } if (id == 0) return null; UserItem userItem = new UserItem(id, baseName, extraData, thGroup, songCode); if (UserHoldsItem(id)) RemoveItem(id, false); if (userItem.BaseItem.InteractionType == Interaction.MusicDisc && !SongDisks.Contains(userItem.Id)) SongDisks.Add(userItem.Id, userItem); if (userItem.IsWallItem && !_wallItems.Contains(userItem.Id)) _wallItems.Add(userItem.Id, userItem); else if(!userItem.IsWallItem && !_floorItems.Contains(userItem.Id)) _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 (IQueryAdapter queryReactor = Yupi.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) { uint id = Convert.ToUInt32(dataRow["id"]); string itemName = dataRow["item_name"].ToString(); if (!Yupi.GetGame().GetItemManager().ContainsItemByName(itemName)) continue; string extraData; if (!DBNull.Value.Equals(dataRow[4])) extraData = (string) dataRow[4]; else extraData = string.Empty; uint group = Convert.ToUInt32(dataRow["group_id"]); string songCode; if (!DBNull.Value.Equals(dataRow["songcode"])) songCode = (string) dataRow["songcode"]; else songCode = string.Empty; UserItem userItem = new UserItem(id, itemName, 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 (IQueryAdapter queryReactor2 = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor2.SetQuery($"SELECT * FROM bots_data WHERE user_id = {UserId} AND room_id = 0"); DataTable table2 = queryReactor2.GetTable(); if (table2 == null) return; foreach (DataRow botRow in table2.Rows) { if ((string) botRow["ai_type"] == "generic") AddBot(BotManager.GenerateBotFromRow(botRow)); } queryReactor2.SetQuery($"SELECT * FROM pets_data WHERE user_id = {UserId} AND room_id = 0"); DataTable table3 = queryReactor2.GetTable(); if (table3 == null) return; foreach (DataRow petRow in table3.Rows) { if ((string) petRow["ai_type"] == "pet") { Pet pet = CatalogManager.GeneratePetFromRow(petRow); if (_inventoryPets.Contains(pet.PetId)) _inventoryPets.Remove(pet.PetId); _inventoryPets.Add(pet.PetId, pet); } } } }
/// <summary> /// Takes the back item. /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="item">The item.</param> internal void TakeBackItem(uint userId, UserItem item) { TradeUser tradeUser = GetTradeUser(userId); if (tradeUser == null || item == null || tradeUser.HasAccepted || _tradeStage != 1) { return; } ClearAccepted(); tradeUser.OfferedItems.Remove(item); UpdateTradeWindow(); }
/// <summary> /// Offers the item. /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="item">The item.</param> internal void OfferItem(uint userId, UserItem item) { TradeUser tradeUser = GetTradeUser(userId); if (tradeUser == null || item == null || !item.BaseItem.AllowTrade || tradeUser.HasAccepted || _tradeStage != 1) { return; } ClearAccepted(); if (!tradeUser.OfferedItems.Contains(item)) { tradeUser.OfferedItems.Add(item); } UpdateTradeWindow(); }