Skip to content

Commit

Permalink
- Allow earning walnuts over 130 in case of problems
Browse files Browse the repository at this point in the history
agilbert1412 committed Oct 22, 2024
1 parent 5bdf069 commit ebe381c
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Linq;
using KaitoKid.ArchipelagoUtilities.Net.Client;
using KaitoKid.ArchipelagoUtilities.Net.Interfaces;
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValley.Extensions;
using StardewValley.Locations;
using StardewValley.Menus;
using StardewValley.Tools;

namespace StardewArchipelago.GameModifications.CodeInjections
{
public static class WalnutInjections
{
private static ILogger _logger;
private static ArchipelagoClient _archipelago;

public static void Initialize(ILogger logger, ArchipelagoClient archipelago)
{
_logger = logger;
_archipelago = archipelago;
}

// public void foundWalnut(int stack = 1)
public static bool FoundWalnut_NoUpperLimit_Prefix(Farmer __instance, int stack)
{
try
{
Game1.netWorldState.Value.GoldenWalnuts += stack;
Game1.netWorldState.Value.GoldenWalnutsFound += stack;
Game1.PerformActionWhenPlayerFree(__instance.showNutPickup);
return false; // don't run original logic
}
catch (Exception ex)
{
_logger.LogError($"Failed in {nameof(FoundWalnut_NoUpperLimit_Prefix)}:\n{ex}");
return true; // run original logic
}
}
}
}
10 changes: 10 additions & 0 deletions StardewArchipelago/GameModifications/RandomizedLogicPatcher.cs
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ public RandomizedLogicPatcher(LogHandler logger, IModHelper modHelper, ModConfig
SpecialOrderBoardInjections.Initialize(logger, modHelper, archipelago, locationChecker);
CraftingPageInjections.Initialize(logger, archipelago);
PanningSpotInjections.Initialize(logger, archipelago);
WalnutInjections.Initialize(logger, archipelago);
OutOfLogicInjections.Initialize(logger, archipelago, stardewItemManager);
DebugPatchInjections.Initialize(logger, archipelago);
_jojaDisabler = new JojaDisabler(logger, modHelper, harmony);
@@ -127,6 +128,7 @@ public void PatchAllGameLogic()
PatchBundles();
PatchCraftingPage();
PatchPanningSpots();
PatchWalnuts();
PatchMysteryBoxesAndPrizeTickets();

_jojaDisabler.DisableJojaRouteShortcuts();
@@ -738,6 +740,14 @@ private void PatchPanningSpots()
);
}

private void PatchWalnuts()
{
_harmony.Patch(
original: AccessTools.Method(typeof(Farmer), nameof(Farmer.foundWalnut)),
prefix: new HarmonyMethod(typeof(WalnutInjections), nameof(WalnutInjections.FoundWalnut_NoUpperLimit_Prefix))
);
}

private void PatchMysteryBoxesAndPrizeTickets()
{
if (!ModEntry.Instance.Config.StrictLogic)

0 comments on commit ebe381c

Please sign in to comment.