Class SeaFightService
- java.lang.Object
-
- ch.sahits.game.openpatrician.engine.sea.SeaFightService
-
@DependentInitialisation(ch.sahits.game.openpatrician.model.initialisation.StartNewGameBean.class) public class SeaFightService extends java.lang.ObjectThe sea fight service helps calculating the winner of a sea fight based on two sets of ships. The central method iscalculateOutcome(INavigableVessel, INavigableVessel, SeaFightContext). There are helper methodsexplodeShipListto convert theIShips to the required List of ships. There are further helper methods to collect the ships lists again after the fight.
The only case the must be handled without the help of a helper method is if a single ship (not a group or convoy) of a player (AI or human) is attacked or defends and is victorious. This might result in a list of ships that should then all travel to the same destination as single ships.- Author:
- Andi Hotz, (c) Sahits GmbH, 2015 Created on Dec 08, 2015
-
-
Constructor Summary
Constructors Constructor Description SeaFightService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcalculateOutcome(ch.sahits.game.openpatrician.model.ship.INavigableVessel attackingVessel, ch.sahits.game.openpatrician.model.ship.INavigableVessel defendingVessel, SeaFightContext context)Calculate the outcome of the fight.java.util.List<ch.sahits.game.openpatrician.model.ship.IShip>explodeShipList(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Convert a vessel into a list of ships.ch.sahits.game.openpatrician.model.ship.IConvoyregroup(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IConvoy oldConvoy)Update the convoy with the ships of the list.ch.sahits.game.openpatrician.model.ship.IShipGroupregroup(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IShipGroup oldGroup)Create a group of ships from the list of ships.
-
-
-
Method Detail
-
calculateOutcome
public void calculateOutcome(ch.sahits.game.openpatrician.model.ship.INavigableVessel attackingVessel, ch.sahits.game.openpatrician.model.ship.INavigableVessel defendingVessel, SeaFightContext context)Calculate the outcome of the fight. This includes damaging, destroying or capturing ships from either list.- Parameters:
attackingVessel- attacking vessel.defendingVessel- defending vessel.
-
explodeShipList
public java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> explodeShipList(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
Convert a vessel into a list of ships.- Parameters:
vessel- input vessel of type IConvoy, IShipGroup or simple IShip- Returns:
- List of type IShip
-
regroup
public ch.sahits.game.openpatrician.model.ship.IShipGroup regroup(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IShipGroup oldGroup)Create a group of ships from the list of ships. As there might have been a group before the fight, this group should be updated with the current ship list. If there was no group, a new group will be created.- Parameters:
ships- List of shipsoldGroup- previous group of ships to be updated, may be null.- Returns:
- Updated
oldGroupor a new instance containing the ships of the list
-
regroup
public ch.sahits.game.openpatrician.model.ship.IConvoy regroup(java.util.List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IConvoy oldConvoy)Update the convoy with the ships of the list.- Parameters:
ships- List of shipsoldConvoy- previous convoy that is to be updated.- Returns:
- Updated
oldConvoy.
-
-