Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        internal UserItem AddNewItem(UInt32 Id, UInt32 BaseItem, string ExtraData, uint Group, bool insert, bool fromRoom, int limno, int limtot, UInt32 songID = 0)
        {
            isUpdated = false;
            if (insert)
            {
                if (fromRoom)
                {
                    using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                            dbClient.runFastQuery("UPDATE items SET room_id='' WHERE id=" + Id + " LIMIT 1");
                    }

                    Item baseItem = SilverwaveEnvironment.GetGame().GetItemManager().GetItem(BaseItem);
                    if (baseItem != null && baseItem.InteractionType == InteractionType.musicdisc)
                    {
                        using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            dbClient.runFastQuery("DELETE FROM room_items_songs WHERE item_id = " + Id);
                        }
                    }
                }
                else
                {
                    using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        dbClient.setQuery("INSERT INTO items (base_item, user_id) VALUES (" + BaseItem + ", " + UserId + ")");
                        Id = (uint)dbClient.insertQuery();

                        SendNewItems(Convert.ToInt32(Id));

                        if(Group > 0)
                            dbClient.runFastQuery("INSERT INTO items_groups VALUES (" + Id + ", " + Group + ")");

                        if (!string.IsNullOrEmpty(ExtraData))
                        {
                            dbClient.setQuery("UPDATE items SET extra_data=@extradata WHERE id=" + Id + " LIMIT 1");
                            dbClient.addParameter("extradata", ExtraData);
                            dbClient.runQuery();
                        }
                        if (limno > 0)
                        {
                           // dbClient.runFastQuery("INSERT INTO items_limited VALUES (" + Id + ", " + limno + ", " + limtot + ")");
                        }
                    }
                }
            }
            UserItem ItemToAdd = new UserItem(Id, BaseItem, ExtraData, Group);

            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);
        }
Ejemplo n.º 4
0
        internal void LoadInventory()
        {
            floorItems.Clear();
            wallItems.Clear();

            DataTable Data;
            DataTable dSongs;

            using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT `items`.* , COALESCE(`items_groups`.`group_id`, 0) AS group_id FROM `items` LEFT OUTER JOIN `items_groups` ON `items`.`id` = `items_groups`.`id` WHERE user_id=@userid AND room_id='' ORDER BY id DESC LIMIT 8000;");

                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;
            uint Group;
            foreach (DataRow Row in Data.Rows)
            {
                id = Convert.ToUInt32(Row[0]);
                baseitem = Convert.ToUInt32(Row[3]);

                if (!DBNull.Value.Equals(Row[4]))
                    extradata = (string)Row[4];
                else
                    extradata = string.Empty;
                Group = Convert.ToUInt32(Row[10]);
                UserItem item = new UserItem(id, baseitem, extradata, Group);

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

            discs.Clear();

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

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

            this.InventoryPets.Clear();
            DataTable Data2;
            using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor())
            {
                //dbClient.addParameter("userid", UserId);
                dbClient.setQuery("SELECT * FROM bots WHERE user_id = " + UserId + " AND room_id = 0 AND ai_type='pet'");
                Data2 = dbClient.getTable();

                if (Data2 != null)
                {
                    foreach (DataRow Row in Data2.Rows)
                    {
                        dbClient.setQuery("SELECT * FROM bots_petdata WHERE id=" + Row[0] + " LIMIT 1");
                        DataRow mRow = dbClient.getRow();
                        if (mRow == null)
                            continue;
                        Pet newPet = Catalog.GeneratePetFromRow(Row, mRow);
                        if (InventoryPets.ContainsKey(newPet.PetId))
                            InventoryPets.Remove(newPet.PetId);
                        InventoryPets.Add(newPet.PetId, newPet);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public SongItem(UserItem item)
 {
     this.itemID = item.Id;
     this.songID = TextHandling.Parse(item.ExtraData);
     this.baseItem = item.GetBaseItem();
 }