/** * Create a new alderman task for destroing a pirats nest, while ignoring the ones that are already worked on. * @param office alderman office * @return capture pirate nest task */ public Optional<ICapturePirateNest> createCapturePirateNestAldermanTask(IAldermanOffice office) { List<IAcceptedAldermanTask> workedOnTasks = office.getWorkedOnTasks(); List<MapSegmentedImage> tasks = new ArrayList<>(); for (IAcceptedAldermanTask workedOnTask : workedOnTasks) { if (workedOnTask.getTask() instanceof ICapturePirateNest) { tasks.add(((ICapturePirateNest)workedOnTask.getTask()).getPirateNestMap()); } } MapSegmentedImage map = segmentImageFactory.getRandomPirateNest(); if (tasks.contains(map)) { return Optional.empty(); } else { int duration = 180; CapturePirateNest task = context.getBean(CapturePirateNest.class, duration, map.getLocation(), map); return Optional.of(task); } }
private MapSegmentedImage getRandomImage(List<MapSegmentedImage> imgList) { MapSegmentedImage img = imgList.get(rnd.nextInt(imgList.size())); int availableSegment = rnd.nextInt(9); img.addSegment(availableSegment); return img; } }
@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); }
INavigableVessel ship = iterator.next(); MapSegmentDataCheck check = dataModel.getCheckList().get(ship); if (ship.getLocation().distance(check.getMapSegment().getLocation()) > locationDistance) { iterator.remove(); } else { // still in the radius IAcceptedAldermanTask task = taskIterator.next(); if (task.getPlayer().equals(ship.getOwner())) { if (task.getTask() instanceof ICapturePirateNest && ((ICapturePirateNest) task.getTask()).getPirateNestMap().equals(pirateNest)) { taskIterator.remove(); if (task.getDeadline().isAfter(now)) {
@Override protected EventHandler<MouseEvent> createAcceptHandler() { return mouseEvent -> { try { removeDecoratedContent(); removeAcceptButton(); MapSegmentedImage imageMap = segmentFactory.getRandomTreasureNest(); String loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernTreasureMapOwnerDialog.acceptMessage", new Object[]{imageMap.getImageName()}, locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); List<Integer> visibleSegs = new ArrayList<>(imageMap.getSegmentIndices()); parameters.put("visibleSegments", visibleSegs); final DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, parameters); Platform.runLater(() -> getContent().add(dt)); IHumanPlayer player = city.getPlayer(); player.setSegmentedMap(imageMap); locationDetector.addSegment(imageMap); ITreasureMapOwner mapOwner = (ITreasureMapOwner) currentPerson.get(); player.getCompany().updateCash(-mapOwner.getPrice()); mapOwner.leave(); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to add treasure map owners offer", e); } }; }
@Override protected EventHandler<MouseEvent> createAcceptHandler() { return mouseEvent -> { try { removeDecoratedContent(); removeAcceptButton(); MapSegmentedImage imageMap = segmentFactory.getRandomPirateNest(); String loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernPirateHunterDialog.acceptMessage", new Object[]{imageMap.getImageName()}, locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); List<Integer> visibleSegs = new ArrayList<>(imageMap.getSegmentIndices()); parameters.put("visibleSegments", visibleSegs); final DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, parameters); Platform.runLater(() -> getContent().add(dt)); IPirateHunter pirateHunter = (IPirateHunter) currentPerson.get(); final IHumanPlayer player = city.getPlayer(); player.getCompany().updateCash(-pirateHunter.getPremium()); player.setSegmentedMap(imageMap); locationDetector.addSegment(imageMap); city.getPlayer().updateCrimialDrive(-1); pirateHunter.leave(); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to accept pirate hunter offer", e); } }; }
@VisibleForTesting void handleShipLocationUpdate() { for (MapSegmentedImage mapSegment : dataModel.getMapSegments()) { Point2D location = mapSegment.getLocation(); List<INavigableVessel> shipsToCheck = locationTracker.getShipsInSegments(location, locationDistance); for (INavigableVessel ship : shipsToCheck) { if (location.distance(ship.getLocation()) <= locationDistance && !dataModel.isInCheckedList(ship)) { LocalDateTime dealine = date.getCurrentDate().plusDays(1); MapSegmentDataCheck check = new MapSegmentDataCheck(ship, mapSegment, dealine); dataModel.getCheckList().put(check.getShip(), check); } } } }