Skip to content

Commit

Permalink
Ensuring default cash is correct for nobility and status
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed May 24, 2021
1 parent 9c0ba3c commit 6b24b2a
Show file tree
Hide file tree
Showing 75 changed files with 300 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

public class RandomName extends RandomSelector<Name> {

public RandomName(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
public RandomName(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class RandomPlanet extends RandomSelector<Planet> {
private static final int NEUTRAL_PLANET = 8;
private static final int ENEMY_PLANET = 1;

public RandomPlanet(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
public RandomPlanet(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

public class RandomSurname extends RandomSelector<Surname> {

public RandomSurname(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
public RandomSurname(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

public class RandomizeCharacter {
private final CharacterPlayer characterPlayer;
private final Set<IRandomPreference> preferences;
private final Set<IRandomPreference<?>> preferences;
private final Set<AvailableSkill> requiredSkills;
private final Set<AvailableSkill> suggestedSkills;
private final Set<Blessing> mandatoryBlessings;
Expand All @@ -82,7 +82,7 @@ public class RandomizeCharacter {
private final Faction requiredFaction;
private final Race requiredRace;

public RandomizeCharacter(CharacterPlayer characterPlayer, int experiencePoints, IRandomPreference... preferences) {
public RandomizeCharacter(CharacterPlayer characterPlayer, int experiencePoints, IRandomPreference<?>... preferences) {
this(characterPlayer, experiencePoints, null, new HashSet<>(Arrays.asList(preferences)), new HashSet<>(), new HashSet<>(),
new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(),
new HashSet<>(), new HashSet<>(), new HashSet<>());
Expand All @@ -94,13 +94,13 @@ public RandomizeCharacter(CharacterPlayer characterPlayer, IRandomPredefined...
new HashSet<>(), new HashSet<>(), new HashSet<>());
}

public RandomizeCharacter(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences, IRandomPredefined... profiles) {
public RandomizeCharacter(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences, IRandomPredefined... profiles) {
this(characterPlayer, null, new HashSet<>(Arrays.asList(profiles)), preferences, new HashSet<>(), new HashSet<>(),
new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(),
new HashSet<>(), new HashSet<>(), new HashSet<>());
}

public RandomizeCharacter(CharacterPlayer characterPlayer, Integer experiencePoints, Set<IRandomPredefined> profiles, Set<IRandomPreference> preferences,
public RandomizeCharacter(CharacterPlayer characterPlayer, Integer experiencePoints, Set<IRandomPredefined> profiles, Set<IRandomPreference<?>> preferences,
Set<AvailableSkill> requiredSkills, Set<AvailableSkill> suggestedSkills,
Set<Blessing> mandatoryBlessings, Set<Blessing> suggestedBlessings,
Set<BeneficeDefinition> mandatoryBenefices, Set<BeneficeDefinition> suggestedBenefices,
Expand Down Expand Up @@ -193,7 +193,7 @@ public void createCharacter() throws InvalidXmlElementException, InvalidRandomEl
setExperiencePoints();
}

private void setDefaultPreferences() {
public void setDefaultPreferences() {
final AgePreferences agePreferences = AgePreferences.getSelected(preferences);
if (agePreferences == null) {
preferences.add(AgePreferences.getDefaultOption());
Expand Down Expand Up @@ -241,11 +241,22 @@ private void setDefaultPreferences() {

final CashPreferences cashPreferences = CashPreferences.getSelected(preferences);
if (cashPreferences == null) {
//Faction and status also change the cash amount.
final CashPreferences factionCashPreference = CashPreferences.get(FactionPreferences.getSelected(preferences));
final CashPreferences statusCashPreference = CashPreferences.get(StatusPreferences.getSelected(preferences));

//Equipment minimum cash.
final AtomicReference<Float> equipmentCost = new AtomicReference<>((float) 0);
mandatoryWeapons.forEach(weapon -> equipmentCost.updateAndGet(v -> (v + weapon.getCost())));
mandatoryArmours.forEach(armour -> equipmentCost.updateAndGet(v -> (v + armour.getCost())));
mandatoryShields.forEach(shield -> equipmentCost.updateAndGet(v -> (v + shield.getCost())));
preferences.add(CashPreferences.get(equipmentCost.get()));
final CashPreferences equipmentCostPreference = CashPreferences.get(equipmentCost.get());

//Select higher value.
final List<IRandomPreference> list = Arrays.asList(factionCashPreference,
statusCashPreference, equipmentCostPreference);
final Optional<IRandomPreference> cashSelected = list.stream().filter(Objects::nonNull).max(Comparator.naturalOrder());
cashSelected.ifPresent(preferences::add);
}
preferences.removeIf(Objects::isNull);
}
Expand Down Expand Up @@ -450,4 +461,8 @@ private void setExperiencePoints() throws InvalidXmlElementException, Restricted
public String toString() {
return characterPlayer.getCompleteNameRepresentation() + " (" + characterPlayer.getRace() + ") [" + characterPlayer.getFaction() + "]";
}

public Set<IRandomPreference<?>> getPreferences() {
return preferences;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public class RandomBeneficeDefinition extends RandomSelector<BeneficeDefinition>
private Integer totalCombatActions;
private final Set<AvailableBenefice> suggestedAvailableBenefices;

public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
throws InvalidXmlElementException, RestrictedElementException {
this(characterPlayer, preferences, new HashSet<>(), new HashSet<>(), new HashSet<>());
}

public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<BeneficeDefinition> mandatoryBenefices, Set<BeneficeDefinition> suggestedBenefices,
Set<AvailableBenefice> suggestedAvailableBenefices)
throws InvalidXmlElementException, RestrictedElementException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class RandomExtraBeneficeDefinition extends RandomBeneficeDefinition {
private static final int MAX_COMBAT_STYLES = 2;

public RandomExtraBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
public RandomExtraBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<BeneficeDefinition> suggestedBenefices, Set<AvailableBenefice> suggestedAvailableBenefices) throws
InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences, new HashSet<>(), suggestedBenefices, suggestedAvailableBenefices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class RandomBlessingDefinition extends RandomSelector<Blessing> {

public RandomBlessingDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences, Set<Blessing> mandatoryBlessings,
public RandomBlessingDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences, Set<Blessing> mandatoryBlessings,
Set<Blessing> suggestedBlessings) throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, null, preferences, mandatoryBlessings, suggestedBlessings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class RandomCursesDefinition extends RandomSelector<Blessing> {

public RandomCursesDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
public RandomCursesDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RandomCharacteristics extends RandomSelector<Characteristic> {
private static final int MIN_FAITH_FOR_THEURGY = 6;
private static final int MIN_WILL_FOR_PSIQUE = 5;

public RandomCharacteristics(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
public RandomCharacteristics(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<Characteristic> characteristicsMinimumValues) throws InvalidXmlElementException,
RestrictedElementException {
super(characterPlayer, null, preferences, characteristicsMinimumValues, new HashSet<>());
Expand All @@ -54,8 +54,8 @@ public void assign() throws InvalidRandomElementSelectedException {
final SpecializationPreferences selectedSpecialization = SpecializationPreferences
.getSelected(getPreferences());

IRandomPreference techPreference = null;
for (final IRandomPreference preference : getPreferences()) {
IRandomPreference<?> techPreference = null;
for (final IRandomPreference<?> preference : getPreferences()) {
if (preference instanceof TechnologicalPreferences) {
techPreference = preference;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

public class RandomCharacteristicsExperience extends RandomCharacteristics {

public RandomCharacteristicsExperience(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences) throws InvalidXmlElementException,
public RandomCharacteristicsExperience(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences) throws InvalidXmlElementException,
RestrictedElementException {
super(characterPlayer, preferences, new HashSet<>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@

public class RandomCharacteristicsExtraPoints extends RandomCharacteristics {

public RandomCharacteristicsExtraPoints(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences) throws InvalidXmlElementException,
public RandomCharacteristicsExtraPoints(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences) throws InvalidXmlElementException,
RestrictedElementException {
super(characterPlayer, preferences, new HashSet<Characteristic>());
super(characterPlayer, preferences, new HashSet<>());
}

public int spendCharacteristicsPoints(int remainingPoints) throws InvalidRandomElementSelectedException {
final IGaussianDistribution specialization = SpecializationPreferences.getSelected(getPreferences());

IRandomPreference techPreference = null;
for (final IRandomPreference preference : getPreferences()) {
IRandomPreference<?> techPreference = null;
for (final IRandomPreference<?> preference : getPreferences()) {
if (preference instanceof TechnologicalPreferences) {
techPreference = preference;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class RandomCybernetics extends RandomSelector<CyberneticDevice> {
private int totalDevices;
private int desiredCyberneticsPoints;

public RandomCybernetics(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
public RandomCybernetics(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences);
totalDevices = CyberneticTotalDevicesPreferences.getSelected(getPreferences()).randomGaussian();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public abstract class EquipmentSelector<E extends Equipment<?>> extends RandomSelector<E> {
private Integer currentMoney = null;

protected EquipmentSelector(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
protected EquipmentSelector(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<E> mandatoryElements) throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, null, preferences, mandatoryElements, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

public class RandomArmour extends EquipmentSelector<Armour> {

public RandomArmour(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
public RandomArmour(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<Armour> mandatoryArmours) throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences, mandatoryArmours);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class RandomShield extends EquipmentSelector<Shield> {

public RandomShield(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
public RandomShield(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<Shield> mandatoryShields) throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences, mandatoryShields);
}
Expand Down Expand Up @@ -138,13 +138,7 @@ protected void assignMandatoryValues(Set<Shield> mandatoryValues) throws Invalid
// We only assign the most expensive one.
if (!mandatoryValues.isEmpty()) {
final List<Shield> sortedShields = new ArrayList<>(mandatoryValues);
Collections.sort(sortedShields, new Comparator<Shield>() {

@Override
public int compare(Shield shield0, Shield shield1) {
return Float.compare(shield0.getCost(), shield1.getCost());
}
});
sortedShields.sort((shield0, shield1) -> Float.compare(shield0.getCost(), shield1.getCost()));
getCharacterPlayer().setShield(sortedShields.get(0));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

public class RandomMeleeWeapon extends RandomWeapon {

public RandomMeleeWeapon(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
public RandomMeleeWeapon(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<Weapon> mandatoryWeapons) throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences, mandatoryWeapons);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ protected Set<WeaponType> weaponTypesFilter() {

@Override
protected int getWeightCostModificator(Weapon weapon) {
if (weapon.getCost() > getCurrentMoney() / (double) 1.1) {
if (weapon.getCost() > getCurrentMoney() / 1.1) {
return 10;
} else if (weapon.getCost() > getCurrentMoney() / (double) 2) {
return 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

public class RandomRangeWeapon extends RandomWeapon {

public RandomRangeWeapon(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
public RandomRangeWeapon(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<Weapon> mandatoryWeapons) throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences, mandatoryWeapons);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ protected Set<WeaponType> weaponTypesFilter() {

@Override
protected int getWeightCostModificator(Weapon weapon) {
if (weapon.getCost() > getCurrentMoney() / (double) 1.1) {
if (weapon.getCost() > getCurrentMoney() / 1.1) {
return 100;
} else if (weapon.getCost() > getCurrentMoney() / (double) 2) {
return 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

public abstract class RandomWeapon extends EquipmentSelector<Weapon> {

protected RandomWeapon(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
protected RandomWeapon(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
Set<Weapon> mandatoryWeapons) throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences, mandatoryWeapons);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class RandomFaction extends RandomSelector<Faction> {

public RandomFaction(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences) throws InvalidXmlElementException,
public RandomFaction(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences) throws InvalidXmlElementException,
RestrictedElementException {
super(characterPlayer, preferences);
}
Expand Down Expand Up @@ -67,17 +67,16 @@ protected int getWeight(Faction faction) throws InvalidRandomElementSelectedExce
// Specialization desired.
final FactionPreferences selectedFactionGroup = FactionPreferences.getSelected(getPreferences());
if (selectedFactionGroup != null) {
if (faction.getFactionGroup() != null && faction.getFactionGroup().name().equalsIgnoreCase(selectedFactionGroup.name())) {
return 1;
if (faction.getFactionGroup() != null && !faction.getFactionGroup().name().equalsIgnoreCase(selectedFactionGroup.name())) {
// Different faction than selected.
throw new InvalidRandomElementSelectedException("Faction '" + faction + "' not in preferences selection '" + selectedFactionGroup + "'.");
}
} else
// No faction preference selected. Xeno factions has preferences by its own factions.
if (getCharacterPlayer().getRace().isXeno() && faction.getRestrictedToRaces().size() == 1 &&
faction.getRestrictedToRaces().contains(getCharacterPlayer().getRace())) {
return 100;
}
// Different faction than selected.
throw new InvalidRandomElementSelectedException("Faction '" + faction + "' not in preferences selection '" + selectedFactionGroup + "'.");
}
// No faction preference selected. Xeno factions has preferences by its own factions.
if (getCharacterPlayer().getRace().isXeno() && faction.getRestrictedToRaces().size() == 1 &&
faction.getRestrictedToRaces().contains(getCharacterPlayer().getRace())) {
return 100;
}
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

public class RandomPsique extends RandomSelector<OccultismType> {

public RandomPsique(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
public RandomPsique(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, preferences);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class RandomPsiquePath extends RandomSelector<OccultismPath> {

private int totalPowers;

public RandomPsiquePath(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences, Set<OccultismPath> mandatoryOccultismPaths)
public RandomPsiquePath(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences, Set<OccultismPath> mandatoryOccultismPaths)
throws InvalidXmlElementException, RestrictedElementException {
super(characterPlayer, null, preferences, mandatoryOccultismPaths, new HashSet<>());
}
Expand Down
Loading

0 comments on commit 6b24b2a

Please sign in to comment.