Added progress sound when catching a fish

master
Mohammad Shoaib Khan 2023-02-12 15:14:46 +05:30
parent 871c0b47cb
commit b89a8f205d
No known key found for this signature in database
GPG Key ID: D8040D966320B620
2 changed files with 44 additions and 0 deletions

View File

@ -274,6 +274,12 @@ namespace stardew_access
original: AccessTools.Method(typeof(GrandpaStory), nameof(GrandpaStory.draw), new Type[] { typeof(SpriteBatch) }),
postfix: new HarmonyMethod(typeof(MiniGamesPatches), nameof(MiniGamesPatches.GrandpaStoryPatch))
);
harmony.Patch(
original: AccessTools.Method(typeof(BobberBar), nameof(BobberBar.update)),
postfix: new HarmonyMethod(typeof(FishingMiniGamePatch), nameof(FishingMiniGamePatch.BobberBarPatch))
);
#endregion
harmony.Patch(

View File

@ -0,0 +1,38 @@
using StardewValley;
using StardewValley.Menus;
namespace stardew_access.Patches {
internal class FishingMiniGamePatch {
private static ICue? progressSound = null;
internal static void BobberBarPatch(BobberBar __instance, float ___distanceFromCatching, float ___bobberPosition, float ___bobberBarPos, bool ___bobberInBar, bool ___fadeOut, bool ___fadeIn) {
try {
handleProgressBarSound(___distanceFromCatching, ___fadeOut, ___fadeIn);
// MainClass.DebugLog($"dist: {___distanceFromCatching}\tbobPos: {___bobberPosition}\tbobbarpos{___bobberBarPos}");
} catch (System.Exception e) {
MainClass.ErrorLog($"An error occured while patching bobber bar:\n{e.Message}\n{e.StackTrace}");
}
}
private static void handleProgressBarSound(float ___distanceFromCatching, bool ___fadeOut, bool ___fadeIn) {
if(Game1.soundBank == null) return;
if (progressSound == null) {
progressSound = Game1.soundBank.GetCue("SinWave");
}
progressSound.SetVariable("Pitch", 2400f * ___distanceFromCatching);
// progressSound.SetVariable("Volume", 300f);
if (___fadeIn && !progressSound.IsPlaying) {
// Start playing the sound on menu open
progressSound.Play();
}
if(___fadeOut && progressSound.IsPlaying) {
// Stop playing the sound on menu close
progressSound.Stop(Microsoft.Xna.Framework.Audio.AudioStopOptions.Immediate);
}
}
}
}