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 Skill Check Dialog Using New Centralized Skill Check Utility #6578

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file added MekHQ/data/images/misc/skill_check_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MekHQ/data/images/misc/skill_check_fail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MekHQ/data/images/misc/skill_check_pass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ setAsCommander.format=%s has been set as the overall unit commander.
enterNewCallsign.text=Enter new callsign
editCallsign.text=Edit Callsign
changeSalary.text=Change Salary (-1 to remove custom salary)
makeSkillCheck.text=Perform Skill Check
changeRank.text=Change Rank
changeRankSystem.text=Change Rank System
useCampaignRankSystem.text=Use Campaign Rank System
Expand Down
10 changes: 5 additions & 5 deletions MekHQ/resources/mekhq/resources/MarginOfSuccess.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# suppress inspection "UnusedProperty" for the whole file
SPECTACULAR.label=<i>Spectacular!</i>
SPECTACULAR.label=<i><b>Spectacular!</b></i>
EXTRAORDINARY.label=<i>Extraordinary!</i>
GOOD.label=<i>Good</i>
IT_WILL_DO.label=<i>It'll do...</i>
GOOD.label=<i>Good.</i>
IT_WILL_DO.label=<i>It''ll do...</i>
BARELY_MADE_IT.label=<i>Barely made it!</i>
ALMOST.label=<i>Almost...</i>
BAD.label=<i>Bad</i>
BAD.label=<i>Bad.</i>
TERRIBLE.label=<i>Terrible!</i>
DISASTROUS.label=<i>Disastrous</i>
DISASTROUS.label=<i><b>Disastrous!</b></i>
1 change: 0 additions & 1 deletion MekHQ/resources/mekhq/resources/PersonViewPanel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ lblPermanentInjury.text=permanent injury
btnMedical.tooltip=View medical details
format.itemHeader=<html><b>%s:</b></html>
format.itemHeader.roleplay=<html><i>%s:</i></html>
format.itemHeader.roleplay.removal=\ (RP Only)
format.kills=Kills: %d
format.killDetail=%s with %s
format.scenarios=Scenarios: %d
Expand Down
65 changes: 65 additions & 0 deletions MekHQ/resources/mekhq/resources/SkillCheckDialog.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# suppress inspection "UnusedProperty" for the whole file
## Buttons
button.cancel=Cancel
button.attempt=Attempt
button.edge=Use Edge
## Out of Character
message.ooc=Select the skill you want to use and enter any modifiers, then click "Accept."\
<p>If Edge is enabled in Campaign Options and the selected character has more than 0 Edge available, you can choose to\
\ use Edge. This will perform the check as usual, but if the check fails, the character will spend 1 Edge to make a\
\ second attempt.</p>\
<p>The result of the second attempt will be kept, even if it is worse than the original.</p>
## Supplemental panel
component.combo=Skill
component.spinner=Modifier
## In Character Variants
message.ic.0=Nothing ventured, nothing gained. Let''s see if luck''s still on our side.
message.ic.1=Nothing ventured, nothing gained. Let''s see if luck''s still on our side.
message.ic.2=Alright, focus up. One shot at this - make it count.
message.ic.3=I''ve pulled off crazier stunts before. Just gotta trust the gut.
message.ic.4=This could go sideways fast... but hey, fortune favors the bold.
message.ic.5=Alright, deep breath. One step at a time. We''ve got this.
message.ic.6=Alright, no guts, no galaxy. Let''s make it happen.
message.ic.7=Steady now... can''t afford any mistakes here.
message.ic.8=I''ve handled worse. Just need a bit of finesse.
message.ic.9=Let''s hope the universe is feeling generous today.
message.ic.10=Alright, no pressure... just gotta make it look easy.
message.ic.11=This is either gonna be genius or a total disaster. Here goes nothing.
message.ic.12=Can''t second-guess it now. Just commit and push through.
message.ic.13=If this works, I''m buying myself a drink. If not... well, I won''t worry about it.
message.ic.14=Eyes forward, stay calm. Just one more move.
message.ic.15=Alright, let''s do this. No point in overthinking it now.
message.ic.16=I''ve come too far to mess this up. Just gotta stay sharp.
message.ic.17=Luck''s gotta turn around sometime. Might as well be now.
message.ic.18=If this doesn''t work, we''ll just pretend it was the plan all along.
message.ic.19=Deep breath. Steady hands. No room for mistakes.
message.ic.20=Alright, here goes nothing. Hope the universe likes a risk-taker.
message.ic.21=I swear, if this works, I''m never letting anyone forget it.
message.ic.22=Sometimes you just gotta trust your gut and hope it''s not lying.
message.ic.23=If I pull this off, it''s gonna be one for the stories.
message.ic.24=No point worrying now. Just gotta see it through.
message.ic.25=Well, no sense in standing around. Let''s see what happens.
message.ic.26=It''s a long shot, but I''ve pulled off crazier moves.
message.ic.27=Can''t win ''em all, but I''ll be damned if I don''t give it a shot.
message.ic.28=If this works, I''m calling it skill. If it doesn''t... well, we''ll cross that bridge.
message.ic.29=Alright, let''s see if the stars are on my side today.
message.ic.30=Alright, let''s see if I''ve still got that lucky touch.
message.ic.31=Can''t back down now. One way or another, we''re seeing this through.
message.ic.32=No time to second-guess it. Just gotta go with the flow.
message.ic.33=I''ve got a feeling about this... let''s hope it''s a good one.
message.ic.34=Alright, universe. Show me what you''ve got.
message.ic.35=Alright, no turning back now. Let''s see how this plays out.
message.ic.36=Sometimes you just gotta throw caution to the wind and hope it sticks.
message.ic.37=If this doesn''t work, at least I''ll have a good story to tell.
message.ic.38=Here goes nothing... or everything. No in-between.
message.ic.39=Just gotta trust myself on this one. No room for doubt.
message.ic.40=Alright, no sense worrying now. Just gotta make it happen.
message.ic.41=Alright, time to see if I can pull a miracle out of thin air.
message.ic.42=No plan survives first contact... but let''s give it our best shot.
message.ic.43=If this doesn''t work, I''m blaming the universe. Just saying.
message.ic.44=One shot, one chance. Here goes everything.
message.ic.45=Sometimes you just gotta trust your instincts and hope for the best.
message.ic.46=If I get through this, I''m calling it pure skill. If not... well, oops.
message.ic.47=Here''s hoping I don''t make a complete fool of myself.
message.ic.48=You know what? I''ve survived worse. Let''s give it a shot.
message.ic.49=Whatever happens, I''m giving it everything I''ve got.
7 changes: 5 additions & 2 deletions MekHQ/resources/mekhq/resources/SkillCheckUtility.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
skillCheck.results={0} {1}<b>failed</b>{2} {3} {4} check with a roll of <b>{5}</b> vs. a target number of <b>{6}</b>. {7}.{8}
skillCheck.rerolled=\ {0} used a point of <b>Edge</b> when making this check.
# suppress inspection "UnusedProperty" for the whole file
skillCheck.results={0} {1}<b>{2}</b>{3} {4} {5} check with a roll of <b>{6}</b> vs. a target number of <b>{7}</b>.
skillCheck.results.success=Passed
skillCheck.results.failure=Failed
skillCheck.rerolled={0} used a point of <b>Edge</b> when making this check.
skillCheck.nullSkillName=ERROR: Skill name is null. Please report this bug to the MegaMek team.
skillCheck.nullPerson=ERROR: Person is null. Please report this bug to the MegaMek team.
3 changes: 2 additions & 1 deletion MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -6407,7 +6407,8 @@ public int getTemporaryPrisonerCapacity() {
}

