Permanent injuries can't be replaced with temporal ones#8803
Permanent injuries can't be replaced with temporal ones#8803rjhancock merged 7 commits intoMegaMek:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the advanced medical system where post-combat stress effects could cause a permanent injury to be replaced by a temporary (healing) injury, resulting in the permanent injury effectively disappearing once the temporary one healed.
Changes:
- Short-circuits
genStressEffect(...)for several injury types when the current injury is permanent, returning noGameEffects. - Prevents stress-driven recovery timer resets and stress-driven “upgrade/replace” injury transitions from applying to permanent injuries.
Comments suppressed due to low confidence (3)
MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java:546
- The displayed chance is always shown as 100% here: for hits < 5, (1 + hits) * 100 / 6 is at most ~83, so Math.max(..., 100) will always return 100. This makes the user-facing stress effect text misleading; use a cap (e.g., Math.min(..., 100)) or compute the percentage directly from the actual 1d6 + hits >= 5 probability.
String secondEffectFluff = "development of a chronic traumatic encephalopathy";
if (hits < 5) {
int worseningChance = Math.max((int) Math.round((1 + hits) * 100.0 / 6.0), 100);
secondEffectFluff = worseningChance + "% chance of " + secondEffectFluff;
}
MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java:710
- The computed "worseningChance" is always 100% for hits < 5 because Math.max(..., 100) forces a minimum of 100. This causes the effect description to be incorrect relative to the real probability check (rnd.applyAsInt(6) + hits >= 5). Consider switching to a cap (Math.min) or deriving the percent from the same condition used in the effect.
String secondEffectFluff = (i.getHits() < 3) ? "internal bleeding worsening" : "death";
if (hits < 5) {
int worseningChance = Math.max((int) Math.round((1 + hits) * 100.0 / 6.0), 100);
secondEffectFluff = worseningChance + "% chance of " + secondEffectFluff;
}
MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java:922
- Same as elsewhere: this percentage calculation always yields 100% for hits < 5 due to Math.max(..., 100), so the effect text will always claim a 100% chance even when the underlying roll is not guaranteed. Adjust the calculation (e.g., cap with Math.min or compute from the 1d6 + hits >= 5 threshold) so the message matches behavior.
String secondEffectFluff = (injury.getHits() == 1) ?
"concussion worsening" :
"development of a cerebral contusion";
if (hits < 5) {
int worseningChance = Math.max((int) Math.round((1 + hits) * 100.0 / 6.0), 100);
secondEffectFluff = worseningChance + "% chance of " + secondEffectFluff;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8803 +/- ##
============================================
+ Coverage 13.20% 13.22% +0.02%
- Complexity 7862 7873 +11
============================================
Files 1306 1306
Lines 169146 169162 +16
Branches 25445 25452 +7
============================================
+ Hits 22340 22378 +38
+ Misses 144643 144606 -37
- Partials 2163 2178 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
MekHQ/src/mekhq/campaign/personnel/medical/advancedMedical/InjuryTypes.java
Outdated
Show resolved
Hide resolved
…/mekhq into vicentecartas/7565
Fixes #7565
The bug report explains the issue pretty well: the worsening of a permanent injury could replace it by a temporal one. This happens in multiple injuries types, not just concussions.
This fix takes the decision that permanent injuries are chronic damage, so combat stress cannot affect them. But non-permanent injuries (representing non chronic injuries) can be made worse by stress. By not returning any GameEffect, the permanent injuries will be left alone.
Added also a parametrized unit test to validate this based on PR feedback.