return;
}
try
{
CropProcure crop = CastleManager.getInstance().getCastleById(manorId).getCrop(itemId, CastleManorManager.PERIOD_CURRENT);
int rewardItemId = L2Manor.getInstance().getRewardItem(itemId,crop.getReward());
L2Item template = ItemTable.getInstance().getTemplate(rewardItemId);
weight += count * template.getWeight();
if (!template.isStackable())
slots += count;
else if (player.getInventory().getItemByItemId(itemId) == null)
slots++;
}
catch (NullPointerException e)
{
continue;
}
}
if (!player.getInventory().validateWeight(weight))
{
sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
return;
}
if (!player.getInventory().validateCapacity(slots))
{
sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
return;
}
// Proceed the purchase
InventoryUpdate playerIU = new InventoryUpdate();
for (int i = 0; i < _size; i++)
{
int objId = _items[i * 4 + 0];
int cropId = _items[i * 4 + 1];
int manorId = _items[i * 4 + 2];
int count = _items[i * 4 + 3];
if (objId == 0 || cropId == 0 || manorId == 0 || count == 0)
continue;
if (count < 1)
continue;
CropProcure crop = null;
try
{
crop = CastleManager.getInstance().getCastleById(manorId).getCrop(cropId, CastleManorManager.PERIOD_CURRENT);
}
catch (NullPointerException e)
{
continue;
}
if (crop == null || crop.getId() == 0 || crop.getPrice() == 0)
continue;
int fee = 0; // fee for selling to other manors
int rewardItem = L2Manor.getInstance().getRewardItem(cropId,
crop.getReward());
if (count > crop.getAmount())
continue;
int sellPrice = (count * L2Manor.getInstance().getCropBasicPrice(
cropId));
int rewardPrice = ItemTable.getInstance().getTemplate(rewardItem)
.getReferencePrice();
if (rewardPrice == 0)
continue;
int rewardItemCount = sellPrice / rewardPrice;
if (rewardItemCount < 1)
{
SystemMessage sm = new SystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1);
sm.addItemName(cropId);
sm.addNumber(count);
player.sendPacket(sm);
continue;
}
if (manorId != currentManorId)
fee = sellPrice * 5 / 100; // 5% fee for selling to other manor
if (player.getInventory().getAdena() < fee)
{
SystemMessage sm = new SystemMessage(SystemMessageId.FAILED_IN_TRADING_S2_OF_CROP_S1);
sm.addItemName(cropId);
sm.addNumber(count);
player.sendPacket(sm);
sm = new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
player.sendPacket(sm);
continue;
}
// Add item to Inventory and adjust update packet
L2ItemInstance itemDel = null;
L2ItemInstance itemAdd = null;
if (player.getInventory().getItemByObjectId(objId) != null)
{
// check if player have correct items count
L2ItemInstance item = player.getInventory().getItemByObjectId(objId);
if (item.getCount() < count)
continue;
itemDel = player.getInventory().destroyItem("Manor", objId, count, player, manorManager);
if (itemDel == null)
continue;
if (fee > 0)
player.getInventory().reduceAdena("Manor", fee, player,manorManager);
crop.setAmount(crop.getAmount() - count);
if (Config.ALT_MANOR_SAVE_ALL_ACTIONS)
CastleManager.getInstance().getCastleById(manorId).updateCrop(crop.getId(), crop.getAmount(), CastleManorManager.PERIOD_CURRENT);
itemAdd = player.getInventory().addItem("Manor", rewardItem,rewardItemCount, player, manorManager);
}
else
{
continue;