This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Redesigned/fixed enhanced health #5
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System; | ||
using System.Collections; | ||
using FistVR; | ||
using HADES.Utilities; | ||
|
@@ -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; | ||
|
@@ -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(); | ||
} | ||
Comment on lines
+50
to
74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put into |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
_hungarianNotation
for private fields, private properties should useCamelCase