Example #1
0
        internal UserItem AddNewItem(UInt32 Id, uint BaseItem, string ExtraData, bool insert, bool fromRoom, UInt32 songID = 0)
        {
            isUpdated = false;
            if (insert)
            {
                if (fromRoom)
                {
                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        dbClient.runFastQuery("REPLACE INTO items_users VALUES (" + Id + "," + UserId + ")");

                        if (!string.IsNullOrEmpty(ExtraData))
                        {
                            dbClient.setQuery("REPLACE INTO items_extradata VALUES (" + Id + ",@extradata)");
                            dbClient.addParameter("extradata", ExtraData);
                            dbClient.runQuery();
                        }
                    }

                    Item baseItem = ButterflyEnvironment.GetGame().GetItemManager().GetItem(BaseItem);
                }
                else
                {
                    using (IQueryAdapter dbClient = ButterflyEnvironment.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 + ",@extradata)");
                            dbClient.addParameter("extradata", ExtraData);
                            dbClient.runQuery();
                        }

                        dbClient.runFastQuery("INSERT INTO items_users VALUES (" + Id + "," + UserId + ")");
                    }
                }
            }
            UserItem ItemToAdd = new UserItem(Id, BaseItem, ExtraData);

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

            if (ItemToAdd.IsWallItem())
                wallItems.Add(ItemToAdd.itemID, ItemToAdd);
            else
                floorItems.Add(ItemToAdd.itemID, ItemToAdd);

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

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

            RegisterItem(ItemToAdd);

            return ItemToAdd;
        }
Example #2
0
        internal void LoadInventory()
        {
            floorItems.Clear();
            wallItems.Clear();

            DataTable Data;

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

                Data = dbClient.getTable();
            }

            uint id;
            uint baseitem;
            string extradata;
            foreach (DataRow Row in Data.Rows)
            {
                id = (uint)Row[0];
                baseitem = (uint)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.IsWallItem())
                    wallItems.Add(id, item);
                else
                    floorItems.Add(id, item);

                RegisterItem(item);
            }

            this.InventoryPets.Clear();
            DataTable Data2;
            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                //dbClient.addParameter("userid", UserId);
                dbClient.setQuery("SELECT * 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);
                }
            }
        }