Hammurabi submitted a new mod: Regeneration - Provides configurable health and stamina regeneration. Read more about this mod...
Source code: Code: using System; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; namespace Regeneration { public class ModConfig { public float healthRegenAbsolutePerSecond { get; set; } public float healthRegenPercentagePerSecond { get; set; } public double healthIdleSeconds { get; set; } public float regenHealthWhileRunningRate { get; set; } public bool loseFractionalHealthWhenInjured { get; set; } public float staminaRegenAbsolutePerSecond { get; set; } public float staminaRegenPercentagePerSecond { get; set; } public double staminaIdleSeconds { get; set; } public float regenStaminaWhileRunningRate { get; set; } public bool removeExhaustion { get; set; } public float removeExhaustionStaminaPercentage { get; set; } public ModConfig() { healthRegenAbsolutePerSecond = 0.1f; healthRegenPercentagePerSecond = 0.0f; healthIdleSeconds = 15.0; regenHealthWhileRunningRate = 0.0f; loseFractionalHealthWhenInjured = false; staminaRegenAbsolutePerSecond = 0.0f; staminaRegenPercentagePerSecond = (1.0f / 270.0f); // Recover 1 stamina per second at game start, but increase as max stamina increases. staminaIdleSeconds = 10.0; regenStaminaWhileRunningRate = 0.25f; removeExhaustion = false; removeExhaustionStaminaPercentage = 1.0f; } } public class Regeneration : Mod { // Health values int lastHealth; float healthAccum; // Accumulated health regenerated while running. double healthRegenStartTime; // The time when health regeneration should next begin. Updated after taking damage. // Stamina values float lastStamina; // Last recorded player stamina value. double staminaRegenStartTime; // The time when stamina regeneration should next begin. Updated after losing stamina. // Control values double lastTickTime; // The time at the last tick processed. bool playerIsRunning; // Whether the player has run since the preceeding update tick. Farmer Player; // Our player. ModConfig myConfig; // Config data. public override void Entry(IModHelper helper) { myConfig = helper.ReadConfig<ModConfig>(); // Validate settings and re-save the config file. // Percentage values can't be greater than 100%. if (myConfig.healthRegenPercentagePerSecond > 1.0) { myConfig.healthRegenPercentagePerSecond = 1.0f; } if (myConfig.staminaRegenPercentagePerSecond > 1.0) { myConfig.staminaRegenPercentagePerSecond = 1.0f; } if (myConfig.removeExhaustionStaminaPercentage > 1.0) { myConfig.removeExhaustionStaminaPercentage = 1.0f; } // Remove Exhaustion percentage shouldn't be less than 0%. if (myConfig.removeExhaustionStaminaPercentage < 0.0) { myConfig.removeExhaustionStaminaPercentage = 0.0f; } // Max running rate can't be higher than base. if (myConfig.regenHealthWhileRunningRate > 1.0) { myConfig.regenHealthWhileRunningRate = 1.0f; } if (myConfig.regenStaminaWhileRunningRate > 1.0) { myConfig.regenStaminaWhileRunningRate = 1.0f; } // Idle times can't be negative. if (myConfig.healthIdleSeconds < 0) { myConfig.healthIdleSeconds = 0; } if (myConfig.staminaIdleSeconds < 0) { myConfig.staminaIdleSeconds = 0; } helper.WriteConfig<ModConfig>(myConfig); healthAccum = 0.0f; lastHealth = 0; lastStamina = 0; lastTickTime = 0.0; playerIsRunning = false; GameEvents.UpdateTick += OnUpdateTick; } private void OnUpdateTick(object sender, EventArgs e) { Player = Game1.player; // If game is running, and time can pass (i.e., are not in an event/cutscene/menu/festival) if (Game1.hasLoadedGame && Game1.shouldTimePass()) { // Make sure we know exactly how much time has elapsed double currentTime = Game1.currentGameTime.TotalGameTime.TotalSeconds; float timeElapsed = (float) (currentTime - lastTickTime); lastTickTime = currentTime; // Check for player injury. If player has been injured since last tick, recalculate the time when health regeneration should start. if (Player.health < lastHealth) { healthRegenStartTime = currentTime + myConfig.healthIdleSeconds; if (myConfig.loseFractionalHealthWhenInjured) { healthAccum = 0; } } // Check for player exertion. If player has used stamina since last tick, recalculate the time when stamina regeneration should start. if (Player.stamina < lastStamina) { staminaRegenStartTime = currentTime + myConfig.staminaIdleSeconds; } /* Determine whether movement status will block normal regeneration: If player is... * 1. running, and * 2. has moved recently, and * 3. is not on horseback, then * movement blocks normal regen and the running rate prevails. (If the running rate is 0, there is no regeneration.) */ if (Player.running && Player.movedDuringLastTick() && !Player.isRidingHorse()) { playerIsRunning = true; } else { playerIsRunning = false; } // Process health regeneration. if (healthRegenStartTime <= currentTime && Player.health < Player.maxHealth) { float absRegen = myConfig.healthRegenAbsolutePerSecond * timeElapsed; float percRegen = myConfig.healthRegenPercentagePerSecond * Player.maxHealth * timeElapsed; healthAccum += (absRegen + percRegen) * (playerIsRunning ? myConfig.regenHealthWhileRunningRate : 1); if (healthAccum >= 1) { Player.health += 1; healthAccum -= 1; } } // Process stamina regeneration. if (staminaRegenStartTime <= currentTime && Player.stamina < Player.maxStamina) { float absRegen = myConfig.staminaRegenAbsolutePerSecond * timeElapsed; float percRegen = myConfig.staminaRegenPercentagePerSecond * Player.maxStamina * timeElapsed; Player.stamina += (absRegen + percRegen) * (playerIsRunning ? myConfig.regenStaminaWhileRunningRate : 1); // Final sanity check if (Player.stamina > Player.maxStamina) { Player.stamina = Player.maxStamina; } } // Updated stored health/stamina values. lastHealth = Player.health; lastStamina = Player.stamina; // Remove exhaustion if the player is sufficiently recovered. if (myConfig.removeExhaustion && (Player.stamina / Player.maxStamina) > myConfig.removeExhaustionStaminaPercentage) { Player.exhausted = false; } } } } }
I was considering it, LOL. Also, major update coming soon; probably tonight, unless I find some unexpected bugs.
Perhaps I'm just a bit confused, but after waiting the initial 10 seconds, my stamina regenerates pretty fast. I haven't tested my health regen yet. My goal is to only be regenerating 0.2% of my max health and stamina per second. Here's my current config. Code: { "healthRegenAbsolutePerSecond": 0.0, "healthRegenPercentagePerSecond": 0.2, "healthIdleSeconds": 10.0, "regenHealthWhileRunningRate": 0.0, "loseFractionalHealthWhenInjured": false, "exhaustionHealthRegenRate": 1.0, "exhaustionHealthIdleMultiplier": 1.0, "regenHealthWhileFishing": true, "HealthRanges": [ { "MinHealthAbsolute": 0, "MinHealthPercentage": 0.0, "MaxHealthAbsolute": 0, "MaxHealthPercentage": 0.25, "RegenRateMultiplier": 0.5, "RunRateMulitiplier": 0.5, "IdleTimeMultiplier": 1.5 }, { "MinHealthAbsolute": 0, "MinHealthPercentage": 0.5, "MaxHealthAbsolute": 0, "MaxHealthPercentage": 0.0, "RegenRateMultiplier": 0.0, "RunRateMulitiplier": 0.0, "IdleTimeMultiplier": 0.0 } ], "staminaRegenAbsolutePerSecond": 0.0, "staminaRegenPercentagePerSecond": 0.2, "staminaIdleSeconds": 10.0, "regenStaminaWhileRunningRate": 0.0, "exhaustionStaminaRegenRate": 0.5, "exhaustionStaminaIdleMultiplier": 2.0, "regenStaminaWhileFishing": true, "StaminaRanges": [ { "MinStaminaAbsolute": 0.0, "MinStaminaPercentage": 0.0, "MaxStaminaAbsolute": 0.0, "MaxStaminaPercentage": 0.5, "RegenRateMultiplier": 0.8, "RunRateMulitiplier": 0.75, "IdleTimeMultiplier": 1.25 }, { "MinStaminaAbsolute": 0.0, "MinStaminaPercentage": 0.0, "MaxStaminaAbsolute": 0.0, "MaxStaminaPercentage": 0.25, "RegenRateMultiplier": 0.75, "RunRateMulitiplier": 0.6666667, "IdleTimeMultiplier": 1.4 }, { "MinStaminaAbsolute": 0.0, "MinStaminaPercentage": 0.75, "MaxStaminaAbsolute": 0.0, "MaxStaminaPercentage": 0.0, "RegenRateMultiplier": 0.0, "RunRateMulitiplier": 0.0, "IdleTimeMultiplier": 0.0 } ], "removeExhaustion": true, "removeExhaustionStaminaPercentage": 0.745 } **EDIT** Never mind, I think I figured it out. Looks the percentage is calculated so that 1.0 = 100%, so I just needed to change it to 0.002. Sorry to trouble you.
I don't know if it's just me and my lack of knowledge about modding, but I have no clue how to input the source code. All that I get when I try to do that is an error. I hope I can get help here since this is rather recent.
Curious, does this work in the latest version? I can't seem to get the stamina to regen, even when I tried the config above that Kiddles mentioned was too fast (Was just going to tweak it based off of that).
I also noticed in the mod page he mentioned a menu and yet there doesn't seem to be any real readme containing instructions on configuring the mod or using it
I was just wondering if someone could explain how to configure the rates for regen. I can see a lot of people have been having trouble with this especially me