{
if(c.getOwnerId() <= 0)
{
continue;
}
L2Clan clan = ClanTable.getInstance().getClan(c.getOwnerId());
if(clan == null)
{
continue;
}
Warehouse cwh = clan.getWarehouse();
for(CropProcure crop : c.getCropProcure(PERIOD_CURRENT))
{
if(crop.getStartAmount() == 0)
{
continue;
}
// adding bought crops to clan warehouse
if(crop.getStartAmount() > crop.getAmount())
{
_log.info("Manor System [" + c.getName() + "]: Start Amount of Crop " + crop.getStartAmount() + " > Amount of current " + crop.getAmount());
long count = crop.getStartAmount() - crop.getAmount();
count = count * 90 / 100;
if(count < 1 && Rnd.get(99) < 90)
{
count = 1;
}
if(count >= 1)
{
int id = L2Manor.getInstance().getMatureCrop(crop.getId());
cwh.addItem(id, count, null);
}
}
// reserved and not used money giving back to treasury
if(crop.getAmount() > 0)
{
c.addToTreasuryNoTax(crop.getAmount() * crop.getPrice(), false, false);
Log.add(c.getName() + "|" + crop.getAmount() * crop.getPrice() + "|ManorManager|" + crop.getAmount() + "*" + crop.getPrice(), "treasury");
}
c.setCollectedShops(0);
c.setCollectedSeed(0);
}
c.setSeedProduction(c.getSeedProduction(PERIOD_NEXT), PERIOD_CURRENT);
c.setCropProcure(c.getCropProcure(PERIOD_NEXT), PERIOD_CURRENT);
long manor_cost = c.getManorCost(PERIOD_CURRENT);
if(c.getTreasury() < manor_cost)
{
c.setSeedProduction(getNewSeedsList(c.getId()), PERIOD_NEXT);
c.setCropProcure(getNewCropsList(c.getId()), PERIOD_NEXT);
Log.add(c.getName() + "|" + manor_cost + "|ManorManager Error@setNextPeriod", "treasury");
}
else
{
GArray<SeedProduction> production = new GArray<SeedProduction>();
GArray<CropProcure> procure = new GArray<CropProcure>();
for(SeedProduction s : c.getSeedProduction(PERIOD_CURRENT))
{
s.setCanProduce(s.getStartProduce());
production.add(s);
}
for(CropProcure cr : c.getCropProcure(PERIOD_CURRENT))
{
cr.setAmount(cr.getStartAmount());
procure.add(cr);
}
c.setSeedProduction(production, PERIOD_NEXT);
c.setCropProcure(procure, PERIOD_NEXT);
}
c.saveCropData();
c.saveSeedData();
// Sending notification to a clan leader
PlayerMessageStack.getInstance().mailto(clan.getLeaderId(), Msg.THE_MANOR_INFORMATION_HAS_BEEN_UPDATED);
c.setNextPeriodApproved(false);
}
}