{
slots = 0;
weight = 0;
for (TradeItem ti : tradeList1)
{
ItemInstance item = parthner1.getInventory().getItemByObjectId(ti.getObjectId());
if ((item == null) || (item.getCount() < ti.getCount()) || !item.canBeTraded(parthner1))
{
return;
}
weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(ti.getCount(), ti.getItem().getWeight()));
if (!ti.getItem().isStackable() || (parthner2.getInventory().getItemByItemId(ti.getItemId()) == null))
{
slots++;
}
}
if (!parthner2.getInventory().validateWeight(weight))
{
parthner2.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
return;
}
if (!parthner2.getInventory().validateCapacity(slots))
{
parthner2.sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
return;
}
slots = 0;
weight = 0;
for (TradeItem ti : tradeList2)
{
ItemInstance item = parthner2.getInventory().getItemByObjectId(ti.getObjectId());
if ((item == null) || (item.getCount() < ti.getCount()) || !item.canBeTraded(parthner2))
{
return;
}
weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(ti.getCount(), ti.getItem().getWeight()));
if (!ti.getItem().isStackable() || (parthner1.getInventory().getItemByItemId(ti.getItemId()) == null))
{
slots++;
}
}
if (!parthner1.getInventory().validateWeight(weight))
{
parthner1.sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
return;
}
if (!parthner1.getInventory().validateCapacity(slots))
{
parthner1.sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
return;
}
for (TradeItem ti : tradeList1)
{
ItemInstance item = parthner1.getInventory().removeItemByObjectId(ti.getObjectId(), ti.getCount());
Log.LogItem(parthner1, Log.TradeSell, item);
Log.LogItem(parthner2, Log.TradeBuy, item);
parthner2.getInventory().addItem(item);
}
for (TradeItem ti : tradeList2)
{
ItemInstance item = parthner2.getInventory().removeItemByObjectId(ti.getObjectId(), ti.getCount());
Log.LogItem(parthner2, Log.TradeSell, item);
Log.LogItem(parthner1, Log.TradeBuy, item);
parthner1.getInventory().addItem(item);
}
parthner1.sendPacket(Msg.YOUR_TRADE_IS_SUCCESSFUL);