/** * A non free pirate becomes free. * @param pirate non free pirate instance that is to be freed. */ public void free(INonFreeSeaPirate pirate) { ISeaPirate freePirate = createNewPirate(pirate.getName(), pirate.getShip()); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(pirate); piratesState.replace(pirate, freePirate); }
@Override protected String computeValue() { if (sailorState.getNumberOfSailors() > 1) { return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernSailorDialog.dialog1", new Object[]{ sailorState.getNumberOfSailors()}, locale.getCurrentLocal()); } else if (sailorState.getNumberOfSailors() == 1) { return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernSailorDialog.dialog2", new Object[]{}, locale.getCurrentLocal()); } else { return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernSailorDialog.dialog3", new Object[]{}, locale.getCurrentLocal()); } } };
public BuyWares(ICityPlayerProxyJFX cityPlayerProxy, IBuyer buyer) { super(); setExecutionTime(buyer.getTimeFrame()); player = cityPlayerProxy.getPlayer(); city = cityPlayerProxy.getCity(); amountable = buyer.getAmountablePrice(); ware = buyer.getWare(); }
public ShipEntersPortEvent(INavigableVessel ship, ICity city) { this.ship = ship; this.city = city; Preconditions.checkArgument(ship.getLocation().equals(city.getCoordinates()), "The ship "+ship.getName()+" of "+ship.getOwner().getName() +" "+ship.getOwner().getLastName()+" is not in city "+city.getName()); } }
@VisibleForTesting double calculateAccuracy(List<IShip> shipsOnTurn) { double accuracy = 0.7; double captainAccuracy = 0; int nbCaptains = 0; for (IShip ship : shipsOnTurn) { if (ship.getCaptian().isPresent()) { nbCaptains++; captainAccuracy += ship.getCaptian().get().getFightSkillLevel(); } } if (nbCaptains > 0) { captainAccuracy = captainAccuracy / (nbCaptains*10.0); } return accuracy + captainAccuracy; }
@Subscribe public void handleDayChange(ClockTickDayChange event) { for (Entry<ICity, TavernState> entry : cities.entrySet()) { ICity city = entry.getKey(); TavernState state = entry.getValue(); int nbSailors = computeNumbersOfSailors(city); state.getSailors().setNumberOfSailors(nbSailors); handlePersonsBecomingAbsent(state); handlePersonsBecomingPresent(city, state); } } /**
} /** * Select a new destination for the pirate. * @param pirate free sea pirate */ private void selectDestination(ISeaPirate pirate) { Point2D destination; if (pirate instanceof INonFreeSeaPirate && ((INonFreeSeaPirate) pirate).roamingNearCity().isPresent()) { ICity city = ((INonFreeSeaPirate) pirate).roamingNearCity().get(); destination = mapService.getRandomPointAtSeaNear(city.getCoordinates()); } else { destination = mapService.getLocationAtOtherEndOfMap(pirate.getShip().getLocation()); } // make sure that the source of the pirate location is in the graph Point2D adjustedDestination = aStarHeuristicProvider.findClosest(destination); aStarHeuristicProvider.addTargetNodeToHeuristic(adjustedDestination); logger.debug("Source point of pirate is {}", pirate.getShip().getLocation()); seafaringService.travelNotBetweenCities(pirate.getShip(), adjustedDestination); }
@VisibleForTesting int calculateAgility(IShip ship) { int agility = shipFactory.getShipSpeed(ship.getShipType()); if (ship.getCaptian().isPresent()) { ICaptain captain = ship.getCaptian().get(); agility += (int)Math.rint(captain.getNavigationSkillLevel() * 0.7); } return agility; }
@Override protected boolean computeValue() { Optional<ITradingOffice> optOffice = city.getPlayer().findTradingOffice(city.getCity()); IShip ship = null; if (city.getActiveShip() instanceof IShip) { ship = (IShip) city.getActiveShip(); } int barrelAmountFactor = 1; if (!trader.getWare().isBarrelSizedWare()) { barrelAmountFactor = 10; } return optOffice.isPresent() && ship == null && ship.getCapacity() < trader.getAmount() * barrelAmountFactor; } };
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; } } }; }
@Override public void run() { if (player instanceof IHumanPlayer) { player.getCompany().updateCash(tenant.getRentPerWeek()); } else { player.getCompany().updateCashDirectly(tenant.getRentPerWeek()); } } }
@Override protected boolean computeValue() { ITransportTrader trader = (ITransportTrader) currentPerson.get(); return tavernDialogUtil.noShipWithEnoughCapacityAvailable(city, trader.getNeededCapacity()); } };
@Override protected boolean computeValue() { ISmuggler smuggler = (ISmuggler) currentPerson.get(); return tavernDialogUtil.noShipWithEnoughCapacityAvailable(city, smuggler.getAmount()/10); } };
@Override public void run() { clientEventBus.post(new DisplayMessage("ch.sahits.game.openpatrician.display.dialog.TavernWarehouseTenantDialog.acceptMessage")); office.setOccupiedSpace(office.getOccupiedSpace() - tenant.getAmount()); } }
@Override protected EventHandler<MouseEvent> createAcceptHandler() { return mouseEvent -> { try { final IBuyer buyer = (IBuyer) currentPerson.get(); timedTaskList.add(taskFactory.getBuyWares(city, buyer)); buyer.leave(); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to accept buyers offer", e); } }; }
/** * Handle the even when a new pirate becomes available. * @param pirateEvent new pirate emerged */ @Subscribe public void handleNewPirate(NewPirateEvent pirateEvent) { IShip ship = (IShip) pirateEvent.getPirate().getShip(); Point2D adjustedSource = aStarHeuristicProvider.findClosest(ship.getLocation()); ship.setLocation(adjustedSource); selectDestination(pirateEvent.getPirate()); }
@VisibleForTesting double calculatePropSurvivingAttack(IShip attackingShip, IShip defendingShip) { double captainCapabilities = 1; if (attackingShip.getCaptian().isPresent()) { captainCapabilities -= attackingShip.getCaptian().get().getFightSkillLevel() * 0.1; } if (defendingShip.getCaptian().isPresent()) { captainCapabilities += defendingShip.getCaptian().get().getFightSkillLevel() * 0.1; } return Math.min(Math.abs(rnd.nextGaussian()) * captainCapabilities, 1); }
public void addCity(TavernState state, ICity city) { cities.put(city, state); int nbSailors = computeNumbersOfSailors(city); final ISailorState sailors = state.getSailors(); sailors.setNumberOfSailors(nbSailors); handlePersonsBecomingAbsent(state); handlePersonsBecomingPresent(city, state); }
@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; } } };
@VisibleForTesting int calculateShipStrength(IShip ship) { int strength = shipStrenghtService.calculateShipsWeaponsStrength(ship); if (ship.getCaptian().isPresent()) { ICaptain captain = ship.getCaptian().get(); strength += captain.getFightSkillLevel()*2; } return strength; }