Skip to content

Commit

Permalink
Merge pull request #5088 from IllianiCBT/personalities_newQuirks
Browse files Browse the repository at this point in the history
Added 100+ New Quirks, Refactored Personality Traits & Quirk Classes
  • Loading branch information
HammerGS authored Oct 21, 2024
2 parents 6112e9e + 0f8cd21 commit 86eda2f
Show file tree
Hide file tree
Showing 10 changed files with 1,461 additions and 1,484 deletions.
1,426 changes: 1,182 additions & 244 deletions MekHQ/resources/mekhq/resources/Personalities.properties

Large diffs are not rendered by default.

53 changes: 42 additions & 11 deletions MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -2207,27 +2207,27 @@ public void writeToXML(final PrintWriter pw, int indent, final Campaign campaign
}

if (aggression != Aggression.NONE) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "aggression", aggression.toString());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "aggression", aggression.ordinal());
}

if (ambition != Ambition.NONE) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "ambition", ambition.toString());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "ambition", ambition.ordinal());
}

if (greed != Greed.NONE) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "greed", greed.toString());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "greed", greed.ordinal());
}

if (social != Social.NONE) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "social", social.toString());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "social", social.ordinal());
}

if (personalityQuirk != PersonalityQuirk.NONE) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "personalityQuirk", personalityQuirk.toString());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "personalityQuirk", personalityQuirk.ordinal());
}

if (intelligence != Intelligence.AVERAGE) {
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "intelligence", intelligence.toString());
MHQXMLUtility.writeSimpleXMLTag(pw, indent, "intelligence", intelligence.ordinal());
}

