private MarriageBrokerAnnouncementState createMarriageBrokerAnnouncementState(ShipEntersPortEvent event, INavigableVessel ship) { return MarriageBrokerAnnouncementState.builder() .date(date.getCurrentDate()) .location(event.getCity().getName()) .fromFirstName(maleFirstNameLoader.getRandomName()) .fromLastName(lastNameLoader.getRandomName()) .toLastName(ship.getOwner().getLastName()) .genderMale(((IPlayer) ship.getOwner()).getPersonalData().isMale()) .build(); }
/** * Trigger the event for a marriage broker. * @param event ship entered port */ @Subscribe public void handleShipEntersPort(ShipEntersPortEvent event) { INavigableVessel ship = event.getShip(); if (ship.getOwner() instanceof IPlayer && disableService.randomEventsEnabled()) { IPlayer player = (IPlayer) ship.getOwner(); // Marriage broker to initialize marriage // unmarried and not already in negotiation. Optional<EEventState> marriageState = eventState.getMarriageState(player); boolean meetBroker = rnd.nextInt(30) < 2; // 5% chance to meet a broker. if (!player.getSpouseData().isPresent() && marriageState != null && meetBroker && !marriageState.isPresent()) { if (player instanceof IAIPlayer) { MarriageBrokerAnnouncementState state = createMarriageBrokerAnnouncementState(event, ship); aiEventHandler.handleMarriageEvent((IAIPlayer) player, state); } else if (player instanceof IHumanPlayer) { MarriageBrokerAnnouncementState state = createMarriageBrokerAnnouncementState(event, ship); eventService.postToHumanPlayer(state, player, "ch.sahits.game.openpatrician.engine.event.EventEngine.message.marriageOffer.title"); clientServerEventBus.post(new TargetedEvent((IHumanPlayer) player, state)); eventState.setMarriageState(player, EEventState.MARRIAGE_UNDER_CONSIDERATION); } } } }
/** * Dissolve the convoy and return the list of ships of the owner. * @param convoy to be disolved * @param city where the convoy is disolved * @return list of ships that were in the convoy that belong to the convoys owner. */ List<IShip> dissolveConvoy(IConvoy convoy, ICity city) { ArrayList<IShip> shipList = new ArrayList<>(); for (IShip ship : convoy.getShips()) { ship.setAvailable(true); IShipOwner owner = ship.getOwner(); convoy.removeShip(ship); ship.parentShipProperty().setValue(null); if (owner instanceof IHumanPlayer) { DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.display.dialog.sea.ConvoyDialog.convoyDissolveNotification", new Object[]{convoy.getName(), ship.getName(), city.getName()}); TargetedEvent targetMsg = new TargetedEvent((IHumanPlayer) owner, msg); clientServerEventBus.post(targetMsg); } if (owner instanceof IPlayer) { IPlayer player = (IPlayer) owner; player.addSelectableVessel(ship); } if (owner.equals(convoy.getOwner())) { shipList.add(ship); } clientServerEventBus.post(new ShipEntersPortEvent(ship, city)); } return shipList; } }
@Override public void handleShipEntersPort(ShipEntersPortEvent event) { super.handleShipEntersPort(event); LocalDateTime now = date.getCurrentDate(); if (now.isAfter(deadline)) { if (player instanceof IHumanPlayer) { DialogTemplateParameterSupplier parameterSupplier = new DialogTemplateParameterSupplier(new Object[]{getShip().getName(), event.getCity().getName(), clientServerFactory.dateSupplier()}); DialogTemplate template = dialogTemplateFactory.createDialogTemplate(EDialogTemplateType.COURIER_SERVICE_FINISHED_UNSUCCESSFUL, parameterSupplier); DisplayTemplateMessage message = new DisplayTemplateMessage("ch.sahits.game.event.handler.impl.NextCourierPatrolStation.unreliable", template); TargetedEvent tagetDisplayMsg = new TargetedEvent((IHumanPlayer) player, message); clientServerEventBus.post(tagetDisplayMsg); } ((IShip)getShip()).leavePassenger(); clientServerEventBus.unregister(this); } }
clientServerEventBus.post(new ShipEntersPortEvent(vessel, city.get())); if (vessel.getOwner() instanceof IHumanPlayer) { DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.engine.sea.model.ShipPositionUpdateTask.shipArrivedInCity",
private EventHandler<MouseEvent> dissolve(IConvoy vessel, ICity city) { return event -> { try { vessel.getOrlegShip().parentShipProperty().setValue(null); for (IShip ship : vessel.getShips()) { IShipOwner owner = ship.getOwner(); vessel.removeShip(ship); ship.parentShipProperty().setValue(null); if (owner instanceof IHumanPlayer) { DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.display.dialog.sea.ConvoyDialog.convoyDissolveNotification", vessel.getName(), ship.getName(), city.getName()); TargetedEvent targetMsg = new TargetedEvent((IHumanPlayer) owner, msg); // TODO: 12.03.17 why do we have a targeted event here? we can sending it directly, as the user is the target. clientServerEventBus.post(targetMsg); } if (owner instanceof IPlayer) { IPlayer player = (IPlayer) owner; player.addSelectableVessel(ship); } clientServerEventBus.post(new ShipEntersPortEvent(ship, city)); } viewState.getCurrentCityProxy().get().leave(vessel); convoyList.remove(vessel); IPlayer player = viewState.getCurrentCityProxy().get().getPlayer(); player.removeSelectableVessel(vessel); executeOnCloseButtonClicked(); } catch (RuntimeException e) { logger.error("Failed to dissolve convoy", e); } }; }
@Subscribe public void handleShipEntersPort(ShipEntersPortEvent event) { ICity eventCity = event.getCity(); INavigableVessel eventShip = event.getShip(); if ((eventCity.equals(city) || ignoreEventCity()) && eventShip.equals(ship) && eventShip.getOwner().equals(player)) { // avoid changing players if (execute(eventCity)) { clientServerEventBus.unregister(this); } } } /**
void dissolveConvoy(IBlockade blockade, ICity city, ICity blockadedCity) { IConvoy convoy = blockade.getBlockadeConvoy(); for (IShip ship : convoy.getShips()) { ship.setAvailable(true); IShipOwner owner = ship.getOwner(); convoy.removeShip(ship); ship.parentShipProperty().setValue(null); if (owner instanceof IHumanPlayer) { DisplayMessage msg = new DisplayMessage("ch.sahits.game.openpatrician.engine.sea.BlockadeEngine.blockadesissolve", new Object[]{blockadedCity.getName(), ship.getName(), city.getName()}); TargetedEvent targetMsg = new TargetedEvent((IHumanPlayer) owner, msg); clientServerEventBus.post(targetMsg); } if (owner instanceof IPlayer) { IPlayer player = (IPlayer) owner; player.addSelectableVessel(ship); } clientServerEventBus.post(new ShipEntersPortEvent(ship, city)); } }
/** * Handling the event when a ship enters the port. Subclasses are intended to override * this implementation by extension implement the correct logic. * This base implementation provides two points: * <ol> * <li>if the player and city that triggered the event match with the ones listed to by this instance * the ship is set on this instance</li> * <li>Then the {@link #execute()} method is called and if it returns true this instance is unregistered from the * event bus. Otherwise the ship is set to null.</li> * </ol> * @param event for the ship entering the port */ @Subscribe public void handleShipEntersPort(ShipEntersPortEvent event) { if (event.getCity().equals(city) && event.getShip().getOwner().equals(player)) { ship = event.getShip(); if (execute()) { clientServerEventBus.unregister(this); } else { ship = null; } } } /**
public void handleRepairPirateShip(ShipEntersPortEvent event) { if (handlePirateShip(event.getShip())) { // repair the ship or group INavigableVessel vessel = event.getShip(); ICity city = event.getCity(); IShipyard shipyard = city.getCityState().getShipyardState(); if (vessel instanceof IShip) { shipyardEngine.repairPirateShip(shipyard, (IShip) vessel); } else if (vessel instanceof IShipGroup) { shipyardEngine.repair(shipyard, (IShipGroup)vessel); } else { logger.warn("Can only repair pirate ships and pirate ship groups."); } } }
@Subscribe public void handeShipReachesPort(ShipEntersPortEvent event) { ICity city = event.getCity(); final IShipOwner owner = event.getShip().getOwner(); Platform.runLater(() -> { if (owner instanceof IHumanPlayer && owner.equals(viewState.getPlayer())) { List<INavigableVessel> ships = ((IHumanPlayer)owner).findShips(city); if (ships.size() == 1) { drawShipPresenceInCity(city); } } }); }
@Subscribe public void handleShipEntersPort(ShipEntersPortEvent event) { ICity city = event.getCity(); final IShipOwner owner = event.getShip().getOwner(); if (owner instanceof IHumanPlayer && owner.equals(viewState.getPlayer())) { List<INavigableVessel> ships = ((IHumanPlayer)owner).findShips(city); if (ships.size() == 1) { Dimension2D dim = map.getDimension(); scale = 192 / dim.getHeight(); double viewportOffset = imgView.getViewport().getMinX(); Platform.runLater(() -> drawShipPresenceInCity(city, viewportOffset)); if (shouldSwitchToCity(city)) { clientEventBus.post(new SwitchCity(city)); } } } } private boolean shouldSwitchToCity(ICity toCity) {
@Subscribe public void handleBlockadeConvoyReturns(ShipEntersPortEvent event) { // disolve the convoy and remove blockade from blockade state INavigableVessel vessel = event.getShip(); if (vessel instanceof IConvoy) { LocalDateTime now = date.getCurrentDate(); ICity aldermanCity = mapService.getAldermanCity(); for (Entry<ICity, IBlockade> blockadeEntry : blockadeState.entrySet()) { IBlockade blockade = blockadeEntry.getValue(); if (blockade.getEndBlockade().isBefore(now)) { IConvoy convoy = blockade.getBlockadeConvoy(); if (convoy.equals(vessel) && event.getCity().equals(aldermanCity)) { final ICity blockadedCity = blockadeEntry.getKey(); dissolveConvoy(blockade, aldermanCity, blockadedCity); blockadeState.finishBlockade(blockadedCity); IGuild guild = guildList.findGuild(aldermanCity).get(); for (IShip ship : blockade.getShipsToAuction()) { LocalDateTime auctionDate = now.plusDays(10); auctionDate = guildService.cleanUpAuctionAndDetermineAuctionDate(auctionDate, guild); IShipAuction auction = modelFactory.createAnonymousShipAuction(auctionDate, ship.getValue(), ship); guild.getAuctions().add(auction); } return; } } } } }
final INavigableVessel vessel = event.getShip(); final ICity city = event.getCity(); if (!vessel.getLocation().equals(city.getCoordinates())) { logger.warn("The vessel is not in the city, but is moving, this can happen when a new destination is chosen after the ShipPositionUpdate task determined the ship entered the port, but the event was not yet handled."); IAIPlayer player = (IAIPlayer) owner; IProductionConsumptionKnowledge knowlege = player.getProductionAndConsumptionKnowledge(); knowlege.updateKnowledge(event.getCity()); ITradeMissionData missionData = player.getTradeMission(vessel); if (missionData instanceof ISpecialMission) { if (missionData instanceof IBlockadeMission) { handleBlockadeMission(vessel, player, event.getCity()); } else { throw new IllegalStateException("The special mission "+missionData+" is not implemented");