@Subscribe public void handleShipNotAuction(ShipNotAuctioned event) { IShipOwner owner = event.getShip().getOwner(); if (owner instanceof IHumanPlayer) { // Post targeted message IShip ship = event.getShip(); ((IHumanPlayer) owner).addShip(ship); Optional<ICity> city = shipService.findCity(ship); DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.engine.player.HumanPlayerEngine.shipNotAuctioned", ship.getName(), city.get().getName()); TargetedEvent targetMsg = new TargetedEvent((IHumanPlayer) event.getNewOwner(), msg); clientServerEventBus.post(targetMsg); } } @Subscribe
private EventHandler<MouseEvent> createAcceptHandler(IShip ship) { return event -> { try { convoy.removeShip(ship); ship.parentShipProperty().setValue(null); final ICityPlayerProxyJFX proxy = viewState.getCurrentCityProxy().get(); proxy.arrive(ship); proxy.getPlayer().addSelectableVessel(ship); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to leave convoy", e); } }; } @Override
@Override protected boolean computeValue() { return !city.getPlayer().findTradingOffice(city.getCity()).isPresent(); } };
/** * Initialize the player that goes with this client. The player does not change later on, * @param newGameDTO parameter object for the new game */ @Subscribe public void initializeState(NewGameClient newGameDTO) { this.player = newGameDTO.getPlayer(); state.setValue(EViewState.CITY); IShip activeShip = null; for (IShip ship : player.getFleet()) { if (ship.isAvailable()) { activeShip = ship; break; } } ICityPlayerProxyJFX proxy = (ICityPlayerProxyJFX) context.getBean("cityPlayerProxy", player.getHometown(), player, activeShip); currentCityProxy = Optional.of(proxy); } @Subscribe
@Override public LinkedHashSet<NoticeBoardMenuEntry> createMenuEntries(ICityPlayerProxyJFX proxy, ENoticeBoardType type) { LinkedHashSet<NoticeBoardMenuEntry> entries = new LinkedHashSet<>(); String s; if (type == ENoticeBoardType.ARMORY) { if (proxy.getPlayer().getRank() == ESocialRank.ALDERMAN || (proxy.getPlayer().getHometown().equals(proxy.getCity()) && proxy.getPlayer().getRank() == ESocialRank.MAYOR)) { s = messageSource.getMessage("ch.sahits.game.openpatrician.display.notice.NoticeBoardFactory.armory.handWeapon", new Object[]{}, locale.getCurrentLocal()); NoticeBoardMenuEntry entry = createNoticeBoardEntry(s, EDialogType.ARMORY_HAND_WEAPONS); entry.disabledProperty().setValue(true); entries.add(entry); } s = messageSource.getMessage("ch.sahits.game.openpatrician.display.notice.NoticeBoardFactory.armory.shipWeapon", new Object[]{}, locale.getCurrentLocal()); NoticeBoardMenuEntry entry = createNoticeBoardEntry(s, EDialogType.ARMORY_SHIP_WEAPONS); entries.add(entry); } return entries; } }
@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); } }; }
@Override public void run() { DisplayMessage msg = new DisplayMessage(messageKey, fine); clientEventBus.post(msg); if (player instanceof IHumanPlayer) { player.getCompany().updateCash(-fine); } else { player.getCompany().updateCashDirectly(-fine); } } }
private IHumanPlayer startupGameEnvironment(NewGame newGameDTO) { date.setStartYear(newGameDTO.getStartYear()); GameFactory gameFactory = serverContext.getBean(GameFactory.class); CityFactory cityFactory = serverContext.getBean(CityFactory.class); ShipFactory shipFactory = serverContext.getBean(ShipFactory.class); gameFactory.createMap(newGameDTO.getMapName()); LocationTracker locationTracker = serverContext.getBean(LocationTracker.class); serverContext.getBean(StartNewGameBean.class); IGame game = gameFactory.createGame(newGameDTO.getObjective(), newGameDTO.getDifficulty(), newGameDTO.getSpeed(), newGameDTO.isSingleplayer()); ICity homeCity = cityFactory.createCityByName(newGameDTO.getHometown()); IHumanPlayer player = gameFactory.createPlayer(newGameDTO.getFirstName(), newGameDTO.getLastName(), homeCity, newGameDTO.isMale(), newGameDTO.getDifficulty().getStartingCapital(), EPlayerColor.BLUE); IShip ship = shipFactory.createCrayer(shipNameLoader.getRandomName(), EShipUpgrade.LEVEL1, 350); ship.setOwner(player); player.addShip(ship); player.addSelectableVessel(ship); ship.setLocation(homeCity.getCoordinates()); locationTracker.add(ship); // Start the game server.startGame(game, 1); server.startStandaloneGame(player); serverContext.getBean("startNewGameHandler"); // Force creation of this lazy bean return player; }
@Override public void run() { IHumanPlayer debitor = (IHumanPlayer) debt.getDebitor(); ICompany company = debitor.getCompany(); int requiredAmount = debt.getAmount(); int amount = (int) Math.min(requiredAmount, company.getCash()); company.updateCash(-amount); if (debt.getCreditor() instanceof IPlayer) { if (debt.getCreditor() instanceof IHumanPlayer) { ((IPlayer) debt.getCreditor()).getCompany().updateCash(amount); } else { ((IPlayer) debt.getCreditor()).getCompany().updateCashDirectly(amount); } if (debt.getCreditor() instanceof IHumanPlayer) { DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.engine.land.city.LoanerEngine.paybackAfterShipAuction", new Object[]{debitor.getName(), debitor.getLastName(), amount}); TargetedEvent message = new TargetedEvent((IHumanPlayer) debt.getCreditor(), msg); clientServerEventBus.post(message); } } } }
String loadedText; if (ware.isBarrelSizedWare()) { loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernTraderDialog.dialogBarrel", new Object[]{city.getPlayer().getLastName(), translator.getLocalDisplayName((EWare) ware)}, locale.getCurrentLocal()); } else { loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernTraderDialog.dialogBale", new Object[]{city.getPlayer().getLastName(), translator.getLocalDisplayName((EWare) ware)}, locale.getCurrentLocal()); IHumanPlayer player = city.getPlayer(); int price = trader.getAmount() * trader.getAvgPricePerItem(); Optional<ITradingOffice> optOffice = city.getPlayer().findTradingOffice(city.getCity()); if (optOffice.isPresent()) { optOffice.get().move(trader.getWare(), trader.getAmount(), trader.getAvgPricePerItem()); player.getCompany().updateCash(-price); trader.leave(); executeOnCloseButtonClicked();
return arg0 -> { ICityPlayerProxyJFX cityProxy = viewState.getCurrentCityProxy().get(); if (viewState.getPlayer().findTradingOffice(cityProxy.getCity()).isPresent()) { ViewChangeCityPlayerProxyJFX proxy = new ViewChangeCityPlayerProxyJFX(cityProxy, EViewChangeEvent.NOTICE_TRADING_OFFICE); clientEventBus.post(new NoticeBoardUpdate(proxy)); clientEventBus.post(new ViewChangeEvent(MainGameView.class, proxy)); } else { logger.debug("There is no trading office for {} {} in {}", viewState.getPlayer().getName(), viewState.getPlayer().getLastName(), cityProxy.getCity().getName());
@Override public void run() { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); int amountRequired = amountable.getAmount(); int retrieved = 0; if (amountable.getAmount()>0) { retrieved = tradingOffice.move(ware, -amountRequired, amountable.getAVGPrice()); player.getCompany().updateCash(amountable.getAVGPrice() * retrieved); List<INavigableVessel> ships = player.findShips(city); for (INavigableVessel ship : ships) { if (ship instanceof IShip) { retrieved += optOffice.get().move(ware, -toRetrieve, amountable.getAVGPrice()); player.getCompany().updateCash(amountable.getAVGPrice() * retrieved); if (retrieved >= amountRequired) { break;
@Override protected EventHandler<MouseEvent> getAction() { return mouseEvent -> { try { ICity city = getCity(); Optional<ITradingOffice> office = getPlayer().findTradingOffice(getCity()); Preconditions.checkArgument(office.isPresent(), "Trading office must be present"); for (EWare ware : MATERIALS) { int buyAmount = requirementsMap.get(ware).getBuyAmount().intValue(); city.move(ware, -buyAmount, getPlayer()); int needed = requirementsMap.get(ware).requiredProperty().get(); int fromWarhouse = needed - buyAmount; office.get().move(ware, -fromWarhouse, 0); } ShipyardOrderBuild event = new ShipyardOrderBuild(city.getCityState().getShipyardState(), getCurrentShipType(), getPlayer()); clientServerEventBus.post(event); getPlayer().getCompany().updateCash(-calculateTotalBuildCosts()); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to order ship construction", e); } }; }
TimedTask task = taskFactory.getFreePirateTask(seaPirate, deadline); timedTaskListener.add(task); city.getPlayer().removeShip(currentShip.get()); city.getPlayer().removeSelectableVessel(currentShip.get()); pirate.leave(); if (caughtProb == 1) { deadline = date.getCurrentDate().plusDays(5); final int fine = (int) (Math.abs(city.getPlayer().getCompany().getCash() / 200 * rnd.nextDouble())); task = taskFactory.getFinedTask(city.getPlayer(), fine, "ch.sahits.game.event.handler.impl.HirePirateEventHandler.fineMessage", deadline); timedTaskListener.add(task); city.getPlayer().updateCrimialDrive(1);
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.JoinGuildDialog.title", new Object[]{}, locale.getCurrentLocal())); IHumanPlayer player = city.getPlayer(); ICity city = this.city.getCity(); int fee = guildService.getEntryFee(player); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.JoinGuildDialog.text", new Object[]{city.getName(), player.getName(), player.getLastName(), fee}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); VBox box = new VBox(text); String s = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.JoinGuildDialog.joinBtn", new Object[]{}, locale.getCurrentLocal()); OpenPatricianLargeWaxButton action = new OpenPatricianLargeWaxButton(s); action.getStyleClass().add("actionButton"); action.setId("joinGuild"); final int actionButtonX = (WIDTH - 124) / 2; action.setLayoutX(actionButtonX); action.setLayoutY(CLOSE_BTN_Y_POS - 24); action.setOnAction(joinGuild(player, city, fee)); box.setLayoutX(50); box.setLayoutY(CLOSE_BTN_Y_POS - 500); getContent().addAll(box, action); }
@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 { IHumanPlayer player = city.getPlayer(); ThieveState burglar = (ThieveState) currentPerson.get(); player.getCompany().updateCash(-burglar.getPrice()); int probability = rnd.nextInt(3); if (probability < 1) { timedTaskListener.add((TimedTask) taskFactory.getDelayedCaughtAction(player, city.getCity())); } else { timedTaskListener.add((TimedTask) taskFactory.getBreakInAction(selectedOponent.get())); } player.updateCrimialDrive(1); burglar.leave(); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to accept burglar offer", e); } }; }
@Override public void postLoad() { state.setValue(EViewState.CITY); PlayerList players = context.getBean(PlayerList.class); for (IPlayer curPlayer : players) { if (curPlayer instanceof IHumanPlayer) { this.player = (IHumanPlayer) curPlayer; break; } } CityPlayerProxyJFX proxy = (CityPlayerProxyJFX) context.getBean("cityPlayerProxy", player.getHometown(), player, null); currentCityProxy = Optional.of(proxy); proxy.postLoad(); } }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernTreasureMapOwnerDialog.title", new Object[]{}, locale.getCurrentLocal())); initializeButtons(); ITreasureMapOwner mapOwner = (ITreasureMapOwner) currentPerson.get(); String loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernTreasureMapOwnerDialog.dialog", new Object[]{city.getPlayer().getLastName()}, locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); parameters.put("price", mapOwner.getPrice()); DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, parameters); getContent().addAll(dt); }
private Table createModel() { ICity cityModel = city.getCity(); Optional<ITradingOffice> optOffice = city.getPlayer().findTradingOffice(cityModel); Preconditions.checkArgument(optOffice.isPresent(), "The trading office must be present"); final ITradingOffice office = optOffice.get(); final List<IWorkShop> workshops = city.getPlayer().findBuildings(cityModel, IWorkShop.class); final List<ITownHouse> townhouse = city.getPlayer().findBuildings(cityModel, ITownHouse.class); Table model = new Table(); TableHeader header = new TableHeader(5);