ItemInstance item = seller.getInventory().getItemByObjectId(objectId);
if ((item == null) || (item.getCount() < count) || !item.canBeTraded(seller))
{
break loop;
}
TradeItem si = null;
for (TradeItem bi : buyList)
{
if (bi.getItemId() == item.getItemId())
{
if (bi.getOwnersPrice() == price)
{
if (count > bi.getCount())
{
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++;
}
si = new TradeItem();
si.setObjectId(objectId);
si.setItemId(item.getItemId());
si.setCount(count);
si.setOwnersPrice(price);
sellList.add(si);
break;
}
}
}
}
}
catch (ArithmeticException ae)
{
sellList.clear();
sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
return;
}
finally
{
try
{
if (sellList.size() != _count)
{
seller.sendPacket(Msg.THE_ATTEMPT_TO_SELL_HAS_FAILED);
seller.sendActionFailed();
return;
}
if (!buyer.getInventory().validateWeight(weight))
{
buyer.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
seller.sendPacket(Msg.THE_ATTEMPT_TO_SELL_HAS_FAILED);
seller.sendActionFailed();
return;
}
if (!buyer.getInventory().validateCapacity(slots))
{
buyer.sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
seller.sendPacket(Msg.THE_ATTEMPT_TO_SELL_HAS_FAILED);
seller.sendActionFailed();
return;
}
if (!buyer.reduceAdena(totalCost))
{
buyer.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
seller.sendPacket(Msg.THE_ATTEMPT_TO_SELL_HAS_FAILED);
seller.sendActionFailed();
return;
}
ItemInstance item;
for (TradeItem si : sellList)
{
item = seller.getInventory().removeItemByObjectId(si.getObjectId(), si.getCount());
for (TradeItem bi : buyList)
{
if (bi.getItemId() == si.getItemId())
{
if (bi.getOwnersPrice() == si.getOwnersPrice())
{
bi.setCount(bi.getCount() - si.getCount());
if (bi.getCount() < 1L)
{
buyList.remove(bi);
}
break;