@Subscribe public void handleShipBreaksBlockade(ShipNearingPortEvent event) { ICity city = event.getCity(); for (Entry<ICity, IBlockade> entry : blockadeState.entrySet()) { if (entry.getKey().equals(city)) { IConvoy blocadingConvoy = entry.getValue().getBlockadeConvoy(); INavigableVessel blockadeBreaker = event.getShip(); BlockadeSeafightContext context = new BlockadeSeafightContext(entry.getValue()); IPlayer owner = (IPlayer) blockadeBreaker.getOwner(); owner.updateCrimialDrive(1); seafightService.calculateOutcome(blocadingConvoy, blockadeBreaker, context); entry.getValue().getShipsToAuction().addAll(context.getCapturedShips()); } } } @Subscribe
@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; } } } } }
IBlockade blockade = blockadeEntry.getValue(); ICity blockadeCity = blockadeEntry.getKey(); if (blockade.getAssemblyDate().isBefore(now) && blockade.getBlockadeConvoy() == null) { IConvoy convoy = blockade.getBlockadeConvoy(); seafaringService.travelBetweenCities(convoy, blockadeCity); } else { if (blockade.getEndBlockade().isBefore(now) && blockade.getBlockadeConvoy() != null && blockade.getBlockadeConvoy().getLocation().equals(blockadeCity.getCoordinates())) { ICity returnTo = mapService.getAldermanCity(); seafaringService.travelBetweenCities(blockade.getBlockadeConvoy(), returnTo);
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)); } }