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 #4 from Frityet/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Frityet authored Jul 26, 2021
2 parents 16dd451 + 021930f commit f100be2
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 59 deletions.
6 changes: 6 additions & 0 deletions .idea/.idea.HADES.H3VR/.idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.HADES.H3VR/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions HADES.Core/HADES.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Common.cs" />
<Compile Include="HADESConfig.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="src\Common.cs" />
<Compile Include="src\HADES.cs" />
<Compile Include="src\EnhancedHealth.cs" />
<Compile Include="src\EnhancedMovement.cs" />
<Compile Include="src\FallDamage.cs" />
<Compile Include="src\HADESConfig.cs" />
<Compile Include="src\HADESEnhancement.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
8 changes: 4 additions & 4 deletions HADES.Core/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using BepInEx;
using System;
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
{
Expand All @@ -11,7 +12,6 @@ public class Plugin : BaseUnityPlugin
{
public static Plugin Mod;
public static ManualLogSource ConsoleLogger;

public Plugin()
{
Mod = this;
Expand Down
10 changes: 9 additions & 1 deletion HADES.Core/Common.cs → HADES.Core/src/Common.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
using System;
using BepInEx.Logging;
using FistVR;
using HADES.Core;
using UnityEngine;

namespace HADES.Common
namespace HADES.Utilities
{
public static class Common
{
public static readonly WaitForSeconds WAIT_A_SEX = new WaitForSeconds(1);
}

public struct PluginInfo
{
public const string NAME = "HADES.Core";
Expand Down
33 changes: 20 additions & 13 deletions HADES.Core/src/EnhancedHealth.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
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
public class EnhancedHealth : HADESEnhancement
{
private HADES _hadesSystem;
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 => _hadesSystem.Player.HealthBar;

private GameObject HealthBars => Player.HealthBar;

private float _initialHealth;

private void Start()
{
_hadesSystem = GetComponent<HADES>();
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!

Expand All @@ -36,18 +37,24 @@ 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;
_hadesSystem.Player.HealPercent(i);
//TODO: make the player heal in n intervals until the regen cap is reached
Player.HealPercent(i);
}

Logging.Debug.Print("Done Regeneration");
Expand Down
48 changes: 35 additions & 13 deletions HADES.Core/src/EnhancedMovement.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
using System;
using System.Collections;
using System.Linq;
using FistVR;
using HADES.Utilities;
using UnityEngine;

namespace HADES.Core
{
public class EnhancedMovement : MonoBehaviour
public class EnhancedMovement : HADESEnhancement
{
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 = Player.QuickbeltSlots;

var weight = 0.0f;

foreach (FVRQuickBeltSlot slot in qbSlots.Where(slot => slot.CurObject != null))
{
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
{
Expand All @@ -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 => Player.GetBodyMovementSpeed();

private void Start()
{
_hadesSystem = GetComponent<HADES>();
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 = 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;
}
}
}
}
36 changes: 15 additions & 21 deletions HADES.Core/src/FallDamage.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -34,25 +34,6 @@ private void Update()
}

public void FixedUpdate()
{
CalculateVelocity();
}

private Tuple<float, float> 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<float, float>(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
Expand All @@ -70,5 +51,18 @@ private void CalculateVelocity()
//get velocity difference
_velocityDifference = _currentVelocity - _previousVelocity;
}

private Tuple<float, float> 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<float, float>(damage, effectiveVelocity);
}
}
}
2 changes: 1 addition & 1 deletion HADES.Core/src/HADES.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FistVR;
using UnityEngine;
using static HADES.Common.Logging;
using static HADES.Utilities.Logging;

namespace HADES.Core
{
Expand Down
19 changes: 15 additions & 4 deletions HADES.Core/HADESConfig.cs → HADES.Core/src/HADESConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> _backpackWeightModifierEntry;
private readonly ConfigEntry<float> _ccbObjWeightModifierEntry;
private readonly ConfigEntry<float> _largeObjWeightModifierEntry;
Expand All @@ -114,6 +114,7 @@ public class EnhancedMovementConfig : ConfigEntry
private readonly ConfigEntry<float> _staminaGainEntry;
private readonly ConfigEntry<float> _staminaLossEntry;
private readonly ConfigEntry<float> _weightModifierEntry;
private readonly ConfigEntry<float> _staminaLossStartSpeedEntry;

public EnhancedMovementConfig()
{
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions HADES.Core/src/HADESEnhancement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using FistVR;
using UnityEngine;

namespace HADES.Core
{
public class HADESEnhancement : MonoBehaviour
{
protected FVRPlayerBody Player => GM.CurrentPlayerBody;
}
}
1 change: 1 addition & 0 deletions HADES.H3VR.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CCB/@EntryIndexedValue">CCB</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HADES/@EntryIndexedValue">HADES</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Quickbelt/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit f100be2

Please sign in to comment.