long subTotal = 0;
int tax = 0;
// Check for buylist validity and calculates summary values
int slots = 0;
int weight = 0;
L2ManorManagerInstance manor = target != null && target instanceof L2ManorManagerInstance ? (L2ManorManagerInstance) target : null;
for(int i = 0; i < _count; i++)
{
int itemId = (int) _items[i * 2 + 0];
long count = _items[i * 2 + 1];
int price = 0;
if(count < 0)
{
sendPacket(Msg.INCORRECT_ITEM_COUNT);
return;
}
Castle castle = manor.getCastle();
if(castle == null)
{
return;
}
CropProcure crop = castle.getCrop(itemId, CastleManorManager.PERIOD_CURRENT);
if(crop == null)
{
return;
}
int rewardId = L2Manor.getInstance().getRewardItem(itemId, crop.getReward());
L2Item template = ItemTable.getInstance().getTemplate(rewardId);
weight += count * template.getWeight();
long add_slot = 0;
if(!template.isStackable())
{
add_slot = count;
}
else if(player.getInventory().getItemByItemId(itemId) == null)
{
add_slot = 1;
}
if(add_slot > 0)
{
try
{
slots = SafeMath.safeAddInt(slots, add_slot);
}
catch(ArithmeticException e)
{
sendPacket(Msg.INCORRECT_ITEM_COUNT);
return;
}
}
}
if(!player.getInventory().validateWeight(weight))
{
sendPacket(Msg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
return;
}
if(!player.getInventory().validateCapacity(slots))
{
sendPacket(Msg.YOUR_INVENTORY_IS_FULL);
return;
}
// Proceed the purchase
_procureList = manor.getCastle().getCropProcure(CastleManorManager.PERIOD_CURRENT);
for(int i = 0; i < _count; i++)
{
int itemId = (int) _items[i * 2 + 0];
long count = _items[i * 2 + 1];
if(count < 0)
{
count = 0;
}
int rewradItemId = L2Manor.getInstance().getRewardItem(itemId, manor.getCastle().getCrop(itemId, CastleManorManager.PERIOD_CURRENT).getReward());
long rewradItemCount = L2Manor.getInstance().getRewardAmountPerCrop(manor.getCastle().getId(), itemId, manor.getCastle().getCropRewardType(itemId));
rewradItemCount = count * rewradItemCount;
// Add item to Inventory and adjust update packet
L2ItemInstance item = player.getInventory().addItem(rewradItemId, rewradItemCount);
L2ItemInstance iteme = player.getInventory().destroyItemByItemId(itemId, count, true);
if(item == null || iteme == null)