int seedId = _items[i * 2 + 0];
int count = _items[i * 2 + 1];
int price = 0;
int residual = 0;
SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
price = seed.getPrice();
residual = seed.getCanProduce();
if(price <= 0)
return;
if(residual < count)
return;
totalPrice += count * price;
L2Item template = ItemTable.getInstance().getTemplate(seedId);
totalWeight += count * template.getWeight();
if(!template.isStackable())
{
slots += count;
}
else if(player.getInventory().getItemByItemId(seedId) == null)
{
slots++;
}
}
if(totalPrice > Integer.MAX_VALUE)
{
Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + Integer.MAX_VALUE + " adena worth of goods.", Config.DEFAULT_PUNISH);
return;
}
if(!player.getInventory().validateWeight(totalWeight))
{
sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
return;
}
if(!player.getInventory().validateCapacity(slots))
{
sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
return;
}
// Charge buyer
if(totalPrice < 0 || !player.reduceAdena("Buy", (int) totalPrice, target, false))
{
sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
return;
}
// Adding to treasury for Manor Castle
castle.addToTreasuryNoTax((int) totalPrice);
// Proceed the purchase
InventoryUpdate playerIU = new InventoryUpdate();
for(int i = 0; i < _count; i++)
{
int seedId = _items[i * 2 + 0];
int count = _items[i * 2 + 1];
if(count < 0)
{
count = 0;
}
// Update Castle Seeds Amount
SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
seed.setCanProduce(seed.getCanProduce() - count);
if(Config.ALT_MANOR_SAVE_ALL_ACTIONS)
{
CastleManager.getInstance().getCastleById(_manorId).updateSeed(seed.getId(), seed.getCanProduce(), CastleManorManager.PERIOD_CURRENT);
}
// Add item to Inventory and adjust update packet
L2ItemInstance item = player.getInventory().addItem("Buy", seedId, count, player, target);