RELEASED [SMAPI 0.37+] Stamina Regen when idle1.2

Discussion in 'Gameplay Mechanics' started by MiZiPex, Mar 7, 2016.

  1. MiZiPex

    MiZiPex Void-Bound Voyager

    [​IMG]

    feature:

    - You will Regenerate 1 Stamina every 3 second when idle.
    - You can change the Regen Rate and the Regen Amount in file "StaminaIdle.ini"

    Config:

    RegenAmount=1 - The amount of stamina restore.
    RegenRate=3 - The rate in seconds.


    Install:
    Make sure you have SMAPI 0.37 from https://github.com/ClxS/SMAPI/releases/tag/0.37
    Extract the DLL from the archive and place it in the /Mods/ folder in the main game directory.

    Change log:

    1.2 - 11/03/2016
    - fix minor bug

    1.1 - 07/03/2016
    - change regen rate 5 ->3

    1.0 - 07/03/2016
    - init release

    Please report any bugs to me, thanks

    Download:
    StaminaIdle 1.2

    Source
    Code:
    using System;
    using System.IO;
    using Microsoft.Xna.Framework;
    using StardewModdingAPI;
    using StardewModdingAPI.Events;
    using StardewValley;
    
    namespace StaminaIdle
    {
        public class StaminaIdle : Mod
        {
            public override string Name
            {
                get { return "Stamina Idle"; }
            }
    
            public override string Authour
            {
                get { return "MiZiP@ILoveStardewValleyThailand"; }
            }
    
            public override string Version
            {
                get { return "1.2"; }
            }
    
            public override string Description
            {
                get { return "Regen stamina when idle Thx:Yoshify, natfoth"; }
            }
    
            public int staminaAmount = 1; //Regen 1 stamina every...
            public int regenRate = 3; //3 seconds.
    
            private float previousTime;
    
            public override void Entry(params object[] objects)
            {
                Console.WriteLine("StaminaIdle Mod has loaded!");
                LoadConfig();
                GameEvents.UpdateTick += Update;
               
            }
    
            void LoadConfig()
            {
                string configFilePath = "Mods\\StaminaIdle.ini";
                StreamReader configReader;
    
                try
                {
                    configReader = File.OpenText(configFilePath);
                    Console.WriteLine("Got StaminaIdle config at " + configFilePath);
                }
                catch
                {
                    Console.WriteLine("StaminaIdle config doesn't exist! Creating one for you.");
    
                    StreamWriter configWriter = new StreamWriter(configFilePath);
                    configWriter.WriteLine("RegenAmount=1");
                    configWriter.WriteLine("RegenRate=3");
                    configWriter.Close();
    
                    configReader = File.OpenText(configFilePath);
                }
    
                string line = configReader.ReadLine();
                bool couldParseA = int.TryParse(line.Split('=')[1], out staminaAmount);
                line = configReader.ReadLine();
                bool couldParseB = int.TryParse(line.Split('=')[1], out regenRate);
    
                if (!couldParseA || !couldParseB)
                {
                    Console.WriteLine("Couldn't load StaminaIdle config! Using default values.");
                    configReader.Close();
                    return;
                }
    
                configReader.Close();
            }
    
            void Update(object sender, EventArgs e)
            {
                if (!Game1.player.isMoving())
                {
                    if (regenRate <= 3)
                        regenRate = 3;
                    if (staminaAmount >= 10)
                        staminaAmount = 10;
    
                    if (Game1.player == null || !Game1.hasLoadedGame ) return;
    
                    if (Game1.currentGameTime.TotalGameTime.TotalSeconds < previousTime + regenRate)
                        return;
    
                    previousTime = (float)Game1.currentGameTime.TotalGameTime.TotalSeconds;
    
                    Game1.player.Stamina += staminaAmount;
                }
            }
        }
    }
    

    Thank : natfoth (original mod) , Yoshify (code for SMAPI 0.37)

     
      Last edited: Mar 11, 2016
    • cantorsdust

      cantorsdust Existential Complex

      Added to mod list!
       
        MiZiPex likes this.
      • KSwitch500

        KSwitch500 Aquatic Astronaut

        This also regens when youre running around. So I just nerfed mine to 1 every 5 seconds. Fantastic Mod otherwise! Thank you!


        Edit: Sorry, I was wrong. The timer keeps counting while you move, the adding of a energy point doesnt happen til you stop moving. My fault!
         
          Last edited: Mar 7, 2016
          MiZiPex likes this.
        • MiZiPex

          MiZiPex Void-Bound Voyager

          Thank you

          yep,mod active when you stop moving.

          Thankyou
           
          • Yoshify

            Yoshify Intergalactic Tourist

            Pardon, you've credited Natfoth but this (for some reason) prints "Sprint Mod loading..." to the Console?
             
              MiZiPex likes this.
            • MiZiPex

              MiZiPex Void-Bound Voyager

              apologize, add to credit :)
               
                Last edited: Mar 11, 2016
              • pigeonsmall

                pigeonsmall Orbital Explorer

                this is a super helpful mod. I'm basically superman now.
                 
                • Kvassny

                  Kvassny Space Hobo

                  can u update the download link? it's not working
                   
                  • MbahGondrong

                    MbahGondrong Seal Broken

                    Is this still working with latest SMAPI and SV?
                     

                    Share This Page