From 21be3656575760cf1693320f88fc03330ef8f1a5 Mon Sep 17 00:00:00 2001 From: Frityet Date: Sun, 25 Jul 2021 16:47:04 -0700 Subject: [PATCH] Cleaned code --- HADES.Core/Common.cs | 13 ++-- HADES.Core/HADESConfig.cs | 96 +++++++++++++++--------------- HADES.Core/Plugin.cs | 1 + HADES.Core/src/EnhancedHealth.cs | 24 +++----- HADES.Core/src/EnhancedMovement.cs | 12 ++-- HADES.Core/src/FallDamage.cs | 29 ++++----- HADES.Core/src/HADES.cs | 11 ++-- 7 files changed, 89 insertions(+), 97 deletions(-) diff --git a/HADES.Core/Common.cs b/HADES.Core/Common.cs index 0c85944..9bff319 100644 --- a/HADES.Core/Common.cs +++ b/HADES.Core/Common.cs @@ -12,13 +12,18 @@ public struct PluginInfo public static class Logging { - public static void Print(object msg, LogLevel level = LogLevel.Info) => Plugin.ConsoleLogger.Log(level, msg); - + public static void Print(object msg, LogLevel level = LogLevel.Info) + { + Plugin.ConsoleLogger.Log(level, msg); + } + public static class Debug { - public static void Print(object msg) => Plugin.ConsoleLogger.Log(LogLevel.Debug, msg); - + public static void Print(object msg) + { + Plugin.ConsoleLogger.Log(LogLevel.Debug, msg); + } } } diff --git a/HADES.Core/HADESConfig.cs b/HADES.Core/HADESConfig.cs index 213256c..104d70f 100644 --- a/HADES.Core/HADESConfig.cs +++ b/HADES.Core/HADESConfig.cs @@ -1,29 +1,24 @@ -using System.Collections.Generic; using BepInEx.Configuration; namespace HADES.Core { public struct HADESConfig { - public static FallDamageConfig FallDamage { get; } - public static EnhancedHealthConfig EnhancedHealth { get; } - public static EnhancedMovementConfig EnhancedMovement { get; } + public static FallDamageConfig FallDamage { get; } + public static EnhancedHealthConfig EnhancedHealth { get; } + public static EnhancedMovementConfig EnhancedMovement { get; } public class ConfigEntry { - public bool Enabled => EnabledEntry.Value; protected ConfigEntry EnabledEntry; + public bool Enabled => EnabledEntry.Value; } - + public class FallDamageConfig : ConfigEntry { private const string CATEGORY_NAME = "Fall Damages"; - - public float FallHeight => _fallHeightEntry.Value; - private readonly ConfigEntry _fallHeightEntry; - - public float DamageMultiplier => _damageMultiplierEntry.Value; private readonly ConfigEntry _damageMultiplierEntry; + private readonly ConfigEntry _fallHeightEntry; public FallDamageConfig() { @@ -51,19 +46,17 @@ public FallDamageConfig() "The multiplier is multiplied by your velocity (distance traveled between 2 points in 1 second) and is what damages you" ); } + + public float FallHeight => _fallHeightEntry.Value; + + public float DamageMultiplier => _damageMultiplierEntry.Value; } public class EnhancedHealthConfig : ConfigEntry { private const string CATEGORY_NAME = "Enhanced Health"; - - public float RegenCap => _regenCapEntry.Value; private readonly ConfigEntry _regenCapEntry; - - public float RegenDelay => _regenDelayEntry.Value; private readonly ConfigEntry _regenDelayEntry; - - public float RegenSpeed => _regenSpeedEntry.Value; private readonly ConfigEntry _regenSpeedEntry; public EnhancedHealthConfig() @@ -100,42 +93,28 @@ public EnhancedHealthConfig() "How long does it take to regenerate to the regeneration cap" ); } + + public float RegenCap => _regenCapEntry.Value; + + public float RegenDelay => _regenDelayEntry.Value; + + public float RegenSpeed => _regenSpeedEntry.Value; } public class EnhancedMovementConfig : ConfigEntry { public const string CATEGORY_NAME = "Enhanced Movement"; - - public float MaxStamina => _maxStaminaEntry.Value; + private readonly ConfigEntry _backpackWeightModifierEntry; + private readonly ConfigEntry _ccbObjWeightModifierEntry; + private readonly ConfigEntry _largeObjWeightModifierEntry; + private readonly ConfigEntry _massiveObjWeightModifierEntry; private readonly ConfigEntry _maxStaminaEntry; - - public float StaminaGain => _staminaGainEntry.Value; + private readonly ConfigEntry _mediumObjWeightModifierEntry; + private readonly ConfigEntry _smallObjWeightModifierEntry; private readonly ConfigEntry _staminaGainEntry; - - public float StaminaLoss => _staminaLossEntry.Value; private readonly ConfigEntry _staminaLossEntry; - - public float WeightModifier => _weightModifierEntry.Value; private readonly ConfigEntry _weightModifierEntry; - public float BackpackWeightModifier => _backpackWeightModifierEntry.Value; - private readonly ConfigEntry _backpackWeightModifierEntry; - - public float SmallObjectWeightModifier => _smallObjWeightModifierEntry.Value; - private readonly ConfigEntry _smallObjWeightModifierEntry; - - public float MediumObjectWeightModifier => _mediumObjWeightModifierEntry.Value; - private readonly ConfigEntry _mediumObjWeightModifierEntry; - - public float LargeObjectWeightModifier => _largeObjWeightModifierEntry.Value; - private readonly ConfigEntry _largeObjWeightModifierEntry; - - public float MassiveObjectWeightModifier => _massiveObjWeightModifierEntry.Value; - private readonly ConfigEntry _massiveObjWeightModifierEntry; - - public float CCBWeightModifer => _ccbObjWeightModifierEntry.Value; - private readonly ConfigEntry _ccbObjWeightModifierEntry; - public EnhancedMovementConfig() { EnabledEntry = Plugin.Mod.Config.Bind @@ -160,7 +139,6 @@ public EnhancedMovementConfig() "Stamina Gain", 5f, "The amount of stamina gained whilst inactive" - ); _staminaLossEntry = Plugin.Mod.Config.Bind @@ -172,7 +150,7 @@ public EnhancedMovementConfig() ); const string WEIGHT_CAT_NAME = CATEGORY_NAME + " - Weight Configuration"; - + _weightModifierEntry = Plugin.Mod.Config.Bind ( WEIGHT_CAT_NAME, @@ -204,7 +182,7 @@ public EnhancedMovementConfig() 2.5f, "How much weight a medium object will add if it is in a Quickbelt slot" ); - + _largeObjWeightModifierEntry = Plugin.Mod.Config.Bind ( WEIGHT_CAT_NAME, @@ -212,7 +190,7 @@ public EnhancedMovementConfig() 5f, "How much weight a large object will add if it is in a Quickbelt slot" ); - + _massiveObjWeightModifierEntry = Plugin.Mod.Config.Bind ( WEIGHT_CAT_NAME, @@ -220,7 +198,7 @@ public EnhancedMovementConfig() 10f, "How much weight a massive object will add if it is in a Quickbelt slot" ); - + _ccbObjWeightModifierEntry = Plugin.Mod.Config.Bind ( WEIGHT_CAT_NAME, @@ -229,8 +207,28 @@ public EnhancedMovementConfig() "How much weight a Can't Carry Big object will add if it is in a Quickbelt slot" ); } + + public float MaxStamina => _maxStaminaEntry.Value; + + public float StaminaGain => _staminaGainEntry.Value; + + public float StaminaLoss => _staminaLossEntry.Value; + + public float WeightModifier => _weightModifierEntry.Value; + + public float BackpackWeightModifier => _backpackWeightModifierEntry.Value; + + public float SmallObjectWeightModifier => _smallObjWeightModifierEntry.Value; + + public float MediumObjectWeightModifier => _mediumObjWeightModifierEntry.Value; + + public float LargeObjectWeightModifier => _largeObjWeightModifierEntry.Value; + + public float MassiveObjectWeightModifier => _massiveObjWeightModifierEntry.Value; + + public float CCBWeightModifer => _ccbObjWeightModifierEntry.Value; } - + static HADESConfig() { FallDamage = new FallDamageConfig(); diff --git a/HADES.Core/Plugin.cs b/HADES.Core/Plugin.cs index 373cbbc..623508b 100644 --- a/HADES.Core/Plugin.cs +++ b/HADES.Core/Plugin.cs @@ -11,6 +11,7 @@ public class Plugin : BaseUnityPlugin { public static Plugin Mod; public static ManualLogSource ConsoleLogger; + public Plugin() { Mod = this; diff --git a/HADES.Core/src/EnhancedHealth.cs b/HADES.Core/src/EnhancedHealth.cs index c2e48a0..bb782ce 100644 --- a/HADES.Core/src/EnhancedHealth.cs +++ b/HADES.Core/src/EnhancedHealth.cs @@ -1,25 +1,22 @@ -using System; using System.Collections; -using HADES.Common; using FistVR; +using HADES.Common; using UnityEngine; -using UnityEngine.UI; using static HADES.Common.Logging; namespace HADES.Core { public class EnhancedHealth : MonoBehaviour { + private float _initialHealth; 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 => HADES.Player.HealthBar; - - private float _initialHealth; private void Start() { @@ -30,12 +27,9 @@ private void Start() private void Update() { //i'm not sure who thought that the formula was (_initialhealth / currenthealth) * 100 lol - potatoes - HealthPercentage = (CurrentHealth / _initialHealth) * 100; //Thanks nathan! + HealthPercentage = CurrentHealth / _initialHealth * 100; //Thanks nathan! - if (HealthPercentage < RegenCap) - { - StartCoroutine(Regenerate()); - } + if (HealthPercentage < RegenCap) StartCoroutine(Regenerate()); } private IEnumerator Regenerate() @@ -43,9 +37,9 @@ private IEnumerator Regenerate() float initHealth = CurrentHealth; regen: yield return new WaitForSeconds(RegenDelay); - + Logging.Debug.Print("Regenerating..."); - + for (float i = 0; i < RegenCap; i += RegenSpeed / 10) { float curHealth = CurrentHealth; @@ -53,8 +47,8 @@ private IEnumerator Regenerate() if (curHealth < initHealth) goto regen; HADES.Player.HealPercent(i); } - + Logging.Debug.Print("Done Regeneration"); } } -} +} \ No newline at end of file diff --git a/HADES.Core/src/EnhancedMovement.cs b/HADES.Core/src/EnhancedMovement.cs index 3752e1e..b795bf5 100644 --- a/HADES.Core/src/EnhancedMovement.cs +++ b/HADES.Core/src/EnhancedMovement.cs @@ -7,8 +7,8 @@ namespace HADES.Core { public class EnhancedMovement : MonoBehaviour { - public float Stamina { get; private set; } + public float Weight { get @@ -16,7 +16,7 @@ public float Weight var qbSlots = HADES.Player.QuickbeltSlots; var weight = 0.0f; - + foreach (FVRQuickBeltSlot slot in qbSlots.Where(slot => slot.CurObject != null)) { FVRPhysicalObject obj = slot.CurObject; @@ -46,10 +46,10 @@ 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 void Start() { Stamina = MaxStamina; @@ -58,10 +58,10 @@ private void Start() private void Update() { if (!HADESConfig.EnhancedMovement.Enabled) return; - + float speed = HADES.Player.GetBodyMovementSpeed(); if (speed < 10f) return; - GM.CurrentMovementManager.SlidingSpeed -= (Stamina / 100); + GM.CurrentMovementManager.SlidingSpeed -= Stamina / 100; } } } \ No newline at end of file diff --git a/HADES.Core/src/FallDamage.cs b/HADES.Core/src/FallDamage.cs index 6e8fc29..765efe8 100644 --- a/HADES.Core/src/FallDamage.cs +++ b/HADES.Core/src/FallDamage.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections; -using HADES.Common; using FistVR; +using HADES.Common; using UnityEngine; using static HADES.Common.Logging; @@ -10,8 +8,8 @@ namespace HADES.Core public class FallDamage : MonoBehaviour { private Vector3 _currentPos; - private Vector3 _previousPos; private float _currentVelocity; + private Vector3 _previousPos; private float _previousVelocity; private float _velocityDifference; @@ -30,6 +28,11 @@ private void Update() HADES.Player.HarmPercent(fallDmg.Item1 / 100); //Harm the player the percentage that they fell } + public void FixedUpdate() + { + CalculateVelocity(); + } + private Tuple CalculateFallDamage() { float damage = 0; @@ -39,36 +42,28 @@ private Tuple CalculateFallDamage() //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; - } + if (effectiveVelocity < 0) damage = effectiveVelocity * HADESConfig.FallDamage.FallHeight; return new Tuple(damage, effectiveVelocity); } - public void FixedUpdate() - { - CalculateVelocity(); - } - //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 - + //set prev pos _previousPos = _currentPos; //probably not a good idea to hard-code the idea that there's only ever one player. _currentPos = HADES.Player.transform.position; - + //get velocity _previousVelocity = _currentVelocity; //calculate velocity _currentVelocity = (_previousPos - _currentPos).magnitude; - + //get velocity difference _velocityDifference = _currentVelocity - _previousVelocity; } } -} +} \ No newline at end of file diff --git a/HADES.Core/src/HADES.cs b/HADES.Core/src/HADES.cs index 3a9dfd1..9893510 100644 --- a/HADES.Core/src/HADES.cs +++ b/HADES.Core/src/HADES.cs @@ -1,18 +1,17 @@ -using System.Collections; using FistVR; using UnityEngine; - using static HADES.Common.Logging; namespace HADES.Core { - public class HADES : MonoBehaviour + public class HADES : MonoBehaviour { public static FVRPlayerBody Player => GM.CurrentPlayerBody; - public FallDamage FallDamage { get; private set; } - public EnhancedHealth EnhancedHealth { get; private set; } - public EnhancedMovement EnhancedMovement { get; private set; } + public FallDamage FallDamage { get; private set; } + public EnhancedHealth EnhancedHealth { get; private set; } + public EnhancedMovement EnhancedMovement { get; private set; } + private void Awake() { Print("Injected EHADS into player");