internal static Boolean CanSellItem(UserItem Item)
        {
            if (!Item.GetBaseItem().AllowTrade || !Item.GetBaseItem().AllowMarketplaceSell)
            {
                return false;
            }

            return true;
        }
Exemple #2
0
        internal void TakeBackItem(int UserId, UserItem Item)
        {
            TradeUser User = GetTradeUser(UserId);

            if (User == null || Item == null || User.HasAccepted || TradeStage != 1)
            {
                return;
            }

            ClearAccepted();

            lock (User.OfferedItems)
            {
                User.OfferedItems.Remove(Item);
            }
            UpdateTradeWindow();
        }
Exemple #3
0
        internal void OfferItem(int UserId, UserItem Item)
        {
            TradeUser User = GetTradeUser(UserId);

            if (User == null || Item == null || !Item.GetBaseItem().AllowTrade || User.HasAccepted || TradeStage != 1)
            {
                return;
            }

            ClearAccepted();
            lock (User.OfferedItems)
            {
                if (!User.OfferedItems.Contains(Item))
                    User.OfferedItems.Add(Item);
            }
            UpdateTradeWindow();
        }
        internal void LoadInventory()
        {
            floorItems.Clear();
            wallItems.Clear();

            DataTable Data;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("CALL getuseritems(@userid)");
                dbClient.addParameter("userid", (int)UserId);

                Data = dbClient.getTable();

                //dbClient.setQuery("SELECT item_id, song_id FROM user_items_songs WHERE user_id = " + UserId);
                //dSongs = dbClient.getTable();
            }

            uint id;
            uint baseitem;
            int dataType;
            string extradata;
            int extra;
            foreach (DataRow Row in Data.Rows)
            {
                id = Convert.ToUInt32(Row[0]);
                baseitem = Convert.ToUInt32(Row[1]);

                    IRoomItemData data;
                    if (DBNull.Value.Equals(Row[2]))
                    {
                        data = new StringData("");
                        extra = 0;
                    }
                    else
                    {
                        dataType = Convert.ToInt32(Row[2]);
                        extradata = (string)Row[3];
                        extra = Convert.ToInt32(Row[4]);
                        switch (dataType)
                        {
                            case 0:
                                data = new StringData(extradata);
                                break;
                            case 1:
                                data = new MapStuffData();
                                break;
                            case 2:
                                data = new StringArrayStuffData();
                                break;
                            case 3:
                                data = new StringIntData();
                                break;
                            default:
                                data = new StringData(extradata);
                                break;
                        }
                        try
                        {
                            data.Parse(extradata);
                        }
                        catch
                        {
                            Logging.LogException(string.Format("Error in furni data! Item ID: \"{0}\" and data: \"{1}\"", id, extradata.Replace(Convert.ToChar(1).ToString(), "[1]")));
                        }
                    }

                UserItem item = new UserItem(id, baseitem, data, extra);

                if (item.GetBaseItem().InteractionType == InteractionType.musicdisc)
                    discs.Add(id, item);
                if (item.isWallItem)
                    wallItems.Add(id, item);
                else
                    floorItems.Add(id, item);
            }

            discs.Clear();

            //uint songItemID;
            //uint songID;
            //foreach (DataRow dRow in dSongs.Rows)
            //{
            //    songItemID = (uint)dRow[0];
            //    songID = (uint)dRow[1];

            //    SongItem song = new SongItem(songItemID, songID);
            //    songs.Add(songItemID, song);
            //}

            this.InventoryPets.Clear();
            DataTable Data2;
            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                //dbClient.addParameter("userid", UserId);
                dbClient.setQuery("SELECT id, user_id, room_id, name, type, race, color, expirience, energy, nutrition, respect, createstamp, x, y, z, have_saddle FROM user_pets WHERE user_id = " + UserId + " AND room_id = 0");
                Data2 = dbClient.getTable();
            }

            if (Data2 != null)
            {
                foreach (DataRow Row in Data2.Rows)
                {
                    Pet newPet = Catalog.GeneratePetFromRow(Row);
                    InventoryPets.Add(newPet.PetId, newPet);
                }
            }
        }
        internal UserItem AddNewItem(UInt32 Id, UInt32 BaseItem, IRoomItemData data, int extra, bool insert, bool fromRoom, UInt32 songID = 0)
        {
            isUpdated = false;
            if (insert)
            {
                if (fromRoom)
                {
                    using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        dbClient.runFastQuery("REPLACE INTO items_users VALUES (" + Id + "," + UserId + ")");

                        //dbClient.setQuery("REPLACE INTO user_items (id, user_id,base_item,extra_data) VALUES ('" + Id + "','" + UserId + "','" + BaseItem + "',@extra_data)");
                        //dbClient.addParameter("extra_data", ExtraData);
                        //dbClient.runQuery();
                    }

                    Item baseItem = FirewindEnvironment.GetGame().GetItemManager().GetItem(BaseItem);

                    if (baseItem != null && baseItem.InteractionType == InteractionType.musicdisc)
                    {
                        using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            dbClient.runFastQuery("DELETE FROM items_rooms_songs WHERE item_id = " + Id);
                            //dbClient.runFastQuery("REPLACE INTO user_items_songs (item_id,user_id,song_id) VALUES (" + Id + "," + UserId + "," + songID + ")");
                        }
                    }
                }
                else
                {
                    using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + BaseItem + ")");
                        Id = (uint)dbClient.insertQuery();

                        //if (!string.IsNullOrEmpty(ExtraData))
                        {
                            dbClient.setQuery("INSERT INTO items_extradata VALUES (" + Id + ",@datatype,@data,@extra)");
                            dbClient.addParameter("datatype", data.GetTypeID());
                            dbClient.addParameter("data", data);
                            dbClient.addParameter("extra", extra);
                            dbClient.runQuery();
                        }

                        dbClient.runFastQuery("INSERT INTO items_users VALUES (" + Id + "," + UserId + ")");
                        //dbClient.setQuery("INSERT INTO user_items (user_id,base_item,extra_data) VALUES ('" + UserId + "','" + BaseItem + "',@extra_data)");
                        //dbClient.addParameter("extra_data", ExtraData);
                        //Id = (uint)dbClient.insertQuery();
                    }
                }
            }
            UserItem ItemToAdd = new UserItem(Id, BaseItem, data, extra);

            if (UserHoldsItem(Id))
            {
                RemoveItem(Id, false);
            }

            if (ItemToAdd.GetBaseItem().InteractionType == InteractionType.musicdisc)
                discs.Add(ItemToAdd.Id, ItemToAdd);
            if (ItemToAdd.isWallItem)
                wallItems.Add(ItemToAdd.Id, ItemToAdd);
            else
                floorItems.Add(ItemToAdd.Id, ItemToAdd);

            if (mRemovedItems.Contains(Id))
                mRemovedItems.Remove(Id);

            if (!mAddedItems.ContainsKey(Id))
                mAddedItems.Add(Id, ItemToAdd);

            return ItemToAdd;
            //Logging.WriteLine("Item added: " + BaseItem);
        }
Exemple #6
0
 public SongItem(UserItem item)
 {
     this.itemID = item.Id;
     this.songID = TextHandling.Parse(item.Data.ToString());
     this.baseItem = item.GetBaseItem();
 }