public void setNextPeriod() {
for (Castle c: CastleManager.getInstance().getCastles()) {
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() > 0) {
int count = crop.getStartAmount() - crop.getAmount();
count = count * 90 / 100;
if (count < 1) {
if (Rnd.nextInt(99) < 90)
count = 1;
}
if (count > 0) {
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);
if (c.getTreasury() < c.getManorCost(PERIOD_CURRENT)) {
c.setSeedProduction(getNewSeedsList(c.getCastleId()), PERIOD_NEXT);
c.setCropProcure(getNewCropsList(c.getCastleId()), PERIOD_NEXT);
} else {
FastList<SeedProduction> production = new FastList<SeedProduction>();
for (SeedProduction s : c.getSeedProduction(PERIOD_CURRENT)) {
s.setCanProduce(s.getStartProduce());
production.add(s);
}
c.setSeedProduction(production, PERIOD_NEXT);
FastList<CropProcure> procure = new FastList<CropProcure>();
for (CropProcure cr : c.getCropProcure(PERIOD_CURRENT)) {
cr.setAmount(cr.getStartAmount());
procure.add(cr);
}
c.setCropProcure(procure, PERIOD_NEXT);
}
if (Config.ALT_MANOR_SAVE_ALL_ACTIONS) {
c.saveCropData();
c.saveSeedData();
}
// Sending notification to a clan leader
L2PcInstance clanLeader = L2World.getInstance().getPlayer(clan.getLeader().getName());
if (clanLeader != null)
clanLeader.sendPacket(new SystemMessage(SystemMessageId.THE_MANOR_INFORMATION_HAS_BEEN_UPDATED));
c.setNextPeriodApproved(false);
}