public void setTemporaryPrisonerCapacity(int temporaryPrisonerCapacity) {
this.temporaryPrisonerCapacity = max(PrisonerEventManager.MINIMUM_TEMPORARY_CAPACITY, temporaryPrisonerCapacity);
this.temporaryPrisonerCapacity = max(PrisonerEventManager.MINIMUM_TEMPORARY_CAPACITY,
temporaryPrisonerCapacity);
}

public RandomEventLibraries getRandomEventLibraries() {
Expand Down
52 changes: 36 additions & 16 deletions MekHQ/src/mekhq/campaign/personnel/skills/SkillCheckUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static mekhq.campaign.personnel.skills.Skill.COUNT_UP_MAX_VALUE;
import static mekhq.campaign.personnel.skills.enums.MarginOfSuccess.BARELY_MADE_IT;
import static mekhq.campaign.personnel.skills.enums.MarginOfSuccess.DISASTROUS;
import static mekhq.campaign.personnel.skills.enums.MarginOfSuccess.getMarginOfSuccessObjectFromMarginValue;
import static mekhq.campaign.personnel.skills.enums.MarginOfSuccess.getMarginOfSuccessString;
import static mekhq.campaign.personnel.skills.enums.MarginOfSuccess.getMarginValue;
import static mekhq.utilities.MHQInternationalization.getFormattedTextAt;
Expand All @@ -46,6 +47,7 @@

import megamek.logging.MMLogger;
import mekhq.MekHQ;
import mekhq.campaign.event.PersonChangedEvent;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.skills.enums.MarginOfSuccess;
import mekhq.campaign.personnel.skills.enums.SkillAttribute;
Expand Down Expand Up @@ -77,6 +79,7 @@ public class SkillCheckUtility {
private int marginOfSuccess;
private String resultsText;
private int targetNumber;
boolean isCountUp;
private int roll;
private boolean usedEdge;

Expand Down Expand Up @@ -108,7 +111,9 @@ public SkillCheckUtility(final Person person, final String skillName, final int
return;
}

targetNumber = determineTargetNumber(person, skillName, miscModifier);
final SkillType skillType = SkillType.getType(skillName);
isCountUp = skillType.isCountUp();
targetNumber = determineTargetNumber(person, skillType, miscModifier);
performCheck(useEdge);
}

Expand Down Expand Up @@ -198,7 +203,6 @@ private String generateResultsText() {
String fullTitle = person.getHyperlinkedFullTitle();
String firstName = person.getFirstName();
String genderedReferenced = HIS_HER_THEIR.getDescriptor(person.getGender());
String marginOfSuccessText = getMarginOfSuccessString(marginOfSuccess);

String colorOpen;
int neutralMarginValue = getMarginValue(BARELY_MADE_IT);
Expand All @@ -209,22 +213,29 @@ private String generateResultsText() {
} else {
colorOpen = spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorPositiveHexColor());
}

String edgeUseText = !usedEdge ? "" : getFormattedTextAt(RESOURCE_BUNDLE, "skillCheck.rerolled", firstName);

return getFormattedTextAt(RESOURCE_BUNDLE,
String status = getFormattedTextAt(RESOURCE_BUNDLE,
"skillCheck.results." + (isSuccess() ? "success" : "failure"));
String mainMessage = getFormattedTextAt(RESOURCE_BUNDLE,
"skillCheck.results",
fullTitle,
colorOpen,
skillName,
colorOpen,
status,
CLOSING_SPAN_TAG,
genderedReferenced,
skillName,
roll,
targetNumber,
marginOfSuccessText,
edgeUseText);
targetNumber);

String edgeUseText = !usedEdge ? "" : getFormattedTextAt(RESOURCE_BUNDLE, "skillCheck.rerolled", firstName);

if (!edgeUseText.isBlank()) {
mainMessage = mainMessage + "<p>" + edgeUseText + "</p>";
}

MarginOfSuccess marginOfSuccessObject = getMarginOfSuccessObjectFromMarginValue(marginOfSuccess);
String marginOfSuccessText = getMarginOfSuccessString(marginOfSuccessObject);

return mainMessage + "<p>" + marginOfSuccessText + "</p>";
}

