@Override protected String computeValue() { return String.valueOf(computablePrice.buyPrice(ware, availableAmount, ONE_INT_BINDING)); } };
@Override protected String computeValue() { return String.valueOf(computablePrice.sellPrice(ware, availableAmount, ONE_INT_BINDING)); } };
/** * 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 } /**
@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; } }
@Override public void updateKnowledge(ICity city) { CityProductionConsumptionKnowledge knowledge = (CityProductionConsumptionKnowledge) productionAndConsumption.get(city); for (EWare ware : EWare.values()) { int amount = productionAndConsumptionService.getProductionOutputCurrentWeek(ware, city); knowledge.updateProduction(ware, amount); amount = (int) Math.floor(consume.getWeeklyConsumption(ware, city)); knowledge.updateConsumption(ware, amount); amount = city.getWare(ware).getAmount(); knowledge.updateStored(ware, amount); } }
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); }
@Override public boolean execute() { IWare ware = getWare(); INavigableVessel vessel = getVessel(); IPlayer player = (IPlayer) vessel.getOwner(); int size = vessel.getSize(); int alreadyLoaded = vessel.getWare(ware).getAmount(); int maxAmountBasedOnPercentage = (int) (size * ware.getAiMaxBuyPercentage()) - alreadyLoaded; int maxAbsoluteAmount = ware.getAiMaxBuyAbsolute() - alreadyLoaded; int affordableAmount = Math.min(maxAmountBasedOnPercentage, maxAbsoluteAmount); transferFromOfficeOrBuyFromCity(player, affordableAmount); return executeNext; }
@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 ">"; } } };
@VisibleForTesting Map<IWare, Integer> calculateBuyAmounts(Set<IWare> buyWares) { Map<IWare, Integer> buyAmounts = new HashMap<>(); for (IWare buyWare : buyWares) { int amount = 5; if (buyWare.isBarrelSizedWare()) { amount *= 10; } buyAmounts.put(buyWare, amount); } return buyAmounts; }
@PostConstruct @IgnoreOnDeserialisation private void init() { for (EWare ware : EWare.values()) { if (!storedAmounts.containsKey(ware)) { storedAmounts.put(ware, 0); } } }
@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; } }
@Override public void run() { final INavigableVessel vessel = transfer.getVessel(); int amountOnShip = vessel.getWare(ware).getAmount(); if (amountOnShip>0){ final ICity city = transfer.getCity(); int amount2Move = transfer.getAmount(amountOnShip); tradeService.sellWareShipToCity(vessel, transfer.getPlayer(), city, ware, amount2Move, Optional.empty()); } } }
/** * Calculate the cost of wares that are consumed in one days production. * The ware is removed from storage in the process. * @param producedWare the ware that is produced. * @param storage where the ware is stored. * @param requiredWareFactor adjustment factor considering, that there may not be a full production due to * missing wares or under staffing. * @param ware that is required for the production * @return the average price of the consumed ware, with the amount taken into account. */ @VisibleForTesting double calculateWareCost(IWare producedWare, ProductionStorage storage, double requiredWareFactor, IWare ware) { double requiredForFullProduction = productionChain.getRequiredAmount(producedWare, ware) * ONE_DAY_OF_WEEK; double remove = -requiredForFullProduction * requiredWareFactor; double price = storage.getAvgPrice(ware); double moved = -storage.transfer(ware, remove, price); return moved * price; }
protected AggregatedBuyTradeStep createAggregatedBuyTradeStep(INavigableVessel vessel, ICity city, List<IWare> waresToBuy) { AggregatedBuyTradeStep buyStepHometown = context.getBean(AggregatedBuyTradeStep.class); buyStepHometown.setCity(city); buyStepHometown.setVessel(vessel); buyStepHometown.setExecuteNext(true); for (IWare ware : waresToBuy) { int maxPrice = ware.getMaxBuyPriceOffensive(); buyStepHometown.addBuyStep(ware, maxPrice); } return buyStepHometown; }
@Override protected int computeValue() { if (buyAmount.get() > 0) { return computablePrice.buyPrice(ware, inCity, buyAmount); } 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; } } };
@Override public boolean execute() { IPlayer player = (IPlayer) getVessel().getOwner(); int maxAmount = getVessel().getCapacity(); if (!getWare().isBarrelSizedWare()) { maxAmount /= 10; } transferFromOfficeOrBuyFromCity(player, maxAmount); return executeNext; }
/** * Create a trade step for buiyn wares into the trading office * @param office trading office for which to buy the wares * @param city from which to buy the wares * @param waresToBuy wares to buy * @return aggregate buy step for the trading offic */ public AggregatedBuyTradingOfficeTradeStep createAggregatedBuyTradingOfficeTradeStep(ITradingOffice office, ICity city, List<IWare> waresToBuy) { AggregatedBuyTradingOfficeTradeStep buyStepHometown = context.getBean(AggregatedBuyTradingOfficeTradeStep.class); buyStepHometown.setCity(city); buyStepHometown.setTradingOffice(office); for (IWare ware : waresToBuy) { int maxPrice = ware.getMaxBuyPriceOffensive(); buyStepHometown.addBuyStep(ware, maxPrice); } return buyStepHometown; } }
@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 "<"; } } };
protected AggregatedCheckedBuyTradeStep createAggregatedCheckedBuyTradeStep(INavigableVessel vessel, ICity city, List<IWare> waresToBuy) { AggregatedCheckedBuyTradeStep buyStepHometown = context.getBean(AggregatedCheckedBuyTradeStep.class); buyStepHometown.setCity(city); buyStepHometown.setVessel(vessel); buyStepHometown.setExecuteNext(true); for (IWare ware : waresToBuy) { int maxPrice = ware.getMaxBuyPriceOffensive(); buyStepHometown.addBuyStep(ware, maxPrice); } return buyStepHometown; }