@Override public boolean execute() { int maxSellAmount = vessel.getWare(ware).getAmount(); int minSellPrice = vessel.getWare(ware).getAVGPrice(); IAIPlayer player = (IAIPlayer) vessel.getOwner(); tradeService.sellWareShipToCity(vessel, player, city, ware, maxSellAmount, Optional.of(minSellPrice)); return executeNext; } }
/** * Retrieve the stored amount * @param ware Reference to the ware * @param ship Reference to the ship * @param office Reference to the trading office * @return read only integer property representing the sored amount. */ private ReadOnlyIntegerProperty getStoredAmountProperty(IWare ware, INavigableVessel ship, Optional<ITradingOffice> office){ AmountablePrice<IWare> amounable = getStoredAmountablePrice(ware, ship, office); return amounable.amountProperty(); // differ between ship and convoi } /**
private List<IWare> getRequiredWares(INavigableVessel vessel, Map<IWare, Integer> requiredWareAmounts) { List<IWare> requiredWares = new ArrayList<>(requiredWareAmounts.keySet()); for (Iterator<IWare> iterator = requiredWares.iterator(); iterator.hasNext(); ) { IWare ware = iterator.next(); int loadedAmount = vessel.getWare(ware).getAmount(); if (loadedAmount >= requiredWareAmounts.get(ware)) { iterator.remove(); } } return requiredWares; }
plusIcon.setOnMouseReleased((e) -> { int newValue = Math.min(cityWall.getRequiredBricks(), numberOfBricks.get() + 1); final int amount = city.getCity().getWare(EWare.BRICK).getAmount(); newValue = Math.min(newValue, amount); numberOfBricks.setValue(newValue); minusIcon.setOnMouseReleased((e) -> { int newValue = Math.max(0, numberOfBricks.get() - 1); newValue = Math.min(newValue, city.getCity().getWare(EWare.BRICK).getAmount()); numberOfBricks.setValue(newValue); }); int price = computablePrice.buyPrice(EWare.BRICK, amount.amountProperty(), new IntegerBinding() {
Optional<IWare> ware = state.findMostNeededWare(); if (ware.isPresent()) { int price = computablePrice.sellPrice(ware.get(), iCity.getWare(ware.get()).amountProperty(), new IntegerBinding() { @Override protected int computeValue() { amountable.add(amount, (int)(price * StateFactory.NOTICE_WARE_PRICE_FACTOR)); IContractBroker broker = peopleFactory.createNewContractBroker(amountable, ware.get()); ICityHallNotice notice = CityHallNotice.builder()
@Override public boolean execute() { int minSellPrice = vessel.getWare(ware).getAVGPrice(); IAIPlayer player = (IAIPlayer) vessel.getOwner(); tradeService.sellWareShipToCity(vessel, player, city, ware, maxAmount, Optional.of(minSellPrice)); return executeNext; } }
row.add(new StaticTextTableCell(translator.getLocalDisplayName(ware))); ReadOnlyIntegerProperty amountAvailableProp = getAvailableAmountProperty(city, ware, optOffice); IntegerBinding amountToTransfer = getAmountProperty(city.getWare(ware).amountProperty()); if (ware.isBarrelSizedWare()) { BarrelAmount barrelAmount = new BarrelAmount(); final NumberBinding avgPriceProperty = amountable.avgPriceProperty(); StringBinding avgPriceStringBinding = new StringBinding() {
int price = computablePrice.buyPrice(ware, new SimpleIntegerProperty(5), new StaticIntegerBinding(amount)); AmountablePrice<IWare> amt = amountableProvider.createWareAmountable(); amt.add(amount, price); buyer.setAmountablePrice(amt); } else if (person instanceof IWarehouseTenant) {
/** * Find all wares that are loaded on the ship. * @param vessel for which to check the wares. * @return list of loaded wares. */ protected List<IWare> getLoadedWares(INavigableVessel vessel) { return vessel.getLoadedWares() .stream() .filter(ware -> vessel.getWare(ware).getAmount() > 0) .collect(Collectors.toList()); }
/** * Transfer the wares in the specified amounts from the ship into the storage.<br> * PRE: there is a trading office in the city. * @param vessel from which the wares are transfered * @param player owner of the trading office and the vessel * @param city in which the transfer happens * @param amounts map of wares and the amounts that should be transfered. */ public void transferFromVesselToStorage(INavigableVessel vessel, IPlayer player, ICity city, Map<IWare, Integer> amounts) { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); Preconditions.checkArgument(optOffice.isPresent(), "There is no trading office for "+player.getName()+" "+player.getLastName()+" in "+city.getName()); for (IWare ware : amounts.keySet()) { int amount = amounts.get(ware); int avgPrice = vessel.getWare(ware).getAVGPrice(); amount = vessel.unload(ware, amount); optOffice.get().move(ware, amount, avgPrice); if (vessel instanceof IConvoy) { distributeIncomeToConvoyParticipants((IConvoy) vessel, player, avgPrice, amount); } } }
private boolean enoughStored(IPlayer player, ICity city) { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { for (IWare ware : minAmounts.keySet()) { ITradingOffice office = optOffice.get(); AmountablePrice<IWare> stored = office.getWare(ware); if (stored.getAmount() < minAmounts.get(ware)) { return false; } } return true; } return false; } }
@Override public void run() { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); int amountRequired = amountable.getAmount(); int retrieved = 0; if (optOffice.isPresent()) { ITradingOffice tradingOffice = optOffice.get(); AmountablePrice<IWare> amountable = tradingOffice.getWare(ware); if (amountable.getAmount()>0) { retrieved = tradingOffice.move(ware, -amountRequired, amountable.getAVGPrice()); player.getCompany().updateCash(amountable.getAVGPrice() * retrieved); if (ship instanceof IShip) { AmountablePrice<IWare> amountable = ship.getWare(ware); if (amountable.getAmount() > 0) { int toRetrieve = amountRequired - retrieved; if (optOffice.isPresent()) { retrieved += optOffice.get().move(ware, -toRetrieve, amountable.getAVGPrice()); player.getCompany().updateCash(amountable.getAVGPrice() * retrieved); if (retrieved >= amountRequired) { break; } else { msg = new DisplayMessage("ch.sahits.game.openpatrician.display.event.task.BuyWares.message2", retrieved, ware, amountable.getAmount(), city.getName());
private ReadOnlyIntegerProperty getAvailableAmountProperty(ICity city, IWare ware, Optional<ITradingOffice> office) { AmountablePrice<IWare> available; switch (type) { case PORT_CITY_TO_SHIP: case PORT_CITY_TO_STORAGE: available = city.getWare(ware); break; default: available = office.map(iTradingOffice -> iTradingOffice.getWare(ware)) .orElseGet(() -> (AmountablePrice<IWare>) context.getBean("amountablePrice", 0, 0)); break; } return available.amountProperty(); } /**
/** * Move <code>amount</code> of <code>ware</code> from the <code>office</code> onto the <code>vessel</code>. If the * vessel is a convoy the distribution to not player ships is considered by a cash transfer. * @param office where the wares are stored * @param vessel to which the wares are transfered * @param player owner of the trading office and vessel * @param ware to be transferred * @param amount to be transferred * @return amount that is actually moved */ public int transferFromStorageToVessel(ITradingOffice office, INavigableVessel vessel, IPlayer player, IWare ware, int amount) { final AmountablePrice<IWare> amountable = office.getWare(ware); int avgPrice = amountable.getAVGPrice(); int moved = office.move(ware, -amount, avgPrice); moved = vessel.load(ware, moved, avgPrice); if (vessel instanceof IConvoy) { // Handle this for any other ship in the convoy as if the ware was bought from the convoy owner at cost. distributeCostToConvoyParticipants((IConvoy) vessel, player, avgPrice, moved); } return moved; }
private void filterWareAvailability(List<EWeapon> producableWeapons, ICity city) { for (Iterator<EWeapon> iterator = producableWeapons.iterator(); iterator.hasNext(); ) { EWeapon weapon = iterator.next(); boolean remove = false; for (EWare ware : wares) { int requiredAmount = getConstructionAmount(weapon, ware); if (city.getWare(ware).getAmount() < requiredAmount) { remove = true; break; } } if (remove) { iterator.remove(); } } }
for (EWare ware : EWare.values()) { AmountablePrice<IWare> amountable = office.getWare(ware); if (amountable.getAmount() > 0) { sb.append("\t\t") .append(ware.name()) .append(": ") .append(amountable.getAmount()) .append(" @ ") .append(amountable.getAVGPrice()) .append("\n"); if (amountable.getAmount() > 0) { sb.append("\t\t") .append(ware.name()) .append(": ") .append(amountable.getAmount()) .append(" @ ") .append(amountable.getAVGPrice()) .append("\n");
public BuyAmountBinding(IWare ware, IntegerBinding requiredAmount) { final Optional<ITradingOffice> office = getPlayer().findTradingOffice(getCity()); if (office.isPresent()) { stored = office.get().getWare(ware).amountProperty(); needed = requiredAmount; super.bind(stored, requiredAmount); } else { stored = new SimpleIntegerProperty(0); needed = requiredAmount; super.bind(requiredAmount); } }
/** * Sort the list of wares that should be bought so that the * wares with the least amount are at the begining of the list. * @return priority sorted ware list. */ private List<BuyTradeStep> getPriorityList() { ArrayList<BuyTradeStep> list = new ArrayList<>(); Map<BuyTradeStep,Integer> loadedWares = new HashMap<>(); for (BuyTradeStep step : tradeSteps) { IWare ware = step.getWare(); int amount = vessel.getWare(ware).getAmount(); loadedWares.put(step, amount); } loadedWares.entrySet() .stream() .sorted(Map.Entry.<BuyTradeStep, Integer>comparingByValue()) .forEach(entry -> list.add(entry.getKey())); return list; }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernBuyerDialog.title", new Object[]{}, locale.getCurrentLocal())); initializeButtons(); IBuyer buyer = (IBuyer) currentPerson.get(); int p = buyer.getAmountablePrice().getAVGPrice()*buyer.getAmountablePrice().getAmount(); Object[] args = new Object[]{buyer.getName(), buyer.getAmountablePrice().getAmount(), translator.getLocalDisplayName((EWare)buyer.getWare()), p}; String key = "ch.sahits.game.openpatrician.display.dialog.TavernBuyerDialog.bale.dialog"; if (buyer.getWare().isBarrelSizedWare()) { key = "ch.sahits.game.openpatrician.display.dialog.TavernBuyerDialog.barrel.dialog"; } String loadedText = messageSource.getMessage(key, args, locale.getCurrentLocal()); DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, new HashMap<>()); getContent().addAll(dt); }
for (EWare material : MATERIALS) { int requiredAmount = shipFactory.getConstructionAmount(getCurrentShipType(), material); ReadOnlyIntegerProperty amountInCity = city.getWare(material).amountProperty(); ReadOnlyIntegerProperty amountInStorage; if (optOffice.isPresent()) { ITradingOffice office = optOffice.get(); amountInStorage = office.getWare(material).amountProperty(); } else { amountInStorage = new SimpleIntegerProperty(0);