Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Heroic and Legendary Skill Levels #6864

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 35 additions & 48 deletions megamek/src/megamek/common/enums/SkillLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import megamek.MegaMek;
import megamek.codeUtilities.MathUtility;
import megamek.logging.MMLogger;

public enum SkillLevel {
Expand All @@ -46,7 +48,7 @@ public enum SkillLevel {
// region Constructors
SkillLevel(final String name, final String toolTipText, final int experienceLevel) {
final ResourceBundle resources = ResourceBundle.getBundle("megamek.common.messages",
MegaMek.getMMOptions().getLocale());
MegaMek.getMMOptions().getLocale());
this.name = resources.getString(name);
this.toolTipText = resources.getString(toolTipText);
this.experienceLevel = experienceLevel;
Expand All @@ -59,8 +61,8 @@ public String getToolTipText() {
}

/**
* Retrieves the current experience level of this entity. Where None is {@code 0}, Ultra-Green
* is {@code 1}, Green is {@code 2} and so forth.
* Retrieves the current experience level of this entity. Where None is {@code 0}, Ultra-Green is {@code 1}, Green
* is {@code 2} and so forth.
*
* @return the experience level as an integer.
*/
Expand Down Expand Up @@ -135,34 +137,26 @@ public int getAdjustedValue() {
}

/**
* This returns the default skill values by level. This should never return the
* value for NONE,
* as NONE means one does not have the skill.
* This returns the default skill values by level. This should never return the value for NONE, as NONE means one
* does not have the skill.
*
* @return the default skill array pairing
*/
public int[] getDefaultSkillValues() {
switch (this) {
case NONE:
MMLogger.create(SkillLevel.class).error(
"Attempting to get illegal default skill values for NONE Skill Level. Returning { 8, 8 }");
return new int[] { 8, 8 };
case ULTRA_GREEN:
return new int[] { 6, 7 };
case GREEN:
return new int[] { 5, 6 };
case VETERAN:
return new int[] { 3, 4 };
case ELITE:
return new int[] { 2, 3 };
case HEROIC:
return new int[] { 1, 2 };
case LEGENDARY:
return new int[] { 0, 1 };
case REGULAR:
default:
return new int[] { 4, 5 };
}
return switch (this) {
case NONE -> {
MMLogger.create(SkillLevel.class)
.error("Attempting to get illegal default skill values for NONE Skill Level. Returning { 8, 8 }");
yield new int[] { 8, 8 };
}
case ULTRA_GREEN -> new int[] { 6, 7 };
case GREEN -> new int[] { 5, 6 };
case VETERAN -> new int[] { 3, 4 };
case ELITE -> new int[] { 2, 3 };
case HEROIC -> new int[] { 1, 2 };
case LEGENDARY -> new int[] { 0, 1 };
default -> new int[] { 4, 5 };
};
}

/**
Expand All @@ -174,41 +168,34 @@ public static List<SkillLevel> getGeneratableValues() {

// region File I/O
public static SkillLevel parseFromString(final String text) {
// From String
try {
return valueOf(text);
return valueOf(text.toUpperCase());
} catch (Exception ignored) {

}

// From Name
try {
switch (Integer.parseInt(text)) {
case 0:
return GREEN;
case 1:
return REGULAR;
case 2:
return VETERAN;
case 3:
return ELITE;
default:
break;
for (SkillLevel skillLevel : values()) {
if (skillLevel.name().equalsIgnoreCase(text)) {
return skillLevel;
}
}
} catch (Exception ignored) {

}

MMLogger.create(SkillLevel.class).error("Unable to parse " + text + " into a SkillLevel. Returning REGULAR.");

return REGULAR;
// From ordinal
return SkillLevel.values()[MathUtility.parseInt(text, REGULAR.ordinal())];
}

/**
* Parses an integer value to a {@link SkillLevel} enumeration.
*
* @param value the integer value to parse
*
* @return the {@link SkillLevel} enum corresponding to the given integer value
* @throws IllegalStateException if the integer value does not match any {@link SkillLevel} enum
* value
*
* @throws IllegalStateException if the integer value does not match any {@link SkillLevel} enum value
*/
public static SkillLevel parseFromInteger(final int value) {
return switch (value) {
Expand All @@ -220,8 +207,8 @@ public static SkillLevel parseFromInteger(final int value) {
case 5 -> ELITE;
case 6 -> HEROIC;
case 7 -> LEGENDARY;
default -> throw new IllegalStateException(
"Unexpected value in megamek/common/enums/SkillLevel.java: " + value);
default ->
throw new IllegalStateException("Unexpected value in megamek/common/enums/SkillLevel.java: " + value);
};
}
// endregion File I/O
Expand Down