private boolean enoughStored(IPlayer player, ICity city) { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { for (IWare ware : minAmounts.keySet()) { ITradingOffice office = optOffice.get(); AmountablePrice<IWare> stored = office.getWare(ware); if (stored.getAmount() < minAmounts.get(ware)) { return false; } } return true; } return false; } }
@Override public int getTotalProduction(IWare ware,ICity city){ int totalProduction = cityProductionAndConsumptionService.getProductionOutputCurrentWeek(ware, city); for (IPlayer player : players) { if (player.findTradingOffice(city).isPresent()) { totalProduction += getProduction(ware, city, player); } } return totalProduction; } @Override
Optional<ITradingOffice> optOffice = player.findTradingOffice(city); Map<IWare, Double> missingWares = new HashMap<>(); if (!optOffice.isPresent()) {
private CelebrationState calculateCelebrationState() { Map<EPopulationClass, Integer> nbGuests = celebrationService.calculateAttendees(city, player); Map<IWare, Integer> requiredAmount = celebrationService.calculateRequiredAmounts(nbGuests); Map<IWare, Double> missingPercentage = celebrationService.calculateMissingWares(requiredAmount, player, city); double avgMissing = missingPercentage.values().stream().mapToDouble(val -> val).sum() / missingPercentage.size(); // calculate amount of required goods CelebrationSuccess success = calculateSuccess(avgMissing); // Use the goods Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { ITradingOffice tradingOffice = optOffice.get(); for (IWare ware : requiredAmount.keySet()) { int amount = requiredAmount.get(ware); tradingOffice.move(ware, -amount, 0); } } int attendance = nbGuests.values().stream().mapToInt(val -> val).sum(); // setup dialog return createCelebrationState(success, attendance); }
@VisibleForTesting double getNegativeReputationFactor(IPlayer player, ICity city) { if (city.equals(player.getHometown())) { return 1; } // Building Permission if (!city.hasBuildingPermission(player)) { return 0.05; } if (!player.findTradingOffice(city).isPresent()) { return 0.12; } int nbBuildings = player.findBuildings(city).size(); if (nbBuildings == 1) { // trading office return 0.18; } if (nbBuildings <= 10) { return 0.3; } if (nbBuildings <= 20) { return 0.6; } if (nbBuildings <= 30) { return 0.8; } return 1; }
/** * Try transferring the required amount from storage if there is a store manager and the transfer is allowed. The * rest is then bought from the city. * @param player for which the transfer happens * @param maxAmount maximum amount of wares that should be loaded onto the vessel. */ protected void transferFromOfficeOrBuyFromCity(IPlayer player, int maxAmount) { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent() && optOffice.get().getSteward().isPresent()) { ITradingOffice office = optOffice.get(); if (office.getOfficeTrading().isMovableToShip(ware)) { int loaded = tradeService.transferFromStorageToVessel(office, vessel, player, ware, maxAmount); maxAmount -= loaded; } } if (maxAmount > 0) { tradeService.buyFromCityToShip(vessel, player, city, ware, maxAmount, Optional.of(maxBuyPrice), vessel.getCaptian()); } } }
@Override public void run() { int availableAmountCity = transfer.getCity().getWare(ware).getAmount(); Optional<ITradingOffice> optOffice = transfer.getPlayer().findTradingOffice(transfer.getCity()); if (availableAmountCity>0 && optOffice.isPresent()){ int amount2Move = transfer.getAmount(availableAmountCity); // This is ware specific size tradeService.buyFromCityToStorage(optOffice.get(), transfer.getPlayer(), transfer.getCity(), ware, amount2Move, Optional.empty(), Optional.empty()); } } }
@Override public void run() { Optional<ITradingOffice> optOffice = transfer.getPlayer().findTradingOffice(transfer.getCity()); if (optOffice.isPresent()) { ITradingOffice office = optOffice.get(); int amountInStorage = office.getWare(ware).getAmount(); if (amountInStorage > 0) { int amount2Move = transfer.getAmount(amountInStorage); tradeService.sellFromStorageToCity(office, transfer.getPlayer(), transfer.getCity(), ware, amount2Move, Optional.empty()); } // end stored amount } // end office }
@Override public void run() { INavigableVessel ship = transfer.getVessel(); final AmountablePrice<IWare> amountable = ship.getWare(this.ware); int availableAmountShip = amountable.getAmount(); final IPlayer player = transfer.getPlayer(); ICity city = transfer.getCity(); Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (availableAmountShip>0 && optOffice.isPresent()){ Map<IWare, Integer> amounts = new HashMap<>(); amounts.put(ware, transfer.getAmount(availableAmountShip)); tradeService.transferFromVesselToStorage(ship, player, city, amounts); } }
/** * Transfer the wares in the specified amounts from the ship into the storage.<br> * PRE: there is a trading office in the city. * @param vessel from which the wares are transfered * @param player owner of the trading office and the vessel * @param city in which the transfer happens * @param amounts map of wares and the amounts that should be transfered. */ public void transferFromVesselToStorage(INavigableVessel vessel, IPlayer player, ICity city, Map<IWare, Integer> amounts) { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); Preconditions.checkArgument(optOffice.isPresent(), "There is no trading office for "+player.getName()+" "+player.getLastName()+" in "+city.getName()); for (IWare ware : amounts.keySet()) { int amount = amounts.get(ware); int avgPrice = vessel.getWare(ware).getAVGPrice(); amount = vessel.unload(ware, amount); optOffice.get().move(ware, amount, avgPrice); if (vessel instanceof IConvoy) { distributeIncomeToConvoyParticipants((IConvoy) vessel, player, avgPrice, amount); } } }
@Override public void run() { INavigableVessel ship = transfer.getVessel(); final IPlayer player = transfer.getPlayer(); Optional<ITradingOffice> optOffice = player.findTradingOffice(transfer.getCity()); if (optOffice.isPresent() && optOffice.get().getWare(ware).getAmount()>0){ ITradingOffice office = optOffice.get(); final AmountablePrice<IWare> amountable = office.getWare(this.ware); int availableAmountStorage = amountable.getAmount(); int amount2Move = transfer.getAmount(availableAmountStorage); // This is ware specific size tradeService.transferFromStorageToVessel(office, ship, player, ware, amount2Move); } }
public ITradingOffice createTradingOffice(IPlayer owner, ICity city, int value) { for (IBuilding building : city.getBuildings()) { if (building.getOwner()==owner && building instanceof ITradingOffice){ throw new IllegalStateException("The player may only obtain one trading office per city"); } } IStorage storage = createStorage(owner, city); IBalanceSheet lastWeek; IBalanceSheet thisWeek; ICity hometown = owner.getHometown(); if (hometown.equals(city)) { lastWeek = interactionFactory.createInitialBalanceSheet(city, owner); thisWeek = interactionFactory.createBalanceSheetFromPreviousWeek((BalanceSheet) lastWeek); } else { Optional<ITradingOffice> mainOffice = owner.findTradingOffice(hometown); Preconditions.checkArgument(mainOffice.isPresent(), "There has to be a trading office in the hometown"); lastWeek = mainOffice.get().getBalanceLastWeek(); thisWeek = mainOffice.get().getCurrentWeek(); } TradingOffice office = (TradingOffice) context.getBean("tradingOffice", new Object[]{owner, city, value, storage, lastWeek, thisWeek}); city.build(office); clientServerEventBus.post(new BuildingFinished(office, owner, city)); return office; } }
Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { sb.append("\tTrading office in ")
Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { ITradingOffice office = optOffice.get(); Optional<ITradingOffice> optMainOffice = player.findTradingOffice(player.getHometown()); Preconditions.checkArgument(optMainOffice.isPresent(), "There must be a trading office in the hometown."); IBalanceSheet balanceSheet = optMainOffice.get().getCurrentWeek();
Optional<ITradingOffice> optOffice = resident.findTradingOffice(hometown); Preconditions.checkArgument(optOffice.isPresent(), "Trading office in hometown must be present"); BalanceSheet sheet = (BalanceSheet) optOffice.get().getCurrentWeek();