From eebd43d81b0d2d03d910eb2e2fa579a63f48675f Mon Sep 17 00:00:00 2001 From: Potatoes Date: Mon, 26 Jul 2021 00:02:02 -0400 Subject: [PATCH] fixed health regen --- HADES.Core/src/EnhancedHealth.cs | 64 +++++++++++++++++++++--------- HADES.Core/src/EnhancedMovement.cs | 4 +- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/HADES.Core/src/EnhancedHealth.cs b/HADES.Core/src/EnhancedHealth.cs index 2634860..6aadfba 100644 --- a/HADES.Core/src/EnhancedHealth.cs +++ b/HADES.Core/src/EnhancedHealth.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using FistVR; using HADES.Common; @@ -13,10 +14,12 @@ public class EnhancedHealth : MonoBehaviour public float HealthPercentage { get; private set; } private float CurrentHealth => GM.GetPlayerHealth(); - private float RegenCap => HADESConfig.EnhancedHealth.RegenCap; - private float RegenDelay => HADESConfig.EnhancedHealth.RegenDelay; private float RegenSpeed => HADESConfig.EnhancedHealth.RegenSpeed; + private float RegenToGo; + private float currentRegenDelayLength; + private float healthMonitor; + private GameObject HealthBars => _hadesSystem.Player.HealthBar; private void Start() @@ -30,27 +33,50 @@ private void Update() { //i'm not sure who thought that the formula was (_initialhealth / currenthealth) * 100 lol - potatoes HealthPercentage = CurrentHealth / _initialHealth * 100; //Thanks nathan! - - if (HealthPercentage < RegenCap) StartCoroutine(Regenerate()); } - - private IEnumerator Regenerate() + + private void FixedUpdate() { - float initHealth = CurrentHealth; - regen: - yield return new WaitForSeconds(RegenDelay); - - Logging.Debug.Print("Regenerating..."); - - for (float i = 0; i < RegenCap; i += RegenSpeed / 10) + //if (HealthPercentage < RegenCap) Regenerate(); + + RegenerationHandler(); + } + + //this is the public entry-way to regenerate the player + public void RegeneratePlayerHP(float amt) + { + RegenToGo += amt; + } + + //this is the bit that actually regenerates your hp + private void RegenerationHandler() + { + /*PSEUDOCODE + if the player's hp goes lower than was last frame, it is cancelled and restarted + */ + + //if player is below RegenCap + if (_hadesSystem.Player.GetPlayerHealth() < + HADESConfig.EnhancedHealth.RegenCap * _hadesSystem.Player.GetMaxHealthPlayerRaw()) { - float curHealth = CurrentHealth; - Logging.Debug.Print($"Current health {curHealth}\nInit health {initHealth}"); - if (curHealth < initHealth) goto regen; - _hadesSystem.Player.HealPercent(i); + //if the delay time's up + if(currentRegenDelayLength >= HADESConfig.EnhancedHealth.RegenDelay * 50) + { + //if the player's hp is lower than what it was, assume damage taken, lower hp + if (_hadesSystem.Player.GetPlayerHealth() < healthMonitor) + { + currentRegenDelayLength = 0; + } + + //go add player hp + _hadesSystem.Player.HealPercent(HADESConfig.EnhancedHealth.RegenSpeed * 0.02f); + } else currentRegenDelayLength++; //count down (up?) if the delay time is not finished } - - Logging.Debug.Print("Done Regeneration"); + else + { + currentRegenDelayLength = 0; + } + healthMonitor = _hadesSystem.Player.GetPlayerHealth(); } } } \ No newline at end of file diff --git a/HADES.Core/src/EnhancedMovement.cs b/HADES.Core/src/EnhancedMovement.cs index ae5fe4c..22b9abf 100644 --- a/HADES.Core/src/EnhancedMovement.cs +++ b/HADES.Core/src/EnhancedMovement.cs @@ -15,9 +15,9 @@ public float Weight get { var qbSlots = _hadesSystem.Player.QuickbeltSlots; - + var weight = 0.0f; - + foreach (FVRQuickBeltSlot slot in qbSlots.Where(slot => slot.CurObject != null)) { FVRPhysicalObject obj = slot.CurObject;