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; } } }; }
final IntegerBinding storedAmount = getAmountStoredWeapons(weapon); // amount owned by the player final IntegerBinding amountToSell = getAmountBinding(storedAmount); final ReadOnlyIntegerProperty dealerOwnedAmount = weaponsDealer.amountAvailableProperty(weapon); city.getPlayer().getCompany().updateCash(-affordableAmount * avgPrice); storage.update(weapon, affordableAmount); weaponsDealer.move(weapon, -amountToBuy); storedAmount.invalidate(); city.getPlayer().getCompany().updateCash(amount * avgPrice); storage.update(weapon, -amount); weaponsDealer.move(weapon, amount); storedAmount.invalidate(); } catch (RuntimeException e) {
@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; } } }; }
@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; } } };