{
if (count > si.getCount())
{
break loop;
}
ItemInstance item = seller.getInventory().getItemByObjectId(objectId);
if ((item == null) || (item.getCount() < count) || !item.canBeTraded(seller))
{
break loop;
}
totalCost = SafeMath.addAndCheck(totalCost, SafeMath.mulAndCheck(count, price));
weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(count, item.getTemplate().getWeight()));
if (!item.isStackable() || (buyer.getInventory().getItemByItemId(item.getItemId()) == null))
{
slots++;
}
bi = new TradeItem();
bi.setObjectId(objectId);
bi.setItemId(item.getItemId());
bi.setCount(count);
bi.setOwnersPrice(price);
buyList.add(bi);
break;
}
}
}
}
}
catch (ArithmeticException ae)
{
buyList.clear();
sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
return;
}
finally
{
try
{
if ((buyList.size() != _count) || ((seller.getPrivateStoreType() == Player.STORE_PRIVATE_SELL_PACKAGE) && (buyList.size() != sellList.size())))
{
buyer.sendPacket(Msg.THE_ATTEMPT_TO_TRADE_HAS_FAILED);
buyer.sendActionFailed();
return;
}
if (!buyer.getInventory().validateWeight(weight))
{
buyer.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
buyer.sendActionFailed();
return;
}
if (!buyer.getInventory().validateCapacity(slots))
{
buyer.sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
buyer.sendActionFailed();
return;
}
if (!buyer.reduceAdena(totalCost))
{
buyer.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
buyer.sendActionFailed();
return;
}
ItemInstance item;
for (TradeItem bi : buyList)
{
item = seller.getInventory().removeItemByObjectId(bi.getObjectId(), bi.getCount());
for (TradeItem si : sellList)
{