@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
((BlockadeSeafightContext) context).addCapturedShip(ship);
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); } }