if(c.getOwnerId() <= 0)
{
continue;
}
L2Clan clan = ClanTable.getInstance().getClan(c.getOwnerId());
if(clan == null)
{
continue;
}
ItemContainer cwh = clan.getWarehouse();
if(!(cwh instanceof ClanWarehouse))
{
_log.info("Can't get clan warehouse for clan " + ClanTable.getInstance().getClan(c.getOwnerId()));
return;
}
for(CropProcure crop : c.getCropProcure(PERIOD_CURRENT))
{
if(crop.getStartAmount() == 0)
{
continue;
}
// adding bought crops to clan warehouse
if(crop.getStartAmount() > crop.getAmount())
{
String text = "Manor System: Start Amount of Crop" + crop.getStartAmount() + "> Amount of currnt" + crop.getAmount();
Log.add(text, "Manor_system");
int count = crop.getStartAmount() - crop.getAmount();
count = count * 90 / 100;
if(count < 1 && Rnd.get(99) < 90)
{
count = 1;
}
if(count >= 1)
{
cwh.addItem("Manor", L2Manor.getInstance().getMatureCrop(crop.getId()), count, null, null);
}
}
// reserved and not used money giving back to treasury
if(crop.getAmount() > 0)
{
c.addToTreasuryNoTax(crop.getAmount() * crop.getPrice());
}
}
c.setSeedProduction(c.getSeedProduction(PERIOD_NEXT), PERIOD_CURRENT);
c.setCropProcure(c.getCropProcure(PERIOD_NEXT), PERIOD_CURRENT);
int manor_cost = c.getManorCost(PERIOD_CURRENT);
if(c.getTreasury() < manor_cost)
{
c.setSeedProduction(getNewSeedsList(c.getCastleId()), PERIOD_NEXT);
c.setCropProcure(getNewCropsList(c.getCastleId()), PERIOD_NEXT);
manor_cost = c.getManorCost(PERIOD_CURRENT);
if(manor_cost > 0)
{
_log.info(c.getName() + "|" + -manor_cost + "|ManorManager Error@setNextPeriod");
}
}
else
{
FastList<SeedProduction> production = new FastList<SeedProduction>();
FastList<CropProcure> procure = new FastList<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);
}
if(Config.ALT_MANOR_SAVE_ALL_ACTIONS)
{
c.saveCropData();
c.saveSeedData();
}
// Sending notification to a clan leader
L2PcInstance clanLeader = null;
if(clan.getLeader()!=null && clan.getLeader().getName()!=null)
{
clanLeader = L2World.getInstance().getPlayer(clan.getLeader().getName());
}
if(clanLeader != null)
{
clanLeader.sendPacket(new SystemMessage(SystemMessageId.THE_MANOR_INFORMATION_HAS_BEEN_UPDATED));