From 4a56197bc897baea50492e30d178c55f3960f35f Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 13 Jan 2025 19:21:27 +0000 Subject: [PATCH] Implemented `WarnOnActiveBotReloadSkill` and `UpdateProfileHealthValues` --- Core/Controllers/GameController.cs | 100 ++++++++++++++++++++++- Core/Models/Eft/Common/Tables/BotBase.cs | 13 +-- 2 files changed, 99 insertions(+), 14 deletions(-) diff --git a/Core/Controllers/GameController.cs b/Core/Controllers/GameController.cs index 23a90972..d4a58705 100644 --- a/Core/Controllers/GameController.cs +++ b/Core/Controllers/GameController.cs @@ -3,6 +3,7 @@ using Core.Context; using Core.Helpers; using Core.Models.Eft.Common; using Core.Models.Eft.Game; +using Core.Models.Eft.Health; using Core.Models.Eft.Profile; using Core.Models.Enums; using Core.Models.Spt.Config; @@ -356,7 +357,11 @@ public class GameController /// Player profile private void WarnOnActiveBotReloadSkill(PmcData pmcProfile) { - throw new NotImplementedException(); + var botReloadSkill = _profileHelper.GetSkillFromProfile(pmcProfile, SkillTypes.BotReload); + if (botReloadSkill?.Progress > 0) + { + _logger.Warning(_localisationService.GetText("server_start_player_active_botreload_skill")); + } } /// @@ -365,7 +370,98 @@ public class GameController /// Profile to adjust values for private void UpdateProfileHealthValues(PmcData pmcProfile) { - throw new NotImplementedException(); + var healthLastUpdated = pmcProfile.Health.UpdateTime; + var currentTimeStamp = _timeUtil.GetTimeStamp(); + var diffSeconds = currentTimeStamp - healthLastUpdated; + + // Last update is in past + if (healthLastUpdated < currentTimeStamp) + { + // Base values + double energyRegenPerHour = 60; + double hydrationRegenPerHour = 60; + double hpRegenPerHour = 456.6; + + // Set new values, whatever is smallest + energyRegenPerHour += pmcProfile.Bonuses + .Where((bonus) => bonus.Type == BonusType.EnergyRegeneration) + .Aggregate(0d, (sum, bonus) => sum + (bonus.Value.Value)); + hydrationRegenPerHour += pmcProfile.Bonuses + .Where((bonus) => bonus.Type == BonusType.HydrationRegeneration) + .Aggregate(0d, (sum, bonus) => sum + (bonus.Value.Value)); + hpRegenPerHour += pmcProfile.Bonuses + .Where((bonus) => bonus.Type == BonusType.HealthRegeneration) + .Aggregate(0d, (sum, bonus) => sum + (bonus.Value.Value)); + + // Player has energy deficit + if (pmcProfile.Health.Energy.Current != pmcProfile.Health.Energy.Maximum) + { + // Set new value, whatever is smallest + pmcProfile.Health.Energy.Current += Math.Round(energyRegenPerHour * (diffSeconds.Value / 3600)); + if (pmcProfile.Health.Energy.Current > pmcProfile.Health.Energy.Maximum) + { + pmcProfile.Health.Energy.Current = pmcProfile.Health.Energy.Maximum; + } + } + + // Player has hydration deficit + if (pmcProfile.Health.Hydration.Current != pmcProfile.Health.Hydration.Maximum) + { + pmcProfile.Health.Hydration.Current += Math.Round(hydrationRegenPerHour * (diffSeconds.Value / 3600)); + if (pmcProfile.Health.Hydration.Current > pmcProfile.Health.Hydration.Maximum) + { + pmcProfile.Health.Hydration.Current = pmcProfile.Health.Hydration.Maximum; + } + } + + // Check all body parts + foreach (var bodyPart in pmcProfile.Health.BodyParts + .Select(bodyPartKvP => bodyPartKvP.Value)) + { + // Check part hp + if (bodyPart.Health.Current < bodyPart.Health.Maximum) + { + bodyPart.Health.Current += Math.Round(hpRegenPerHour * (diffSeconds.Value / 3600)); + } + if (bodyPart.Health.Current > bodyPart.Health.Maximum) + { + bodyPart.Health.Current = bodyPart.Health.Maximum; + } + + + if (bodyPart.Effects is null || bodyPart.Effects.Count == 0) + { + continue; + } + + // Look for effects + foreach (var effectKvP in bodyPart.Effects) { + // remove effects below 1, .e.g. bleeds at -1 + if (effectKvP.Value.Time < 1) + { + // More than 30 mins has passed + if (diffSeconds > 1800) + { + bodyPart.Effects.Remove(effectKvP.Key); + } + + continue; + } + + // Decrement effect time value by difference between current time and time health was last updated + effectKvP.Value.Time -= diffSeconds; + if (effectKvP.Value.Time < 1) + { + // Effect time was sub 1, set floor it can be + effectKvP.Value.Time = 1; + } + } + } + + // Update both values as they've both been updated + pmcProfile.Health.UpdateTime = currentTimeStamp; + } + } /// diff --git a/Core/Models/Eft/Common/Tables/BotBase.cs b/Core/Models/Eft/Common/Tables/BotBase.cs index cc1913ce..6c6f1b41 100644 --- a/Core/Models/Eft/Common/Tables/BotBase.cs +++ b/Core/Models/Eft/Common/Tables/BotBase.cs @@ -231,22 +231,11 @@ public class BotBaseHealth public CurrentMax? Hydration { get; set; } public CurrentMax? Energy { get; set; } public CurrentMax? Temperature { get; set; } - public BodyPartsHealth? BodyParts { get; set; } + public Dictionary? BodyParts { get; set; } public double? UpdateTime { get; set; } public bool? Immortal { get; set; } } -public class BodyPartsHealth -{ - public BodyPartHealth? Head { get; set; } - public BodyPartHealth? Chest { get; set; } - public BodyPartHealth? Stomach { get; set; } - public BodyPartHealth? LeftArm { get; set; } - public BodyPartHealth? RightArm { get; set; } - public BodyPartHealth? LeftLeg { get; set; } - public BodyPartHealth? RightLeg { get; set; } -} - public class BodyPartHealth { public CurrentMax? Health { get; set; }