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

Commit

Permalink
Cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
Frityet committed Jul 25, 2021
1 parent c9e9830 commit 21be365
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 97 deletions.
13 changes: 9 additions & 4 deletions HADES.Core/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
96 changes: 47 additions & 49 deletions HADES.Core/HADESConfig.cs
Original file line number Diff line number Diff line change
@@ -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<bool> 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<float> _fallHeightEntry;

public float DamageMultiplier => _damageMultiplierEntry.Value;
private readonly ConfigEntry<float> _damageMultiplierEntry;
private readonly ConfigEntry<float> _fallHeightEntry;

public FallDamageConfig()
{
Expand Down Expand Up @@ -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<float> _regenCapEntry;

public float RegenDelay => _regenDelayEntry.Value;
private readonly ConfigEntry<float> _regenDelayEntry;

public float RegenSpeed => _regenSpeedEntry.Value;
private readonly ConfigEntry<float> _regenSpeedEntry;

public EnhancedHealthConfig()
Expand Down Expand Up @@ -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<float> _backpackWeightModifierEntry;
private readonly ConfigEntry<float> _ccbObjWeightModifierEntry;
private readonly ConfigEntry<float> _largeObjWeightModifierEntry;
private readonly ConfigEntry<float> _massiveObjWeightModifierEntry;
private readonly ConfigEntry<float> _maxStaminaEntry;

public float StaminaGain => _staminaGainEntry.Value;
private readonly ConfigEntry<float> _mediumObjWeightModifierEntry;
private readonly ConfigEntry<float> _smallObjWeightModifierEntry;
private readonly ConfigEntry<float> _staminaGainEntry;

public float StaminaLoss => _staminaLossEntry.Value;
private readonly ConfigEntry<float> _staminaLossEntry;

public float WeightModifier => _weightModifierEntry.Value;
private readonly ConfigEntry<float> _weightModifierEntry;

public float BackpackWeightModifier => _backpackWeightModifierEntry.Value;
private readonly ConfigEntry<float> _backpackWeightModifierEntry;

public float SmallObjectWeightModifier => _smallObjWeightModifierEntry.Value;
private readonly ConfigEntry<float> _smallObjWeightModifierEntry;

public float MediumObjectWeightModifier => _mediumObjWeightModifierEntry.Value;
private readonly ConfigEntry<float> _mediumObjWeightModifierEntry;

public float LargeObjectWeightModifier => _largeObjWeightModifierEntry.Value;
private readonly ConfigEntry<float> _largeObjWeightModifierEntry;

public float MassiveObjectWeightModifier => _massiveObjWeightModifierEntry.Value;
private readonly ConfigEntry<float> _massiveObjWeightModifierEntry;

public float CCBWeightModifer => _ccbObjWeightModifierEntry.Value;
private readonly ConfigEntry<float> _ccbObjWeightModifierEntry;

public EnhancedMovementConfig()
{
EnabledEntry = Plugin.Mod.Config.Bind
Expand All @@ -160,7 +139,6 @@ public EnhancedMovementConfig()
"Stamina Gain",
5f,
"The amount of stamina gained whilst inactive"

);

_staminaLossEntry = Plugin.Mod.Config.Bind
Expand All @@ -172,7 +150,7 @@ public EnhancedMovementConfig()
);

const string WEIGHT_CAT_NAME = CATEGORY_NAME + " - Weight Configuration";

_weightModifierEntry = Plugin.Mod.Config.Bind
(
WEIGHT_CAT_NAME,
Expand Down Expand Up @@ -204,23 +182,23 @@ 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,
"Large Object Weight Modifier",
5f,
"How much weight a large object will add if it is in a Quickbelt slot"
);

_massiveObjWeightModifierEntry = Plugin.Mod.Config.Bind
(
WEIGHT_CAT_NAME,
"Massive Object Weight Modifier",
10f,
"How much weight a massive object will add if it is in a Quickbelt slot"
);

_ccbObjWeightModifierEntry = Plugin.Mod.Config.Bind
(
WEIGHT_CAT_NAME,
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions HADES.Core/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Plugin : BaseUnityPlugin
{
public static Plugin Mod;
public static ManualLogSource ConsoleLogger;

public Plugin()
{
Mod = this;
Expand Down
24 changes: 9 additions & 15 deletions HADES.Core/src/EnhancedHealth.cs
Original file line number Diff line number Diff line change
@@ -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()
{
Expand All @@ -30,31 +27,28 @@ 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()
{
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;
Logging.Debug.Print($"Current health {curHealth}\nInit health {initHealth}");
if (curHealth < initHealth) goto regen;
HADES.Player.HealPercent(i);
}

Logging.Debug.Print("Done Regeneration");
}
}
}
}
12 changes: 6 additions & 6 deletions HADES.Core/src/EnhancedMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ namespace HADES.Core
{
public class EnhancedMovement : MonoBehaviour
{

public float Stamina { get; private set; }

public float Weight
{
get
{
var qbSlots = HADES.Player.QuickbeltSlots;

var weight = 0.0f;

foreach (FVRQuickBeltSlot slot in qbSlots.Where(slot => slot.CurObject != null))
{
FVRPhysicalObject obj = slot.CurObject;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
}
Loading

0 comments on commit 21be365

Please sign in to comment.