@Override public Optional<ICaptain> getCaptain(ICity city) { return captainsState.getCaptain(city); } @Override
@Subscribe public void handleDayChange(ClockTickDayChange event) { LocalDateTime today = date.getCurrentDate(); LocalDateTime shouldLeaveWhenArrivedBefore = today.minusDays(captainsState.getMaxDaysPresent()); for (ICaptain captain : captainsState.getAllFreeCaptains()) { Optional<ICity> city = captainsState.findCaptainsCurrentCity(captain); if (city.isPresent()) { LocalDateTime arrival = captainsState.getArrivalDate(captain); if (arrival.isBefore(shouldLeaveWhenArrivedBefore)) { ICity nextCity = getRandomCity(); while (city.get().equals(nextCity)) { nextCity = getRandomCity(); } // calculate days in between double distance = Math.abs(city.get().getCoordinates().getX() - nextCity.getCoordinates().getX()); double percentage = distance/map.getDimension().getWidth(); int days = (int) Math.rint(10*percentage); captainsState.hireCaptain(captain, city.get()); // This removes the current mapping LocalDateTime arrivalDate = date.getCurrentDate().plusDays(days); captainsState.assignCaptainToCity(captain, city.get(), arrivalDate); } } } }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernCaptainDialog.title", new Object[]{}, locale.getCurrentLocal())); captain = captainsState.getCaptain(city.getCity()).get(); Text intro = new Text(); intro.getStyleClass().add("dialogText"); try { currentShip.get().setCaptain(captain); captainsState.hireCaptain(captain, city.getCity()); clientServerEventBus.post(new PersonLeavesTavernEvent(city.getCity(), captain)); executeOnCloseButtonClicked();
@Override public void hire(IAIPlayer player, IShip vessel, ICaptain captain, ICity city) { vessel.setCaptain(captain); captainsState.hireCaptain(captain, city); clientServerEventBus.post(new PersonLeavesTavernEvent(city, captain)); } }
@PostConstruct public void init() { for (int i = 0; i<maxFreeCaptains; i++) { // select town ICity city = getRandomCity(); // create arival date in intervall [now-maxTimeInTown,now] LocalDateTime currentDate = date.getCurrentDate(); double nextGaussian = rnd.nextDouble(); LocalDateTime arrival = currentDate.minusDays((int)Math.rint(nextGaussian*maxTimeInTown)); // create captain ICaptain captain = peopleFactory.createNewCaptainProperty(); captainsState.addCaptain(city, arrival, captain); } timerEventBus.register(this); } @PreDestroy
@Override public boolean shouldHire(IAIPlayer player, IShip vessel, ICity city) { if (vessel.getCaptian().isPresent()) { return false; } Optional<ICaptain> optCaptain = captainsState.getCaptain(city); return optCaptain.isPresent(); }
@Subscribe public void handleDayChange(ClockTickDayChange dayChange) { Optional<ICaptain> captain = captainsState.getCaptain(city.getCity()); if (!captain.isPresent()) { executeOnCloseButtonClicked(); } }
@Override public LinkedHashSet<NoticeBoardMenuEntry> createMenuEntries(ICityPlayerProxyJFX proxy, ENoticeBoardType type) { LinkedHashSet<NoticeBoardMenuEntry> entries = new LinkedHashSet<>(); final TavernState tavernState = getTavernState(proxy.getCity()); Optional<ICaptain> captain = captainsState.getCaptain(proxy.getCity()); List<IPerson> present = tavernState.presentPersonsProperty(); List<ISideRoomPerson> sideRoom = Lists.newArrayList(); List<IPerson> mainRoom = Lists.newArrayList(); IPlayer player = proxy.getPlayer(); collectPresentPersons(tavernState, present, sideRoom, mainRoom, player); captain.ifPresent(mainRoom::add); for (IPerson pers : mainRoom) { String s = messageSource.getMessage(pers.getClass().getName() + ".noticeboardTitle", new Object[0], locale.getCurrentLocal()); NoticeBoardMenuEntry entry = createNoticeBoardEntryMainRoom(s, pers, tavernState, player); entries.add(entry); } if (!sideRoom.isEmpty()) { String s = messageSource.getMessage("ch.sahits.game.openpatrician.display.notice.NoticeBoardFactory.sideRoom", new Object[]{}, locale.getCurrentLocal()); NoticeBoardMenuEntry entry = createNoticeBoardEntrySideRoom(s, sideRoom.get(0), tavernState, player); entries.add(entry); } return entries; } @VisibleForTesting