RELEASED Fishing Tuner

Discussion in 'Gameplay Mechanics' started by Hammurabi, May 19, 2016.

  1. Hammurabi

    Hammurabi Big Damn Hero

    Fishing Tuner: Tune Your Fishing Experience.

    This is an extended version of Zoryn4163's FishingMod, adding several new features as detailed below. Except for those changes, it should be functionally identical.

    • Allowed for the rebinding of the refresh-config key. It still defaults to F5.
    • Removed the "Easier fishing" setting (which combined a reduced difficulty value with always using the "Smooth" movement pattern).
    • Added an optional multiplier to progress gained (i.e., you can reel in the fish more quickly/slowly).
    • Changed the "Loss additive" to a loss rate multiplier, which now takes the trap bobber into account.
    • Added an "Extra treasure chance" setting, which gives an additional percentage chance of finding treasure after the game has already checked for treasure. Additionally, there is a TreasureBobberChanceBonus, which is the same thing but only used if the player is using Treasure Hunter tackle.
    • Added InitialFishCatchPercentageBonus, which is a multiplier of your starting catch progress (by default, Stardew Valley starts you with 10% progress if you haven't caught that fish type before, and 30% progress if you have).
    • Added InitialTreasureCatchPercentageBonus, which allows you to set a starting percentage for catching treasure.
    • Added multiplier and additive settings for bobber bar size. Also added the same for cork bobbers, to allow the customizing of their bonus.
    Default config settings are equivalent to unmodified Stardew Valley values, but you can tweak them to make the minigame pretty much as easy or difficult as you like.

    Code:
    using System;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Input;
    using StardewModdingAPI;
    using StardewModdingAPI.Events;
    using StardewModdingAPI.Inheritance.Menus;
    using StardewValley;
    using StardewValley.Menus;
    using StardewValley.Tools;
    
    namespace FishingTuner {
       public class FishingTunerMod : Mod
      {
         public static Farmer Player => Game1.player;
         public static IClickableMenu ActiveMenu => Game1.activeClickableMenu;
         public static BobberBar BaseBobber => ActiveMenu as BobberBar;
    
         public static SBobberBar Bobber { get; protected set; }
         public static bool BeganFishingGame { get; protected set; }
         public static int UpdateIndex { get; protected set; }
         public static FishConfig ModConfig { get; protected set; }
    
         private static Random rand;
         Keys RefreshConfigKey;
    
         public override void Entry(params object[] objects) {
           rand = new Random();
           ModConfig = new FishConfig().InitializeConfig(BaseConfigPath);
           ModConfig.ConstrainValues();
           ConfigExtensions.WriteConfig<FishConfig>(ModConfig);
           RefreshConfigKey = (Keys) Enum.Parse(typeof(Keys), ModConfig.RefreshConfigKey.ToUpper());
           MenuEvents.MenuChanged += MenuEvents_MenuChanged;
           GameEvents.OneSecondTick += GameEvents_OneSecondTick;
           GameEvents.UpdateTick += GameEvents_OnUpdateTick;
           ControlEvents.KeyPressed += ControlEvents_KeyPressed;
         }
    
         private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) {
           if (e.NewMenu is BobberBar) {
             Bobber = SBobberBar.ConstructFromBaseClass((BobberBar) e.NewMenu);
           }
         }
    
         private void GameEvents_OneSecondTick(object sender, EventArgs e) {
           if (ModConfig.InfiniteBait && Player?.CurrentTool is FishingRod && Player?.CurrentTool?.attachments?.Length > 1 && Player.CurrentTool.attachments[1] != null) {
             Player.CurrentTool.attachments[0].Stack = Player.CurrentTool.attachments[0].maximumStackSize();
           }
           if (ModConfig.InfiniteTackle && Player?.CurrentTool is FishingRod && Player?.CurrentTool?.attachments?.Length > 1 && Player.CurrentTool.attachments[1] != null) {
             Player.CurrentTool.attachments[1].Stack = Player.CurrentTool.attachments[1].maximumStackSize();
             Player.CurrentTool.attachments[1].scale = new Vector2(Player.CurrentTool.attachments[1].scale.X, 1.1f);
           }
         }
    
         private void GameEvents_OnUpdateTick(object sender, EventArgs e) {
           if (ActiveMenu is BobberBar && Bobber != null) {
             //Begin fishing game
             if (!BeganFishingGame && UpdateIndex > 15) {
               //Do these things once per fishing minigame, 1/4 second after it updates.
               Bobber.difficulty *= ModConfig.DifficultyMultiplier;
               Bobber.difficulty += ModConfig.DifficultyAdditive;
    
               if (ModConfig.BobberBarSizeMultiplier != 1.0f) {
                 Bobber.bobberBarHeight = (int) (Bobber.bobberBarHeight * ModConfig.BobberBarSizeMultiplier);
               }
               Bobber.bobberBarHeight += ModConfig.BobberBarSizeAdditive;
               Bobber.bobberBarHeight = Math.Max(Bobber.bobberBarHeight, 1);
    
               if (Bobber.whichBobber == 695) {
                 Bobber.bobberBarHeight -= 24;
                 if (ModConfig.CorkBobberSizeMultiplier != 1.0f) {
                   Bobber.bobberBarHeight = (int) (Bobber.bobberBarHeight * ModConfig.CorkBobberSizeMultiplier);
                 }
                 Bobber.bobberBarHeight += ModConfig.CorkBobberSizeAdditive;
                 Bobber.bobberBarHeight = Math.Max(Bobber.bobberBarHeight, 1);
               }
    
               if (ModConfig.AlwaysFindTreasure) {
                 Bobber.treasure = true;
               }
               else if (!Bobber.treasure) {
                 float BonusChance = ModConfig.ExtraTreasureChance;
                 //Treasure Hunter tackle
                 if (Bobber.whichBobber == 693) {
                   BonusChance += ModConfig.TreasureBobberChanceBonus;
                 }
                 if (BonusChance > 0.0f) {
                   if (rand.NextDouble() < (ModConfig.ExtraTreasureChance)) {
                     Bobber.treasure = true;
                   }
                 }
               }
    
               if (ModConfig.InstantCatchFish) {
                 Bobber.distanceFromCatching += 100;
               }
               else if (ModConfig.InitialFishCatchPercentageBonus > 0) {
                 Bobber.distanceFromCatching *= (1 + ModConfig.InitialFishCatchPercentageBonus);
               }
    
               if (Bobber.treasure) {
                 if (ModConfig.InstantCatchTreasure) {
                   Bobber.treasureCaught = true;
                 }
                 else if (ModConfig.InitialTreasureCatchPercentageBonus > 0) {
                   Bobber.treasureCatchLevel = ModConfig.InitialTreasureCatchPercentageBonus;
                 }
               }
    
               BeganFishingGame = true;
             }
    
             if (UpdateIndex < 20) {
               UpdateIndex++;
             }
    
             if (ModConfig.AlwaysPerfect) {
               Bobber.perfect = true;
             }
    
             if (Bobber.bobberInBar) {
               Bobber.distanceFromCatching += 0.002f * (ModConfig.ProgressGainMultiplier - 1.0f);
             }
             else {
               //Take into account the trap bobber, which reduces fish escape rate.
               if (Bobber.whichBobber == 694) {
                 Bobber.distanceFromCatching -= 0.002f * (ModConfig.ProgressLossMultiplier - 1.0f);
               }
               else {
                 Bobber.distanceFromCatching -= 0.003f * (ModConfig.ProgressLossMultiplier - 1.0f);
               }
             }
           }
           else {
             //End fishing game
             BeganFishingGame = false;
             UpdateIndex = 0;
           }
         }
    
         private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e) {
           if (e.KeyPressed == RefreshConfigKey) {
             ModConfig = ModConfig.ReloadConfig();
             ModConfig.ConstrainValues();
             ConfigExtensions.WriteConfig<FishConfig>(ModConfig);
             RefreshConfigKey = (Keys) Enum.Parse(typeof(Keys), ModConfig.RefreshConfigKey.ToUpper());
             Log.Success("Config reloaded for " + GetType().Name);
           }
         }
      }
    
       public class FishConfig : Config {
         public string RefreshConfigKey { get; set; }
         public bool AlwaysPerfect { get; set; }
         public bool AlwaysFindTreasure { get; set; }
         public bool InstantCatchFish { get; set; }
         public bool InstantCatchTreasure { get; set; }
         public bool InfiniteTackle { get; set; }
         public bool InfiniteBait { get; set; }
         public float ProgressGainMultiplier { get; set; }
         public float ProgressLossMultiplier { get; set; }
         public float DifficultyMultiplier { get; set; }
         public float DifficultyAdditive { get; set; }
         public float ExtraTreasureChance { get; set; }
         public float TreasureBobberChanceBonus { get; set; }
         public float InitialFishCatchPercentageBonus { get; set; }
         public float InitialTreasureCatchPercentageBonus { get; set; }
         public float BobberBarSizeMultiplier { get; set; }
         public int BobberBarSizeAdditive { get; set; }
         public float CorkBobberSizeMultiplier { get; set; }
         public int CorkBobberSizeAdditive { get; set; }
    
         public void ConstrainValues() {
           ProgressLossMultiplier = Math.Max(0.0f, ProgressLossMultiplier);
           DifficultyMultiplier = Math.Max(0.0f, DifficultyMultiplier);
           ExtraTreasureChance = Math.Max(0.0f, Math.Min(1.0f, ExtraTreasureChance));
           TreasureBobberChanceBonus = Math.Max(0.0f, Math.Min(1.0f, TreasureBobberChanceBonus));
           InitialFishCatchPercentageBonus = Math.Max(-1.0f, InitialFishCatchPercentageBonus);
           InitialTreasureCatchPercentageBonus = Math.Max(0.0f, Math.Min(1.0f, InitialTreasureCatchPercentageBonus));
           BobberBarSizeMultiplier = Math.Max(0.0f, BobberBarSizeMultiplier);
           CorkBobberSizeMultiplier = Math.Max(0.0f, CorkBobberSizeMultiplier);
         }
    
         public override T GenerateDefaultConfig<T>() {
           RefreshConfigKey = "F5";
           AlwaysPerfect = false;
           AlwaysFindTreasure = false;
           InstantCatchFish = false;
           InstantCatchTreasure = false;
           InfiniteTackle = false;
           InfiniteBait = false;
           ProgressGainMultiplier = 1.0f;
           ProgressLossMultiplier = 1.0f;
           DifficultyMultiplier = 1.0f;
           DifficultyAdditive = 0;
           ExtraTreasureChance = 0.0f;
           TreasureBobberChanceBonus = 0.0f;
           InitialFishCatchPercentageBonus = 0.0f;
           InitialTreasureCatchPercentageBonus = 0.0f;
           BobberBarSizeMultiplier = 1.0f;
           BobberBarSizeAdditive = 0;
           CorkBobberSizeMultiplier = 1.0f;
           CorkBobberSizeAdditive = 24;
           return this as T;
         }
       }
    }
    
     

      Attached Files:

    • TheCoryGuy

      TheCoryGuy Void-Bound Voyager

      Been using this, but I just wish the lines in the config were explained a bit more. I'm a newb, you see.
       
      • Hammurabi

        Hammurabi Big Damn Hero

        Sorry for the late reply, it's been a busy week for me.

        RefreshConfigKey : The key you press to reload config files (so you can tweak things while the game is running). F5 by default.
        AlwaysPerfect : Makes it so that you always get the "Perfect!" result, even if the fish indicator leaves your bobber bar.
        AlwaysFindTreasure : Makes it so that a treasure chest will always appear when you hook a fish.
        InstantCatchFish : Fish get caught instantly, essentially bypasses the minigame. Note that unless the InstantCatchTreasure option is also set, this will prevent you from getting treasure chests from fishing.
        InstantCatchTreasure : Treasure chests get instantly caught as soon as the minigame starts if they appear.
        InfiniteTackle : Your tackle's durability will always be at max. Only does anything if you have a tackle equipped to your rod and your rod is currently held.
        InfiniteBait : Your bait stack will always be full. Only does anything if you have bait equipped to your rod and your rod is currently held.
        ProgressGainMultiplier : Multiplier for how quickly you reel fish in. Greater than 1 means you reel fish in faster, between 0 and 1 means you reel in fish slower.
        ProgressLossMultiplier : Multiplier for how quickly fish escape when they are outside of your bobber bar. Greater than 1 means they escape faster, between 0 and 1 means they escape slower.
        DifficultyMultiplier : Multiplier for the "Difficulty" value of fish that get hooked. This affects both how quickly the fish indicator moves, and how much fishing experience you earn.
        DifficultyAdditive : This is added to the "Difficulty" value of the fish that get hooked, and is added after the multiplier is applied.
        ExtraTreasureChance : This gives a second chance for treasure to appear when a fish gets hooked, if no treasure was set to appear. It should be between 0 and 1. So, for a 25% chance, you would put 0.25
        TreasureBobberChanceBonus : Same as the previous one, but only added if a Treasure Hunter bobber is used. This is added to the ExtraTreasureChance value.
        InitialFishCatchPercentageBonus : Bonus to how far along the catch meter is when you first hook a fish. It should be between 0 and 1.
        InitialTreasureCatchPercentageBonus : Same as the previous one, but for treasure instead of fish.
        BobberBarSizeMultiplier : Multiplier for how big the bobber bar is. Greater than 1 makes it bigger, between 0 and 1 makes it smaller.
        BobberBarSizeAdditive : This is added to the bobber bar's size. Positive values make it bigger, negative values make it smaller.
        CorkBobberSizeMultiplier : Same as BobberBarSizeMultiplier, but only used when a Cork Bobber is equipped. This is used in addition to BobberBarSizeMultiplier.
        CorkBobberSizeAdditive : Same as BobberBarSizeAdditive, but only used when a Cork Bobber is equipped. This is used in addition to BobberBarSizeAdditive.
         
          TheCoryGuy likes this.
        • TheCoryGuy

          TheCoryGuy Void-Bound Voyager

          Thank you for this, by the way. I came back to this guide today for reference. :)
           
          • Pianobeats

            Pianobeats Subatomic Cosmonaut

            Hi, I just wanted to let you know that this mod no longer works with the current version of Stardew Valley. Are you by any chance going to update it?
             

            Share This Page