@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageOne.title", new Object[]{informant.getName()}, locale.getCurrentLocal())); StringBuilder template = new StringBuilder(); HashMap<String, Object> parameters = new HashMap<>(); if (informant.getWareNeeded().isPresent()) { GenericPair<ICity, IWare> needed = informant.getWareNeeded().get(); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog1", new Object[]{needed.getFirst().getName(), translator.getLocalDisplayName((EWare) needed.getSecond())}, locale.getCurrentLocal())); } if (informant.getWareSurplus().isPresent()) { GenericPair<ICity, IWare> surplus = informant.getWareSurplus().get(); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog2", new Object[]{surplus.getFirst().getName(), translator.getLocalDisplayName((EWare) surplus.getSecond())}, locale.getCurrentLocal())); } final Optional<MapSegmentedImage> mapSectionPart = informant.getMapSectionPart(city.getPlayer()); mapSectionPart.ifPresent(mapSegmentedImage -> { List<Integer> visibleSegs = new ArrayList<>(mapSegmentedImage.getSegmentIndices()); parameters.put("visibleSegments", visibleSegs); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog4", new Object[]{mapSegmentedImage.getImageName()}, locale.getCurrentLocal())); }); if (informant.getPirateLocation().isPresent()) { GenericPair<String, ICity> pirate = informant.getPirateLocation().get(); template.append(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageTwo.dialog3", new Object[]{pirate.getFirst(), pirate.getSecond().getName()}, locale.getCurrentLocal())); } DecoratedText dt = decoratedTextFactory.createDecoratedText(template.toString(), parameters); getContent().addAll(dt); }
private void updateWareNeedOrSurplus(int val, IInformant informant) { switch (val) { case 0: // need Optional<GenericPair<ICity, IWare>> missing = cityState.findCityWithMostNeededWare(); missing.ifPresent(iCityIWareGenericPair -> { GenericPair<ICity, IWare> pair = iCityIWareGenericPair; informant.setNeededWare(pair.getFirst(), pair.getSecond()); }); break; case 1: // surplus Optional<GenericPair<ICity, IWare>> surplus = cityState.findCityWithSurplusWare(); surplus.ifPresent(iCityIWareGenericPair -> { GenericPair<ICity, IWare> pair = iCityIWareGenericPair; informant.setWareSurplus(pair.getFirst(), pair.getSecond()); }); break; default: throw new IllegalStateException("Invalid random number: "+val); } }
IInformant informant = (IInformant) person; int val = rnd.nextInt(2); informant.setShowMapIfAvailable(rnd.nextInt(3) == 0); informant.setPrice(rnd.nextInt(1000)+120); // consider age of the game updateWareNeedOrSurplus(val, informant); int nextVal = rnd.nextInt(2); boolean noInformationYet = !informant.getWareNeeded().isPresent() && !informant.getWareSurplus().isPresent(); if (rnd.nextBoolean() || noInformationYet) { ISeaPirate pirate = pirateState.findSuccessfulPirate(); ICity nearest = cityUtils.findNearestCity(pirate.getShip().getLocation()); informant.setPirateLocation(pirate, nearest);
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageOne.title", new Object[]{informant.getName()}, locale.getCurrentLocal())); String loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageOne.dialog", new Object[0], locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); final int price = informant.getPrice(city.getPlayer()); parameters.put("price", price); DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, parameters); final OpenPatricianLargeWaxButton acceptButton = new OpenPatricianLargeWaxButton(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernInformantDialogPageOne.buy", new Object[]{}, locale.getCurrentLocal())); acceptButton.getStyleClass().add("actionButton"); int BUTTON_X = (WIDTH - 124) / 2; acceptButton.setLayoutX(BUTTON_X); int LOWER_BUTTON_Y = CLOSE_BTN_Y_POS - 24; acceptButton.setLayoutY(LOWER_BUTTON_Y); acceptButton.setOnAction(mouseEvent -> { try { city.getPlayer().getCompany().updateCash(-price); clientEventBus.post(new ViewChangeEvent(MainGameView.class, EDialogType.TAVERN_INFORMANT_2)); } catch (RuntimeException e) { logger.error("Failed to accept informant offer", e); } }); getContent().addAll(dt, acceptButton); }