{
int seedId = _items[i];
long count = _itemQ[i];
long price = 0;
long residual = 0;
SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
price = seed.getPrice();
residual = seed.getCanProduce();
if (price < 1)
{
return;
}
if (residual < count)
{
return;
}
totalPrice = SafeMath.addAndCheck(totalPrice, SafeMath.mulAndCheck(count, price));
ItemTemplate item = ItemHolder.getInstance().getTemplate(seedId);
if (item == null)
{
return;
}
weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(count, item.getWeight()));
if (!item.isStackable() || (activeChar.getInventory().getItemByItemId(seedId) == null))
{
slots++;
}
}
}
catch (ArithmeticException ae)
{
sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
return;
}
activeChar.getInventory().writeLock();
try
{
if (!activeChar.getInventory().validateWeight(weight))
{
sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
return;
}
if (!activeChar.getInventory().validateCapacity(slots))
{
sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
return;
}
if (!activeChar.reduceAdena(totalPrice, true))
{
sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
return;
}
castle.addToTreasuryNoTax(totalPrice, false, true);
for (int i = 0; i < _count; i++)
{
int seedId = _items[i];
long count = _itemQ[i];
SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
seed.setCanProduce(seed.getCanProduce() - count);
castle.updateSeed(seed.getId(), seed.getCanProduce(), CastleManorManager.PERIOD_CURRENT);
activeChar.getInventory().addItem(seedId, count);
activeChar.sendPacket(SystemMessage2.obtainItems(seedId, count, 0));
}
}
finally