/**
Expand Down Expand Up @@ -330,7 +341,7 @@ public boolean isUsedEdge() {
* linked attributes. Otherwise, it is based on the final skill value and attribute modifiers.</p>
*
* @param person the {@link Person} performing the skill check
* @param skillName the name of the skill being used
* @param skillType the associated {@link SkillType} for the {@link Skill} being used.
* @param miscModifier any special modifiers, as an {@link Integer}. These values are subtracted from the target
* number, if the associated skill is classified as 'count up', otherwise they are added to the
* target number. This means negative values are bonuses, positive values are penalties.
Expand All @@ -340,8 +351,8 @@ public boolean isUsedEdge() {
* @author Illiani
* @since 0.50.5
*/
static int determineTargetNumber(Person person, String skillName, int miscModifier) {
final SkillType skillType = SkillType.getType(skillName);
public static int determineTargetNumber(Person person, SkillType skillType, int miscModifier) {
final String skillName = skillType.getName();
final Attributes characterAttributes = person.getATOWAttributes();

boolean isUntrained = !person.hasSkill(skillName);
Expand Down Expand Up @@ -419,7 +430,15 @@ boolean performInitialRoll(boolean useEdge) {
int availableEdge = person.getCurrentEdge();

if (roll >= targetNumber || !useEdge || availableEdge < 1) {
marginOfSuccess = MarginOfSuccess.getMarginOfSuccess(roll);
int difference = isCountUp ? targetNumber - roll : roll - targetNumber;

logger.info("Initial roll for skill check {}: {} vs {}. Margin of success: {}.",
skillName,
roll,
targetNumber,
difference);

marginOfSuccess = MarginOfSuccess.getMarginOfSuccess(difference);
resultsText = generateResultsText();
return true;
}
Expand All @@ -439,9 +458,10 @@ boolean performInitialRoll(boolean useEdge) {
*/
private void rollWithEdge() {
person.changeCurrentEdge(-1);
MekHQ.triggerEvent(new PersonChangedEvent(person));
usedEdge = true;

marginOfSuccess = MarginOfSuccess.getMarginOfSuccess(roll);
marginOfSuccess = MarginOfSuccess.getMarginOfSuccess(roll - targetNumber);
resultsText = generateResultsText();
}

Expand Down
Loading
Loading