/** * Even distirbution of the total cash by ship capacity in the convoy. */ private void updatePlayerByCapacityPercentage(IConvoy convoy, Map<IPlayer, Integer> capacityMap, long totalCash) { double totalCapacity = convoy.getCapacity(); for (Entry<IPlayer, Integer> entry : capacityMap.entrySet()) { double percentage = entry.getValue()/totalCapacity; long partialAmount = Math.round(totalCash*percentage); IPlayer player = entry.getKey(); if (player instanceof IHumanPlayer) { player.getCompany().updateCash(partialAmount); } else { player.getCompany().updateCashDirectly(partialAmount); } } }
private DecoratedText getCandidateRow(ICitizen candidate) { Object[] args; String template; DecoratedText text; if (candidate instanceof IPlayer) { IPlayer p = (IPlayer) candidate; args = new Object[]{modelTranslator.getLocalDisplayDistinctArticle(p.getPersonalData().isMale(), true), modelTranslator.getLocalDisplayName(p.getCareerLevel()), modelTranslator.getLocalDisplayName(p.getRank()), p.getName()+" "+p.getLastName()}; } else { args = new Object[]{modelTranslator.getLocalDisplayDistinctArticle(true, true), modelTranslator.getLocalDisplayName(EEconomicCareer.SMART), modelTranslator.getLocalDisplayName(candidate.getRank()), candidate.getName()+" "+candidate.getLastName()}; } template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.TownInfoNotice.candidate", args, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); return text; }
/** * 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); } } }
private boolean canBeCandidate(IPlayer player, ICity town) { ESocialRank rank = player.getRank(); if (rank == ESocialRank.COUNCILMAN || rank == ESocialRank.PATRICIAN || rank == ESocialRank.MAYOR || rank == ESocialRank.ALDERMAN) { final ICity hometown = player.getHometown(); return town.equals(hometown); } return false; }
public Optional<ISpouseData> calculateSpouseDeath(IPlayer player, ICity city) { Optional<ISpouseData> killedSpouse = Optional.empty(); if (player.getHometown().equals(city) && player.getSpouseData().isPresent()) { if (rnd.nextInt(5) == 0) { killedSpouse = Optional.of(player.getSpouseData().get()); player.spouseDies(); } } return killedSpouse; } /**
@Override public String getLabel() { return getItem().getName() + " " + getItem().getLastName(); } }
IPlayer member = itemNavigator.getCurrent(); Label header = new Label(member.getName() + " " +member.getLastName()); header.getStyleClass().addAll("subTitle"); header.setId("playerName"); new Object[]{modelTranslations.getLocalDisplayName(member.getCareerLevel()), modelTranslations.getLocalDisplayName(member.getRank()), member.getName(), member.getLastName(), member.getHometown().getName(), modelTranslations.toDisplayString(foundingDate), oldest.getCity().getName()}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); box.getChildren().add(text); box.getChildren().add(new PlaceHolder(1, 30)); IPersonalData personalData = member.getPersonalData(); template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.GuildMembersDialog.age", new Object[]{personalData.getAge(date.getCurrentDate())}, locale.getCurrentLocal()); box.getChildren().add(text); if (member.getSpouseData().isPresent()) { ISpouseData spouseData = member.getSpouseData().get(); template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.GuildMembersDialog.married", new Object[]{spouseData.getName(), spouseData.getLastName(), spouseData.getBirthPlace().getName()}, locale.getCurrentLocal()); new Object[]{offices.size(), member.getFleet().size()}, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); text.setId("details");
sb.append(player.getName()) .append(" ") .append(player.getLastName()) .append(" from ") .append(player.getHometown().getName()) .append(" has $") .append(player.getCompany().getCash()) .append("\n"); Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { sb.append("\tTrading office in ") for (IShip ship : player.getFleet()) { sb.append("\tShip ") .append(ship.getShipType())
Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { ITradingOffice office = optOffice.get(); List<ITownHouse> townHouses = player.findBuildings(city, ITownHouse.class); for (IBuilding building : townHouses) { rentalIncome += ((ITownHouse) building).computeRentalIncome(); List<IWorkShop> workshops = player.findBuildings(city, IWorkShop.class); IStorage storage = office.getStorage(); for (IBuilding building : workshops) { List<IShip> fleet = player.getFleet(); for (IShip ship : fleet) { double sailorSalary = ship.getNumberOfSailors() * dailySailorCost; player.getCompany().updateCash(sum); 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(); balanceSheet.updateOtherExpensesRegular(otherCosts); } else { player.getCompany().updateCashDirectly(sum);
MarriageCelebrationState marriageState = (MarriageCelebrationState) wrappedDialogState.getState(); ISpouseData spouse = marriageState.getSpouseData(); player.marry(spouse); eventState.resetMarriedState(player); long value = player.getCompany().getCompanyValue(); IShip ship; ICity birthPlace = spouse.getBirthPlace(); ship.setLocation(player.getHometown().getCoordinates()); ship.setOwner(player); player.addShip(ship); updateReputation += spouse.getConnectionsInHerHomeTown() * 2 * repConnectionCounsilman; rep.update(updateReputation); rep = player.getHometown().getReputation(player); updateReputation = (int)(0.5 * spouse.getPopularityInYourHomeTown()); updateReputation += spouse.getConnectionsInYourHomeTown() * repConnectionCounsilman; .location(player.getHometown().getName()) .date(date.getCurrentDate()) .ship(ship) } else { logger.debug("Dowry ship {} of {} {} enters port", ship.getName(), player.getName(), player.getLastName()); aiEventHandler.initializeNewShip(ship, (IAIPlayer) player);
private boolean isNextRankAchievable(IPlayer player){ ESocialRank rank = player.getRank(); if (rank==ESocialRank.PATRICIAN || rank==ESocialRank.MAYOR || rank==ESocialRank.ALDERMAN){ return false; } final ICompany company = player.getCompany(); ICity homeTown = player.getHometown(); long compValue = company.getCompanyValue(); ESocialRank nextRank = rank.getNextRank(); double remapedRep = repCalculator.remapReputation(homeTown, player); if (compValue>=nextRank.getCompanyValue() && remapedRep>=nextRank.getSocialRank()){ if (nextRank==ESocialRank.COUNCILMAN){ IGuild guild = guildList.findGuild(homeTown).get(); return guild.getMembers().contains(player); } return true; } return false; }
setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.PersonalDialog.personal", new Object[]{}, locale.getCurrentLocal())); IPlayer player = city.getPlayer(); IPersonalData personalData = player.getPersonalData(); IReputation rep = city.getCity().getReputation(player); personalData.getName(), personalData.getLastName(), modelTranslator.getLocalDisplayName(player.getCareerLevel()), modelTranslator.getLocalDisplayName(player.getRank()) }, locale.getCurrentLocal())); createAndAddNewText(box, messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.PersonalDialog.hometown", new Object[]{player.getHometown().getName()}, locale.getCurrentLocal())); if (player.getSpouseData().isPresent()) { ISpouseData spouseData = player.getSpouseData().get(); createAndAddNewText(box, messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.PersonalDialog.married", new Object[]{ getPrefix(spouseData), createAndAddNewText(box, messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.PersonalDialog.children", new Object[]{player.getChildren().size()}, locale.getCurrentLocal()));
@Override public void run() { ICompany company = debitor.getCompany(); int requiredAmount = debt.getAmount(); int amount = (int) Math.min(requiredAmount, company.getCash()); if (debitor instanceof IHumanPlayer) { company.updateCash(-amount); } else { company.updateCashDirectly(-amount); } if (debt.getCreditor() instanceof IPlayer) { if (debt.getCreditor() instanceof IHumanPlayer) { ((IPlayer) debt.getCreditor()).getCompany().updateCash(amount); } else { ((IPlayer) debt.getCreditor()).getCompany().updateCashDirectly(amount); } if (debt.getCreditor() instanceof IHumanPlayer) { DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.engine.land.city.LoanerEngine.paybackAfterWithoutAuction", new Object[]{debitor.getName(), debitor.getLastName(), amount}); TargetedEvent message = new TargetedEvent((IHumanPlayer) debt.getCreditor(), msg); clientServerEventBus.post(message); } } } }
boolean childBirth = false; boolean spouseDeath = false; if (player.getSpouseData().isPresent() && !catastopheEvent) { childBirth = rnd.nextInt(400 * (player.getChildren().size() + 1)) == 42; int spouseDeathPropLimit = 5000; boolean spuseDeathSingle = rnd.nextInt(spouseDeathPropLimit) == 42; if (!player.getPersonalData().isMale()) { spuseDeathSingle = false; .location(player.getHometown().getName()) .date(date.getCurrentDate()) .male(male) .name(name) .build(); player.getChildren().add(child); if (spuseDeathSingle) { player.spouseDies(); .location(player.getHometown().getName()) .date(date.getCurrentDate()) .build(); player.spouseDies(); eventService.postToHumanPlayer(state, player, "ch.sahits.game.openpatrician.engine.event.EventEngine.message.spouseDeath.title");
@Override public void run() { int bounty = (int)(Math.abs(opponent.getCompany().getCash()/2000*rnd.nextDouble())); if (opponent instanceof IHumanPlayer) { opponent.getCompany().updateCash(-bounty); } else { opponent.getCompany().updateCashDirectly(-bounty); } DisplayMessage msg = new DisplayMessage("ch.sahits.game.graphic.event.task.BreakInAction.message", bounty, opponent.getLastName()); clientEventBus.post(msg); }
@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; }
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; } }
@VisibleForTesting void updateCompanyValue() { for (IPlayer player : players) { ICompany company = player.getCompany(); long newCompanyValue = company.getCash(); List<IShip> ships = player.getFleet(); for (IShip ship : ships) { newCompanyValue += ship.getValue(); List<IBuilding> buildings = player.findBuildings(city); for (IBuilding building : buildings) { newCompanyValue += building.getValue();
private boolean notEnoughMoney(IPlayer player) { ESocialRank rank = player.getRank(); ESocialRank nextRank = rank.getNextRank(); final ICompany company = player.getCompany(); long compValue = company.getCompanyValue(); return compValue < nextRank.getCompanyValue(); }
public void doMonthlyCheck() { // TODO: andi 1/9/17 appropriate messages for mayor, alderman, tradesman for (IPlayer player : players) { ESocialRank rank = player.getRank(); if (isNextRankAchievable(player)){ ESocialRank nextRank = rank.getNextRank(); player.updateRank(nextRank); if (player instanceof IHumanPlayer) { SocialAdvancementState state = SocialAdvancementState.builder() .location(player.getHometown().getName()) .rank(nextRank) .date(date.getCurrentDate()) SocialAdvancementDeficitState state = SocialAdvancementDeficitState.builder() .date(date.getCurrentDate()) .location(player.getHometown().getName()) .money(moneyMissing) .reputation(reputationLow) ICareer career = repCalculator.calculateCareer(player.getHometown(), player); player.setCareerLevel(career); for (ICity city : map.getCities()) { if (!city.hasBuildingPermission(player)) {