deleteItem() public method

public deleteItem ( Item item ) : void
item Item
return void
Example #1
0
        private void btnDeleteItem_Click(object sender, System.EventArgs e)
        {
            if (lstInventory.SelectedIndex != -1)             // if something's selected
            {
                var item = lstInventory.SelectedItem as Item; // cast it to an Item

                inventory.deleteItem(item);                   // delete
                updateUI();
            }
        }
Example #2
0
    public void removeItem(string id, int number)
    {
        inv.removeItem(id, number);
        int index = inv.findItemIndex(id);

        if (index != -1)
        {
            updateSlot(index);
        }

        if (inv.getNum(index) <= 0)
        {
            inv.deleteItem(id);
            Destroy(inventoryArray[index]);
            inventoryArray.RemoveAt(index);
        }
    }
Example #3
0
    public void askDrop(int x, int y, bool all, NetworkPlayer player)
    {
        GameObject playerModel = NetworkUserList.getModelFromPlayer(player);

        if (playerModel != null)
        {
            Inventory inventory = playerModel.GetComponent <Inventory>();
            if (x >= 0 && y >= 0 && x < inventory.width && y < inventory.height && inventory.items[x, y].amount > 0)
            {
                Vector3 position = inventory.transform.position;
                if (inventory.transform.GetComponent <Player>().vehicle != null)
                {
                    position = inventory.transform.GetComponent <Player>().vehicle.getPosition();
                }
                if (!ItemStackable.getStackable(inventory.items[x, y].id))
                {
                    SpawnItems.drop(inventory.items[x, y].id, inventory.items[x, y].amount, inventory.items[x, y].state, position);
                    inventory.useItem(x, y);
                }
                else if (!all)
                {
                    SpawnItems.drop(inventory.items[x, y].id, 1, inventory.items[x, y].state, position);
                    inventory.useItem(x, y);
                }
                else
                {
                    for (int i = 0; i < inventory.items[x, y].amount; i++)
                    {
                        SpawnItems.drop(inventory.items[x, y].id, 1, inventory.items[x, y].state, position);
                    }
                    inventory.deleteItem(x, y);
                }
                inventory.syncItem(x, y);
                NetworkSounds.askSound("Sounds/General/drop", position, 0.2f, UnityEngine.Random.Range(0.9f, 1.1f), 1f);
            }
        }
    }
        //TODO redump GE prices with all 3 prices, then edit 'sellitem' to give min price
        //and 'buyitem' to give medium price

        public void sellItem(int slot, int amount)
        {
            Inventory inv = player.getInventory();

            if (slot < 0 || slot > 28)
            {
                return;
            }
            if (inv.getItemInSlot(slot) == -1)
            {
                return;
            }
            int  itemId                 = inv.getItemInSlot(slot);
            bool noted                  = ItemData.forId(itemId).isNoted();
            int  itemToRemove           = itemId;
            long currentCurrencyInInven = player.getInventory().getItemAmount(shop.getCurrency());

            if (noted)
            {
                itemToRemove = ItemData.getUnNotedItem(itemId);
            }
            if (!shopWillBuyItem(itemToRemove))
            {
                return;
            }
            int price    = ItemData.forId(itemToRemove).getPrice().getMinimumPrice();
            int shopSlot = shop.findItem(itemToRemove);

            if (shopSlot == -1)
            {
                shopSlot = shop.findFreeSlot();
                if (shopSlot == -1)
                {
                    player.getPackets().sendMessage("This shop is too full to buy anymore stock.");
                    return;
                }
            }
            if (inv.getAmountInSlot(slot) > amount)
            {
                if (inv.findFreeSlot() == -1 && !inv.hasItem(shop.getCurrency()))
                {
                    player.getPackets().sendMessage("Not enough space in your inventory.");
                    return;
                }
            }
            if (amount == 1)
            {
                if ((currentCurrencyInInven + price) >= int.MaxValue)
                {
                    player.getPackets().sendMessage("Not enough space in your inventory");
                    return;
                }
                if (!inv.deleteItem(itemId))
                {
                    return;
                }
                if (price > 0)
                {
                    inv.addItem(shop.getCurrency(), price);
                }
                shop.getSlot(shopSlot).setItemId(itemToRemove);
                shop.getSlot(shopSlot).setItemAmount(shop.getSlot(shopSlot).getItemAmount() + 1);
                refreshShop();
            }
            else
            {
                for (int i = 0; i < amount; i++)
                {
                    if ((currentCurrencyInInven + price) >= int.MaxValue)
                    {
                        player.getPackets().sendMessage("Not enough space in your inventory");
                        break;
                    }
                    if (!inv.deleteItem(itemId))
                    {
                        break;
                    }
                    if (price > 0)
                    {
                        inv.addItem(shop.getCurrency(), price);
                        currentCurrencyInInven += price;
                    }
                    shop.getSlot(shopSlot).setItemId(itemToRemove);
                    shop.getSlot(shopSlot).setItemAmount(shop.getSlot(shopSlot).getItemAmount() + 1);
                }
                refreshShop();
            }
            if (inMainStock)
            {
                openPlayerShop();
            }
        }
        public void buyItem(int slot, int amount)
        {
            Item item        = null;
            int  stockLength = inMainStock ? shop.getMainItems().Length : shop.getStock().Length;

            if (slot < 0 || slot > stockLength)
            {
                return;
            }
            if (inMainStock)
            {
                item = shop.getMainItem(slot);
            }
            else
            {
                item = shop.getStockItem(slot);
            }
            if (item == null || item.getItemAmount() < 1 || item.getItemId() < 1)
            {
                return;
            }
            if (ItemData.forId(item.getItemId()).isPlayerBound() && !inMainStock)
            {
                player.getPackets().sendMessage("How did this get in here..");
                return;
            }
            if (amount > item.getItemAmount())
            {
                amount = item.getItemAmount();
            }
            Inventory inv         = player.getInventory();
            bool      stackable   = item.getDefinition().isStackable();
            int       amountToAdd = amount;
            int       itemToAdd   = item.getItemId();
            int       itemPrice   = item.getDefinition().getPrice().getMaximumPrice();
            long      totalPrice  = (amountToAdd * itemPrice);

            if (totalPrice > int.MaxValue || totalPrice < 0)
            {
                amountToAdd = inv.getItemAmount(995) / itemPrice;
            }
            if (itemPrice <= 0)
            {
                itemPrice = 1;
            }
            if (!inv.hasItemAmount(shop.getCurrency(), itemPrice))
            {
                player.getPackets().sendMessage("You don't have enough coins to purchase that item.");
                return;
            }
            if (!stackable)
            {
                if (inv.findFreeSlot() == -1)
                {
                    player.getPackets().sendMessage("Not enough space in your inventory.");
                    return;
                }
                if (amount > 1)
                {
                    for (int i = 0; i < amount; i++)
                    {
                        if (!inMainStock && shop.getStockItem(slot).getItemId() != itemToAdd || !inMainStock && shop.getStockItem(slot).getItemAmount() < 1)
                        {
                            player.getPackets().sendMessage("An error occured whilst buying the item.");
                            break;
                        }
                        if (!inv.deleteItem(shop.getCurrency(), itemPrice) && itemPrice > 0)
                        {
                            player.getPackets().sendMessage("You didn't have enough coins to purchase the full amount.");
                            break;
                        }
                        if (!inv.addItem(itemToAdd))
                        {
                            player.getPackets().sendMessage("You didn't have enough inventory space to purchase the full amount.");
                            break;
                        }
                        if (!inMainStock)
                        {
                            shop.getStockItem(slot).setItemAmount(shop.getStockItem(slot).getItemAmount() - 1);
                            if (shop.getStockItem(slot).getItemAmount() <= 0)
                            {
                                shop.getStockItem(slot).setItemId(-1);
                                shop.getStockItem(slot).setItemAmount(0);
                                refreshShop();
                                break;
                            }
                            refreshShop();
                        }
                        else
                        {
                            player.getPackets().sendItems(-1, 64209, 93, player.getInventory().getItems());
                        }
                    }
                }
                else if (amount == 1)
                {
                    if (!inMainStock && shop.getStockItem(slot).getItemId() != itemToAdd || !inMainStock && shop.getStockItem(slot).getItemAmount() < 1)
                    {
                        player.getPackets().sendMessage("An error occured whilst buying the item.");
                        return;
                    }
                    if (!inv.deleteItem(shop.getCurrency(), itemPrice) && itemPrice > 0)
                    {
                        player.getPackets().sendMessage("You didn't have enough coins to purchase the full amount.");
                        return;
                    }
                    if (!inv.addItem(itemToAdd))
                    {
                        player.getPackets().sendMessage("You didn't have enough inventory space to purchase the full amount.");
                        return;
                    }
                    if (!inMainStock)
                    {
                        shop.getStockItem(slot).setItemAmount(shop.getStockItem(slot).getItemAmount() - 1);
                        if (shop.getStockItem(slot).getItemAmount() <= 0)
                        {
                            shop.getStockItem(slot).setItemId(-1);
                            shop.getStockItem(slot).setItemAmount(0);
                        }
                        refreshShop();
                        return;
                    }
                    player.getPackets().sendItems(-1, 64209, 93, player.getInventory().getItems());
                    return;
                }
            }
            else
            {
                if (inv.findFreeSlot() == -1 && inv.findItemSlot(itemToAdd) == -1)
                {
                    player.getPackets().sendMessage("Not enough space in your inventory.");
                    return;
                }
                if (!inMainStock && shop.getStockItem(slot).getItemId() != itemToAdd || !inMainStock && shop.getStockItem(slot).getItemAmount() < 1)
                {
                    player.getPackets().sendMessage("An error occured whilst buying the item.");
                    return;
                }
                bool moneyShort = false;
                if (!inv.hasItemAmount(shop.getCurrency(), itemPrice * amountToAdd))
                {
                    moneyShort  = true;
                    amountToAdd = inv.getItemAmount(995) / itemPrice;
                    if (amountToAdd < 1)
                    {
                        player.getPackets().sendMessage("You don't have enough coins to purchase that item.");
                        return;
                    }
                }
                if (inv.deleteItem(shop.getCurrency(), itemPrice * amountToAdd) && itemPrice > 0)
                {
                    if (inv.addItem(itemToAdd, amountToAdd))
                    {
                        if (moneyShort)
                        {
                            player.getPackets().sendMessage("You didn't have enough money to purchase the full amount.");
                        }
                        if (!inMainStock)
                        {
                            shop.getStockItem(slot).setItemAmount(shop.getStockItem(slot).getItemAmount() - amountToAdd);
                            if (shop.getStockItem(slot).getItemAmount() <= 0)
                            {
                                shop.getStockItem(slot).setItemId(-1);
                                shop.getStockItem(slot).setItemAmount(0);
                            }
                            refreshShop();
                            return;
                        }
                        player.getPackets().sendItems(-1, 64209, 93, player.getInventory().getItems());
                    }
                }
            }
        }
 public void deleteItem()
 {
     inven.deleteItem();
 }