@Override protected String computeValue() { return String.valueOf(computablePrice.buyPrice(ware, availableAmount, ONE_INT_BINDING)); } };
@Override protected int computeValue() { if (buyAmount.get() > 0) { return computablePrice.buyPrice(ware, inCity, buyAmount); } else { return 0; } } };
@Override protected String computeValue() { switch (type) { case PORT_CITY_TO_SHIP: case PORT_CITY_TO_STORAGE: if (availableAmount.get() > 0){ return String.valueOf(computablePrice.buyPrice(ware, availableAmount, amountToBuy)); } else { return "0"; // cannot buy anything if nothing is there } default: return "<"; } } };
@Override protected int computeValue() { int availableAmount = getAmountInArmory(weapon).get(); int buyAmount = transferUtil.calculateAvailableAmount(ETransferAmount.ONE, availableAmount); if (buyAmount>0) { return computablePrice.buyPrice(weapon, new SimpleIntegerProperty(availableAmount), new StaticIntegerBinding(buyAmount)) * 2; } else { return 0; } } };
@Override protected int computeValue() { int availableAmount = getAmountInArmory(weapon).get(); int buyAmount = transferUtil.calculateAvailableAmount(ETransferAmount.ONE, availableAmount); if (buyAmount>0) { return computablePrice.buyPrice(weapon, new SimpleIntegerProperty(availableAmount), new StaticIntegerBinding(buyAmount)) * 2; } else { return 0; } } };
/** * Calculate how much can be bought due to monetary restrictions. To be on the save side, if the amount is larger than * 10 items, one is deduced. * @param cash available cash * @param desiredAmount amount that is desired to be bought * @param availableAmountCity amount of the ware available in the city * @param maxAvgPrice limit of the maximal avg price to be payed per item. * @return Pair containing the affordable amount and the average price. */ @VisibleForTesting Pair<Integer, Integer> calculateAffordableAmountToBuy(IWare ware, long cash, int desiredAmount, int availableAmountCity, int maxAvgPrice) { int buyAmount = computablePrice.calculateBuyAmount(ware, availableAmountCity, maxAvgPrice, desiredAmount, cash); if (buyAmount > 10) { buyAmount--; } if (buyAmount == 0) { return new Pair<>(0, 0); } int price = computablePrice.buyPrice(ware, new SimpleIntegerProperty(availableAmountCity), new ConstantIntegerBinding(buyAmount)); return new Pair<>(buyAmount, price); }
buyer.setWare(ware); int amount = rnd.nextInt(21)+3; // TODO aho Jan 27, 2013: differentiate between bale and barrel int price = computablePrice.buyPrice(ware, new SimpleIntegerProperty(5), new StaticIntegerBinding(amount)); AmountablePrice<IWare> amt = amountableProvider.createWareAmountable(); amt.add(amount, price);
@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; } } };
private Pair<Integer, Integer> buyWareFromCity(IPlayer player, ICity city, int availableAmountCity, IWare ware, long cash, int amountToBuy, int maxAvgPrice) { Pair<Integer, Integer> affordable = calculateAffordableAmountToBuy(ware, cash, amountToBuy, availableAmountCity, maxAvgPrice); amountToBuy = affordable.getKey(); int avgPriceCompleteAmount = affordable.getValue(); if (amountToBuy == 0) { return new Pair<>(0, 0); } int movedAmount = city.move(ware, -amountToBuy, player); if (amountToBuy != -movedAmount) { avgPriceCompleteAmount = computablePrice.buyPrice(ware, new SimpleIntegerProperty(city.getWare(ware).getAmount() + movedAmount), new ConstantIntegerBinding(movedAmount)); amountToBuy = -movedAmount; } return new Pair<>(amountToBuy, avgPriceCompleteAmount); }
/** * Check the amount of bricks required and if the price is not too heigh buy it. */ @Override public void run() { ICity city = cityHall.getCity(); CityWall cityWall = city.getCityState().getCityWall(); if (cityWall.getUsedBricks() == cityWall.getBoughtBricks()) { int amountRequired = Math.min(10, cityWall.getRequiredBricks() - cityWall.getBoughtBricks()); int availableAmountCity = city.getWare(EWare.BRICK).getAmount(); int avgPrice = computablePrice.buyPrice(EWare.BRICK, new SimpleIntegerProperty(availableAmountCity), new ConstantIntegerBinding(amountRequired)); if (avgPrice < 90) { int bought = city.move(EWare.BRICK,-amountRequired, cityHall.getMayor()); cityWall.setBoughtBricks(cityWall.getBoughtBricks() - bought); avgPrice = computablePrice.buyPrice(EWare.BRICK, new SimpleIntegerProperty(availableAmountCity), new ConstantIntegerBinding(-bought)); ((Treasury)cityHall.getTreasury()).subtractBuildingCosts(avgPrice * bought); LocalDateTime buildDate = date.getCurrentDate().plusDays(5); CityWallBuildingTask task = engineFactory.getCityWallBuildingTask(cityWall, buildDate); timedTaskListener.add(task); } } } }
int price = computablePrice.buyPrice(EWare.BRICK, amount.amountProperty(), new IntegerBinding() {
int buyHandWeapons = Math.min(availableHandWeapons, target.getHandWeapons()); armory.updateCutlassAmount(-buyHandWeapons); int price = computablePrice.buyPrice(EWeapon.HAND_WEAPON, new SimpleIntegerProperty(availableHandWeapons), new ConstantIntegerBinding(buyHandWeapons)); costs = price * buyHandWeapons; for (int i = 0; i < buyHandWeapons; i++) { if (boughtWeapon != null) { ReadOnlyIntegerProperty available = new SimpleIntegerProperty(getWeaponAmount(armory, boughtWeapon)); price = computablePrice.buyPrice(boughtWeapon, available, new ConstantIntegerBinding(1)); costs += price; boughtLargeWeapons++; if (boughtWeapon != null) { ReadOnlyIntegerProperty available = new SimpleIntegerProperty(getWeaponAmount(armory, boughtWeapon)); price = computablePrice.buyPrice(boughtWeapon, available, new ConstantIntegerBinding(1)); costs += price; boughtSmallWeapons++;