예제 #1
0
        public void confirmOffer()
        {
            /*
             * Confirm a Buyer or Seller listing.
             */
            if (currentOffer == null)
            {
                p.getPackets().sendMessage("[confirmOffer]: Nice try cheater!, If this is bug please report it.");
                return;
            }

            long gpAmountCalculated = Math.BigMul(currentOffer.getTotalAmount(), currentOffer.getPriceEach());

            if (gpAmountCalculated > Inventory.MAX_ITEM_AMOUNT)
            {
                if (currentOffer is BuyOffer)
                {
                    p.getPackets().sendMessage("You won't be able to cover the offer, it exceeds maximum gold.");
                    return;
                }
                else if (currentOffer is SellOffer)
                {
                    p.getPackets().sendMessage("You can't sell that many, it would create too much gold to be able to take out.");
                    return;
                }
            }

            if (currentOffer is BuyOffer)
            {
                int gpAmount = (int)gpAmountCalculated;
                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()))
                    {
                        p.getPackets().sendMessage("[confirmOffer]: Nice try cheater!, you don't have this item!.");
                        return;
                    }
                }
                else
                {
                    //UnNoted variant of this item, so remove multiple items from inventory.
                    int amountTotalDeleted = p.getInventory().deleteItemAndShowAmountDeleted(currentOffer.getUnNotedId(), currentOffer.getTotalAmount());
                    currentOffer.setTotalAmount(amountTotalDeleted);
                    p.getPackets().sendConfig(1110, currentOffer.getTotalAmount());
                }
            }

            p.getPackets().sendConfig(1113, -1);
            p.getPackets().sendConfig(1112, -1);
            currentOffer.setSubmitting(true);
            p.getPackets().updateGEProgress(currentOffer);
            Server.getGrandExchange().addOffer(currentOffer);
            GEItem offer = currentOffer;

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

            updateGEProgressEvent.setAction(() => {
                updateGEProgressEvent.stop();
                offer.setSubmitting(false); //done submitting = orangebar
                p.getPackets().updateGEProgress(offer);
            });
            Server.registerEvent(updateGEProgressEvent);
        }