@DependentInitialisation(value=ch.sahits.game.openpatrician.util.StartNewGameBean.class) public class SeaFightService extends Object
calculateOutcome(INavigableVessel, INavigableVessel, SeaFightContext). There are helper methods explodeShipList
to convert the IShips to the required List of ships. There are further helper methods to collect the ships
lists again after the fight.| Modifier and Type | Field and Description |
|---|---|
private com.google.common.eventbus.AsyncEventBus |
clientServerEventBus |
private org.springframework.context.ApplicationContext |
context |
private double |
damagePerStrength |
private double |
deathTollPerDamage |
private org.apache.logging.log4j.Logger |
logger |
private ch.sahits.game.openpatrician.model.people.impl.SeaPiratesState |
piratesState |
private ch.sahits.game.openpatrician.util.spring.DependentPropertyInitializer |
propertyInitializer |
private Random |
rnd |
private ShipFactory |
shipFactory |
private ShipService |
shipStrenghtService |
| Constructor and Description |
|---|
SeaFightService() |
| Modifier and Type | Method and Description |
|---|---|
private void |
addPairing(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips,
List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairings,
int i) |
(package private) void |
addToFleet(ch.sahits.game.openpatrician.model.ship.IShip ship,
ch.sahits.game.openpatrician.model.people.IShipOwner owner) |
(package private) double |
calculateAccuracy(List<ch.sahits.game.openpatrician.model.ship.IShip> shipsOnTurn) |
(package private) int |
calculateAgility(ch.sahits.game.openpatrician.model.ship.IShip ship) |
private int |
calculateAgility(List<ch.sahits.game.openpatrician.model.ship.IShip> ships) |
(package private) int |
calculateDamage(int strength,
double accuracy,
double evasionProbability) |
(package private) int |
calculateDeathToll(List<ch.sahits.game.openpatrician.model.ship.IShip> shipsNotOnTurn,
int damage) |
(package private) double |
calculateEvasionProbability(int attackingAgility,
int defendingAgility) |
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.
|
(package private) List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> |
calculatePairing(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips) |
(package private) int |
calculateShipStrength(ch.sahits.game.openpatrician.model.ship.IShip ship) |
private int |
calculateStrength(List<ch.sahits.game.openpatrician.model.ship.IShip> ships) |
(package private) int |
captureShip(ch.sahits.game.openpatrician.model.ship.IShip attackingShip,
ch.sahits.game.openpatrician.model.ship.IShip defendingShip) |
private List<ch.sahits.game.openpatrician.model.ship.IShip> |
explodeShipList(ch.sahits.game.openpatrician.model.ship.IConvoy convoy)
Create a list of ships from a
IConvoy. |
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.
|
private List<ch.sahits.game.openpatrician.model.ship.IShip> |
explodeShipList(ch.sahits.game.openpatrician.model.ship.IShip ship)
Create a list of ships from a single ship that is neither a
IConvoy
or IShipGroup. |
private List<ch.sahits.game.openpatrician.model.ship.IShip> |
explodeShipList(ch.sahits.game.openpatrician.model.ship.IShipGroup group)
Create a list of ships from a group of ships.
|
(package private) ch.sahits.game.openpatrician.model.ship.IShip |
findMaxSailorsOnShip(List<ch.sahits.game.openpatrician.model.ship.IShip> ships) |
(package private) ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>> |
findWeakest(List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> parings,
boolean lookInAttackingShips) |
private String |
getNameOfSingleLostShip(List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips) |
(package private) StringBuffer |
getShipNameListWithoutTheLastShip(List<ch.sahits.game.openpatrician.model.ship.IShip> shipList) |
private void |
init() |
(package private) void |
postAttackOutcome(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defeatedDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defeatedAttackingShips,
ch.sahits.game.openpatrician.model.ship.INavigableVessel attackingVessel,
ch.sahits.game.openpatrician.model.ship.INavigableVessel defendingVessel) |
(package private) void |
postMessageBlockadeFight(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips,
ch.sahits.game.openpatrician.model.people.IShipOwner attacker,
ch.sahits.game.openpatrician.model.people.IShipOwner defender) |
(package private) void |
postMessageStandardFight(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips,
ch.sahits.game.openpatrician.model.people.IShipOwner attacker,
ch.sahits.game.openpatrician.model.people.IShipOwner defender) |
private void |
redistributeShips(List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairings,
boolean attackShipTurn,
List<ch.sahits.game.openpatrician.model.ship.IShip> survivingShips) |
ch.sahits.game.openpatrician.model.ship.IConvoy |
regroup(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.IShipGroup |
regroup(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.
|
(package private) void |
removeFromFleet(ch.sahits.game.openpatrician.model.ship.IShip ship,
ch.sahits.game.openpatrician.model.people.IShipOwner owner) |
private void |
runAttackMove(List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairings,
List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips,
Iterator<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairingIter,
ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>> pairing,
boolean attackShipTurn,
SeaFightContext context) |
(package private) void |
updateCapturedShip(List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips,
boolean attackShipTurn,
ch.sahits.game.openpatrician.model.ship.IShip shipWithMaxSailors,
ch.sahits.game.openpatrician.model.ship.IShip captureShip,
SeaFightContext context) |
private void |
updateCapturedShipInternal(List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips,
boolean attackShipTurn,
ch.sahits.game.openpatrician.model.ship.IShip shipWithMaxSailors,
ch.sahits.game.openpatrician.model.ship.IShip captureShip,
SeaFightContext context) |
private final org.apache.logging.log4j.Logger logger
@DependentValue(value="seafight.damage.per.strength") private double damagePerStrength
@DependentValue(value="seafight.death.toll.per.damage") private double deathTollPerDamage
@Autowired private ShipService shipStrenghtService
@Autowired private ShipFactory shipFactory
@Autowired private Random rnd
@Autowired @Qualifier(value="serverClientEventBus") private com.google.common.eventbus.AsyncEventBus clientServerEventBus
@Autowired private org.springframework.context.ApplicationContext context
@Autowired private ch.sahits.game.openpatrician.model.people.impl.SeaPiratesState piratesState
@Autowired private ch.sahits.game.openpatrician.util.spring.DependentPropertyInitializer propertyInitializer
@PostConstruct private void init()
public void calculateOutcome(ch.sahits.game.openpatrician.model.ship.INavigableVessel attackingVessel,
ch.sahits.game.openpatrician.model.ship.INavigableVessel defendingVessel,
SeaFightContext context)
attackingVessel - attacking vessel.defendingVessel - defending vessel.void postAttackOutcome(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defeatedDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defeatedAttackingShips, ch.sahits.game.openpatrician.model.ship.INavigableVessel attackingVessel, ch.sahits.game.openpatrician.model.ship.INavigableVessel defendingVessel)
void postMessageBlockadeFight(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips, ch.sahits.game.openpatrician.model.people.IShipOwner attacker, ch.sahits.game.openpatrician.model.people.IShipOwner defender)
void postMessageStandardFight(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips, ch.sahits.game.openpatrician.model.people.IShipOwner attacker, ch.sahits.game.openpatrician.model.people.IShipOwner defender)
StringBuffer getShipNameListWithoutTheLastShip(List<ch.sahits.game.openpatrician.model.ship.IShip> shipList)
private String getNameOfSingleLostShip(List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips)
private void runAttackMove(List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairings, List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> sunkenAttackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips, Iterator<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairingIter, ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>> pairing, boolean attackShipTurn, SeaFightContext context)
private void redistributeShips(List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairings, boolean attackShipTurn, List<ch.sahits.game.openpatrician.model.ship.IShip> survivingShips)
void updateCapturedShip(List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips, boolean attackShipTurn, ch.sahits.game.openpatrician.model.ship.IShip shipWithMaxSailors, ch.sahits.game.openpatrician.model.ship.IShip captureShip, SeaFightContext context)
private void updateCapturedShipInternal(List<ch.sahits.game.openpatrician.model.ship.IShip> capturedDefendingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> capturedAttackingShips, boolean attackShipTurn, ch.sahits.game.openpatrician.model.ship.IShip shipWithMaxSailors, ch.sahits.game.openpatrician.model.ship.IShip captureShip, SeaFightContext context)
void addToFleet(ch.sahits.game.openpatrician.model.ship.IShip ship,
ch.sahits.game.openpatrician.model.people.IShipOwner owner)
void removeFromFleet(ch.sahits.game.openpatrician.model.ship.IShip ship,
ch.sahits.game.openpatrician.model.people.IShipOwner owner)
int captureShip(ch.sahits.game.openpatrician.model.ship.IShip attackingShip,
ch.sahits.game.openpatrician.model.ship.IShip defendingShip)
ch.sahits.game.openpatrician.model.ship.IShip findMaxSailorsOnShip(List<ch.sahits.game.openpatrician.model.ship.IShip> ships)
int calculateDeathToll(List<ch.sahits.game.openpatrician.model.ship.IShip> shipsNotOnTurn, int damage)
int calculateDamage(int strength,
double accuracy,
double evasionProbability)
double calculateAccuracy(List<ch.sahits.game.openpatrician.model.ship.IShip> shipsOnTurn)
double calculateEvasionProbability(int attackingAgility,
int defendingAgility)
private int calculateAgility(List<ch.sahits.game.openpatrician.model.ship.IShip> ships)
int calculateAgility(ch.sahits.game.openpatrician.model.ship.IShip ship)
List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> calculatePairing(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips)
ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>> findWeakest(List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> parings, boolean lookInAttackingShips)
private int calculateStrength(List<ch.sahits.game.openpatrician.model.ship.IShip> ships)
int calculateShipStrength(ch.sahits.game.openpatrician.model.ship.IShip ship)
private void addPairing(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips, List<ch.sahits.datastructure.GenericPair<List<ch.sahits.game.openpatrician.model.ship.IShip>,List<ch.sahits.game.openpatrician.model.ship.IShip>>> pairings, int i)
private List<ch.sahits.game.openpatrician.model.ship.IShip> explodeShipList(ch.sahits.game.openpatrician.model.ship.IConvoy convoy)
IConvoy.convoy - representing a number of shipspublic List<ch.sahits.game.openpatrician.model.ship.IShip> explodeShipList(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
vessel - input vessel of type IConvoy, IShipGroup or simple IShipprivate List<ch.sahits.game.openpatrician.model.ship.IShip> explodeShipList(ch.sahits.game.openpatrician.model.ship.IShipGroup group)
group - of shipsprivate List<ch.sahits.game.openpatrician.model.ship.IShip> explodeShipList(ch.sahits.game.openpatrician.model.ship.IShip ship)
IConvoy
or IShipGroup.ship - single shippublic ch.sahits.game.openpatrician.model.ship.IShipGroup regroup(List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IShipGroup oldGroup)
ships - List of shipsoldGroup - previous group of ships to be updated, may be null.oldGroup or a new instance containing the ships of the listpublic ch.sahits.game.openpatrician.model.ship.IConvoy regroup(List<ch.sahits.game.openpatrician.model.ship.IShip> ships, ch.sahits.game.openpatrician.model.ship.IConvoy oldConvoy)
ships - List of shipsoldConvoy - previous convoy that is to be updated.oldConvoy.Copyright © 2011-2017 Sahits GmbH. All Rights Reserved.