Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"healthMultipliers": {
"blacked": 0.1
"blacked": 0.1,
"death": 0.3
},
"save": {
"health": true
Expand Down
13 changes: 0 additions & 13 deletions Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,6 @@ public static QuestStatusEnum GetQuestStatus(this PmcData pmcData, MongoId quest
return quest?.Status ?? QuestStatusEnum.Locked;
}

/// <summary>
/// Use values from the profiles template to reset all body part max values
/// </summary>
/// <param name="profile">Profile to update</param>
/// <param name="profileTemplate">Template used to create profile</param>
public static void ResetMaxLimbHp(this PmcData profile, TemplateSide profileTemplate)
{
foreach (var (partKey, bodyPart) in profile.Health.BodyParts)
{
bodyPart.Health.Maximum = profileTemplate.Character.Health.BodyParts[partKey].Health.Maximum;
}
}

/// <summary>
/// Handle Remove event
/// Remove item from player inventory + insured items array
Expand Down
34 changes: 22 additions & 12 deletions Libraries/SPTarkov.Server.Core/Helpers/HealthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Eft.Health;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
Expand All @@ -23,7 +24,7 @@ public class HealthHelper(ISptLogger<HealthHelper> logger, TimeUtil timeUtil, Co
/// <param name="sessionId">Session id</param>
/// <param name="pmcProfileToUpdate">Player profile to apply changes to</param>
/// <param name="healthChanges">Changes to apply </param>
public void ApplyHealthChangesToProfile(MongoId sessionId, PmcData pmcProfileToUpdate, BotBaseHealth healthChanges)
public void ApplyHealthChangesToProfile(MongoId sessionId, PmcData pmcProfileToUpdate, BotBaseHealth healthChanges, bool isDead)
{
/* TODO: Not used here, need to check node or a live profile, commented out for now to avoid the potential alloc - Cj
var fullProfile = saveServer.GetProfile(sessionId);
Expand All @@ -44,7 +45,7 @@ public void ApplyHealthChangesToProfile(MongoId sessionId, PmcData pmcProfileToU
var playerWasCursed = !PlayerHadGearOnRaidStart(pmcProfileToUpdate.Inventory);

// Alter saved profiles Health with values from post-raid client data
ModifyProfileHealthProperties(pmcProfileToUpdate, healthChanges.BodyParts, EffectsToSkip, playerWasCursed);
ModifyProfileHealthProperties(pmcProfileToUpdate, healthChanges.BodyParts, EffectsToSkip, isDead, playerWasCursed);

// Adjust hydration/energy/temperature
AdjustProfileHydrationEnergyTemperature(pmcProfileToUpdate, healthChanges);
Expand Down Expand Up @@ -103,11 +104,13 @@ protected bool PlayerHadGearOnRaidStart(BotBaseInventory inventory)
/// <param name="profileToAdjust">Player profile on server</param>
/// <param name="bodyPartChanges">Changes to apply</param>
/// <param name="effectsToSkip"></param>
/// <param name="isDead"></param>
/// <param name="playerWasCursed">Did player enter raid with no equipment</param>
protected void ModifyProfileHealthProperties(
PmcData profileToAdjust,
Dictionary<string, BodyPartHealth> bodyPartChanges,
HashSet<string>? effectsToSkip = null,
bool isDead = false,
bool playerWasCursed = false
)
{
Expand All @@ -131,17 +134,24 @@ protected void ModifyProfileHealthProperties(
if (HealthConfig.Save.Health)
{
// Apply hp changes to profile
matchingProfilePart.Health.Current =
partProperties.Health.Current == 0
? partProperties.Health.Maximum * HealthConfig.HealthMultipliers.Blacked
: partProperties.Health.Current;

matchingProfilePart.Health.Maximum = partProperties.Health.Maximum;

// Cursed player + limb was not lost, reset to 20%
if (playerWasCursed && matchingProfilePart.Health.Current > 20)
if (!isDead)
{
// If the player isn't dead, restore blacked limbs with a penalty
matchingProfilePart.Health.Current =
partProperties.Health.Current == 0
? matchingProfilePart.Health.Maximum * HealthConfig.HealthMultipliers.Blacked
: partProperties.Health.Current;
}
else
{
matchingProfilePart.Health.Current = 20;
// If the player died, set all limbs with a penalty
matchingProfilePart.Health.Current = matchingProfilePart.Health.Maximum * HealthConfig.HealthMultipliers.Death;

// Cursed player, body part gets set to 1 on death
if (playerWasCursed)
{
matchingProfilePart.Health.Current = 1;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public record HealthMultipliers
{
[JsonPropertyName("blacked")]
public double Blacked { get; set; }

[JsonPropertyName("death")]
public double Death { get; set; }
}

public record HealthSave
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,7 @@ string locationName
MergePmcAndScavEncyclopedias(serverPmcProfile, scavProfile);

// Handle temp, hydration, limb hp/effects
healthHelper.ApplyHealthChangesToProfile(sessionId, serverPmcProfile, postRaidProfile.Health);

// Required when player loses limb in-raid and fixes it, max now stuck at 50% or less if lost multiple times
var profileTemplate = profileHelper.GetProfileTemplateForSide(fullServerProfile.ProfileInfo.Edition, serverPmcProfile.Info.Side);
serverPmcProfile.ResetMaxLimbHp(profileTemplate);
healthHelper.ApplyHealthChangesToProfile(sessionId, serverPmcProfile, postRaidProfile.Health, isDead);

if (isTransfer)
{
Expand Down
Loading