Skip to content

Commit 98305f1

Browse files
committed
- Introduced a miscModifier parameter to the SkillCheckUtility methods and constructor for customizable target number adjustments.
- Updated `determineTargetNumber` logic to incorporate `miscModifier` for both "count up" and "count down" skill types. - Changed method calls and tests to include the new parameter, ensuring compatibility and correctness.
1 parent 161c080 commit 98305f1

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

MekHQ/src/mekhq/campaign/personnel/skills/SkillCheckUtility.java

+26-14
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public class SkillCheckUtility {
7272
*/
7373
protected static final int UNTRAINED_TARGET_NUMBER_TWO_LINKED_ATTRIBUTES = 18; // ATOW pg 43
7474

75-
private Person person;
76-
private String skillName;
75+
private final Person person;
76+
private final String skillName;
7777
private int marginOfSuccess;
7878
private String resultsText;
7979
private int targetNumber;
@@ -89,22 +89,26 @@ public class SkillCheckUtility {
8989
* <p><b>Usage:</b> This constructor gives you a lot of control over what information you need, but for most
9090
* use-cases you can get away with using the lazy method: {@link #performQuickSkillCheck(Person, String)}.</p>
9191
*
92-
* @param person the {@link Person} performing the skill check
93-
* @param skillName the name of the skill being used
94-
* @param useEdge whether the person should use edge for a re-roll if the first attempt fails
92+
* @param person the {@link Person} performing the skill check
93+
* @param skillName the name of the skill being used
94+
* @param miscModifier any special modifiers, as an {@link Integer}. These values are subtracted from the target
95+
* number, if the associated skill is classified as 'count up', otherwise they are added to the
96+
* target number. This means negative values are bonuses, positive values are penalties.
97+
* @param useEdge whether the person should use edge for a re-roll if the first attempt fails
9598
*
9699
* @author Illiani
97100
* @since 0.50.5
98101
*/
99-
public SkillCheckUtility(final Person person, final String skillName, final boolean useEdge) {
102+
public SkillCheckUtility(final Person person, final String skillName, final int miscModifier,
103+
final boolean useEdge) {
100104
this.person = person;
101105
this.skillName = skillName;
102106

103107
if (isPersonNull()) {
104108
return;
105109
}
106110

107-
targetNumber = determineTargetNumber(person, skillName);
111+
targetNumber = determineTargetNumber(person, skillName, miscModifier);
108112
performCheck(useEdge);
109113
}
110114

@@ -117,16 +121,19 @@ public SkillCheckUtility(final Person person, final String skillName, final bool
117121
* <p><b>Usage:</b> This is a nice, quick lazy method for performing a skill check. For most use-cases across
118122
* MekHQ this is the method you want to use. If you need more control use the class constructor, instead.</p>
119123
*
120-
* @param person the {@link Person} performing the skill check
121-
* @param skillName the name of the skill being checked
124+
* @param person the {@link Person} performing the skill check
125+
* @param skillName the name of the skill being checked
126+
* @param miscModifier any special modifiers, as an {@link Integer}. These values are subtracted from the target
127+
* number, if the associated skill is classified as 'count up', otherwise they are added to the
128+
* target number. This means negative values are bonuses, positive values are penalties.
122129
*
123130
* @return {@code true} if the skill check is successful, {@code false} otherwise
124131
*
125132
* @author Illiani
126133
* @since 0.50.5
127134
*/
128-
public static boolean performQuickSkillCheck(final Person person, final String skillName) {
129-
SkillCheckUtility skillCheck = new SkillCheckUtility(person, skillName, false);
135+
public static boolean performQuickSkillCheck(final Person person, final String skillName, final int miscModifier) {
136+
SkillCheckUtility skillCheck = new SkillCheckUtility(person, skillName, miscModifier, false);
130137
return skillCheck.isSuccess();
131138
}
132139

@@ -322,15 +329,18 @@ public boolean isUsedEdge() {
322329
* <p>If the person is untrained, the target number is based on constants for untrained rolls and the number of
323330
* linked attributes. Otherwise, it is based on the final skill value and attribute modifiers.</p>
324331
*
325-
* @param person the {@link Person} performing the skill check
326-
* @param skillName the name of the skill being used
332+
* @param person the {@link Person} performing the skill check
333+
* @param skillName the name of the skill being used
334+
* @param miscModifier any special modifiers, as an {@link Integer}. These values are subtracted from the target
335+
* number, if the associated skill is classified as 'count up', otherwise they are added to the
336+
* target number. This means negative values are bonuses, positive values are penalties.
327337
*
328338
* @return the target number for the skill check
329339
*
330340
* @author Illiani
331341
* @since 0.50.5
332342
*/
333-
static int determineTargetNumber(Person person, String skillName) {
343+
static int determineTargetNumber(Person person, String skillName, int miscModifier) {
334344
final SkillType skillType = SkillType.getType(skillName);
335345
final Attributes characterAttributes = person.getATOWAttributes();
336346

@@ -356,8 +366,10 @@ static int determineTargetNumber(Person person, String skillName) {
356366

357367
targetNumber -= attributeModifier;
358368
if (skillType.isCountUp()) {
369+
targetNumber -= miscModifier;
359370
return min(targetNumber, COUNT_UP_MAX_VALUE);
360371
} else {
372+
targetNumber += miscModifier;
361373
return max(targetNumber, COUNT_DOWN_MIN_VALUE);
362374
}
363375
}

MekHQ/unittests/mekhq/campaign/personnel/skills/SkillCheckUtilityTest.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
class SkillCheckUtilityTest {
7878
@Test
7979
void testIsPersonNull_EdgeDisallowed() {
80-
SkillCheckUtility checkUtility = new SkillCheckUtility(null, S_GUN_MEK, false);
80+
SkillCheckUtility checkUtility = new SkillCheckUtility(null, S_GUN_MEK, 0, false);
8181

8282
int expectedMarginOfSuccess = getMarginValue(DISASTROUS);
8383
assertEquals(expectedMarginOfSuccess, checkUtility.getMarginOfSuccess());
@@ -95,7 +95,7 @@ void testIsPersonNull_EdgeDisallowed() {
9595

9696
@Test
9797
void testIsPersonNull_EdgeAllowed() {
98-
SkillCheckUtility checkUtility = new SkillCheckUtility(null, S_GUN_MEK, true);
98+
SkillCheckUtility checkUtility = new SkillCheckUtility(null, S_GUN_MEK, 0, true);
9999

100100
int expectedMarginOfSuccess = getMarginValue(DISASTROUS);
101101
assertEquals(expectedMarginOfSuccess, checkUtility.getMarginOfSuccess());
@@ -113,7 +113,7 @@ void testIsPersonNull_EdgeAllowed() {
113113

114114
@Test
115115
void testIsPersonNull_PerformQuickSkillCheck() {
116-
boolean results = performQuickSkillCheck(null, S_GUN_MEK);
116+
boolean results = performQuickSkillCheck(null, S_GUN_MEK, 0);
117117
assertFalse(results);
118118
}
119119

@@ -305,7 +305,7 @@ void testDetermineTargetNumber_UntrainedWithOneLinkedAttribute() {
305305
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(testSkillType);
306306

307307
// Act
308-
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK);
308+
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK, 0);
309309

310310
// Assert
311311
int expectedTargetNumber = UNTRAINED_TARGET_NUMBER_ONE_LINKED_ATTRIBUTE -
@@ -326,7 +326,7 @@ void testDetermineTargetNumber_UntrainedWithTwoLinkedAttributes() {
326326
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(testSkillType);
327327

328328
// Act
329-
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK);
329+
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK, 0);
330330

331331
// Assert
332332
int expectedTargetNumber = UNTRAINED_TARGET_NUMBER_TWO_LINKED_ATTRIBUTES -
@@ -364,7 +364,7 @@ void testDetermineTargetNumber_TrainedWithOneLinkedAttribute() {
364364
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(testSkillType);
365365

366366
// Act
367-
int targetNumber = SkillCheckUtility.determineTargetNumber(mockPerson, S_GUN_MEK);
367+
int targetNumber = SkillCheckUtility.determineTargetNumber(mockPerson, S_GUN_MEK, 0);
368368

369369
// Assert
370370
int skillTargetNumber = skill.getFinalSkillValue(new PersonnelOptions(), 0);
@@ -403,7 +403,7 @@ void testDetermineTargetNumber_TrainedWithOneLinkedAttribute_AboveNormalAttribut
403403
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(testSkillType);
404404

405405
// Act
406-
int targetNumber = SkillCheckUtility.determineTargetNumber(mockPerson, S_GUN_MEK);
406+
int targetNumber = SkillCheckUtility.determineTargetNumber(mockPerson, S_GUN_MEK, 0);
407407

408408
// Assert
409409
int skillTargetNumber = skill.getFinalSkillValue(new PersonnelOptions(), 0);
@@ -439,7 +439,7 @@ void testDetermineTargetNumber_TrainedWithTwoLinkedAttributes() {
439439
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(testSkillType);
440440

441441
// Act
442-
int targetNumber = SkillCheckUtility.determineTargetNumber(mockPerson, S_GUN_MEK);
442+
int targetNumber = SkillCheckUtility.determineTargetNumber(mockPerson, S_GUN_MEK, 0);
443443

444444
// Assert
445445
int skillTargetNumber = skill.getFinalSkillValue(new PersonnelOptions(), 0);
@@ -468,7 +468,7 @@ void testDetermineTargetNumber_InvalidAttributes() {
468468
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(testSkillType);
469469

470470
// Act
471-
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK);
471+
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK, 0);
472472

473473
// Assert
474474
int expectedTargetNumber = UNTRAINED_TARGET_NUMBER_TWO_LINKED_ATTRIBUTES -
@@ -494,7 +494,7 @@ void testDetermineTargetNumber_EdgeCaseSkillType() {
494494
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(edgeCaseSkillType);
495495

496496
// Act
497-
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK);
497+
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK, 0);
498498

499499
// Assert
500500
assertEquals(UNTRAINED_TARGET_NUMBER_ONE_LINKED_ATTRIBUTE, targetNumber);
@@ -523,7 +523,7 @@ void testDetermineTargetNumber_NegativeAttributeModifier() {
523523
mockSkillType.when(() -> SkillType.getType(S_GUN_MEK)).thenReturn(testSkillType);
524524

525525
// Act
526-
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK);
526+
int targetNumber = SkillCheckUtility.determineTargetNumber(person, S_GUN_MEK, 0);
527527

528528
// Assert
529529
int expectedTargetNumber = UNTRAINED_TARGET_NUMBER_TWO_LINKED_ATTRIBUTES -

0 commit comments

Comments
 (0)