From 078e1b1b364046093a74866a33eeaa80302e3b87 Mon Sep 17 00:00:00 2001 From: CWX Date: Tue, 28 Jan 2025 15:27:45 +0000 Subject: [PATCH] Improve Health system to Use EFT's models and actual Types, also fixed some RequestData not using the base record --- Libraries/Core/Helpers/HealthHelper.cs | 382 +++++++++--------- .../Eft/Health/HealthTreatmentRequestData.cs | 7 +- .../Eft/Health/OffraidEatRequestData.cs | 3 +- .../Eft/Health/OffraidHealRequestData.cs | 14 +- ...rcleOfCultistProductionStartRequestData.cs | 3 +- ...outContinuousProductionStartRequestData.cs | 3 +- .../HideoutCustomizationApplyRequestData.cs | 3 +- ...outCustomizationSetMannequinPoseRequest.cs | 3 +- .../HideoutDeleteProductionRequestData.cs | 3 +- .../Hideout/HideoutImproveAreaRequestData.cs | 3 +- .../Hideout/HideoutPutItemInRequestData.cs | 3 +- .../HideoutScavCaseStartRequestData.cs | 3 +- ...HideoutSingleProductionStartRequestData.cs | 3 +- .../Hideout/HideoutTakeItemOutRequestData.cs | 3 +- .../HideoutTakeProductionRequestData.cs | 3 +- .../Hideout/HideoutToggleAreaRequestData.cs | 3 +- .../HideoutUpgradeCompleteRequestData.cs | 3 +- .../Eft/Hideout/HideoutUpgradeRequestData.cs | 3 +- .../Eft/Hideout/RecordShootingRangePoints.cs | 3 +- .../Models/Eft/Insurance/InsureRequestData.cs | 3 +- .../Core/Models/Eft/Profile/SptProfile.cs | 97 +---- .../Routers/SaveLoad/HealthSaveLoadRouter.cs | 111 +++-- .../Core/Services/LocationLifecycleService.cs | 2 +- 23 files changed, 324 insertions(+), 340 deletions(-) diff --git a/Libraries/Core/Helpers/HealthHelper.cs b/Libraries/Core/Helpers/HealthHelper.cs index 9be8bcd6..61262a60 100644 --- a/Libraries/Core/Helpers/HealthHelper.cs +++ b/Libraries/Core/Helpers/HealthHelper.cs @@ -1,34 +1,27 @@ using SptCommon.Annotations; using Core.Models.Eft.Common; using Core.Models.Eft.Common.Tables; -using Core.Models.Eft.Health; using Core.Models.Eft.Profile; using Core.Models.Spt.Config; -using Core.Models.Utils; using Core.Servers; using Core.Services; using Core.Utils; -using Core.Utils.Cloners; using SptCommon.Extensions; using BodyPartHealth = Core.Models.Eft.Common.Tables.BodyPartHealth; -using Effects = Core.Models.Eft.Profile.Effects; -using Health = Core.Models.Eft.Profile.Health; using Vitality = Core.Models.Eft.Profile.Vitality; namespace Core.Helpers; [Injectable] public class HealthHelper( - ISptLogger _logger, TimeUtil _timeUtil, SaveServer _saveServer, DatabaseService _databaseService, - ConfigServer _configServer, - ICloner _cloner + ConfigServer _configServer ) { protected HealthConfig _healthConfig = _configServer.GetConfig(); - + /// /// Resets the profiles vitality/health and vitality/effects properties to their defaults /// @@ -38,34 +31,90 @@ public class HealthHelper( { var profile = _saveServer.GetProfile(sessionID); - profile.VitalityData ??= new Vitality { Health = null, Effects = null }; - - profile.VitalityData.Health = new Health { - Hydration = 0, - Energy = 0, - Temperature = 0, - Head = 0, - Chest = 0, - Stomach = 0, - LeftArm = 0, - RightArm = 0, - LeftLeg = 0, - RightLeg = 0, - }; - - profile.VitalityData.Effects = new Effects { - Head = new Head(), - Chest = new Chest(), - Stomach = new Stomach(), - LeftArm = new LeftArm(), - RightArm = new RightArm(), - LeftLeg = new LeftLeg(), - RightLeg = new RightLeg(), - }; + DefaultVitality(profile.VitalityData); 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 /// @@ -86,10 +135,11 @@ public class HealthHelper( var profileSide = fullProfile.CharacterData.PmcData.Info.Side; var defaultTemperature = - _databaseService.GetProfiles() - .GetByJsonProp(profileEdition) - .GetByJsonProp(profileSide.ToLower()) - ?.Character?.Health?.Temperature ?? new CurrentMinMax { Current = 36.6 }; + _databaseService.GetProfiles() + .GetByJsonProp(profileEdition) + .GetByJsonProp(profileSide.ToLower()) + ?.Character?.Health?.Temperature ?? + new CurrentMinMax { Current = 36.6 }; StoreHydrationEnergyTempInProfile( fullProfile, @@ -99,22 +149,23 @@ public class HealthHelper( ); // Store limb effects from post-raid in profile - foreach (var bodyPart in postRaidHealth.BodyParts) { + foreach (var bodyPart in postRaidHealth.BodyParts) + { // Effects - if (postRaidHealth.BodyParts[bodyPart.Key].Effects is not null) { - // fullProfile.VitalityData.Effects[bodyPart.Key] = postRaidHealth.BodyParts[bodyPart.Key].Effects; - // TODO: this will need to change, typing is all fucked up + if (postRaidHealth.BodyParts[bodyPart.Key].Effects is not null) + { + fullProfile.VitalityData.Health[bodyPart.Key].Effects = postRaidHealth.BodyParts[bodyPart.Key].Effects; } // Limb hp if (!isDead) { // Player alive, not is limb alive - var byJsonProp = fullProfile.VitalityData.Health.GetByJsonProp(bodyPart.Key); - byJsonProp = postRaidHealth.BodyParts[bodyPart.Key].Health.Current ?? 0; - } else { - var byJsonProp = fullProfile.VitalityData.Health.GetByJsonProp(bodyPart.Key); - byJsonProp = (pmcData.Health.BodyParts[bodyPart.Key].Health.Maximum * _healthConfig.HealthMultipliers.Death) ?? 0; + fullProfile.VitalityData.Health[bodyPart.Key].Health.Current = postRaidHealth.BodyParts[bodyPart.Key].Health.Current ?? 0; + } + else + { + fullProfile.VitalityData.Health[bodyPart.Key].Health.Current = (pmcData.Health.BodyParts[bodyPart.Key].Health.Maximum * _healthConfig.HealthMultipliers.Death) ?? 0; } } @@ -136,9 +187,9 @@ public class HealthHelper( double energy, double temprature) { - fullProfile.VitalityData.Health.Hydration = hydration; - fullProfile.VitalityData.Health.Energy = energy; - fullProfile.VitalityData.Health.Temperature = temprature; + fullProfile.VitalityData.Hydration = hydration; + fullProfile.VitalityData.Energy = energy; + fullProfile.VitalityData.Temperature = temprature; } /// @@ -150,10 +201,12 @@ public class HealthHelper( { // Iterate over each body part List effectsToIgnore = ["Dehydration", "Exhaustion"]; - foreach (var bodyPartId in postRaidBodyParts) { + foreach (var bodyPartId in postRaidBodyParts) + { // Get effects on body part from profile var bodyPartEffects = postRaidBodyParts[bodyPartId.Key].Effects; - foreach (var effect in bodyPartEffects) { + foreach (var effect in bodyPartEffects) + { var effectDetails = bodyPartEffects[effect.Key]; // Null guard @@ -161,82 +214,33 @@ public class HealthHelper( // Effect already exists on limb in server profile, skip var profileBodyPartEffects = profileData.Health.BodyParts[bodyPartId.Key].Effects; - if (profileBodyPartEffects[effect.Key] is not null) { - if (effectsToIgnore.Contains(effect.Key)) { + if (profileBodyPartEffects.TryGetValue(effect.Key, out var dictEffect)) + { + if (effectsToIgnore.Contains(effect.Key)) + { // Get rid of certain effects we dont want to persist out of raid - profileBodyPartEffects[effect.Key] = null; + dictEffect = null; } continue; } - if (effectsToIgnore.Contains(effect.Key)) { + if (effectsToIgnore.Contains(effect.Key)) + { // Do not pass some effects to out of raid profile continue; } + var effectToAdd = new BodyPartEffectProperties { Time = effectDetails.Time ?? -1 }; // Add effect to server profile - profileBodyPartEffects[effect.Key] = new BodyPartEffectProperties { Time = effectDetails.Time ?? -1 }; + if (profileBodyPartEffects.TryAdd(effect.Key, effectToAdd)) + { + profileBodyPartEffects[effect.Key] = effectToAdd; + } } } } - /// - /// Update player profile vitality values with changes from client request object - /// - /// Player profile - /// Heal request - /// Session id - /// Should effects be added to profile (default - true) - /// Should all prior effects be removed before apply new ones (default - true) - public void SaveVitality( - PmcData pmcData, - SyncHealthRequestData request, - string sessionID, - bool addEffects = true, - bool deleteExistingEffects = true) - { - var postRaidBodyParts = request.Health; // post raid health settings - var fullProfile = _saveServer.GetProfile(sessionID); - var profileEffects = fullProfile.VitalityData.Effects; - - StoreHydrationEnergyTempInProfile(fullProfile, request.Hydration ?? 0, request.Energy ?? 0, request.Temperature ?? 0); - - // Process request data into profile - foreach (var bodyPart in postRaidBodyParts) { - // Transfer effects from request to profile - if (bodyPart.Effects is not null) { - // profileEffects[bodyPart] = postRaidBodyParts[bodyPart].Effects; - } - - if (request.IsAlive ?? false) { - // Player alive, not is limb alive - // fullProfile.VitalityData.Health[bodyPart] = postRaidBodyParts[bodyPart].Current; - } else { - // fullProfile.VitalityData.Health[bodyPart] = - // pmcData.Health.BodyParts[bodyPart].Health.Maximum * _healthConfig.HealthMultipliers.Death; - }// TODO: this will need to change, typing is all fucked up - } - - // Add effects to body parts if enabled - if (addEffects) { - SaveEffects( - pmcData, - sessionID, - _cloner.Clone(_saveServer.GetProfile(sessionID).VitalityData.Effects), - deleteExistingEffects - ); - } - - // Adjust hydration/energy/temp and limb hp - SaveHealth(pmcData, sessionID); - - ResetVitality(sessionID); - - // Update last edited timestamp - pmcData.Health.UpdateTime = _timeUtil.GetTimeStamp(); - } - /// /// Adjust hydration/energy/temperate and body part hp values in player profile to values in profile.vitality /// @@ -244,40 +248,45 @@ public class HealthHelper( /// Session id protected void SaveHealth(PmcData pmcData, string sessionID) { - // TODO: this will need to change, typing is all fucked up - // if (!_healthConfig.Save.Health) { - // return; - // } - // - // var profileHealth = _saveServer.GetProfile(sessionID).VitalityData.Health; - // foreach (var healthModifier in profileHealth) { - // let target = profileHealth[healthModifier]; - // - // if (["Hydration", "Energy", "Temperature"].includes(healthModifier)) { - // // Set resources - // if (target > pmcData.Health[healthModifier].Maximum) { - // target = pmcData.Health[healthModifier].Maximum; - // } - // - // pmcData.Health[healthModifier].Current = Math.round(target); - // } else { - // // Over max, limit - // if (target > pmcData.Health.BodyParts[healthModifier].Health.Maximum) { - // target = pmcData.Health.BodyParts[healthModifier].Health.Maximum; - // } - // - // // Part was zeroed out in raid - // if (target === 0) { - // // Blacked body part - // target = Math.round( - // pmcData.Health.BodyParts[healthModifier].Health.Maximum * - // this.healthConfig.healthMultipliers.blacked, - // ); - // } - // - // pmcData.Health.BodyParts[healthModifier].Health.Current = Math.round(target); - // } - // } + if (!_healthConfig.Save.Health) { + return; + } + + var profileHealth = _saveServer.GetProfile(sessionID).VitalityData; + + if (profileHealth.Hydration > pmcData.Health.Hydration.Maximum) + { + profileHealth.Hydration = pmcData.Health.Hydration.Maximum; + } + + if (profileHealth.Energy > pmcData.Health.Energy.Maximum) + { + profileHealth.Energy = pmcData.Health.Energy.Maximum; + } + + if (profileHealth.Temperature > pmcData.Health.Temperature.Maximum) + { + profileHealth.Temperature = pmcData.Health.Temperature.Maximum; + } + + pmcData.Health.Hydration.Current = Math.Round(profileHealth.Hydration ?? 0); + pmcData.Health.Energy.Current = Math.Round(profileHealth.Energy ?? 0); + pmcData.Health.Temperature.Current = Math.Round(profileHealth.Temperature ?? 0); + + foreach (var bodyPart in pmcData.Health.BodyParts) + { + if (profileHealth.Health[bodyPart.Key].Health.Maximum > bodyPart.Value.Health.Maximum) + { + profileHealth.Health[bodyPart.Key].Health.Maximum = bodyPart.Value.Health.Maximum; + } + + if (profileHealth.Health[bodyPart.Key].Health.Current == 0) + { + profileHealth.Health[bodyPart.Key].Health.Current = bodyPart.Value.Health.Maximum * _healthConfig.HealthMultipliers.Blacked; + } + + bodyPart.Value.Health.Current = Math.Round(profileHealth.Health[bodyPart.Key].Health.Current ?? 0); + } } /// @@ -292,45 +301,35 @@ public class HealthHelper( protected void SaveEffects( PmcData pmcData, string sessionID, - Effects bodyPartsWithEffects, + Dictionary bodyPartsWithEffects, bool deleteExistingEffects = true) { // TODO: this will need to change, typing is all fucked up - // if (!this.healthConfig.save.effects) { - // return; - // } - // - // for (const bodyPart in bodyPartsWithEffects) { - // // clear effects from profile bodyPart - // if (deleteExistingEffects) { - // // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the effect. - // delete pmcData.Health.BodyParts[bodyPart].Effects; - // } - // - // for (const effectType in bodyPartsWithEffects[bodyPart]) { - // if (typeof effectType !== "string") { - // this.logger.warning(`Effect ${effectType} on body part ${bodyPart} not a string, report this`); - // } - // - // // // data can be index or the effect string (e.g. "Fracture") itself - // // const effect = /^-?\d+$/.test(effectValue) // is an int - // // ? nodeEffects[bodyPart][effectValue] - // // : effectValue; - // let time = bodyPartsWithEffects[bodyPart][effectType]; - // if (time) { - // // Sometimes the value can be Infinity instead of -1, blame HealthListener.cs in modules - // if (time === "Infinity") { - // this.logger.warning( - // `Effect ${effectType} found with value of Infinity, changed to -1, this is an issue with HealthListener.cs`, - // ); - // time = -1; - // } - // this.addEffect(pmcData, bodyPart, effectType, time); - // } else { - // this.addEffect(pmcData, bodyPart, effectType); - // } - // } - // } + if (!_healthConfig.Save.Effects) + { + return; + } + + foreach ( var bodyPart in bodyPartsWithEffects) { + // clear effects from profile bodyPart + if (deleteExistingEffects) + { + pmcData.Health.BodyParts[bodyPart.Key].Effects = new Dictionary(); + } + + foreach ( var effectType in bodyPartsWithEffects[bodyPart.Key].Effects) { + + var time = effectType.Value.Time; + if (time is not null && time > 0) + { + AddEffect(pmcData, effectType, time); + } + else + { + AddEffect(pmcData, effectType); + } + } + } } /// @@ -340,20 +339,11 @@ public class HealthHelper( /// Body part to edit /// Effect to add to body part /// How long the effect has left in seconds (-1 by default, no duration). - protected void AddEffect(PmcData pmcData, string effectBodyPart, string effectType, int duration = -1) + protected void AddEffect(PmcData pmcData, KeyValuePair effectType, double? duration = -1) { - // TODO: this will need to change, typing is all fucked up - // const profileBodyPart = pmcData.Health.BodyParts[effectBodyPart]; - // if (!profileBodyPart.Effects) { - // profileBodyPart.Effects = {}; - // } - // - // profileBodyPart.Effects[effectType] = { Time: duration }; - // - // // Delete empty property to prevent client bugs - // if (this.isEmpty(profileBodyPart.Effects)) { - // // biome-ignore lint/performance/noDelete: Delete is fine here, we're removing an empty property to prevent game bugs. - // delete profileBodyPart.Effects; - // } + var profileBodyPart = pmcData.Health.BodyParts[effectType.Key]; + profileBodyPart.Effects ??= new Dictionary(); + + profileBodyPart.Effects[effectType.Key] = new BodyPartEffectProperties { Time = duration }; } } diff --git a/Libraries/Core/Models/Eft/Health/HealthTreatmentRequestData.cs b/Libraries/Core/Models/Eft/Health/HealthTreatmentRequestData.cs index 1196ea9f..837a43ce 100644 --- a/Libraries/Core/Models/Eft/Health/HealthTreatmentRequestData.cs +++ b/Libraries/Core/Models/Eft/Health/HealthTreatmentRequestData.cs @@ -1,10 +1,11 @@ using System.Text.Json.Serialization; using Core.Models.Common; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Health; -public record HealthTreatmentRequestData : BaseInteractionRequestData +public record HealthTreatmentRequestData : InventoryBaseActionRequestData { [JsonPropertyName("trader")] @@ -28,10 +29,10 @@ public record Difference public BodyParts? BodyParts { get; set; } [JsonPropertyName("Energy")] - public int? Energy { get; set; } + public double? Energy { get; set; } [JsonPropertyName("Hydration")] - public int? Hydration { get; set; } + public double? Hydration { get; set; } } public record BodyParts diff --git a/Libraries/Core/Models/Eft/Health/OffraidEatRequestData.cs b/Libraries/Core/Models/Eft/Health/OffraidEatRequestData.cs index f3cc4046..4e5c4104 100644 --- a/Libraries/Core/Models/Eft/Health/OffraidEatRequestData.cs +++ b/Libraries/Core/Models/Eft/Health/OffraidEatRequestData.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Health; -public record OffraidEatRequestData : BaseInteractionRequestData +public record OffraidEatRequestData : InventoryBaseActionRequestData { [JsonPropertyName("item")] public string? Item { get; set; } diff --git a/Libraries/Core/Models/Eft/Health/OffraidHealRequestData.cs b/Libraries/Core/Models/Eft/Health/OffraidHealRequestData.cs index 5ce1a832..aafb2a29 100644 --- a/Libraries/Core/Models/Eft/Health/OffraidHealRequestData.cs +++ b/Libraries/Core/Models/Eft/Health/OffraidHealRequestData.cs @@ -1,12 +1,20 @@ -using Core.Models.Eft.Common.Request; +using System.Text.Json.Serialization; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Health; -public record OffraidHealRequestData : BaseInteractionRequestData +public record OffraidHealRequestData : InventoryBaseActionRequestData { + [JsonPropertyName("item")] public string? Item { get; set; } - public BodyPart? Part { get; set; } + + [JsonPropertyName("part")] + public string? Part { get; set; } + + [JsonPropertyName("count")] public int? Count { get; set; } + + [JsonPropertyName("time")] public long? Time { get; set; } } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutCircleOfCultistProductionStartRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutCircleOfCultistProductionStartRequestData.cs index 90bf6c03..5cb372d9 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutCircleOfCultistProductionStartRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutCircleOfCultistProductionStartRequestData.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutCircleOfCultistProductionStartRequestData : BaseInteractionRequestData +public record HideoutCircleOfCultistProductionStartRequestData : InventoryBaseActionRequestData { [JsonPropertyName("timestamp")] public long? Timestamp { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutContinuousProductionStartRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutContinuousProductionStartRequestData.cs index dd1c3c83..4e4e3eb6 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutContinuousProductionStartRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutContinuousProductionStartRequestData.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutContinuousProductionStartRequestData : BaseInteractionRequestData +public record HideoutContinuousProductionStartRequestData : InventoryBaseActionRequestData { [JsonPropertyName("recipeId")] public string? RecipeId { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationApplyRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationApplyRequestData.cs index 680e0288..30c54b48 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationApplyRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationApplyRequestData.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutCustomizationApplyRequestData: BaseInteractionRequestData +public record HideoutCustomizationApplyRequestData : InventoryBaseActionRequestData { /// diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationSetMannequinPoseRequest.cs b/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationSetMannequinPoseRequest.cs index 166cdeec..d2833405 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationSetMannequinPoseRequest.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutCustomizationSetMannequinPoseRequest.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutCustomizationSetMannequinPoseRequest : BaseInteractionRequestData +public record HideoutCustomizationSetMannequinPoseRequest : InventoryBaseActionRequestData { [JsonPropertyName("poses")] public Dictionary? Poses { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutDeleteProductionRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutDeleteProductionRequestData.cs index 98620e40..9b9ca28e 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutDeleteProductionRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutDeleteProductionRequestData.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutDeleteProductionRequestData: BaseInteractionRequestData +public record HideoutDeleteProductionRequestData : InventoryBaseActionRequestData { [JsonPropertyName("recipeId")] public string? RecipeId { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutImproveAreaRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutImproveAreaRequestData.cs index 7724c3c4..4477de42 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutImproveAreaRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutImproveAreaRequestData.cs @@ -1,11 +1,12 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; using Core.Models.Eft.Common.Tables; +using Core.Models.Eft.Inventory; using Core.Models.Enums; namespace Core.Models.Eft.Hideout; -public record HideoutImproveAreaRequestData : BaseInteractionRequestData +public record HideoutImproveAreaRequestData : InventoryBaseActionRequestData { /** Hideout area id from areas.json */ [JsonPropertyName("id")] diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutPutItemInRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutPutItemInRequestData.cs index be3e971f..a937b246 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutPutItemInRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutPutItemInRequestData.cs @@ -1,11 +1,12 @@ using System.Text.Json.Serialization; using Core.Models.Common; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; using Core.Models.Enums; namespace Core.Models.Eft.Hideout; -public record HideoutPutItemInRequestData : BaseInteractionRequestData +public record HideoutPutItemInRequestData : InventoryBaseActionRequestData { [JsonPropertyName("areaType")] diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutScavCaseStartRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutScavCaseStartRequestData.cs index a8f1456e..d390ac45 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutScavCaseStartRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutScavCaseStartRequestData.cs @@ -1,10 +1,11 @@ using System.Text.Json.Serialization; using Core.Models.Common; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutScavCaseStartRequestData : BaseInteractionRequestData +public record HideoutScavCaseStartRequestData : InventoryBaseActionRequestData { [JsonPropertyName("recipeId")] public string? RecipeId { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutSingleProductionStartRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutSingleProductionStartRequestData.cs index 4423d5a3..06ba91f0 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutSingleProductionStartRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutSingleProductionStartRequestData.cs @@ -1,10 +1,11 @@ using System.Text.Json.Serialization; using Core.Models.Common; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutSingleProductionStartRequestData : BaseInteractionRequestData +public record HideoutSingleProductionStartRequestData : InventoryBaseActionRequestData { [JsonPropertyName("recipeId")] public string? RecipeId { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutTakeItemOutRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutTakeItemOutRequestData.cs index 0b534670..d96a9bad 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutTakeItemOutRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutTakeItemOutRequestData.cs @@ -1,10 +1,11 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; using Core.Models.Enums; namespace Core.Models.Eft.Hideout; -public record HideoutTakeItemOutRequestData : BaseInteractionRequestData +public record HideoutTakeItemOutRequestData : InventoryBaseActionRequestData { [JsonPropertyName("areaType")] public HideoutAreas? AreaType { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutTakeProductionRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutTakeProductionRequestData.cs index 44085182..8ab02548 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutTakeProductionRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutTakeProductionRequestData.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record HideoutTakeProductionRequestData : BaseInteractionRequestData +public record HideoutTakeProductionRequestData : InventoryBaseActionRequestData { [JsonPropertyName("recipeId")] public string? RecipeId { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutToggleAreaRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutToggleAreaRequestData.cs index 3d17c0bf..5e050d38 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutToggleAreaRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutToggleAreaRequestData.cs @@ -1,10 +1,11 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; using Core.Models.Enums; namespace Core.Models.Eft.Hideout; -public record HideoutToggleAreaRequestData : BaseInteractionRequestData +public record HideoutToggleAreaRequestData : InventoryBaseActionRequestData { [JsonPropertyName("areaType")] public HideoutAreas? AreaType { get; set; } diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeCompleteRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeCompleteRequestData.cs index 097cfd65..25bad14a 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeCompleteRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeCompleteRequestData.cs @@ -1,10 +1,11 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; using Core.Models.Enums; namespace Core.Models.Eft.Hideout; -public record HideoutUpgradeCompleteRequestData : BaseInteractionRequestData +public record HideoutUpgradeCompleteRequestData : InventoryBaseActionRequestData { [JsonPropertyName("areaType")] diff --git a/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeRequestData.cs b/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeRequestData.cs index 6e1a3088..5b532439 100644 --- a/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeRequestData.cs +++ b/Libraries/Core/Models/Eft/Hideout/HideoutUpgradeRequestData.cs @@ -1,11 +1,12 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; using Core.Models.Eft.Common.Tables; +using Core.Models.Eft.Inventory; using Core.Models.Enums; namespace Core.Models.Eft.Hideout; -public record HideoutUpgradeRequestData : BaseInteractionRequestData +public record HideoutUpgradeRequestData : InventoryBaseActionRequestData { [JsonPropertyName("areaType")] diff --git a/Libraries/Core/Models/Eft/Hideout/RecordShootingRangePoints.cs b/Libraries/Core/Models/Eft/Hideout/RecordShootingRangePoints.cs index 84458cc0..e0c6528a 100644 --- a/Libraries/Core/Models/Eft/Hideout/RecordShootingRangePoints.cs +++ b/Libraries/Core/Models/Eft/Hideout/RecordShootingRangePoints.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Hideout; -public record RecordShootingRangePoints : BaseInteractionRequestData +public record RecordShootingRangePoints : InventoryBaseActionRequestData { [JsonPropertyName("points")] public int? Points { get; set; } diff --git a/Libraries/Core/Models/Eft/Insurance/InsureRequestData.cs b/Libraries/Core/Models/Eft/Insurance/InsureRequestData.cs index 89337560..03fc1be0 100644 --- a/Libraries/Core/Models/Eft/Insurance/InsureRequestData.cs +++ b/Libraries/Core/Models/Eft/Insurance/InsureRequestData.cs @@ -1,9 +1,10 @@ using System.Text.Json.Serialization; using Core.Models.Eft.Common.Request; +using Core.Models.Eft.Inventory; namespace Core.Models.Eft.Insurance; -public record InsureRequestData : BaseInteractionRequestData +public record InsureRequestData : InventoryBaseActionRequestData { [JsonPropertyName("tid")] public string? TransactionId { get; set; } diff --git a/Libraries/Core/Models/Eft/Profile/SptProfile.cs b/Libraries/Core/Models/Eft/Profile/SptProfile.cs index 23eec21f..59b6f0a3 100644 --- a/Libraries/Core/Models/Eft/Profile/SptProfile.cs +++ b/Libraries/Core/Models/Eft/Profile/SptProfile.cs @@ -410,105 +410,18 @@ public record ReceivedGift } public record Vitality -{ - [JsonPropertyName("health")] - public Health? Health { get; set; } - - [JsonPropertyName("effects")] - public Effects? Effects { get; set; } -} - -public record Health { [JsonPropertyName("Hydration")] public double? Hydration { get; set; } - + [JsonPropertyName("Energy")] public double? Energy { get; set; } - + [JsonPropertyName("Temperature")] public double? Temperature { get; set; } - - [JsonPropertyName("Head")] - public double? Head { get; set; } - - [JsonPropertyName("Chest")] - public double? Chest { get; set; } - - [JsonPropertyName("Stomach")] - public double? Stomach { get; set; } - - [JsonPropertyName("LeftArm")] - public double? LeftArm { get; set; } - - [JsonPropertyName("RightArm")] - public double? RightArm { get; set; } - - [JsonPropertyName("LeftLeg")] - public double? LeftLeg { get; set; } - - [JsonPropertyName("RightLeg")] - public double? RightLeg { get; set; } -} - -public record Effects -{ - [JsonPropertyName("Head")] - public Head? Head { get; set; } - - [JsonPropertyName("Chest")] - public Chest? Chest { get; set; } - - [JsonPropertyName("Stomach")] - public Stomach? Stomach { get; set; } - - [JsonPropertyName("LeftArm")] - public LeftArm? LeftArm { get; set; } - - [JsonPropertyName("RightArm")] - public RightArm? RightArm { get; set; } - - [JsonPropertyName("LeftLeg")] - public LeftLeg? LeftLeg { get; set; } - - [JsonPropertyName("RightLeg")] - public RightLeg? RightLeg { get; set; } -} - -public record Head -{ -} - -public record Chest -{ -} - -public record Stomach -{ -} - -public record LeftArm -{ - [JsonPropertyName("Fracture")] - public double? Fracture { get; set; } -} - -public record RightArm -{ - [JsonPropertyName("Fracture")] - public double? Fracture { get; set; } -} - -public record LeftLeg -{ - [JsonPropertyName("Fracture")] - public double? Fracture { get; set; } -} - -public record RightLeg -{ - [JsonPropertyName("Fracture")] - public double? Fracture { get; set; } + + [JsonPropertyName("Health")] // This now does health and effects to each bodypart + public Dictionary? Health { get; set; } } public record Inraid diff --git a/Libraries/Core/Routers/SaveLoad/HealthSaveLoadRouter.cs b/Libraries/Core/Routers/SaveLoad/HealthSaveLoadRouter.cs index c75aede4..ba545ae7 100644 --- a/Libraries/Core/Routers/SaveLoad/HealthSaveLoadRouter.cs +++ b/Libraries/Core/Routers/SaveLoad/HealthSaveLoadRouter.cs @@ -1,11 +1,13 @@ using SptCommon.Annotations; using Core.DI; +using Core.Helpers; +using Core.Models.Eft.Common.Tables; using Core.Models.Eft.Profile; namespace Core.Routers.SaveLoad; [Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))] -public class HealthSaveLoadRouter : SaveLoadRouter +public class HealthSaveLoadRouter() : SaveLoadRouter { protected override List GetHandledRoutes() { @@ -14,34 +16,87 @@ public class HealthSaveLoadRouter : SaveLoadRouter public override SptProfile HandleLoad(SptProfile profile) { - if (profile?.VitalityData == null) - profile.VitalityData = new() { Health = null, Effects = null }; - - profile.VitalityData.Health = new() - { - Hydration = 0, - Energy = 0, - Temperature = 0, - Head = 0, - Chest = 0, - Stomach = 0, - LeftArm = 0, - RightArm = 0, - LeftLeg = 0, - RightLeg = 0 - }; - - profile.VitalityData.Effects = new() - { - Head = new(), - Chest = new(), - Stomach = new(), - LeftArm = new(), - RightArm = new(), - LeftLeg = new(), - RightLeg = new() - }; + DefaultVitality(profile.VitalityData); 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() + } + } + }; + } } diff --git a/Libraries/Core/Services/LocationLifecycleService.cs b/Libraries/Core/Services/LocationLifecycleService.cs index 51499fe5..276948a8 100644 --- a/Libraries/Core/Services/LocationLifecycleService.cs +++ b/Libraries/Core/Services/LocationLifecycleService.cs @@ -365,7 +365,7 @@ public class LocationLifecycleService /** Handle client/match/local/end */ public void EndLocalRaid(string sessionId, EndLocalRaidRequestData request) { - // Clear bot loot cache + // Clear bot loot cache _botLootCacheService.ClearCache(); var fullProfile = _profileHelper.GetFullProfile(sessionId);