if (!StringUtility.isNullOrBlank(personalityDescription)) {
Expand Down Expand Up @@ -2564,17 +2564,48 @@ public static Person generateInstanceFromXML(Node wn, Campaign c, Version versio
} else if (wn2.getNodeName().equalsIgnoreCase("eduEducationTime")) {
retVal.eduEducationTime = Integer.parseInt(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("aggression")) {
retVal.aggression = Aggression.parseFromString(wn2.getTextContent());
try {
// <50.01 compatibility handler
retVal.aggression = Aggression.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.aggression = Aggression.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("ambition")) {
retVal.ambition = Ambition.parseFromString(wn2.getTextContent());
try {
// <50.01 compatibility handler
retVal.ambition = Ambition.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.ambition = Ambition.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("greed")) {
retVal.greed = Greed.parseFromString(wn2.getTextContent());
try {
// <50.01 compatibility handler
retVal.greed = Greed.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.greed = Greed.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("social")) {
try {
// <50.01 compatibility handler
retVal.social = Social.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.social = Social.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
retVal.social = Social.parseFromString(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("personalityQuirk")) {
retVal.personalityQuirk = PersonalityQuirk.parseFromString(wn2.getTextContent());
try {
// <50.01 compatibility handler
retVal.personalityQuirk = PersonalityQuirk.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.personalityQuirk = PersonalityQuirk.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("intelligence")) {
retVal.intelligence = Intelligence.parseFromString(wn2.getTextContent());
try {
// <50.01 compatibility handler
retVal.intelligence = Intelligence.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.intelligence = Intelligence.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("personalityDescription")) {
retVal.personalityDescription = wn2.getTextContent();
} else if (wn2.getNodeName().equalsIgnoreCase("clanPersonnel")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import mekhq.campaign.personnel.enums.PersonnelStatus;
import mekhq.campaign.personnel.enums.education.EducationLevel;
import mekhq.campaign.personnel.enums.education.EducationStage;
import mekhq.campaign.personnel.randomEvents.enums.personalities.Intelligence;
import mekhq.utilities.ReportingUtilities;

import java.time.DayOfWeek;
Expand Down Expand Up @@ -1357,7 +1356,7 @@ private static void graduateChild(Campaign campaign, Person person, Academy acad
}

if (campaign.getCampaignOptions().isUseRandomPersonalities()) {
graduationRoll += Intelligence.parseToInt(person.getIntelligence()) - 12;
graduationRoll += person.getIntelligence().ordinal() - 12;
}

if (graduationRoll < 30) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,15 @@

package mekhq.campaign.personnel.randomEvents;

import static mekhq.campaign.personnel.randomEvents.enums.personalities.Intelligence.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Random;

import megamek.common.Compute;
import megamek.common.enums.Gender;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.enums.GenderDescriptors;
import mekhq.campaign.personnel.randomEvents.enums.personalities.Aggression;
import mekhq.campaign.personnel.randomEvents.enums.personalities.Ambition;
import mekhq.campaign.personnel.randomEvents.enums.personalities.Greed;
import mekhq.campaign.personnel.randomEvents.enums.personalities.Intelligence;
import mekhq.campaign.personnel.randomEvents.enums.personalities.PersonalityQuirk;
import mekhq.campaign.personnel.randomEvents.enums.personalities.Social;
import mekhq.campaign.personnel.randomEvents.enums.personalities.*;

import java.util.*;

import static mekhq.campaign.personnel.randomEvents.enums.personalities.Intelligence.*;

public class PersonalityController {
public static void generatePersonality(Person person) {
Expand Down Expand Up @@ -97,10 +88,10 @@ private static void setPersonalityTrait(Person person, int tableRoll, int traitR
}

switch (tableRoll) {
case 0 -> person.setAggression(Aggression.parseFromInt(traitRoll));
case 1 -> person.setAmbition(Ambition.parseFromInt(traitRoll));
case 2 -> person.setGreed(Greed.parseFromInt(traitRoll));
case 3 -> person.setSocial(Social.parseFromInt(traitRoll));
case 0 -> person.setAggression(Aggression.fromOrdinal(traitRoll));
case 1 -> person.setAmbition(Ambition.fromOrdinal(traitRoll));
case 2 -> person.setGreed(Greed.fromOrdinal(traitRoll));
case 3 -> person.setSocial(Social.fromOrdinal(traitRoll));
default -> throw new IllegalStateException(
"Unexpected value in mekhq/campaign/personnel/randomEvents/personality/PersonalityController.java/setPersonalityTrait: "
+ tableRoll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
*/
package mekhq.campaign.personnel.randomEvents.enums.personalities;

import java.util.ResourceBundle;

import megamek.logging.MMLogger;
import mekhq.MekHQ;

import java.util.ResourceBundle;

public enum Aggression {
// region Enum Declarations
NONE("Personality.NONE.text", "Personality.NONE.description", false, false),
Expand Down Expand Up @@ -106,126 +107,6 @@ public boolean isTraitMajor() {
public boolean isNone() {
return this == NONE;
}

public boolean isBloodthirsty() {
return this == BLOODTHIRSTY;
}

public boolean isBold() {
return this == BOLD;
}

public boolean isAggressive() {
return this == AGGRESSIVE;
}

public boolean isAssertive() {
return this == ASSERTIVE;
}

public boolean isBelligerent() {
return this == BELLIGERENT;
}

public boolean isBrash() {
return this == BRASH;
}

public boolean isConfident() {
return this == CONFIDENT;
}

public boolean isCourageous() {
return this == COURAGEOUS;
}

public boolean isDaring() {
return this == DARING;
}

public boolean isDecisive() {
return this == DECISIVE;
}

public boolean isDetermined() {
return this == DETERMINED;
}

public boolean isDiplomatic() {
return this == DIPLOMATIC;
}

public boolean isDomineering() {
return this == DOMINEERING;
}

public boolean isFearless() {
return this == FEARLESS;
}

public boolean isHostile() {
return this == HOSTILE;
}

public boolean isHotHeaded() {
return this == HOT_HEADED;
}

public boolean isImpetuous() {
return this == IMPETUOUS;
}

public boolean isImpulsive() {
return this == IMPULSIVE;
}

public boolean isInflexible() {
return this == INFLEXIBLE;
}

public boolean isIntrepid() {
return this == INTREPID;
}

public boolean isMurderous() {
return this == MURDEROUS;
}

public boolean isOverbearing() {
return this == OVERBEARING;
}

public boolean isPacifistic() {
return this == PACIFISTIC;
}

public boolean isReckless() {
return this == RECKLESS;
}

public boolean isResolute() {
return this == RESOLUTE;
}

public boolean isSadistic() {
return this == SADISTIC;
}

public boolean isSavage() {
return this == SAVAGE;
}

public boolean isStubborn() {
return this == STUBBORN;
}

public boolean isTenacious() {
return this == TENACIOUS;
}

public boolean isVigilant() {
return this == VIGILANT;
}
// endregion Boolean Comparison Methods

// region File I/O
Expand All @@ -238,7 +119,7 @@ public boolean isVigilant() {
* @throws IllegalStateException if the given string does not match any valid
* Aggression
*/

@Deprecated
public static Aggression parseFromString(final String aggression) {
return switch (aggression) {
case "0", "None" -> NONE;
Expand Down Expand Up @@ -282,54 +163,23 @@ public static Aggression parseFromString(final String aggression) {
}

/**
* Parses an integer value into an Aggression enum.
* Returns the {@link Aggression} associated with the given ordinal.
*
* @param aggression the integer value representing the Aggression level
* @return the corresponding Aggression enum value
* @throws IllegalStateException if the integer value does not correspond to any
* valid Aggression enum value
* @param ordinal the ordinal value of the {@link Aggression}
* @return the {@link Aggression} associated with the given ordinal, or default value
* {@code NONE} if not found
*/
public static Aggression fromOrdinal(int ordinal) {
for (Aggression aggression : values()) {
if (aggression.ordinal() == ordinal) {
return aggression;
}
}

public static Aggression parseFromInt(final int aggression) {
return switch (aggression) {
case 0 -> NONE;
// Minor Characteristics
case 1 -> BOLD;
case 2 -> AGGRESSIVE;
case 3 -> ASSERTIVE;
case 4 -> BELLIGERENT;
case 5 -> BRASH;
case 6 -> CONFIDENT;
case 7 -> COURAGEOUS;
case 8 -> DARING;
case 9 -> DECISIVE;
case 10 -> DETERMINED;
case 11 -> DOMINEERING;
case 12 -> FEARLESS;
case 13 -> HOSTILE;
case 14 -> HOT_HEADED;
case 15 -> IMPETUOUS;
case 16 -> IMPULSIVE;
case 17 -> INFLEXIBLE;
case 18 -> INTREPID;
case 19 -> OVERBEARING;
case 20 -> RECKLESS;
case 21 -> RESOLUTE;
case 22 -> STUBBORN;
case 23 -> TENACIOUS;
case 24 -> VIGILANT;
// Major Characteristics
case 25 -> BLOODTHIRSTY;
case 26 -> DIPLOMATIC;
case 27 -> MURDEROUS;
case 28 -> PACIFISTIC;
case 29 -> SADISTIC;
case 30 -> SAVAGE;
default ->
throw new IllegalStateException(
"Unexpected value in mekhq/campaign/personnel/enums/randomEvents/personalities/Aggression.java/parseFromInt: "
+ aggression);
};
final MMLogger logger = MMLogger.create(Aggression.class);
logger.error(String.format("Unknown Aggression ordinal: %s - returning NONE.", ordinal));

return NONE;
}

@Override
Expand Down
Loading

0 comments on commit 86eda2f

Please sign in to comment.