Class PirateEngine
- java.lang.Object
-
- ch.sahits.game.openpatrician.engine.AbstractEngine
-
- ch.sahits.game.openpatrician.engine.sea.PirateEngine
-
@Lazy @Service @DependentInitialisation(StartNewGameBean.class) public class PirateEngine extends AbstractEngine
Engine governing all pirates.- Author:
- Andi Hotz, (c) Sahits GmbH, 2013 Created on Jan 29, 2013
-
-
Field Summary
Fields Modifier and Type Field Description private AStarHeuristicProvider
aStarHeuristicProvider
private MapService
cityService
private com.google.common.eventbus.AsyncEventBus
clientServerEventBus
private Date
date
private static RandomNameLoader
firstNameLoader
private boolean
graphInitialized
private static RandomNameLoader
lastNameLoader
private LocationTracker
locationTracker
private IMapImageServiceFacade
mapService
private PeopleFactory
peopleFactory
private SeaPiratesState
piratesState
private java.util.Random
rnd
private java.util.concurrent.ScheduledExecutorService
schedulableServerThreadPool
private SeafaringService
seafaringService
private SeaFightService
seaFightService
private ShipFactory
shipFactory
private static RandomNameLoader
shipLoader
private ShipService
shipService
private ShipyardEngine
shipyardEngine
private com.google.common.eventbus.EventBus
syncServerClientEventBus
private com.google.common.eventbus.AsyncEventBus
timerEventBus
-
Constructor Summary
Constructors Constructor Description PirateEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private IShip
createInitialPiratesShip()
Create a ship for the pirateprivate void
destroy()
private EWeapon
getBigWeaponType()
java.util.List<AbstractEngine>
getChildren()
Any engine may hold various child engines.private EWeapon
getSmallWeaponType()
void
handleNewPirate(NewPirateEvent pirateEvent)
Handle the even when a new pirate becomes available.private boolean
handlePirateShip(INavigableVessel vessel)
Check if the vessel should be handled by this engine.void
handleRepairFinished(RepairFinishedEvent event)
Handle the event for the finished repair.void
handleRepairPirateShip(ShipEntersPortEvent event)
When a pirate ship enters a port it does so for repair.void
handleShipPositionUpdate(ShipPositionUpdateEvent event)
Check if there is a ship near the new position and decide if an attack should be initiated.void
handleShipReachesDestination(ShipArrivesAtDestinationEvent event)
Ship has reached it's destination, select a new one.void
handleWeeklyUpdate(PeriodicalTimeWeekEndUpdate event)
Periodically check if there is a free pirate and if not, create one.private void
initialize()
void
initializedGraph(GraphInitialisationComplete event)
private void
selectDestination(ISeaPirate pirate)
Select a new destination for the pirate.private void
sendForRepairs(INavigableVessel vessel)
Send a vessel to be repaired.
-
-
-
Field Detail
-
rnd
@Autowired private java.util.Random rnd
-
piratesState
@Autowired private SeaPiratesState piratesState
-
locationTracker
@Autowired private LocationTracker locationTracker
-
clientServerEventBus
@Autowired @Qualifier("serverClientEventBus") private com.google.common.eventbus.AsyncEventBus clientServerEventBus
-
timerEventBus
@Autowired @Qualifier("timerEventBus") private com.google.common.eventbus.AsyncEventBus timerEventBus
-
syncServerClientEventBus
@Autowired @Qualifier("syncServerClientEventBus") private com.google.common.eventbus.EventBus syncServerClientEventBus
-
shipFactory
@Autowired private ShipFactory shipFactory
-
mapService
@Autowired private IMapImageServiceFacade mapService
-
seafaringService
@Autowired private SeafaringService seafaringService
-
shipyardEngine
@Autowired private ShipyardEngine shipyardEngine
-
cityService
@Autowired private MapService cityService
-
date
@Autowired private Date date
-
seaFightService
@Autowired private SeaFightService seaFightService
-
peopleFactory
@Autowired private PeopleFactory peopleFactory
-
aStarHeuristicProvider
@Autowired private AStarHeuristicProvider aStarHeuristicProvider
-
schedulableServerThreadPool
@Autowired @Qualifier("schedulableServerThreadPool") private java.util.concurrent.ScheduledExecutorService schedulableServerThreadPool
-
shipService
@Autowired private ShipService shipService
-
graphInitialized
private boolean graphInitialized
-
firstNameLoader
private static RandomNameLoader firstNameLoader
-
lastNameLoader
private static RandomNameLoader lastNameLoader
-
shipLoader
private static RandomNameLoader shipLoader
-
-
Method Detail
-
initialize
@PostConstruct private void initialize()
-
destroy
@PreDestroy private void destroy()
-
getChildren
public java.util.List<AbstractEngine> getChildren()
Description copied from class:AbstractEngine
Any engine may hold various child engines. This is the way to retrieve them. If there are no child engines, return an empty list. Subclasses have to implement this in the proper way.- Specified by:
getChildren
in classAbstractEngine
- Returns:
- list of child engines.
-
initializedGraph
public void initializedGraph(GraphInitialisationComplete event)
-
handleNewPirate
public void handleNewPirate(NewPirateEvent pirateEvent)
Handle the even when a new pirate becomes available.- Parameters:
pirateEvent
- new pirate emerged
-
handleShipReachesDestination
public void handleShipReachesDestination(ShipArrivesAtDestinationEvent event)
Ship has reached it's destination, select a new one.- Parameters:
event
- ship arrives at destination
-
selectDestination
private void selectDestination(ISeaPirate pirate)
Select a new destination for the pirate.- Parameters:
pirate
- free sea pirate
-
handleShipPositionUpdate
public void handleShipPositionUpdate(ShipPositionUpdateEvent event)
Check if there is a ship near the new position and decide if an attack should be initiated.- Parameters:
event
- ship changes position
-
sendForRepairs
private void sendForRepairs(INavigableVessel vessel)
Send a vessel to be repaired.- Parameters:
vessel
- to be repaired
-
handleRepairPirateShip
public void handleRepairPirateShip(ShipEntersPortEvent event)
When a pirate ship enters a port it does so for repair.
-
handleRepairFinished
public void handleRepairFinished(RepairFinishedEvent event)
Handle the event for the finished repair.- Parameters:
event
- repair has finished
-
handleWeeklyUpdate
public void handleWeeklyUpdate(PeriodicalTimeWeekEndUpdate event)
Periodically check if there is a free pirate and if not, create one.- Parameters:
event
- weekly update
-
createInitialPiratesShip
private IShip createInitialPiratesShip()
Create a ship for the pirate- Returns:
- initial pirate ship
-
handlePirateShip
private boolean handlePirateShip(INavigableVessel vessel)
Check if the vessel should be handled by this engine. Only ships with hissed pirate flag that do not belong to a player should be considered.- Parameters:
vessel
- to be checked- Returns:
- true if the vessel is flaged as pirate ship and the owner is not a player.
-
getBigWeaponType
private EWeapon getBigWeaponType()
-
getSmallWeaponType
private EWeapon getSmallWeaponType()
-
-