Beispiel #1
0
 /// <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;
 }
Beispiel #2
0
 /// <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)
 {
     var tradeUser = GetTradeUser(userId);
     if (tradeUser == null || item == null || tradeUser.HasAccepted || _tradeStage != 1)
     {
         return;
     }
     ClearAccepted();
     tradeUser.OfferedItems.Remove(item);
     UpdateTradeWindow();
 }
Beispiel #3
0
 /// <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)
 {
     var 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();
 }
        /// <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="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, uint baseItem, string extraData, uint thGroup, bool insert, bool fromRoom, int limno, int limtot, string songCode = "")
        {
            _isUpdated = false;

            if (insert)
            {
                if (fromRoom)
                {
                    using (var queryReactor = Azure.GetDatabaseManager().GetQueryReactor())
                        queryReactor.RunFastQuery("UPDATE items_rooms SET user_id = '" + UserId + "', room_id= '0' WHERE (id='" + id + "')");
                }
                else
                {
                    using (var queryReactor = Azure.GetDatabaseManager().GetQueryReactor())
                    {
                        queryReactor.SetQuery($"INSERT INTO items_rooms (base_item, user_id, group_id) VALUES ('{baseItem}', '{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.SetQuery($"UPDATE items_rooms SET songcode='{songCode}' WHERE id='{id}' LIMIT 1");
                            queryReactor.RunQuery();
                        }
                    }
                }
            }

            if (id == 0)
                return null;

            var userItem = new UserItem(id, baseItem, extraData, thGroup, 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 = Azure.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 (!Azure.GetGame().GetItemManager().ContainsItem(itemId))
                    continue;

                string extraData;

                if (!DBNull.Value.Equals(dataRow[4]))
                    extraData = (string) dataRow[4];
                else
                    extraData = string.Empty;

                var group = Convert.ToUInt32(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 = Azure.GetDatabaseManager().GetQueryReactor())
            {
                queryReactor2.SetQuery($"SELECT * FROM bots WHERE user_id = {UserId} AND room_id = 0");
                var table2 = queryReactor2.GetTable();

                if (table2 == null)
                    return;

                foreach (DataRow botRow in table2.Rows)
                {
                    if ((string) botRow["ai_type"] == "pet")
                    {
                        queryReactor2.SetQuery($"SELECT * FROM pets_data WHERE id={botRow[0]} LIMIT 1");
                        var row = queryReactor2.GetRow();

                        if (row == null)
                            continue;

                        var pet = CatalogManager.GeneratePetFromRow(botRow, row);

                        if (_inventoryPets.Contains(pet.PetId))
                            _inventoryPets.Remove(pet.PetId);

                        _inventoryPets.Add(pet.PetId, pet);
                    }
                    else if ((string) botRow["ai_type"] == "generic")
                        AddBot(BotManager.GenerateBotFromRow(botRow));
                }
            }
        }