/** * Recieve the event from the event bus and delegate it. * @param event shipyard order refit */ @Subscribe public void handleORderRefit(ShipyardOrderRefit event) { refit(event.getShipyard(), event.getShip(), event.getUpgradeLevel(), event.getProxy()); } @VisibleForTesting
/** * Recieve the event from the event bus and delegate it. * @param event shipyard order build */ @Subscribe public void handleOrderBuildEvent(ShipyardOrderBuild event) { orderShipBuilding(event.getShipyard(), event.getShipType(), event.getOwner()); }
/** * Recieve the event from the event bus and delegate it. * @param event shipyard order repair */ @Subscribe public void handleOrderRepair(ShipyardOrderRepair event) { repair(event.getShipyard(), event.getShip(), event.getProxy()); } /**
@VisibleForTesting void postAttackOutcome(List<IShip> attackingShips, List<IShip> defendingShips, List<IShip> defeatedDefendingShips, List<IShip> defeatedAttackingShips, INavigableVessel attackingVessel, INavigableVessel defendingVessel) { if (defendingShips.size() == defeatedDefendingShips.size()) { clientServerEventBus.post(new ShipAttackEvent(defendingVessel, attackingVessel)); if (attackingVessel.getPirateFlag()) { IShipOwner owner = attackingVessel.getOwner(); String name = owner.getName() + " " + owner.getLastName(); String titleKey = "ch.sahits.game.openpatrician.engine.sea.SeaFightService.eventvideo.title"; Object[] titleParams = new Object[]{}; DisplayEventVideo event = DisplayEventVideo.builder() .mediaType(EEventMediaType.PIRATE_ATTACK) .durationInSeconds(23) .titleKey(titleKey) .titleParams(titleParams) .descriptionKey("ch.sahits.game.openpatrician.engine.sea.SeaFightService.eventvideo.message") .descriptionParams(new Object[]{name}) .build(); for (IPlayer player : players ) { if (player instanceof IHumanPlayer) { clientServerEventBus.post(new TargetedEvent((IHumanPlayer) player, event)); } } } } if (attackingShips.size() == defeatedAttackingShips.size()) { clientServerEventBus.post(new ShipDefenseEvent(defendingVessel, attackingVessel)); } }
@Subscribe public void handleBid(AuctionBid bid) { Preconditions.checkArgument(!bid.getBidder().equals(bid.getAuction().getBiddingPlayer()), "The bidder has to change"); IAuction auction = bid.getAuction(); auction.getCurrentTask().cancel(); auction.setBidLevel(EBidLevel.INITIAL); auction.setBiddingPlayer(bid.getBidder()); auction.setCurrentBid(bid.getAmount()); clientServerEventBus.post(new AuctionBidLevel(auction.getBidLevel(), EBidLevel.INITIAL, bid.getBidder(), auction)); CancelableRunnable task = factory.createNextBidTask(auction); auction.setCurrentTask(task); timer.schedule(task, 30, TimeUnit.SECONDS); }
@Subscribe public void handlePirateDefeated(ShipAttackEvent event) { INavigableVessel vessel = event.getAttackedShip(); INavigableVessel attackingShip = event.getAttackingShip(); updateReputationDueToPirateDefeat(vessel, attackingShip); } @Subscribe
private void handleNewGame(NewGame newGameDTO) { PropertyInitializer propInit = serverContext.getBean(PropertyInitializer.class); propInit.setKeySuffix(newGameDTO.getDifficulty().getLevel()); serverContext.getBean("dependentPropertyInitializer"); // Force initialisation IHumanPlayer player = startupGameEnvironment(newGameDTO); // todo: andi 18/01/14: notify the client so the GameStatus can be updated NewGameClient newGameClientDTO = NewGameClient.builder().player(player).build(); clientServerEventBus.post(new ResumeGame()); clientServerEventBus.post(newGameClientDTO); }
@Subscribe public void handleBuildingAuctionFinished(BuildingAuctionFinished event) { if (event.getNewOwner() instanceof IAIPlayer) { event.getBuilding().setOwner(event.getNewOwner()); } } @Subscribe
@Subscribe public void handlePirateDefeated(ShipDefenseEvent event) { INavigableVessel playerVessel = event.getAttackedShip(); INavigableVessel attackingShip = event.getAttackingShip(); updateReputationDueToPirateDefeat(attackingShip, playerVessel); }
@Subscribe public void handleShipReachesDestination(ShipArrivesAtDestinationEvent event) { INavigableVessel vessel = event.getShip(); vessels.remove(vessel); } }
@Subscribe public void handleShipAttack(ShipAttackEvent event) { if (event.getAttackedShip().equals(ship)) { state.incAttackCounter(); } } }
@Override public void run() { if (run) { if (auction instanceof IShipAuction) { if (auction.getOwner().isPresent()) { IShipAuction shipAuction = (IShipAuction) auction; clientServerEventBus.post(new ShipNotAuctioned(shipAuction.getAuctionedShip(), shipAuction.getOwner().get())); } } else { IBuildingAuction buildingAuction = (IBuildingAuction) auction; clientServerEventBus.post(new BuildingNotAuctioned(buildingAuction.getAuctionedBuilding(), buildingAuction.getOwner().get())); } } } };
private void switchToCity(ICity city) { clientEventBus.post(new SwitchCity(city)); }
/** * Initialize the player that goes with this client. The player does not change later on, * @param newGameDTO parameter object for the new game client */ @Subscribe public void initializeState(NewGameClient newGameDTO) { final IPlayer player = newGameDTO.getPlayer(); initializeMapImage(player); }
@Subscribe public void handleMapChange(MapUpdateCityAdd event) { initializeMapImage(event.getPlayer()); } @Subscribe
@Subscribe public void handleSwitchToCity(SwitchCity event) { setCity(event.getToCity().getName()); } }
@Override public void run() { if (vessel instanceof IShip) { IShip ship = (IShip) vessel; executeRepair(ship); } else { for (IShip ship : ((IShipGroup)vessel).getShips()) { executeRepair(ship); } } clientServerEventBus.post(new RepairFinishedEvent(vessel)); }