Skip to content

Commit

Permalink
Merge pull request #5703 from IllianiCBT/personality_bug
Browse files Browse the repository at this point in the history
Fixed Personality Loading
  • Loading branch information
Sleet01 authored Jan 9, 2025
2 parents 03f2dfb + 117e9ce commit 440b9d2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 416 deletions.
43 changes: 30 additions & 13 deletions MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -2585,44 +2585,61 @@ public static Person generateInstanceFromXML(Node wn, Campaign c, Version versio
} else if (wn2.getNodeName().equalsIgnoreCase("aggression")) {
try {
// <50.01 compatibility handler
retVal.aggression = Aggression.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.aggression = Aggression.valueOf(wn2.getTextContent()
.toUpperCase()
.replaceAll("-", "_")
.replaceAll(" ", "_"));
} catch (IllegalArgumentException e) {
retVal.aggression = Aggression.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("ambition")) {
try {
// <50.01 compatibility handler
retVal.ambition = Ambition.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.ambition = Ambition.valueOf(wn2.getTextContent()
.toUpperCase()
.replaceAll("-", "_")
.replaceAll(" ", "_"));
} catch (IllegalArgumentException e) {
retVal.ambition = Ambition.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("greed")) {
try {
// <50.01 compatibility handler
retVal.greed = Greed.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.greed = Greed.valueOf(wn2.getTextContent()
.toUpperCase()
.replaceAll("-", "_")
.replaceAll(" ", "_"));
} catch (IllegalArgumentException 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.valueOf(wn2.getTextContent()
.toUpperCase()
.replaceAll("-", "_")
.replaceAll(" ", "_"));
} catch (IllegalArgumentException e) {
retVal.social = Social.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
retVal.social = Social.parseFromString(wn2.getTextContent());
} else if (wn2.getNodeName().equalsIgnoreCase("personalityQuirk")) {
try {
// <50.01 compatibility handler
retVal.personalityQuirk = PersonalityQuirk.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.personalityQuirk = PersonalityQuirk.valueOf(wn2.getTextContent()
.toUpperCase()
.replaceAll("-", "_")
.replaceAll(" ", "_"));
} catch (IllegalArgumentException e) {
retVal.personalityQuirk = PersonalityQuirk.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("intelligence")) {
try {
// <50.01 compatibility handler
retVal.intelligence = Intelligence.parseFromString(wn2.getTextContent());
} catch (Exception e) {
retVal.intelligence = Intelligence.valueOf(wn2.getTextContent()
.toUpperCase()
.replaceAll("-", "_")
.replaceAll(" ", "_"));
} catch (IllegalArgumentException e) {
retVal.intelligence = Intelligence.fromOrdinal(Integer.parseInt(wn2.getTextContent()));
}
} else if (wn2.getNodeName().equalsIgnoreCase("personalityDescription")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,58 +110,6 @@ public boolean isNone() {
// endregion Boolean Comparison Methods

// region File I/O
/**
* Parses a given string and returns the corresponding Aggression enum.
* Accepts either the ENUM ordinal value or its name
*
* @param aggression the string to be parsed
* @return the Aggression enum that corresponds to the given string
* @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;
// Minor Characteristics
case "1", "Bold" -> BOLD;
case "2", "Aggressive" -> AGGRESSIVE;
case "3", "Assertive" -> ASSERTIVE;
case "4", "Belligerent" -> BELLIGERENT;
case "5", "Brash" -> BRASH;
case "6", "Confident" -> CONFIDENT;
case "7", "Courageous" -> COURAGEOUS;
case "8", "Daring" -> DARING;
case "9", "Decisive" -> DECISIVE;
case "10", "Determined" -> DETERMINED;
case "11", "Domineering" -> DOMINEERING;
case "12", "Fearless" -> FEARLESS;
case "13", "Hostile" -> HOSTILE;
case "14", "Hot-Headed" -> HOT_HEADED;
case "15", "Impetuous" -> IMPETUOUS;
case "16", "Impulsive" -> IMPULSIVE;
case "17", "Inflexible" -> INFLEXIBLE;
case "18", "Intrepid" -> INTREPID;
case "19", "Overbearing" -> OVERBEARING;
case "20", "Reckless" -> RECKLESS;
case "21", "Resolute" -> RESOLUTE;
case "22", "Stubborn" -> STUBBORN;
case "23", "Tenacious" -> TENACIOUS;
case "24", "Vigilant" -> VIGILANT;
// Major Characteristics
case "25", "Bloodthirsty" -> BLOODTHIRSTY;
case "26", "Diplomatic" -> DIPLOMATIC;
case "27", "Murderous" -> MURDEROUS;
case "28", "Pacifistic" -> PACIFISTIC;
case "29", "Sadistic" -> SADISTIC;
case "30", "Savage" -> SAVAGE;
default ->
throw new IllegalStateException(
"Unexpected value in mekhq/campaign/personnel/enums/randomEvents/personalities/Aggression.java/parseFromString: "
+ aggression);
};
}

/**
* Returns the {@link Aggression} associated with the given ordinal.
*
Expand All @@ -170,13 +118,11 @@ public static Aggression parseFromString(final String aggression) {
* {@code NONE} if not found
*/
public static Aggression fromOrdinal(int ordinal) {
for (Aggression aggression : values()) {
if (aggression.ordinal() == ordinal) {
return aggression;
}
if ((ordinal >= 0) && (ordinal < values().length)) {
return values()[ordinal];
}

final MMLogger logger = MMLogger.create(Aggression.class);
MMLogger logger = MMLogger.create(Aggression.class);
logger.error(String.format("Unknown Aggression ordinal: %s - returning NONE.", ordinal));

return NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,58 +108,6 @@ public boolean isNone() {
// endregion Boolean Comparison Methods

// region File I/O
/**
* Parses a given string and returns the corresponding Ambition enum.
* Accepts either the ENUM ordinal value or its name
*
* @param ambition the string to be parsed
* @return the Ambition enum that corresponds to the given string
* @throws IllegalStateException if the given string does not match any valid
* Ambition
*/
@Deprecated
public static Ambition parseFromString(final String ambition) {
return switch (ambition) {
case "0", "None" -> NONE;
// Minor Characteristics
case "1", "Ambitious" -> AMBITIOUS;
case "2", "Arrogant" -> ARROGANT;
case "3", "Aspiring" -> ASPIRING;
case "4", "Calculating" -> CALCULATING;
case "5", "Conniving" -> CONNIVING;
case "6", "Controlling" -> CONTROLLING;
case "7", "Cutthroat" -> CUTTHROAT;
case "8", "Diligent" -> DILIGENT;
case "9", "Driven" -> DRIVEN;
case "10", "Energetic" -> ENERGETIC;
case "11", "Excessive" -> EXCESSIVE;
case "12", "Focused" -> FOCUSED;
case "13", "Goal-Oriented" -> GOAL_ORIENTED;
case "14", "Motivated" -> MOTIVATED;
case "15", "Opportunistic" -> OPPORTUNISTIC;
case "16", "Overconfident" -> OVERCONFIDENT;
case "17", "Persistent" -> PERSISTENT;
case "18", "Proactive" -> PROACTIVE;
case "19", "Resilient" -> RESILIENT;
case "20", "Ruthless" -> RUTHLESS;
case "21", "Selfish" -> SELFISH;
case "22", "Strategic" -> STRATEGIC;
case "23", "Unambitious" -> UNAMBITIOUS;
case "24", "Unscrupulous" -> UNSCRUPULOUS;
// Major Characteristics
case "25", "Dishonest" -> DISHONEST;
case "26", "Innovative" -> INNOVATIVE;
case "27", "Manipulative" -> MANIPULATIVE;
case "28", "Resourceful" -> RESOURCEFUL;
case "29", "Tyrannical" -> TYRANNICAL;
case "30", "Visionary" -> VISIONARY;
default ->
throw new IllegalStateException(
"Unexpected value in mekhq/campaign/personnel/enums/randomEvents/personalities/Ambition.java/parseFromString: "
+ ambition);
};
}

/**
* Returns the {@link Ambition} associated with the given ordinal.
*
Expand All @@ -168,13 +116,11 @@ public static Ambition parseFromString(final String ambition) {
* {@code NONE} if not found
*/
public static Ambition fromOrdinal(int ordinal) {
for (Ambition ambition : values()) {
if (ambition.ordinal() == ordinal) {
return ambition;
}
if ((ordinal >= 0) && (ordinal < values().length)) {
return values()[ordinal];
}

final MMLogger logger = MMLogger.create(Ambition.class);
MMLogger logger = MMLogger.create(Ambition.class);
logger.error(String.format("Unknown Ambition ordinal: %s - returning NONE.", ordinal));

return NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,58 +108,6 @@ public boolean isNone() {
// endregion Boolean Comparison Methods

// region File I/O
/**
* Parses a given string and returns the corresponding Greed enum.
* Accepts either the ENUM ordinal value, or its name
*
* @param greed the string to be parsed
* @return the Greed enum that corresponds to the given string
* @throws IllegalStateException if the given string does not match any valid
* Greed
*/
@Deprecated
public static Greed parseFromString(final String greed) {
return switch (greed) {
case "0", "None" -> NONE;
// Minor Characteristics
case "1", "Astute" -> ASTUTE;
case "2", "Adept" -> ADEPT;
case "3", "Avaricious" -> AVARICIOUS;
case "4", "Dynamic" -> DYNAMIC;
case "5", "Eager" -> EAGER;
case "6", "Exploitative" -> EXPLOITATIVE;
case "7", "Fraudulent" -> FRAUDULENT;
case "8", "Generous" -> GENEROUS;
case "9", "Greedy" -> GREEDY;
case "10", "Hoarding" -> HOARDING;
case "11", "Insatiable" -> INSATIABLE;
case "12", "Insightful" -> INSIGHTFUL;
case "13", "Judicious" -> JUDICIOUS;
case "14", "Lustful" -> LUSTFUL;
case "15", "Mercenary" -> MERCENARY;
case "16", "Overreaching" -> OVERREACHING;
case "17", "Profitable" -> PROFITABLE;
case "18", "Savvy" -> SAVVY;
case "19", "Self-Serving" -> SELF_SERVING;
case "20", "Shameless" -> SHAMELESS;
case "21", "Shrewd" -> SHREWD;
case "22", "Tactical" -> TACTICAL;
case "23", "Unprincipled" -> UNPRINCIPLED;
case "24", "Voracious" -> VORACIOUS;
// Major Characteristics
case "25", "Corrupt" -> CORRUPT;
case "26", "Enterprising" -> ENTERPRISING;
case "27", "Intuitive" -> INTUITIVE;
case "28", "Meticulous" -> METICULOUS;
case "29", "Nefarious" -> NEFARIOUS;
case "30", "Thief" -> THIEF;
default ->
throw new IllegalStateException(
"Unexpected value in mekhq/campaign/personnel/enums/randomEvents/personalities/Greed.java/parseFromString: "
+ greed);
};
}

/**
* Returns the {@link Greed} associated with the given ordinal.
*
Expand All @@ -168,13 +116,11 @@ public static Greed parseFromString(final String greed) {
* {@code NONE} if not found
*/
public static Greed fromOrdinal(int ordinal) {
for (Greed greed : values()) {
if (greed.ordinal() == ordinal) {
return greed;
}
if ((ordinal >= 0) && (ordinal < values().length)) {
return values()[ordinal];
}

final MMLogger logger = MMLogger.create(Greed.class);
MMLogger logger = MMLogger.create(Greed.class);
logger.error(String.format("Unknown Greed ordinal: %s - returning NONE.", ordinal));

return NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,50 +80,6 @@ public boolean isAverage() {
// endregion Boolean Comparison Methods

// region File I/O
/**
* Parses a given string and returns the corresponding Quirk enum.
* Accepts either the ENUM ordinal value, or its name
*
* @param quirk the string to be parsed
* @return the Greed enum that corresponds to the given string
* @throws IllegalStateException if the given string does not match any valid
* Quirk
*/
@Deprecated
public static Intelligence parseFromString(final String quirk) {
return switch (quirk) {
case "0", "Brain Dead" -> BRAIN_DEAD;
case "1", "Unintelligent" -> UNINTELLIGENT;
case "2", "Feeble Minded", "Foolish" -> FOOLISH;
case "3", "Simple" -> SIMPLE;
case "4", "Slow to Comprehend", "Slow" -> SLOW;
case "5", "Uninspired" -> UNINSPIRED;
case "6", "Dull" -> DULL;
case "7", "Dimwitted" -> DIMWITTED;
case "8", "Obtuse" -> OBTUSE;
case "9", "Below Average" -> BELOW_AVERAGE;
case "10", "Under Performing" -> UNDER_PERFORMING;
case "11", "Limited Insight" -> LIMITED_INSIGHT;
case "12", "Average" -> AVERAGE;
case "13", "Above Average" -> ABOVE_AVERAGE;
case "14", "Studious" -> STUDIOUS;
case "15", "Discerning" -> DISCERNING;
case "16", "Sharp" -> SHARP;
case "17", "Quick-Witted" -> QUICK_WITTED;
case "18", "Perceptive" -> PERCEPTIVE;
case "19", "Bright" -> BRIGHT;
case "20", "Clever" -> CLEVER;
case "21", "Intellectual" -> INTELLECTUAL;
case "22", "Brilliant" -> BRILLIANT;
case "23", "Exceptional" -> EXCEPTIONAL;
case "24", "Genius" -> GENIUS;
default ->
throw new IllegalStateException(
"Unexpected value in mekhq/campaign/personnel/enums/randomEvents/personalities/PersonalityQuirk.java/parseFromString: "
+ quirk);
};
}

/**
* Returns the {@link Intelligence} associated with the given ordinal.
*
Expand All @@ -132,13 +88,11 @@ public static Intelligence parseFromString(final String quirk) {
* {@code AVERAGE} if not found
*/
public static Intelligence fromOrdinal(int ordinal) {
for (Intelligence intelligence : values()) {
if (intelligence.ordinal() == ordinal) {
return intelligence;
}
if ((ordinal >= 0) && (ordinal < values().length)) {
return values()[ordinal];
}

final MMLogger logger = MMLogger.create(Intelligence.class);
MMLogger logger = MMLogger.create(Intelligence.class);
logger.error(String.format("Unknown Intelligence ordinal: %s - returning AVERAGE.", ordinal));

return AVERAGE;
Expand Down
Loading

0 comments on commit 440b9d2

Please sign in to comment.