From c2a0779f62793ab738c6b30b618763a7a8d9333e Mon Sep 17 00:00:00 2001 From: Alex Gilbert Date: Tue, 16 Jan 2024 11:21:22 -0500 Subject: [PATCH] - Fixed some buffs not resetting on newday --- StardewArchipelago/Items/ItemManager.cs | 5 ++-- StardewArchipelago/Items/ItemParser.cs | 5 ++-- StardewArchipelago/Items/Traps/TrapManager.cs | 30 ++++++++++++++++++- StardewArchipelago/ModEntry.cs | 2 +- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/StardewArchipelago/Items/ItemManager.cs b/StardewArchipelago/Items/ItemManager.cs index 81fff8951..3b8bef125 100644 --- a/StardewArchipelago/Items/ItemManager.cs +++ b/StardewArchipelago/Items/ItemManager.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using HarmonyLib; using StardewArchipelago.Archipelago; using StardewArchipelago.Items.Mail; using StardewArchipelago.Items.Traps; @@ -17,10 +18,10 @@ public class ItemManager private Mailman _mail; private HashSet _itemsAlreadyProcessed; - public ItemManager(IModHelper helper, ArchipelagoClient archipelago, StardewItemManager itemManager, Mailman mail, TileChooser tileChooser, IEnumerable itemsAlreadyProcessed) + public ItemManager(IModHelper helper, Harmony harmony, ArchipelagoClient archipelago, StardewItemManager itemManager, Mailman mail, TileChooser tileChooser, IEnumerable itemsAlreadyProcessed) { _archipelago = archipelago; - _itemParser = new ItemParser(helper, archipelago, itemManager, tileChooser); + _itemParser = new ItemParser(helper, harmony, archipelago, itemManager, tileChooser); _mail = mail; _itemsAlreadyProcessed = itemsAlreadyProcessed.ToHashSet(); } diff --git a/StardewArchipelago/Items/ItemParser.cs b/StardewArchipelago/Items/ItemParser.cs index 33fddc0b7..024a0c141 100644 --- a/StardewArchipelago/Items/ItemParser.cs +++ b/StardewArchipelago/Items/ItemParser.cs @@ -1,4 +1,5 @@ using System; +using HarmonyLib; using StardewArchipelago.Archipelago; using StardewArchipelago.Items.Mail; using StardewArchipelago.Items.Traps; @@ -18,11 +19,11 @@ public class ItemParser private UnlockManager _unlockManager; private TrapManager _trapManager; - public ItemParser(IModHelper helper, ArchipelagoClient archipelago, StardewItemManager itemManager, TileChooser tileChooser) + public ItemParser(IModHelper helper, Harmony harmony, ArchipelagoClient archipelago, StardewItemManager itemManager, TileChooser tileChooser) { _itemManager = itemManager; _unlockManager = new UnlockManager(archipelago); - _trapManager = new TrapManager(helper, archipelago, tileChooser); + _trapManager = new TrapManager(helper, harmony, archipelago, tileChooser); } public TrapManager TrapManager => _trapManager; diff --git a/StardewArchipelago/Items/Traps/TrapManager.cs b/StardewArchipelago/Items/Traps/TrapManager.cs index a2e33359d..78ee4cab7 100644 --- a/StardewArchipelago/Items/Traps/TrapManager.cs +++ b/StardewArchipelago/Items/Traps/TrapManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Archipelago.MultiClient.Net.Enums; +using HarmonyLib; using Microsoft.Xna.Framework; using Netcode; using StardewArchipelago.Archipelago; @@ -16,6 +17,7 @@ using StardewValley.BellsAndWhistles; using StardewValley.Characters; using StardewValley.Locations; +using StardewValley.Menus; using StardewValley.Monsters; using StardewValley.Objects; using StardewValley.TerrainFeatures; @@ -46,6 +48,7 @@ public class TrapManager private const string DROUGHT = "Drought"; private readonly IModHelper _helper; + private readonly Harmony _harmony; private readonly ArchipelagoClient _archipelago; private readonly TrapDifficultyBalancer _difficultyBalancer; private readonly TileChooser _tileChooser; @@ -73,9 +76,10 @@ public class TrapManager {DROUGHT, () => true}, }; - public TrapManager(IModHelper helper, ArchipelagoClient archipelago, TileChooser tileChooser) + public TrapManager(IModHelper helper, Harmony harmony, ArchipelagoClient archipelago, TileChooser tileChooser) { _helper = helper; + _harmony = harmony; _archipelago = archipelago; _difficultyBalancer = new TrapDifficultyBalancer(); _tileChooser = tileChooser; @@ -83,6 +87,11 @@ public TrapManager(IModHelper helper, ArchipelagoClient archipelago, TileChooser _inventoryShuffler = new InventoryShuffler(); _traps = new Dictionary(); RegisterTraps(); + + _harmony.Patch( + original: AccessTools.Method(typeof(BuffsDisplay), nameof(BuffsDisplay.clearAllBuffs)), + prefix: new HarmonyMethod(typeof(TrapManager), nameof(ClearAllBuffs_ClearOtherBuffs_Prefix)) + ); } public bool IsTrap(string unlockName) @@ -593,5 +602,24 @@ private IEnumerable GetAllWateringCans() } } } + + // public void clearAllBuffs() + public bool ClearAllBuffs_ClearOtherBuffs_Prefix(BuffsDisplay __instance) + { + try + { + foreach (var otherBuff in __instance.otherBuffs) + { + otherBuff.removeBuff(); + } + + return true; + } + catch (Exception ex) + { + // _monitor.Log($"Failed in {nameof(ClearAllBuffs_ClearOtherBuffs_Prefix)}:\n{ex}", LogLevel.Error); + return true; // run original logic + } + } } } diff --git a/StardewArchipelago/ModEntry.cs b/StardewArchipelago/ModEntry.cs index 0eec88056..8b84b5291 100644 --- a/StardewArchipelago/ModEntry.cs +++ b/StardewArchipelago/ModEntry.cs @@ -248,7 +248,7 @@ private void OnSaveLoaded(object sender, SaveLoadedEventArgs e) } } - _itemManager = new ItemManager(_helper, _archipelago, _stardewItemManager, _mail, tileChooser, State.ItemsReceived); + _itemManager = new ItemManager(_helper, _harmony, _archipelago, _stardewItemManager, _mail, tileChooser, State.ItemsReceived); _mailPatcher = new MailPatcher(Monitor, _harmony, _archipelago, _locationChecker, new LetterActions(_helper, _mail, _archipelago, _itemManager.TrapManager)); _locationsPatcher = new LocationPatcher(Monitor, _helper, _harmony, _archipelago, _locationChecker, _bundleReader, _stardewItemManager, State); _chatForwarder.ListenToChatMessages();