Skip to content

Commit

Permalink
- Fixed some buffs not resetting on newday
Browse files Browse the repository at this point in the history
  • Loading branch information
agilbert1412 committed Jan 16, 2024
1 parent adba9b2 commit c2a0779
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
5 changes: 3 additions & 2 deletions StardewArchipelago/Items/ItemManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using StardewArchipelago.Archipelago;
using StardewArchipelago.Items.Mail;
using StardewArchipelago.Items.Traps;
Expand All @@ -17,10 +18,10 @@ public class ItemManager
private Mailman _mail;
private HashSet<ReceivedItem> _itemsAlreadyProcessed;

public ItemManager(IModHelper helper, ArchipelagoClient archipelago, StardewItemManager itemManager, Mailman mail, TileChooser tileChooser, IEnumerable<ReceivedItem> itemsAlreadyProcessed)
public ItemManager(IModHelper helper, Harmony harmony, ArchipelagoClient archipelago, StardewItemManager itemManager, Mailman mail, TileChooser tileChooser, IEnumerable<ReceivedItem> itemsAlreadyProcessed)
{
_archipelago = archipelago;
_itemParser = new ItemParser(helper, archipelago, itemManager, tileChooser);
_itemParser = new ItemParser(helper, harmony, archipelago, itemManager, tileChooser);
_mail = mail;
_itemsAlreadyProcessed = itemsAlreadyProcessed.ToHashSet();
}
Expand Down
5 changes: 3 additions & 2 deletions StardewArchipelago/Items/ItemParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using HarmonyLib;
using StardewArchipelago.Archipelago;
using StardewArchipelago.Items.Mail;
using StardewArchipelago.Items.Traps;
Expand All @@ -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;
Expand Down
30 changes: 29 additions & 1 deletion StardewArchipelago/Items/Traps/TrapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -73,16 +76,22 @@ 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;
_monsterSpawner = new MonsterSpawner(_tileChooser);
_inventoryShuffler = new InventoryShuffler();
_traps = new Dictionary<string, Action>();
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)
Expand Down Expand Up @@ -593,5 +602,24 @@ private IEnumerable<WateringCan> 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
}
}
}
}
2 changes: 1 addition & 1 deletion StardewArchipelago/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c2a0779

Please sign in to comment.