From 65d8d7432dacca0fc72e9dcda631a605a5684f74 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 28 Jun 2025 09:00:23 +0100 Subject: [PATCH] Converted `DefaultVitality` into extension method --- .../Extensions/VitalityExtensions.cs | 79 +++++++++++++++++++ .../Helpers/HealthHelper.cs | 77 +----------------- .../SPTarkov.Server.Core.csproj | 17 +--- 3 files changed, 85 insertions(+), 88 deletions(-) create mode 100644 Libraries/SPTarkov.Server.Core/Extensions/VitalityExtensions.cs diff --git a/Libraries/SPTarkov.Server.Core/Extensions/VitalityExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/VitalityExtensions.cs new file mode 100644 index 00000000..b3839475 --- /dev/null +++ b/Libraries/SPTarkov.Server.Core/Extensions/VitalityExtensions.cs @@ -0,0 +1,79 @@ +using SPTarkov.Server.Core.Models.Eft.Common.Tables; +using SPTarkov.Server.Core.Models.Eft.Profile; + +namespace SPTarkov.Server.Core.Extensions +{ + public static class VitalityExtensions + { + public static void SetDefaults(this Vitality? vitality) + { + vitality ??= new Vitality + { + Health = null, + Energy = 0, + Temperature = 0, + Hydration = 0, + }; + + vitality.Health = new Dictionary + { + { + "Head", + new BodyPartHealth + { + Health = new CurrentMinMax { Current = 0 }, + Effects = new Dictionary(), + } + }, + { + "Chest", + new BodyPartHealth + { + Health = new CurrentMinMax { Current = 0 }, + Effects = new Dictionary(), + } + }, + { + "Stomach", + new BodyPartHealth + { + Health = new CurrentMinMax { Current = 0 }, + Effects = new Dictionary(), + } + }, + { + "LeftArm", + new BodyPartHealth + { + Health = new CurrentMinMax { Current = 0 }, + Effects = new Dictionary(), + } + }, + { + "RightArm", + new BodyPartHealth + { + Health = new CurrentMinMax { Current = 0 }, + Effects = new Dictionary(), + } + }, + { + "LeftLeg", + new BodyPartHealth + { + Health = new CurrentMinMax { Current = 0 }, + Effects = new Dictionary(), + } + }, + { + "RightLeg", + new BodyPartHealth + { + Health = new CurrentMinMax { Current = 0 }, + Effects = new Dictionary(), + } + }, + }; + } + } +} diff --git a/Libraries/SPTarkov.Server.Core/Helpers/HealthHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/HealthHelper.cs index 7433363e..907d39b9 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/HealthHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/HealthHelper.cs @@ -1,4 +1,5 @@ using SPTarkov.DI.Annotations; +using SPTarkov.Server.Core.Extensions; using SPTarkov.Server.Core.Models.Eft.Common; using SPTarkov.Server.Core.Models.Eft.Common.Tables; using SPTarkov.Server.Core.Models.Eft.Profile; @@ -6,7 +7,6 @@ using SPTarkov.Server.Core.Models.Spt.Config; using SPTarkov.Server.Core.Servers; using SPTarkov.Server.Core.Utils; using BodyPartHealth = SPTarkov.Server.Core.Models.Eft.Common.Tables.BodyPartHealth; -using Vitality = SPTarkov.Server.Core.Models.Eft.Profile.Vitality; namespace SPTarkov.Server.Core.Helpers; @@ -18,7 +18,7 @@ public class HealthHelper( ConfigServer _configServer ) { - protected HealthConfig _healthConfig = _configServer.GetConfig(); + protected readonly HealthConfig _healthConfig = _configServer.GetConfig(); /// /// Resets the profiles vitality/health and vitality/effects properties to their defaults @@ -29,82 +29,11 @@ public class HealthHelper( { var profile = _saveServer.GetProfile(sessionID); - DefaultVitality(profile.VitalityData); + profile.VitalityData.SetDefaults(); return profile; } - public void DefaultVitality(Vitality? vitality) - { - vitality ??= new Vitality - { - Health = null, - Energy = 0, - Temperature = 0, - Hydration = 0, - }; - - vitality.Health = new Dictionary - { - { - "Head", - new BodyPartHealth - { - Health = new CurrentMinMax { Current = 0 }, - Effects = new Dictionary(), - } - }, - { - "Chest", - new BodyPartHealth - { - Health = new CurrentMinMax { Current = 0 }, - Effects = new Dictionary(), - } - }, - { - "Stomach", - new BodyPartHealth - { - Health = new CurrentMinMax { Current = 0 }, - Effects = new Dictionary(), - } - }, - { - "LeftArm", - new BodyPartHealth - { - Health = new CurrentMinMax { Current = 0 }, - Effects = new Dictionary(), - } - }, - { - "RightArm", - new BodyPartHealth - { - Health = new CurrentMinMax { Current = 0 }, - Effects = new Dictionary(), - } - }, - { - "LeftLeg", - new BodyPartHealth - { - Health = new CurrentMinMax { Current = 0 }, - Effects = new Dictionary(), - } - }, - { - "RightLeg", - new BodyPartHealth - { - Health = new CurrentMinMax { Current = 0 }, - Effects = new Dictionary(), - } - }, - }; - } - /// /// Update player profile vitality values with changes from client request object /// diff --git a/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj b/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj index c86a3248..83a3cbe4 100644 --- a/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj +++ b/Libraries/SPTarkov.Server.Core/SPTarkov.Server.Core.csproj @@ -32,22 +32,11 @@ - - + + - +