@Override protected String computeValue() { return String.valueOf(computablePrice.sellPrice(ware, availableAmount, ONE_INT_BINDING)); } };
@Override protected String computeValue() { switch (type) { case PORT_CITY_TO_SHIP: case PORT_CITY_TO_STORAGE: if (movableAmount.get()==ETransferAmount.MAX){ return String.valueOf(ware.getMaxValueSell()); } else if (amountToSell.get() > 0){ return String.valueOf(computablePrice.sellPrice(ware, availableAmount, amountToSell)); } else { return String.valueOf(ware.getMaxValueSell()); } default: return ">"; } } };
@Override protected int computeValue() { if (amountToSell.get() > 0) { int availableAmount = weaponsDealer.amountAvailableProperty(weapon).getValue(); // that should be the amount of the dealer return computablePrice.sellPrice(weapon, new SimpleIntegerProperty(availableAmount), amountToSell); // amountToSell is the amount stored on ship/office } else { return 0; } } };
@Override protected int computeValue() { int availableAmount = getAmountInArmory(weapon).get(); int buyAmount = transferUtil.calculateAvailableAmount(ETransferAmount.ONE, availableAmount); if (buyAmount>0) { return computablePrice.sellPrice(weapon, new SimpleIntegerProperty(availableAmount), new StaticIntegerBinding(buyAmount)) * 2; } else { return 0; } } };
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() {
trader.setAmount(amount); double variance = rnd.nextDouble() * 0.25 - 0.125; int newPrice = (int) Math.abs(Math.rint(variance * computablePrice.sellPrice(ware, new SimpleIntegerProperty(availableAmount), new StaticIntegerBinding(amount)))); trader.setAvgPricePerItem(newPrice); trader.setWare(ware);
/** * Sell <code>amount</code> of <code>ware</code> from the <code>office</code> to the <code>city</code>. * @param office where the ware is stored. * @param player owner of the office * @param city to which to sell to * @param ware to be sold * @param amount to be sold * @param minAvgPrice minimal avg price that has to be payed per item. If no value is passed the whole lot will be sold. * @return total price of all sold wares (always positiv) */ public int sellFromStorageToCity(ITradingOffice office, IPlayer player, ICity city, IWare ware, int amount, Optional<Integer> minAvgPrice) { int availableAmountCity = city.getWare(ware).getAmount(); int amountToBeSold = amount; if (minAvgPrice.isPresent()) { amountToBeSold = computablePrice.calculateSellAmount(ware, availableAmountCity, minAvgPrice.get(), amount); } final int avgPrice = computablePrice.sellPrice(ware, new SimpleIntegerProperty(availableAmountCity), new ConstantIntegerBinding(amountToBeSold)); city.move(ware, amountToBeSold, player); // The price here is irrelevant int sold = office.move(ware, -amountToBeSold, avgPrice); if (player instanceof IHumanPlayer) { player.getCompany().updateCash(avgPrice * sold); } else { player.getCompany().updateCashDirectly(avgPrice * sold); } return avgPrice * sold; }
/** * Sell <code>amount</code> of <code>ware</code> from <code>vessel</code> to the <code>city</code>. This method also * considers distribution of the gained income, in the case of a mixed convoy. * @param vessel from which to sell the ware * @param player owner of the vessel * @param city to which to sell * @param ware to be sold * @param amount to be sold */ public void sellWareShipToCity(INavigableVessel vessel, IPlayer player, ICity city, IWare ware, int amount, Optional<Integer> minAvgPrice) { int availableAmountCity = city.getWare(ware).getAmount(); int amountToBeSold = amount; if (minAvgPrice.isPresent()) { amountToBeSold = computablePrice.calculateSellAmount(ware, availableAmountCity, minAvgPrice.get(), amount); } if (amountToBeSold > 0) { int avgPrice = computablePrice.sellPrice(ware, new SimpleIntegerProperty(availableAmountCity), new ConstantIntegerBinding(amountToBeSold)); city.move(ware, amountToBeSold, player); // The price here is irrelevant int sold = vessel.unload(ware, amountToBeSold); if (vessel instanceof IShip) { if (player instanceof IHumanPlayer) { player.getCompany().updateCash(avgPrice * sold); } else { player.getCompany().updateCashDirectly(avgPrice * sold); } } else { distributeIncomeToConvoyParticipants((IConvoy) vessel, avgPrice, sold); } } }
@Override public boolean execute() { int availableAmount = city.getWare(ware).getAmount(); int sellAmount = vessel.getWare(ware).getAmount(); if (sellAmount > 0) { int sellPrice = computablePrice.sellPrice(getWare(), new SimpleIntegerProperty(availableAmount), new ConstantIntegerBinding(sellAmount)); IAIPlayer player = (IAIPlayer) vessel.getOwner(); ICompany company = player.getCompany(); LOGGER.trace("Before: cash={}, in city={}, on ship={}", company.getCash(), city.getWare(ware).getAmount(), vessel.getWare(ware).getAmount()); company.updateCashDirectly(sellPrice * sellAmount); city.move(getWare(), sellAmount, player); vessel.load(getWare(), sellAmount, sellPrice); LOGGER.trace("Sold {} of {} for a total of: {} ", sellAmount, ware.name(), sellPrice * sellAmount); LOGGER.trace("After: cash={}, in city={}, on ship={}", company.getCash(), city.getWare(ware).getAmount(), vessel.getWare(ware).getAmount()); // TODO ahotz 20.05.2016: handle case where there are ships owned by other players in the convoy } return true; } }