Skip to content

Conversation

@DrakiaXYZ
Copy link
Contributor

  • Re-add death penalty for limbs
  • Correctly set body part HP to 1 for cursed death only
  • Use the server profile body part max HP for calculating penalties
  • Never modify the body part max HP on the profile
  • Remove ResetMaxLimbHp as it's unnecessary if we never update max HP elsewhere

- Re-add death penalty for limbs
- Correctly set body part HP to 1 for cursed death only
- Use the server profile body part max HP for calculating penalties
- Never modify the body part max HP on the profile
- Remove ResetMaxLimbHp as it's unnecessary if we never update max HP elsewhere
@qodo-merge-for-open-source
Copy link

qodo-merge-for-open-source bot commented Oct 26, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix compilation error from incorrect operator
Suggestion Impact:The commit removed the "?? 0" from the health calculation and consolidated the expression into a single line, resolving the compilation issue.

code diff:

-                    matchingProfilePart.Health.Current =
-                        matchingProfilePart.Health.Maximum
-                            * HealthConfig.HealthMultipliers.Death
-                        ?? 0;
+                    matchingProfilePart.Health.Current = matchingProfilePart.Health.Maximum * HealthConfig.HealthMultipliers.Death;

Remove the null-coalescing operator ?? 0 from the health calculation, as it is
incorrectly applied to a non-nullable double and will cause a compilation error.

Libraries/SPTarkov.Server.Core/Helpers/HealthHelper.cs [148-151]

 matchingProfilePart.Health.Current =
     matchingProfilePart.Health.Maximum
-        * HealthConfig.HealthMultipliers.Death
-    ?? 0;
+    * HealthConfig.HealthMultipliers.Death;
Suggestion importance[1-10]: 10

__

Why: The suggestion correctly identifies a compilation error caused by applying the null-coalescing operator ?? to a non-nullable double type, which is a critical issue introduced in the PR.

High
Learned
best practice
Add eligibility checks and try/catch

Validate that the state mutation is only applied to eligible PMC raids and wrap
the mutation in try/catch with clear logging to avoid corrupting profiles on
unexpected inputs.

Libraries/SPTarkov.Server.Core/Helpers/HealthHelper.cs [27-62]

 public void ApplyHealthChangesToProfile(MongoId sessionId, PmcData pmcProfileToUpdate, BotBaseHealth healthChanges, bool isDead)
 {
-    ...
-    ModifyProfileHealthProperties(pmcProfileToUpdate, healthChanges.BodyParts, EffectsToSkip, isDead, playerWasCursed);
-    ...
-    pmcProfileToUpdate.Health.UpdateTime = timeUtil.GetTimeStamp();
+    if (pmcProfileToUpdate is null || healthChanges is null || healthChanges.BodyParts is null)
+    {
+        logger.Error("Invalid health change request; skipping apply. Session: {SessionId}", sessionId);
+        return;
+    }
+
+    try
+    {
+        var playerWasCursed = !PlayerHadGearOnRaidStart(pmcProfileToUpdate.Inventory);
+
+        ModifyProfileHealthProperties(pmcProfileToUpdate, healthChanges.BodyParts, EffectsToSkip, isDead, playerWasCursed);
+        AdjustProfileHydrationEnergyTemperature(pmcProfileToUpdate, healthChanges);
+
+        if (pmcProfileToUpdate.Health is null)
+        {
+            throw new HealthHelperException("pmcProfileToUpdate.Health is null when trying to apply health changes");
+        }
+
+        pmcProfileToUpdate.Health.UpdateTime = timeUtil.GetTimeStamp();
+    }
+    catch (Exception ex)
+    {
+        logger.Error(ex, "Failed to apply health changes; leaving previous health state. Session: {SessionId}", sessionId);
+    }
 }
Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Guard high-risk state mutations with precise eligibility checks and robust error handling; restrict actions to the correct context and default to safe behavior.

Low
  • Update

@chompDev chompDev merged commit d375879 into sp-tarkov:develop Oct 26, 2025
5 checks passed
@DrakiaXYZ DrakiaXYZ deleted the fix-postraidhealth branch October 28, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants