@DependentInitialisation(value=ch.sahits.game.openpatrician.util.StartNewGameBean.class) public class SeaFightService extends Object
calculateOutcome(List, List). 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 static int |
DAMAGE_PER_STRENGTH |
private static double |
DEATH_TOLL_PER_DAMAGE |
private Random |
rnd |
private ch.sahits.game.openpatrician.model.ship.ShipFactory |
shipFactory |
private ch.sahits.game.openpatrician.model.service.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) |
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(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips,
List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips)
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) |
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.IShip ship)
Create a list of ships from a single ship that is neither a
IConvoy
or IShipGroup. |
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) |
(package private) void |
postMessage(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.
|
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) |
(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) |
private static final int DAMAGE_PER_STRENGTH
private static final double DEATH_TOLL_PER_DAMAGE
@Autowired private ch.sahits.game.openpatrician.model.service.ShipService shipStrenghtService
@Autowired private ch.sahits.game.openpatrician.model.ship.ShipFactory shipFactory
@Autowired private Random rnd
@Autowired @Qualifier(value="serverClientEventBus") private com.google.common.eventbus.AsyncEventBus clientServerEventBus
public void calculateOutcome(List<ch.sahits.game.openpatrician.model.ship.IShip> attackingShips, List<ch.sahits.game.openpatrician.model.ship.IShip> defendingShips)
attackingShips - list of attacking ships.defendingShips - list of defending ships.void postMessage(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)
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)
private void addToFleet(ch.sahits.game.openpatrician.model.ship.IShip ship,
ch.sahits.game.openpatrician.model.people.IShipOwner owner)
private 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)
public 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.IShipGroup group)
group - of shipspublic 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-2016 Sahits GmbH. All Rights Reserved.