@Subscribe public void handleShipEntersPort(ShipEntersPortEvent event) { if (getCity().equals(event.getCity()) ) { arrive(event.getShip()); } } @Subscribe
@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); } } } /**
/** * 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; } } } /**
@Subscribe public void handleShipArrival(ShipEntersPortEvent event) { INavigableVessel vessel = event.getShip(); ICity city = event.getCity(); city.getCityState().getPopUpdateStatistic().arrives(vessel); }
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 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; } } } } }
/** * 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); } } } }
@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) {
final INavigableVessel vessel = event.getShip(); final ICity city = event.getCity(); if (!vessel.getLocation().equals(city.getCoordinates())) {