Ejemplo n.º 1
0
        public void confirmOffer()
        {
            if (currentOffer == null)
            {
                return;
            }
            if (currentOffer is BuyOffer)
            {
                int gpAmount = currentOffer.getTotalAmount() * currentOffer.getPriceEach();
                if (currentOffer.getTotalAmount() <= 0)
                {
                    p.getPackets().sendMessage("You must choose the quantity you wish to buy!");
                    return;
                }
                else if (!p.getInventory().hasItemAmount(995, gpAmount))
                {
                    p.getPackets().sendMessage("You don't have enough coins in your inventory to cover the offer.");
                    return;
                }
                else if (!p.getInventory().deleteItem(995, gpAmount))
                {
                    return;
                }
            }
            else if (currentOffer is SellOffer)
            {
                if (currentOffer.getTotalAmount() <= 0)
                {
                    p.getPackets().sendMessage("You must choose the quantity you wish to sell!");
                    return;
                }
                else if (!p.getInventory().hasItemAmount(currentOffer.getItem(), currentOffer.getTotalAmount()))
                {
                    p.getPackets().sendMessage("You do not have enough of this item in your inventory to cover the offer.");
                    return;
                }
                if (ItemData.forId(currentOffer.getItem()).isNoted() || ItemData.forId(currentOffer.getItem()).isStackable())
                {
                    if (!p.getInventory().deleteItem(currentOffer.getItem(), currentOffer.getTotalAmount()))
                    {
                        return;
                    }
                }
                else
                {
                    //UnNoted variant of this item, so remove multiple items from inventory.
                    int i = 0;
                    for (int j = 0; j < currentOffer.getTotalAmount(); j++)
                    {
                        if (!p.getInventory().deleteItem(currentOffer.getUnNotedId()))
                        {
                            currentOffer.setTotalAmount(i);
                            p.getPackets().sendConfig(1110, currentOffer.getTotalAmount());
                            break;
                        }
                        i++;
                    }
                }
            }
            p.getPackets().sendConfig(1113, -1);
            p.getPackets().sendConfig(1112, -1);
            currentOffer.setProgress(currentOffer.getSubmittingId());
            p.getPackets().updateGEProgress(currentOffer);
            Server.getGrandExchange().addOffer(currentOffer);
            GEItem offer = currentOffer;

            currentOffer = null;
            Event updateGEProgressEvent = new Event(500);

            updateGEProgressEvent.setAction(() => {
                updateGEProgressEvent.stop();
                offer.setProgress(offer.getOrangeBarId());
                p.getPackets().updateGEProgress(offer);
            });
            Server.registerEvent(updateGEProgressEvent);
        }