@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 EventHandler<MouseEvent> joinGuild(final IHumanPlayer player,final ICity city, final int fee) { return mouseEvent -> { try { ICompany company = player.getCompany(); company.updateCash(-fee); IGuild guild = guildList.findGuild(city).get(); guild.join(player); ViewChangeCityPlayerProxyJFX proxy = new ViewChangeCityPlayerProxyJFX(this.city, EViewChangeEvent.MAIN_VIEW_GUILD); clientEventBus.post(new NoticeBoardUpdate(proxy)); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to join the quild", e); } }; } }
private EventHandler<MouseEvent> getAction() { return evt -> { try { final ICompany company = city.getPlayer().getCompany(); company.updateCash(-moneyTransfer.getAmount()); city.getCity().getReputation(city.getPlayer()).update(moneyTransfer.getAmount() / 1000); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to make a donation to the city", e); } }; }
public IntegerBinding buyPriceBinding(final ObjectProperty<ETransferAmount> amount, final EWeapon weapon) { return new IntegerBinding() { { super.bind(weaponsDealer.amountAvailableProperty(weapon), amount, city.getPlayer().getCompany().cashProperty()); } @Override protected int computeValue() { int availableAmount = weaponsDealer.amountAvailableProperty(weapon).get(); int buyAmount = transferUtil.calculateAvailableAmount(amount, availableAmount); int affordableAmount = computablePrice.calculateAffordableAmount(weapon, availableAmount, buyAmount, city.getPlayer().getCompany().getCash()); if (affordableAmount>0) { return computablePrice.buyPrice(weapon, new SimpleIntegerProperty(availableAmount), new StaticIntegerBinding(affordableAmount)); } else { return 0; } } }; }
@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); }
@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> 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); } }; }
@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); } }; }
private EventHandler<MouseEvent> getAction(final IChurch church) { return evt -> { try { final ICompany company = city.getPlayer().getCompany(); company.updateCash(-moneyTransfer.getAmount()); church.makeDonation(moneyTransfer.getAmount()); city.getCity().getReputation(city.getPlayer()).update(moneyTransfer.getAmount() / 1000); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to make donation", e); } }; }
private EventHandler<MouseEvent> createAcceptHandler() { return mouseEvent -> { try { final ICompany company = city.getPlayer().getCompany(); long cash = company.getCash(); final IDebt debt = selectedDebt.get(); int debtTotal = loanerService.calculatePaybacksum(debt); if (cash < debtTotal) { clearContent(); addDecoratedText("ch.sahits.game.openpatrician.display.dialog.LoanerPaybackDialog.noRepay", "noRepay"); } else { debt.getCreditor().receiveSum(debtTotal); company.updateCash(-debtTotal); loaner.getDebts().remove(debt); executeOnCloseButtonClicked(); } } catch (RuntimeException e) { logger.error("Failed to pay back loan", 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 protected int computeValue() { int availableAmount = weaponsDealer.amountAvailableProperty(weapon).get(); int buyAmount = transferUtil.calculateAvailableAmount(amount, availableAmount); int affordableAmount = computablePrice.calculateAffordableAmount(weapon, availableAmount, buyAmount, city.getPlayer().getCompany().getCash()); if (affordableAmount>0) { return computablePrice.buyPrice(weapon, new SimpleIntegerProperty(availableAmount), new StaticIntegerBinding(affordableAmount)); } else { return 0; } } };
@Override protected EventHandler<MouseEvent> getAction() { return mouseEvent -> { try { city.getPlayersShips().remove(currentShip.get()); ShipyardOrderRepair event = new ShipyardOrderRepair(getCity().getCityState().getShipyardState(), currentShip.get(), city); clientServerEventBus.post(event); getPlayer().getCompany().updateCash(-calculateRepairCosts()); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to order repair of ship", e); } }; }
@Override protected EventHandler<MouseEvent> getAction() { return mouseEvent -> { 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(); getCity().move(ware, -buyAmount, getPlayer()); int needed = shipFactory.getUpgradeAmount(currentShip.get().getShipType(), ware); int fromWarhouse = needed - buyAmount; office.get().move(ware, -fromWarhouse, 0); } ShipyardOrderRefit event = new ShipyardOrderRefit(getCity().getCityState().getShipyardState(),currentShip.get(), currentShip.get().getShipUpgradeLevel().nextLevel(), city); clientServerEventBus.post(event); city.getPlayersShips().remove(currentShip.get()); getPlayer().getCompany().updateCash(-calculateTotalUpgradeCosts()); executeOnCloseButtonClicked(); }; }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.church.ChurchGiftDialog.title", new Object[]{}, locale.getCurrentLocal())); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.church.ChurchGiftDialog.introText", new Object[]{}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); VBox box = new VBox(text); final ICompany company = city.getPlayer().getCompany(); moneyTransfer = fxUtils.getMoneyTransfer(imageLoader); moneyTransfer.setStepSize(500); moneyTransfer.maxTransfereableProperty().bind(company.cashProperty()); moneyTransfer.setAmount(0); box.setLayoutX(50); box.setLayoutY(CLOSE_BTN_Y_POS - 500); moneyTransfer.setPadding(new Insets(100, 0, 0, 100)); box.getChildren().addAll(moneyTransfer); final int actionButtonX = (WIDTH - 124) / 2; String s = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.church.ChurchFeedingDialog.donate", new Object[]{}, locale.getCurrentLocal()); final OpenPatricianLargeWaxButton action = new OpenPatricianLargeWaxButton(s); action.getStyleClass().add("actionButton"); action.setOnAction(getAction()); action.setLayoutX(actionButtonX); action.setLayoutY(CLOSE_BTN_Y_POS - 24); BooleanBinding actionEnabled = actionEnabledBinding(); action.setDisable(!actionEnabled.get()); actionEnabled.addListener((observableValue, oldValue, newValue) -> action.setDisable(!newValue)); getContent().addAll(box, action); }
VBox box = new VBox(text); final ICompany company = city.getPlayer().getCompany();
final int withdrawl = moneyTransfer.getAmount(); treasury.subtractOtherCosts(withdrawl); city.getPlayer().getCompany().updateCash(withdrawl);
try { grid.getChildren().removeAll(donation, withdraw); final ICompany company = city.getPlayer().getCompany(); MoneyTransfer moneyTransfer = fxUtils.getMoneyTransfer(imageLoader); moneyTransfer.setStepSize(100);
@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); } } } }
if (!weaponBuyBtn.isDisable()) { IHumanPlayer player = city.getPlayer(); ICompany company = player.getCompany(); reduceStoredAmount(weapon); weaponStorage.update(weapon, 1);