/** * Retrieve the church model for a city. * @param city for which the church is to be looked up. * @return instance of IChurch in the city. */ public IChurch getChurch(ICity city) { return churchMap.get(city); }
/** * Retrieve the tavern model for a city. * @param city for witch the tavern is to be looked up * @return instance of the tavern model. */ public TavernState getTavernState(ICity city ) { return cities.get(city); }
public void establishChurch(ICity city) { IChurch church = stateFactory.createChurch(); churchMap.put(city, church); }
@Subscribe public void handleDayChange(ClockTickDayChange event) { for (Entry<ICity, TavernState> entry : cities.entrySet()) { ICity city = entry.getKey(); TavernState state = entry.getValue(); int nbSailors = computeNumbersOfSailors(city); state.getSailors().setNumberOfSailors(nbSailors); handlePersonsBecomingAbsent(state); handlePersonsBecomingPresent(city, state); } } /**
public void addCity(TavernState state, ICity city) { cities.put(city, state); int nbSailors = computeNumbersOfSailors(city); final ISailorState sailors = state.getSailors(); sailors.setNumberOfSailors(nbSailors); handlePersonsBecomingAbsent(state); handlePersonsBecomingPresent(city, state); }
@Subscribe public void handleWeeklyUpdate(PeriodicalTimeWeekEndUpdate event) { // check if an upgrade can be made for (ICity iCity : churchMap.keySet()) { IChurch church = churchProvider.getChurch(iCity); if (church.getExtensionLevel().getNextExtensionLevel().isPresent()) { EChurchExtension next = church.getExtensionLevel().getNextExtensionLevel().get(); final int collectedDonationsForExtension = church.getCollectedDonationsForExtension(); if (collectedDonationsForExtension >= next.getRequiredCash()) { // start upgrade int delay = rnd.nextInt(30); LocalDateTime executionTime = date.getCurrentDate().plusDays(delay); TimedTask task = taskFactory.getChurchUpgradeTask(church, executionTime); timedTaskListener.add(task); } } } } public void establishChurch(ICity city) {