示例#1
0
        public void valueItem(int slot, bool inventory)
        {
            Item item = inventory ? player.getInventory().getSlot(slot) : inMainStock?shop.getMainItem(slot) : shop.getSlot(slot);

            int id = item.getItemId();

            if (item.getItemId() <= 0)
            {
                return;
            }
            bool noted = ItemData.forId(item.getItemId()).isNoted();

            if (noted)
            {
                id = ItemData.getUnNotedItem(item.getItemId());
            }
            if (!shopWillBuyItem(id))
            {
                return;
            }
            ItemData.Item def = ItemData.forId(id);
            if (inventory)
            {
                player.getPackets().sendMessage("This shop will pay " + def.getPrice().getMinimumPrice().ToString("#,##0") + " coins for 1 " + def.getName() + ".");
                return;
            }
            player.getPackets().sendMessage("1 " + def.getName() + " costs " + def.getPrice().getMaximumPrice().ToString("#,##0") + " coins.");
        }
示例#2
0
 public static GroundItem newPlayerDroppedItem(Player player, Item item)
 {
     return(new GroundItem(item.getItemId(), item.getItemAmount(), player.getLocation(), player));
 }
示例#3
0
        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.findItem(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());
                    }
                }
            }
        }
示例#4
0
 public static GroundItem newPlayerDroppedItem(Player player, Item item)
 {
     return new GroundItem(item.getItemId(), item.getItemAmount(), player.getLocation(), player);
 }