Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from potatoes1286/master
Browse files Browse the repository at this point in the history
Redesigned/fixed enhanced health
  • Loading branch information
Frityet authored Jul 26, 2021
2 parents f100be2 + 319a458 commit 6864b1e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
69 changes: 41 additions & 28 deletions HADES.Core/src/EnhancedHealth.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using FistVR;
using HADES.Utilities;
Expand All @@ -11,14 +12,13 @@ public class EnhancedHealth : HADESEnhancement
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 GameObject HealthBars => Player.HealthBar;

private float _initialHealth;

private float RegenToGo;
private float currentRegenDelayLength;
private float healthMonitor;

private GameObject HealthBars => _hadesSystem.Player.HealthBar;
private void Start()
{
if (!HADESConfig.EnhancedHealth.Enabled) return;
Expand All @@ -31,33 +31,46 @@ private void Update()
if (!HADESConfig.EnhancedHealth.Enabled) return;
//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; //Get the health at the execution of the function

regen:
yield return new WaitForSeconds(RegenDelay); //Wait the delay out

Logging.Debug.Print("Regenerating...");
//if (HealthPercentage < RegenCap) Regenerate();

//Loop through until the regen cap is reached, i is iterated by the regeneration speed
for (float i = 0; i < RegenCap; i += RegenSpeed / 10)
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()
{
//if player is below RegenCap
if (_hadesSystem.Player.GetPlayerHealth() <
HADESConfig.EnhancedHealth.RegenCap * _hadesSystem.Player.GetMaxHealthPlayerRaw())
{
//The health before healing
float curHealth = CurrentHealth;
Logging.Debug.Print($"Current health {curHealth}\nInit health {initHealth}");
//If the player was damaged (The current health before healing is less than the health before starting regeneration),
//then restart the loop with the cooldown
if (curHealth < initHealth) goto regen;
//TODO: make the player heal in n intervals until the regen cap is reached
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();
}
}
}
2 changes: 1 addition & 1 deletion HADES.Core/src/EnhancedMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public float Weight
var qbSlots = Player.QuickbeltSlots;

var weight = 0.0f;

foreach (FVRQuickBeltSlot slot in qbSlots.Where(slot => slot.CurObject != null))
{
FVRPhysicalObject obj = slot.CurObject;
Expand Down

0 comments on commit 6864b1e

Please sign in to comment.