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

Refactored Edge Handling to Use Adjusted Edge Values #6573

Open
wants to merge 2 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
23 changes: 22 additions & 1 deletion MekHQ/src/mekhq/campaign/personnel/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -4208,7 +4208,28 @@ public String getOptionList(@Nullable String sep, final String groupKey) {
// endregion Personnel Options

// region edge

/**
* Retrieves the edge value for the current person.
*
* <p><b>Usage:</b> This method gets the character's raw Edge score. Generally you likely want to use
* {@link #getAdjustedEdge()} instead, as that includes adjustments for the character's {@code unlucky} trait.</p>
*
* @return The edge value defined in the person's options.
*/
public int getEdge() {
return getOptions().intOption(OptionsConstants.EDGE);
}

/**
* Retrieves the adjusted edge value for the current person.
*
* <p>The adjusted Edge value is calculated by subtracting the person's level of bad luck (unlucky)
* from their base Edge value.</p>
*
* @return The adjusted edge value after accounting for the person's level of bad luck.
*/
public int getAdjustedEdge() {
return getOptions().intOption(OptionsConstants.EDGE) - unlucky;
}

Expand All @@ -4229,7 +4250,7 @@ public void changeEdge(final int amount) {
* Resets support personnel edge points to the purchased level. Used for weekly refresh.
*/
public void resetCurrentEdge() {
setCurrentEdge(getEdge());
setCurrentEdge(getAdjustedEdge());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions MekHQ/src/mekhq/campaign/unit/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4829,12 +4829,12 @@ public void resetPilotAndEntity() {
if (getCampaign().getCampaignOptions().isUseEdge()) {
double sumEdge = 0;
for (Person p : drivers) {
sumEdge += p.getEdge();
sumEdge += p.getCurrentEdge();
}
// Again, don't count infantrymen twice
if (!entity.hasETypeFlag(Entity.ETYPE_INFANTRY)) {
for (Person p : gunners) {
sumEdge += p.getEdge();
sumEdge += p.getCurrentEdge();
}
}
// Average the edge values of pilots and gunners. The Spacecraft Engineer
Expand Down Expand Up @@ -5228,7 +5228,7 @@ public void resetEngineer() {
}
sumEdgeUsed = engineer.getEdgeUsed();
}
sumEdge += p.getEdge();
sumEdge += p.getAdjustedEdge();

if (p.hasSkill(SkillType.S_TECH_VESSEL)) {
sumSkill += p.getSkill(SkillType.S_TECH_VESSEL).getLevel();
Expand Down Expand Up @@ -5262,7 +5262,7 @@ public void resetEngineer() {
}
engineer.addSkill(SkillType.S_TECH_VESSEL, sumSkill / nCrew, sumBonus / nCrew);
engineer.setEdgeUsed(sumEdgeUsed);
engineer.setCurrentEdge((sumEdge - sumEdgeUsed) / nCrew);
engineer.setCurrentEdge(max(0, (sumEdge - sumEdgeUsed) / nCrew));
engineer.setUnit(this);
} else {
engineer = null;
Expand Down
7 changes: 3 additions & 4 deletions MekHQ/src/mekhq/gui/view/PersonViewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
import mekhq.gui.utilities.MarkdownRenderer;
import mekhq.gui.utilities.WrapLayout;

import static megamek.client.ui.WrapLayout.wordWrap;

/**
* A custom panel that gets filled in with goodies from a Person record
*
Expand Down Expand Up @@ -1602,7 +1600,8 @@ private JPanel fillSkills() {
}
}

if (campaign.getCampaignOptions().isUseEdge() && (person.getEdge() > 0)) {
int edge = person.getAdjustedEdge();
if (campaign.getCampaignOptions().isUseEdge() && (edge != 0)) {
lblEdge1.setName("lblEdge1");
lblEdge1.setText(resourceMap.getString("lblEdge1.text"));
gridBagConstraints = new GridBagConstraints();
Expand All @@ -1614,7 +1613,7 @@ private JPanel fillSkills() {

lblEdge2.setName("lblEdge2");
lblEdge1.setLabelFor(lblEdge2);
lblEdge2.setText(Integer.toString(person.getEdge()));
lblEdge2.setText(Integer.toString(edge));
lblEdge2.setToolTipText(person.getEdgeTooltip());
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
Expand Down
Loading