From 47d1516c0300b3e7f928e6e6ffaa79a5b02694a8 Mon Sep 17 00:00:00 2001 From: Frityet Date: Sun, 25 Jul 2021 19:46:28 -0700 Subject: [PATCH 1/3] Work on stamina --- .idea/.idea.HADES.H3VR/.idea/discord.xml | 6 +++ .idea/.idea.HADES.H3VR/.idea/indexLayout.xml | 8 ++++ HADES.Core/HADES.Core.csproj | 4 +- HADES.Core/Plugin.cs | 5 +-- HADES.Core/{ => src}/Common.cs | 10 ++++- HADES.Core/src/EnhancedHealth.cs | 17 ++++---- HADES.Core/src/EnhancedMovement.cs | 46 +++++++++++++++----- HADES.Core/src/FallDamage.cs | 4 +- HADES.Core/src/HADES.cs | 2 +- HADES.Core/{ => src}/HADESConfig.cs | 19 ++++++-- HADES.H3VR.sln.DotSettings | 1 + 11 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 .idea/.idea.HADES.H3VR/.idea/discord.xml create mode 100644 .idea/.idea.HADES.H3VR/.idea/indexLayout.xml rename HADES.Core/{ => src}/Common.cs (76%) rename HADES.Core/{ => src}/HADESConfig.cs (92%) diff --git a/.idea/.idea.HADES.H3VR/.idea/discord.xml b/.idea/.idea.HADES.H3VR/.idea/discord.xml new file mode 100644 index 0000000..cd711a0 --- /dev/null +++ b/.idea/.idea.HADES.H3VR/.idea/discord.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.HADES.H3VR/.idea/indexLayout.xml b/.idea/.idea.HADES.H3VR/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.HADES.H3VR/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HADES.Core/HADES.Core.csproj b/HADES.Core/HADES.Core.csproj index 436d411..745ae44 100644 --- a/HADES.Core/HADES.Core.csproj +++ b/HADES.Core/HADES.Core.csproj @@ -82,14 +82,14 @@ - - + + diff --git a/HADES.Core/Plugin.cs b/HADES.Core/Plugin.cs index 623508b..81b3bf6 100644 --- a/HADES.Core/Plugin.cs +++ b/HADES.Core/Plugin.cs @@ -1,8 +1,8 @@ using BepInEx; using BepInEx.Logging; using FistVR; -using static HADES.Common.Logging; -using PluginInfo = HADES.Common.PluginInfo; +using static HADES.Utilities.Logging; +using PluginInfo = HADES.Utilities.PluginInfo; namespace HADES.Core { @@ -11,7 +11,6 @@ public class Plugin : BaseUnityPlugin { public static Plugin Mod; public static ManualLogSource ConsoleLogger; - public Plugin() { Mod = this; diff --git a/HADES.Core/Common.cs b/HADES.Core/src/Common.cs similarity index 76% rename from HADES.Core/Common.cs rename to HADES.Core/src/Common.cs index 9bff319..e00e111 100644 --- a/HADES.Core/Common.cs +++ b/HADES.Core/src/Common.cs @@ -1,8 +1,16 @@ using BepInEx.Logging; +using FistVR; using HADES.Core; +using UnityEngine; -namespace HADES.Common +namespace HADES.Utilities { + public static class Common + { + public static FVRPlayerBody Player => GM.CurrentPlayerBody; + public static readonly WaitForSeconds WAIT_A_SEX = new WaitForSeconds(1); + } + public struct PluginInfo { public const string NAME = "HADES.Core"; diff --git a/HADES.Core/src/EnhancedHealth.cs b/HADES.Core/src/EnhancedHealth.cs index 2634860..f17c802 100644 --- a/HADES.Core/src/EnhancedHealth.cs +++ b/HADES.Core/src/EnhancedHealth.cs @@ -1,15 +1,13 @@ using System.Collections; using FistVR; -using HADES.Common; +using HADES.Utilities; using UnityEngine; -using static HADES.Common.Logging; +using static HADES.Utilities.Logging; namespace HADES.Core { public class EnhancedHealth : MonoBehaviour { - private HADES _hadesSystem; - private float _initialHealth; public float HealthPercentage { get; private set; } private float CurrentHealth => GM.GetPlayerHealth(); @@ -17,17 +15,20 @@ public class EnhancedHealth : MonoBehaviour private float RegenDelay => HADESConfig.EnhancedHealth.RegenDelay; private float RegenSpeed => HADESConfig.EnhancedHealth.RegenSpeed; - private GameObject HealthBars => _hadesSystem.Player.HealthBar; - + private GameObject HealthBars => Common.Player.HealthBar; + + private float _initialHealth; + private void Start() { - _hadesSystem = GetComponent(); + if (!HADESConfig.EnhancedHealth.Enabled) return; Print("Injected EnhancedHealth into player"); _initialHealth = GM.GetPlayerHealth(); } 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! @@ -47,7 +48,7 @@ private IEnumerator Regenerate() float curHealth = CurrentHealth; Logging.Debug.Print($"Current health {curHealth}\nInit health {initHealth}"); if (curHealth < initHealth) goto regen; - _hadesSystem.Player.HealPercent(i); + Common.Player.HealPercent(i); } Logging.Debug.Print("Done Regeneration"); diff --git a/HADES.Core/src/EnhancedMovement.cs b/HADES.Core/src/EnhancedMovement.cs index ae5fe4c..822b110 100644 --- a/HADES.Core/src/EnhancedMovement.cs +++ b/HADES.Core/src/EnhancedMovement.cs @@ -1,20 +1,21 @@ using System; +using System.Collections; using System.Linq; using FistVR; +using HADES.Utilities; using UnityEngine; namespace HADES.Core { public class EnhancedMovement : MonoBehaviour { - private HADES _hadesSystem; public float Stamina { get; private set; } - + public float StaminaPercentage { get; private set; } public float Weight { get { - var qbSlots = _hadesSystem.Player.QuickbeltSlots; + var qbSlots = Common.Player.QuickbeltSlots; var weight = 0.0f; @@ -22,7 +23,8 @@ public float Weight { FVRPhysicalObject obj = slot.CurObject; - if (slot.Type == FVRQuickBeltSlot.QuickbeltSlotType.Backpack) weight += BackpackWeightModifer; + if (slot.Type == FVRQuickBeltSlot.QuickbeltSlotType.Backpack) + weight += HADESConfig.EnhancedMovement.BackpackWeightModifier; weight += obj.Size switch { @@ -47,23 +49,43 @@ public float Weight private float MaxStamina => HADESConfig.EnhancedMovement.MaxStamina; private float StaminaGain => HADESConfig.EnhancedMovement.StaminaGain; private float StaminaLoss => HADESConfig.EnhancedMovement.StaminaLoss; - - private float WeightModifier => HADESConfig.EnhancedMovement.WeightModifier; - private float BackpackWeightModifer => HADESConfig.EnhancedMovement.BackpackWeightModifier; - + private float PlayerSpeed => Common.Player.GetBodyMovementSpeed(); + private void Start() { - _hadesSystem = GetComponent(); Stamina = MaxStamina; + StaminaPercentage = MaxStamina / Stamina * 100; } private void Update() { if (!HADESConfig.EnhancedMovement.Enabled) return; - float speed = _hadesSystem.Player.GetBodyMovementSpeed(); - if (speed < 10f) return; - GM.CurrentMovementManager.SlidingSpeed -= Stamina / 100; + float speed = Common.Player.GetBodyMovementSpeed(); + if (speed < HADESConfig.EnhancedMovement.StaminaLossStartSpeed) return; + StartCoroutine(DrainStamina()); + } + + private IEnumerator DrainStamina() + { + StaminaPercentage = Stamina / MaxStamina * 100; + + //Burn through the stamina, we use StaminaLoss in the loop because + //that is how many seconds are to be elapsed to completely drain the stamina. + //How much you are carrying also is a factor, so we subtract the weight from the + //number of seconds that are to be elapsed + for (float i = 0; + i < StaminaLoss - Weight; //This is how long (in seconds) it takes to drain all of the stamina + i++) + { + //If the player isn't going over the threshold, stop the function + if (PlayerSpeed < HADESConfig.EnhancedMovement.StaminaLossStartSpeed || Stamina <= 0) + yield break; + + + + yield return Common.WAIT_A_SEX; + } } } } \ No newline at end of file diff --git a/HADES.Core/src/FallDamage.cs b/HADES.Core/src/FallDamage.cs index 44f0a6d..2ad8b3a 100644 --- a/HADES.Core/src/FallDamage.cs +++ b/HADES.Core/src/FallDamage.cs @@ -1,7 +1,7 @@ using FistVR; -using HADES.Common; +using HADES.Utilities; using UnityEngine; -using static HADES.Common.Logging; +using static HADES.Utilities.Logging; namespace HADES.Core { diff --git a/HADES.Core/src/HADES.cs b/HADES.Core/src/HADES.cs index 48b1d1f..ed67666 100644 --- a/HADES.Core/src/HADES.cs +++ b/HADES.Core/src/HADES.cs @@ -1,6 +1,6 @@ using FistVR; using UnityEngine; -using static HADES.Common.Logging; +using static HADES.Utilities.Logging; namespace HADES.Core { diff --git a/HADES.Core/HADESConfig.cs b/HADES.Core/src/HADESConfig.cs similarity index 92% rename from HADES.Core/HADESConfig.cs rename to HADES.Core/src/HADESConfig.cs index 104d70f..1b37f47 100644 --- a/HADES.Core/HADESConfig.cs +++ b/HADES.Core/src/HADESConfig.cs @@ -103,7 +103,7 @@ public EnhancedHealthConfig() public class EnhancedMovementConfig : ConfigEntry { - public const string CATEGORY_NAME = "Enhanced Movement"; + private const string CATEGORY_NAME = "Enhanced Movement"; private readonly ConfigEntry _backpackWeightModifierEntry; private readonly ConfigEntry _ccbObjWeightModifierEntry; private readonly ConfigEntry _largeObjWeightModifierEntry; @@ -114,6 +114,7 @@ public class EnhancedMovementConfig : ConfigEntry private readonly ConfigEntry _staminaGainEntry; private readonly ConfigEntry _staminaLossEntry; private readonly ConfigEntry _weightModifierEntry; + private readonly ConfigEntry _staminaLossStartSpeedEntry; public EnhancedMovementConfig() { @@ -137,16 +138,24 @@ public EnhancedMovementConfig() ( CATEGORY_NAME, "Stamina Gain", - 5f, - "The amount of stamina gained whilst inactive" + 15f, + "The speed of which stamina regenerates" ); _staminaLossEntry = Plugin.Mod.Config.Bind ( CATEGORY_NAME, "Stamina Loss", + 30f, + "The speed of which stamina drains" + ); + + _staminaLossStartSpeedEntry = Plugin.Mod.Config.Bind + ( + CATEGORY_NAME, + "Stamina Loss Speed", 10f, - "The amount of stamina lost whilst active" + "The speed that must be reached for stamina to drain" ); const string WEIGHT_CAT_NAME = CATEGORY_NAME + " - Weight Configuration"; @@ -214,6 +223,8 @@ public EnhancedMovementConfig() public float StaminaLoss => _staminaLossEntry.Value; + public float StaminaLossStartSpeed => _staminaLossStartSpeedEntry.Value; + public float WeightModifier => _weightModifierEntry.Value; public float BackpackWeightModifier => _backpackWeightModifierEntry.Value; diff --git a/HADES.H3VR.sln.DotSettings b/HADES.H3VR.sln.DotSettings index 3ec6ef2..0445353 100644 --- a/HADES.H3VR.sln.DotSettings +++ b/HADES.H3VR.sln.DotSettings @@ -1,3 +1,4 @@  + CCB HADES True \ No newline at end of file From 8f543a8da41e0a9538d4a2301010e1f0e4bd9fbf Mon Sep 17 00:00:00 2001 From: Frityet Date: Sun, 25 Jul 2021 20:41:43 -0700 Subject: [PATCH 2/3] Attempt to clean code --- HADES.Core/Plugin.cs | 3 ++- HADES.Core/src/Common.cs | 1 + HADES.Core/src/EnhancedHealth.cs | 14 ++++++++++---- HADES.Core/src/FallDamage.cs | 32 +++++++++++++------------------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/HADES.Core/Plugin.cs b/HADES.Core/Plugin.cs index 81b3bf6..a1a5db4 100644 --- a/HADES.Core/Plugin.cs +++ b/HADES.Core/Plugin.cs @@ -1,4 +1,5 @@ -using BepInEx; +using System; +using BepInEx; using BepInEx.Logging; using FistVR; using static HADES.Utilities.Logging; diff --git a/HADES.Core/src/Common.cs b/HADES.Core/src/Common.cs index e00e111..87dd887 100644 --- a/HADES.Core/src/Common.cs +++ b/HADES.Core/src/Common.cs @@ -1,3 +1,4 @@ +using System; using BepInEx.Logging; using FistVR; using HADES.Core; diff --git a/HADES.Core/src/EnhancedHealth.cs b/HADES.Core/src/EnhancedHealth.cs index f17c802..49e316a 100644 --- a/HADES.Core/src/EnhancedHealth.cs +++ b/HADES.Core/src/EnhancedHealth.cs @@ -37,17 +37,23 @@ private void Update() private IEnumerator Regenerate() { - float initHealth = CurrentHealth; + float initHealth = CurrentHealth; //Get the health at the execution of the function + regen: - yield return new WaitForSeconds(RegenDelay); + yield return new WaitForSeconds(RegenDelay); //Wait the delay out Logging.Debug.Print("Regenerating..."); - - for (float i = 0; i < RegenCap; i += RegenSpeed / 10) + + //Loop through until the regen cap is reached, i is iterated by the regeneration speed + for (float i = 0; i < RegenCap; i += RegenSpeed / 10) { + //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 Common.Player.HealPercent(i); } diff --git a/HADES.Core/src/FallDamage.cs b/HADES.Core/src/FallDamage.cs index 2ad8b3a..c865fed 100644 --- a/HADES.Core/src/FallDamage.cs +++ b/HADES.Core/src/FallDamage.cs @@ -34,25 +34,6 @@ private void Update() } public void FixedUpdate() - { - CalculateVelocity(); - } - - private Tuple CalculateFallDamage() - { - float damage = 0; - // * 0.02 is effectively / 50 but mult because muh optimization - float effectiveVelocity = _velocityDifference + HADESConfig.FallDamage.FallHeight * 0.02f; - - //if EV is less than 0, it means that the velocity was negative enough that the VDT could not - //bring it back up to positive. Also, the velocity being negative means its slowing down. - //The VDT is to prevent coming from a run to a stop doesnt hurt you lol - if (effectiveVelocity < 0) damage = effectiveVelocity * HADESConfig.FallDamage.FallHeight; - return new Tuple(damage, effectiveVelocity); - } - - //this exists to not clog up fixedupdate - private void CalculateVelocity() { //note that the time frame for everything here is per step //etc, if the velocity is 1, that means 1 meter every 50th of a second @@ -70,5 +51,18 @@ private void CalculateVelocity() //get velocity difference _velocityDifference = _currentVelocity - _previousVelocity; } + + private Tuple CalculateFallDamage() + { + float damage = 0; + // * 0.02 is effectively / 50 but mult because muh optimization + float effectiveVelocity = _velocityDifference + HADESConfig.FallDamage.FallHeight * 0.02f; + + //if EV is less than 0, it means that the velocity was negative enough that the VDT could not + //bring it back up to positive. Also, the velocity being negative means its slowing down. + //The VDT is to prevent coming from a run to a stop doesnt hurt you lol + if (effectiveVelocity < 0) damage = effectiveVelocity * HADESConfig.FallDamage.FallHeight; + return new Tuple(damage, effectiveVelocity); + } } } \ No newline at end of file From 021930f223d59e839bc55cae4deb943b74223141 Mon Sep 17 00:00:00 2001 From: Frityet Date: Sun, 25 Jul 2021 20:52:20 -0700 Subject: [PATCH 3/3] Make CurrentPlayerBody unstatic --- HADES.Core/HADES.Core.csproj | 1 + HADES.Core/src/Common.cs | 1 - HADES.Core/src/EnhancedHealth.cs | 6 +++--- HADES.Core/src/EnhancedMovement.cs | 8 ++++---- HADES.Core/src/HADESEnhancement.cs | 10 ++++++++++ 5 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 HADES.Core/src/HADESEnhancement.cs diff --git a/HADES.Core/HADES.Core.csproj b/HADES.Core/HADES.Core.csproj index 745ae44..940f317 100644 --- a/HADES.Core/HADES.Core.csproj +++ b/HADES.Core/HADES.Core.csproj @@ -90,6 +90,7 @@ + diff --git a/HADES.Core/src/Common.cs b/HADES.Core/src/Common.cs index 87dd887..33533dd 100644 --- a/HADES.Core/src/Common.cs +++ b/HADES.Core/src/Common.cs @@ -8,7 +8,6 @@ namespace HADES.Utilities { public static class Common { - public static FVRPlayerBody Player => GM.CurrentPlayerBody; public static readonly WaitForSeconds WAIT_A_SEX = new WaitForSeconds(1); } diff --git a/HADES.Core/src/EnhancedHealth.cs b/HADES.Core/src/EnhancedHealth.cs index 49e316a..1c1324e 100644 --- a/HADES.Core/src/EnhancedHealth.cs +++ b/HADES.Core/src/EnhancedHealth.cs @@ -6,7 +6,7 @@ namespace HADES.Core { - public class EnhancedHealth : MonoBehaviour + public class EnhancedHealth : HADESEnhancement { public float HealthPercentage { get; private set; } @@ -15,7 +15,7 @@ public class EnhancedHealth : MonoBehaviour private float RegenDelay => HADESConfig.EnhancedHealth.RegenDelay; private float RegenSpeed => HADESConfig.EnhancedHealth.RegenSpeed; - private GameObject HealthBars => Common.Player.HealthBar; + private GameObject HealthBars => Player.HealthBar; private float _initialHealth; @@ -54,7 +54,7 @@ private IEnumerator Regenerate() //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 - Common.Player.HealPercent(i); + Player.HealPercent(i); } Logging.Debug.Print("Done Regeneration"); diff --git a/HADES.Core/src/EnhancedMovement.cs b/HADES.Core/src/EnhancedMovement.cs index 822b110..90b1a80 100644 --- a/HADES.Core/src/EnhancedMovement.cs +++ b/HADES.Core/src/EnhancedMovement.cs @@ -7,7 +7,7 @@ namespace HADES.Core { - public class EnhancedMovement : MonoBehaviour + public class EnhancedMovement : HADESEnhancement { public float Stamina { get; private set; } public float StaminaPercentage { get; private set; } @@ -15,7 +15,7 @@ public float Weight { get { - var qbSlots = Common.Player.QuickbeltSlots; + var qbSlots = Player.QuickbeltSlots; var weight = 0.0f; @@ -49,7 +49,7 @@ public float Weight private float MaxStamina => HADESConfig.EnhancedMovement.MaxStamina; private float StaminaGain => HADESConfig.EnhancedMovement.StaminaGain; private float StaminaLoss => HADESConfig.EnhancedMovement.StaminaLoss; - private float PlayerSpeed => Common.Player.GetBodyMovementSpeed(); + private float PlayerSpeed => Player.GetBodyMovementSpeed(); private void Start() { @@ -61,7 +61,7 @@ private void Update() { if (!HADESConfig.EnhancedMovement.Enabled) return; - float speed = Common.Player.GetBodyMovementSpeed(); + float speed = Player.GetBodyMovementSpeed(); if (speed < HADESConfig.EnhancedMovement.StaminaLossStartSpeed) return; StartCoroutine(DrainStamina()); } diff --git a/HADES.Core/src/HADESEnhancement.cs b/HADES.Core/src/HADESEnhancement.cs new file mode 100644 index 0000000..5f92034 --- /dev/null +++ b/HADES.Core/src/HADESEnhancement.cs @@ -0,0 +1,10 @@ +using FistVR; +using UnityEngine; + +namespace HADES.Core +{ + public class HADESEnhancement : MonoBehaviour + { + protected FVRPlayerBody Player => GM.CurrentPlayerBody; + } +} \ No newline at end of file