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

            return true;
        }
Esempio n. 2
0
 public SongItem(UserItem item)
 {
     this.itemID = item.Id;
     this.songID = TextHandling.Parse(item.ExtraData);
     this.baseItem = item.GetBaseItem();
 }
Esempio n. 3
0
        internal void LoadInventory()
        {
            floorItems.Clear();
            wallItems.Clear();

            DataTable Data;

            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                {
                    dbClient.setQuery("CALL getuseritems(@userid)");
                }
                else
                {
                    dbClient.setQuery("EXECUTE 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;
            string extradata;
            foreach (DataRow Row in Data.Rows)
            {
                id = Convert.ToUInt32(Row[0]);
                baseitem = Convert.ToUInt32(Row[1]);

                if (!DBNull.Value.Equals(Row[2]))
                    extradata = (string)Row[2];
                else
                    extradata = string.Empty;

                UserItem item = new UserItem(id, baseitem, extradata);

                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 = PiciEnvironment.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 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);
                }
            }
        }
Esempio n. 4
0
        internal UserItem AddNewItem(UInt32 Id, UInt32 BaseItem, string ExtraData, bool insert, bool fromRoom, UInt32 songID = 0)
        {
            isUpdated = false;
            if (insert)
            {
                if (fromRoom)
                {
                    using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MSSQL)
                        {
                            dbClient.setQuery("DELETE FROM items_users WHERE item_id = " + Id);
                            dbClient.setQuery("INSERT INTO items_users VALUES (" + Id + "," + UserId + ")");
                        }
                        else
                        {
                            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 = PiciEnvironment.GetGame().GetItemManager().GetItem(BaseItem);

                    if (baseItem != null && baseItem.InteractionType == InteractionType.musicdisc)
                    {
                        using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            dbClient.runFastQuery("DELETE FROM room_items_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 = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MSSQL)
                            dbClient.setQuery("INSERT INTO items (base_id) OUTPUT INSERTED.* VALUES (" + BaseItem + ")");
                        else
                            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 + ",@extradata)");
                            dbClient.addParameter("extradata", ExtraData);
                            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, ExtraData);

            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;
            //Console.WriteLine("Item added: " + BaseItem);
        }
Esempio n. 5
0
        internal void TakeBackItem(UInt32 UserId, UserItem Item)
        {
            TradeUser User = GetTradeUser(UserId);

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

            ClearAccepted();

            User.OfferedItems.Remove(Item);
            UpdateTradeWindow();
        }
Esempio n. 6
0
        internal void OfferItem(UInt32 UserId, UserItem Item)
        {
            TradeUser User = GetTradeUser(UserId);

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

            ClearAccepted();
            if(!User.OfferedItems.Contains(Item))
                User.OfferedItems.Add(Item);
            UpdateTradeWindow();
        }