private IntegerBinding sellPriceBinding(final EWeapon weapon) { return new IntegerBinding() { { super.bind(getAmountInArmory(weapon)); } @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; } } }; } @Override
/** * Bind the amount that can be transferred on the maximal available amount * as well as the selected transfer amount. This reflects the amount the * dealer owns. * @param maxAmount binding of the amount the dealer owns * @return integer binding */ private IntegerBinding getAmountBinding(final IntegerBinding maxAmount) { return new IntegerBinding() { { super.bind(movableAmount, maxAmount); } @Override protected int computeValue() { return transferUtil.calculateAvailableAmount(movableAmount, maxAmount.get()); } }; } /**
/** * Bind the amount that can be transferred on the maximal available amount * as well as the selected transfer amount. * @param maxAmount maximum amount * @return integer binding representing the available amount. */ private IntegerBinding getAmountProperty(final ReadOnlyIntegerProperty maxAmount) { return new IntegerBinding() { { super.bind(movableAmount, maxAmount); } @Override protected int computeValue() { return transferUtil.calculateAvailableAmount(movableAmount, maxAmount.get()); } }; }
private IntegerBinding buyPriceBinding(final EWeapon weapon) { return new IntegerBinding() { { super.bind(getAmountInArmory(weapon)); } @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
private IntegerBinding buyPriceBinding(final EWeapon weapon) { return new IntegerBinding() { { super.bind(getAmountInArmory(weapon)); } @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; } } }; } private IntegerBinding sellPriceBinding(final EWeapon weapon) {
/** * Retrieve the binding for the amount of the weapon currently stored. * @param weapon type of the weapon * @return integer binding of the stored amount of the weapon */ private IntegerBinding getAmountStoredWeapons(final EWeapon weapon) { return new IntegerBinding() { { if (storage != null) { super.bind(storage.getWeaponProperty(weapon)); } } @Override protected int computeValue() { if (storage != null) { return storage.getWeapon(weapon); } else { return 0; } } }; } /**
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); } }
public IntegerBinding sellPriceBinding(final EWeapon weapon, final IntegerBinding amountToSell) { return new IntegerBinding() { { super.bind(weaponsDealer.amountAvailableProperty(weapon), amountToSell); } @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; } } }; }
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; } } }; }
IntegerBinding additionalAmount = new IntegerBinding() { super.bind(office.storedAmountBinding(), office.capacityProperty());