Skip to content

Commit 6b24b2a

Browse files
Ensuring default cash is correct for nobility and status
1 parent 9c0ba3c commit 6b24b2a

File tree

75 files changed

+300
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+300
-239
lines changed

think-machine-random/src/main/java/com/softwaremagico/tm/character/RandomName.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public class RandomName extends RandomSelector<Name> {
4242

43-
public RandomName(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
43+
public RandomName(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
4444
throws InvalidXmlElementException, RestrictedElementException {
4545
super(characterPlayer, preferences);
4646
}

think-machine-random/src/main/java/com/softwaremagico/tm/character/RandomPlanet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class RandomPlanet extends RandomSelector<Planet> {
4141
private static final int NEUTRAL_PLANET = 8;
4242
private static final int ENEMY_PLANET = 1;
4343

44-
public RandomPlanet(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
44+
public RandomPlanet(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
4545
throws InvalidXmlElementException, RestrictedElementException {
4646
super(characterPlayer, preferences);
4747
}

think-machine-random/src/main/java/com/softwaremagico/tm/character/RandomSurname.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public class RandomSurname extends RandomSelector<Surname> {
4242

43-
public RandomSurname(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
43+
public RandomSurname(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
4444
throws InvalidXmlElementException, RestrictedElementException {
4545
super(characterPlayer, preferences);
4646
}

think-machine-random/src/main/java/com/softwaremagico/tm/character/RandomizeCharacter.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
public class RandomizeCharacter {
6868
private final CharacterPlayer characterPlayer;
69-
private final Set<IRandomPreference> preferences;
69+
private final Set<IRandomPreference<?>> preferences;
7070
private final Set<AvailableSkill> requiredSkills;
7171
private final Set<AvailableSkill> suggestedSkills;
7272
private final Set<Blessing> mandatoryBlessings;
@@ -82,7 +82,7 @@ public class RandomizeCharacter {
8282
private final Faction requiredFaction;
8383
private final Race requiredRace;
8484

85-
public RandomizeCharacter(CharacterPlayer characterPlayer, int experiencePoints, IRandomPreference... preferences) {
85+
public RandomizeCharacter(CharacterPlayer characterPlayer, int experiencePoints, IRandomPreference<?>... preferences) {
8686
this(characterPlayer, experiencePoints, null, new HashSet<>(Arrays.asList(preferences)), new HashSet<>(), new HashSet<>(),
8787
new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(),
8888
new HashSet<>(), new HashSet<>(), new HashSet<>());
@@ -94,13 +94,13 @@ public RandomizeCharacter(CharacterPlayer characterPlayer, IRandomPredefined...
9494
new HashSet<>(), new HashSet<>(), new HashSet<>());
9595
}
9696

97-
public RandomizeCharacter(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences, IRandomPredefined... profiles) {
97+
public RandomizeCharacter(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences, IRandomPredefined... profiles) {
9898
this(characterPlayer, null, new HashSet<>(Arrays.asList(profiles)), preferences, new HashSet<>(), new HashSet<>(),
9999
new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>(),
100100
new HashSet<>(), new HashSet<>(), new HashSet<>());
101101
}
102102

103-
public RandomizeCharacter(CharacterPlayer characterPlayer, Integer experiencePoints, Set<IRandomPredefined> profiles, Set<IRandomPreference> preferences,
103+
public RandomizeCharacter(CharacterPlayer characterPlayer, Integer experiencePoints, Set<IRandomPredefined> profiles, Set<IRandomPreference<?>> preferences,
104104
Set<AvailableSkill> requiredSkills, Set<AvailableSkill> suggestedSkills,
105105
Set<Blessing> mandatoryBlessings, Set<Blessing> suggestedBlessings,
106106
Set<BeneficeDefinition> mandatoryBenefices, Set<BeneficeDefinition> suggestedBenefices,
@@ -193,7 +193,7 @@ public void createCharacter() throws InvalidXmlElementException, InvalidRandomEl
193193
setExperiencePoints();
194194
}
195195

196-
private void setDefaultPreferences() {
196+
public void setDefaultPreferences() {
197197
final AgePreferences agePreferences = AgePreferences.getSelected(preferences);
198198
if (agePreferences == null) {
199199
preferences.add(AgePreferences.getDefaultOption());
@@ -241,11 +241,22 @@ private void setDefaultPreferences() {
241241

242242
final CashPreferences cashPreferences = CashPreferences.getSelected(preferences);
243243
if (cashPreferences == null) {
244+
//Faction and status also change the cash amount.
245+
final CashPreferences factionCashPreference = CashPreferences.get(FactionPreferences.getSelected(preferences));
246+
final CashPreferences statusCashPreference = CashPreferences.get(StatusPreferences.getSelected(preferences));
247+
248+
//Equipment minimum cash.
244249
final AtomicReference<Float> equipmentCost = new AtomicReference<>((float) 0);
245250
mandatoryWeapons.forEach(weapon -> equipmentCost.updateAndGet(v -> (v + weapon.getCost())));
246251
mandatoryArmours.forEach(armour -> equipmentCost.updateAndGet(v -> (v + armour.getCost())));
247252
mandatoryShields.forEach(shield -> equipmentCost.updateAndGet(v -> (v + shield.getCost())));
248-
preferences.add(CashPreferences.get(equipmentCost.get()));
253+
final CashPreferences equipmentCostPreference = CashPreferences.get(equipmentCost.get());
254+
255+
//Select higher value.
256+
final List<IRandomPreference> list = Arrays.asList(factionCashPreference,
257+
statusCashPreference, equipmentCostPreference);
258+
final Optional<IRandomPreference> cashSelected = list.stream().filter(Objects::nonNull).max(Comparator.naturalOrder());
259+
cashSelected.ifPresent(preferences::add);
249260
}
250261
preferences.removeIf(Objects::isNull);
251262
}
@@ -450,4 +461,8 @@ private void setExperiencePoints() throws InvalidXmlElementException, Restricted
450461
public String toString() {
451462
return characterPlayer.getCompleteNameRepresentation() + " (" + characterPlayer.getRace() + ") [" + characterPlayer.getFaction() + "]";
452463
}
464+
465+
public Set<IRandomPreference<?>> getPreferences() {
466+
return preferences;
467+
}
453468
}

think-machine-random/src/main/java/com/softwaremagico/tm/character/benefices/RandomBeneficeDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public class RandomBeneficeDefinition extends RandomSelector<BeneficeDefinition>
5252
private Integer totalCombatActions;
5353
private final Set<AvailableBenefice> suggestedAvailableBenefices;
5454

55-
public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
55+
public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
5656
throws InvalidXmlElementException, RestrictedElementException {
5757
this(characterPlayer, preferences, new HashSet<>(), new HashSet<>(), new HashSet<>());
5858
}
5959

60-
public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
60+
public RandomBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
6161
Set<BeneficeDefinition> mandatoryBenefices, Set<BeneficeDefinition> suggestedBenefices,
6262
Set<AvailableBenefice> suggestedAvailableBenefices)
6363
throws InvalidXmlElementException, RestrictedElementException {

think-machine-random/src/main/java/com/softwaremagico/tm/character/benefices/RandomExtraBeneficeDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
public class RandomExtraBeneficeDefinition extends RandomBeneficeDefinition {
4040
private static final int MAX_COMBAT_STYLES = 2;
4141

42-
public RandomExtraBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences,
42+
public RandomExtraBeneficeDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences,
4343
Set<BeneficeDefinition> suggestedBenefices, Set<AvailableBenefice> suggestedAvailableBenefices) throws
4444
InvalidXmlElementException, RestrictedElementException {
4545
super(characterPlayer, preferences, new HashSet<>(), suggestedBenefices, suggestedAvailableBenefices);

think-machine-random/src/main/java/com/softwaremagico/tm/character/blessings/RandomBlessingDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
public class RandomBlessingDefinition extends RandomSelector<Blessing> {
4141

42-
public RandomBlessingDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences, Set<Blessing> mandatoryBlessings,
42+
public RandomBlessingDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences, Set<Blessing> mandatoryBlessings,
4343
Set<Blessing> suggestedBlessings) throws InvalidXmlElementException, RestrictedElementException {
4444
super(characterPlayer, null, preferences, mandatoryBlessings, suggestedBlessings);
4545
}

think-machine-random/src/main/java/com/softwaremagico/tm/character/blessings/RandomCursesDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
public class RandomCursesDefinition extends RandomSelector<Blessing> {
4141

42-
public RandomCursesDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences)
42+
public RandomCursesDefinition(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences)
4343
throws InvalidXmlElementException, RestrictedElementException {
4444
super(characterPlayer, preferences);
4545
}

think-machine-random/src/main/java/com/softwaremagico/tm/character/characteristics/RandomCharacteristics.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class RandomCharacteristics extends RandomSelector<Characteristic> {
4343
private static final int MIN_FAITH_FOR_THEURGY = 6;
4444
private static final int MIN_WILL_FOR_PSIQUE = 5;
4545

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

57-
IRandomPreference techPreference = null;
58-
for (final IRandomPreference preference : getPreferences()) {
57+
IRandomPreference<?> techPreference = null;
58+
for (final IRandomPreference<?> preference : getPreferences()) {
5959
if (preference instanceof TechnologicalPreferences) {
6060
techPreference = preference;
6161
}

think-machine-random/src/main/java/com/softwaremagico/tm/character/characteristics/RandomCharacteristicsExperience.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
public class RandomCharacteristicsExperience extends RandomCharacteristics {
4343

44-
public RandomCharacteristicsExperience(CharacterPlayer characterPlayer, Set<IRandomPreference> preferences) throws InvalidXmlElementException,
44+
public RandomCharacteristicsExperience(CharacterPlayer characterPlayer, Set<IRandomPreference<?>> preferences) throws InvalidXmlElementException,
4545
RestrictedElementException {
4646
super(characterPlayer, preferences, new HashSet<>());
4747
}

0 commit comments

Comments
 (0)