@Override protected EventHandler<MouseEvent> createAcceptHandler() { return mouseEvent -> { try { if (!tavernDialogUtil.noShipWithEnoughCapacityAvailable(city, AMOUNT)) { for (IShip ship : city.getPlayersShips()) { if (ship.getCapacity() >= AMOUNT * 10) { final ICourier courier = (ICourier) currentPerson.get(); ship.addPassenger(courier); CourierPatrolStateInternal patrolState = new CourierPatrolStateInternal(courier.getPremium(), courier.getDestinations()); IPlayer player = city.getPlayer(); int minutes = rnd.nextInt(600); LocalDateTime postMessage = date.getCurrentDate().plusMinutes(minutes); String cityName = patrolState.nextDestination().get().getName(); taskFactory.getPostponedDisplayMessage(postMessage, "ch.sahits.game.openpatrician.display.dialog.TavernPatrolDialog.acceptMessage", ship.getName(), cityName); LocalDateTime firstDeadline = date.getCurrentDate().plusDays(6); eventHandlerFactory.getNextCourierPatrolStationHanlder(ship, patrolState.nextDestination().get(), patrolState, player, firstDeadline); courier.leave(); executeOnCloseButtonClicked(); break; } } } } catch (RuntimeException e) { logger.error("Failed to accept couriers offer", e); } }; }
if (person instanceof ICourier) { ICourier courier = (ICourier) person; courier.setName(firstNameLoader.getRandomName() + " " + lastNameLoader.getRandomName()); courier.setPremium(rnd.nextInt(2000) + 4300); int nbDestinations = rnd.nextInt(3) + 3; ICity[] destinations = new ICity[nbDestinations]; courier.setDestinations(destinations); fillDestinations(city, destinations); courier.setCurrentDestIndex(0); } else if (person instanceof ITransportTrader) { ITransportTrader transportTrader = (ITransportTrader) person;