/** * Ship has reached it's destination, select a new one. * @param event ship arrives at destination */ @Subscribe public void handleShipReachesDestination(ShipArrivesAtDestinationEvent event) { INavigableVessel vessel = event.getShip(); if (handlePirateShip(vessel)) { int damageInv = vessel.getDamage(); if (damageInv < 20) { selectDestination((ISeaPirate) vessel.getOwner()); } else { sendForRepairs(vessel); } } } /** * Select a new destination for the pirate.
int nbBigWeapons = slotCount.getNbLargeSlots()/3; int nbSmallWeapons = (slotCount.getNbLargeSlots()*2 + slotCount.getNbSmallSlots())/(2 * 3); EWeapon bigWeaponType = getBigWeaponType(); EWeapon smallWeaponType = getSmallWeaponType(); for (int i = 0; i < nbBigWeapons; i++) { shipService.placeWeapon(bigWeaponType, ship);
/** * Handle the event for the finished repair. * @param event repair has finished */ @Subscribe public void handleRepairFinished(RepairFinishedEvent event) { if (handlePirateShip(event.getShip())) { INavigableVessel vessel = event.getShip(); Point2D destination = mapService.getRandomPointAtSeaNear(vessel.getLocation()); seafaringService.travelFromCity(vessel, destination); vessel.togglePirateFlag(); } }
/** * Periodically check if there is a free pirate and if not, create one. * @param event weekly update */ @Subscribe public void handleWeeklyUpdate(PeriodicalTimeWeekEndUpdate event) { // Check if there is a free pirate and if not spawn a new one if (piratesState.getFreePirates().isEmpty()) { IShip ship = createInitialPiratesShip(); String name = firstNameLoader.getRandomName()+" "+lastNameLoader.getRandomName(); ISeaPirate pirate = peopleFactory.createNewPirate(name, ship); ship.setOwner(pirate); piratesState.add(pirate); } } /**
/** * Handle the even when a new pirate becomes available. * @param pirateEvent new pirate emerged */ @Subscribe public void handleNewPirate(NewPirateEvent pirateEvent) { IShip ship = (IShip) pirateEvent.getPirate().getShip(); Point2D adjustedSource = aStarHeuristicProvider.findClosest(ship.getLocation()); ship.setLocation(adjustedSource); selectDestination(pirateEvent.getPirate()); }
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."); } } }
public void handleShipPositionUpdate(ShipPositionUpdateEvent event) { INavigableVessel vessel = event.getShip(); if (handlePirateShip(vessel)) {