IBlockade blockade = blockadeEntry.getValue(); ICity blockadeCity = blockadeEntry.getKey(); if (blockade.getAssemblyDate().isBefore(now) && blockade.getBlockadeConvoy() == null) { List<IPlayer> players = blockade.getPlayersWithRequestedShips(); for (IPlayer player : players) { ArrayList<IShip> ships = new ArrayList<>(); int requestedNumber = blockade.getNumberOfRequestedShips(player); for (IShip ship : player.getFleet()) { if (ship.getLocation().equals(aldermanCity.getCoordinates())) { blockade.addShips(player, ships); if (blockade.getShips().size() > 0) { createConvoy(blockade, aldermanCity); 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);
@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; } } } } }
@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
void createConvoy(IBlockade blockade, ICity city) { List<IShip> allShips = blockade.getShips(); IConvoy convoy = shipFactory.getConvoy(allShips.get(0), false); for (int i = 1; i < allShips.size(); i++) { IShip ship = allShips.get(i); convoy.addShip(ship); ship.parentShipProperty().setValue(convoy.getOrlegShip()); } for (IShip ship : allShips) { ship.setAvailable(false); IPlayer owner = (IPlayer) ship.getOwner(); if (owner instanceof IHumanPlayer) { clientServerEventBus.post(new TargetedEvent((IHumanPlayer) owner, new ShipBecomesUnavailableEvent(ship, city))); } owner.removeSelectableVessel(ship); } blockade.setConvoy(convoy); } }
private void handleBlockadeMission(INavigableVessel vessel, IAIPlayer player, ICity city) { LocalDateTime now = date.getCurrentDate(); ICity aldermanCity = mapService.getAldermanCity(); if (city.equals(aldermanCity)) { if (blockadeState.entrySet().isEmpty()) { initializeStrategyForVessel(player, vessel); } else { for (Entry<ICity, IBlockade> entry : blockadeState.entrySet()) { IBlockade blockade = entry.getValue(); if (blockade.getAssemblyDate().isBefore(now)) { // Missed assemby date initializeStrategyForVessel(player, vessel); } } } } else { initializeStrategyForVessel(player, vessel); } }
private void updateCapturedShipInternal(List<IShip> capturedDefendingShips, List<IShip> capturedAttackingShips, boolean attackShipTurn, IShip shipWithMaxSailors, IShip captureShip, SeaFightContext context) { final int numberOfSailors = captureShip.getNumberOfSailors(); int halfTheSailors = numberOfSailors /2; captureShip.setNumberOfSailors(numberOfSailors - halfTheSailors); IShipOwner previousOwner = shipWithMaxSailors.getOwner(); removeFromFleet(shipWithMaxSailors, previousOwner); shipWithMaxSailors.setNumberOfSailors(halfTheSailors); shipWithMaxSailors.setOwner(captureShip.getOwner()); if (context.getType() == ESeaFightType.BLOCKADE && attackShipTurn) { IBlockade blockade = ((BlockadeSeafightContext)context).getBlockade(); blockade.getShipsToAuction().add(captureShip); } else { addToFleet(shipWithMaxSailors, captureShip.getOwner()); } if (attackShipTurn) { // shipWithMaxSailors belongs to attacking fleet capturedAttackingShips.add(shipWithMaxSailors); } else { capturedDefendingShips.add(shipWithMaxSailors); } }
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)); } }