From 95fd88c9ff6b274f1eb0171f450bff83d0e62999 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 14 Jun 2025 15:09:40 +0100 Subject: [PATCH] Updated transit health system to only remove `DestroyedPart` effect and not heal limbs by default #300 Exposed values in config Also apply code to PMC transits --- .../Assets/configs/location.json | 8 +++- .../Models/Spt/Config/LocationConfig.cs | 15 ++++++ .../Services/LocationLifecycleService.cs | 48 +++++++++++++++---- 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/Libraries/SPTarkov.Server.Assets/Assets/configs/location.json b/Libraries/SPTarkov.Server.Assets/Assets/configs/location.json index 5da282cf..525c91f1 100644 --- a/Libraries/SPTarkov.Server.Assets/Assets/configs/location.json +++ b/Libraries/SPTarkov.Server.Assets/Assets/configs/location.json @@ -510,5 +510,11 @@ "63a898a328e385334e0640a5", "634959225289190e5e773b3b" ], - "nonMaps": ["Base", "Develop", "Hideout", "PrivateArea", "Suburbs", "Terminal", "Town"] + "nonMaps": ["Base", "Develop", "Hideout", "PrivateArea", "Suburbs", "Terminal", "Town"], + "transitSettings": { + "effectsToRemove": ["DestroyedPart"], + "adjustLimbHealthPoints": false, + "limbHealPercent": 1 + + } } diff --git a/Libraries/SPTarkov.Server.Core/Models/Spt/Config/LocationConfig.cs b/Libraries/SPTarkov.Server.Core/Models/Spt/Config/LocationConfig.cs index b28ca7ca..6a3ff5d8 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Spt/Config/LocationConfig.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Spt/Config/LocationConfig.cs @@ -233,6 +233,21 @@ public record LocationConfig : BaseConfig get; set; } + + [JsonPropertyName("transitSettings")] + public TransitSettings? TransitSettings { get; set; } +} + +public record TransitSettings +{ + [JsonPropertyName("effectsToRemove")] + public HashSet? EffectsToRemove { get; set; } + + [JsonPropertyName("adjustLimbHealthPoints")] + public bool? AdjustLimbHealthPoints { get; set; } + + [JsonPropertyName("limbHealPercent")] + public int? LimbHealPercent { get; set; } } public record ReserveRaiderSpawnChanceOverrides diff --git a/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs b/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs index 3fddbdec..7e1b9a8c 100644 --- a/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs @@ -677,8 +677,8 @@ public class LocationLifecycleService // Transfer over hp and effects - not necessary for runthroughs, but it causes no issues scavProfile.Health = postRaidProfile.Health; - // Apply minor healing to limb hp and effects - ResetLimbHpMidTransit(scavProfile.Health); + // Adjust limb hp and effects while transiting + UpdateLimbValuesAfterTransit(scavProfile.Health); // We want scav inventory to persist into next raid when pscav is moving between maps // Also adjust FiR status when exit was runthrough @@ -790,20 +790,42 @@ public class LocationLifecycleService /// Slightly fix broken limbs and remove effects /// /// Profile health data to adjust - protected void ResetLimbHpMidTransit(BotBaseHealth? profileHealth) + protected void UpdateLimbValuesAfterTransit(BotBaseHealth? profileHealth) { - foreach (var (limbId, hpValues) in profileHealth.BodyParts) + var transitSettings = _locationConfig.TransitSettings; + if (transitSettings == null) { - if (hpValues.Health.Minimum <= 0) + _logger.Warning("Unable to find: _locationConfig.TransitSettings"); + + return; + } + + // Check each body part + foreach (var (_, hpValues) in profileHealth.BodyParts) + { + if (transitSettings.AdjustLimbHealthPoints.GetValueOrDefault() + && hpValues.Health.Minimum <= 0) { - // Limb has been destroyed, reset to 30% TODO: Expose 30% in config - hpValues.Health.Current = _randomUtil.GetPercentOfValue(30, hpValues.Health.Maximum.Value); + // Limb has been destroyed, reset + hpValues.Health.Current = _randomUtil.GetPercentOfValue( + transitSettings.LimbHealPercent.GetValueOrDefault(30), + hpValues.Health.Maximum.Value); } - // Limb has effects, remove them all - if (hpValues.Effects.Count > 0) + if (!(hpValues.Effects?.Count > 0)) { - hpValues.Effects.Clear(); + // No effects on limb, skip + continue; + } + + // Limb has effects, check for blacklisted values and remove + var keysToRemove = hpValues.Effects.Keys + .Where(key => transitSettings.EffectsToRemove.Contains(key)) + .ToHashSet(); + + foreach (var key in keysToRemove) + { + hpValues.Effects.Remove(key); } } } @@ -896,6 +918,12 @@ public class LocationLifecycleService // Handle temp, hydration, limb hp/effects _healthHelper.UpdateProfileHealthPostRaid(pmcProfile, postRaidProfile.Health, sessionId, isDead); + if (isTransfer) + { + // Adjust limb hp and effects while transiting + UpdateLimbValuesAfterTransit(pmcProfile.Health); + } + // This must occur _BEFORE_ `deleteInventory`, as that method clears insured items HandleInsuredItemLostEvent(sessionId, pmcProfile, request, locationName);