Skip to content

Commit 54c341f

Browse files
committed
add crestSanity to SwapCrestOnHit config menu
1 parent 45283c1 commit 54c341f

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

SwapCrestOnHit/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# SwapCrestOnHit
22

33
Swaps Hornet's crest every time she takes damage.
4-
Currently swaps Hornet's active crest only with other unlocked crests. The mod ensures that the chest changes, so typically if you have two crests unlocked the crest will cycle between the two in a predictable way.
4+
Swaps Hornet's active crest with other unlocked crests or any other crest in the game (off by default, can be toggled in config menu). The mod ensures that the chest changes, so typically if you have two crests unlocked the crest will cycle between the two in a predictable way.
55

66
The loadout of each crest is *per-crest*, so you will alternate loadouts as you change crest when taking damage.
77

8+
Configurable: You can toggle a `Crest Sanity`. It's on by default, in which case the mod will swap only with other unlocked crests. If you turn it off, ANY other crest in the game can be selected, whether that be Shaman, Cloakless, Cursed, or any of the Hunter Crest evolutions (which, yes, are separate crests internally). Use this at your own risk, if you only want pure chaos.
9+
810
Plans for the future maybe:
9-
- Add a config option to swap with *any other valid crest in the game*, including Cloakless and Cursed crests, regardless of unlock status or in-game logic.
11+
- ~~Add a config option to swap with *any other valid crest in the game*, including Cloakless and Cursed crests, regardless of unlock status or in-game logic.~~
1012

1113
## Install
1214

SwapCrestOnHit/SwapCrestOnHit.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
using BepInEx;
2+
using BepInEx.Configuration;
23
using GlobalSettings;
34
using HarmonyLib;
45
using System;
56
using System.Collections.Generic;
67

7-
[BepInPlugin("com.chrismzz.swapcrestonhit", "Swap Crest On Hit", "1.0.0")]
8+
[BepInPlugin("com.chrismzz.swapcrestonhit", "Swap Crest On Hit", "1.1.0")]
89

910
public class SwapCrestOnHit : BaseUnityPlugin
1011
{
1112
public static readonly Random rnd = new Random();
13+
internal static ConfigEntry<bool> crestSanity;
1214
private void Awake()
1315
{
1416

1517
Logger.LogInfo("SwapCrestOnHit loaded and initialized.");
16-
18+
crestSanity = Config.Bind(
19+
"General",
20+
"Crest Sanity",
21+
true,
22+
"Only use unlocked and available crests. Set to false if you want pure chaos."
23+
);
1724

1825

1926
Harmony.CreateAndPatchAll(typeof(SwapCrestOnHit), null);
@@ -23,6 +30,7 @@ private void Awake()
2330
[HarmonyPostfix]
2431
private static void TakeDamagePostfix(HeroController __instance)
2532
{
33+
int currentSilk = __instance.playerData.silk;
2634
List<ToolCrest> allCrests = ToolItemManager.GetAllCrests();
2735
List<ToolCrest> availableCrests = new List<ToolCrest>();
2836
int crestCount = ToolItemManager.GetUnlockedCrestsCount();
@@ -31,20 +39,27 @@ private static void TakeDamagePostfix(HeroController __instance)
3139
if (!crest.IsHidden && crest.IsBaseVersion && crest.IsUnlocked)
3240
availableCrests.Add(crest);
3341
}
34-
35-
if (crestCount > 1 && __instance.playerData.CurrentCrestID != Gameplay.CursedCrest.name && __instance.playerData.CurrentCrestID != Gameplay.CloaklessCrest.name)
42+
bool canSwap = (crestCount > 1 && __instance.playerData.CurrentCrestID != Gameplay.CursedCrest.name && __instance.playerData.CurrentCrestID != Gameplay.CloaklessCrest.name);
43+
List<ToolCrest> crestsList = crestSanity.Value ? availableCrests : allCrests;
44+
int count = crestSanity.Value ? crestCount : allCrests.Count;
45+
if (!crestSanity.Value)
46+
crestsList.Add(Gameplay.CursedCrest);
47+
if (canSwap || !crestSanity.Value)
3648
{
3749
__instance.ResetAllCrestState();
38-
int crestIdx = rnd.Next(0, crestCount);
39-
ToolCrest newCrest = availableCrests[crestIdx];
50+
int crestIdx = rnd.Next(0, count);
51+
ToolCrest newCrest = crestsList[crestIdx];
4052
while (__instance.playerData.CurrentCrestID == newCrest.name)
4153
{
42-
crestIdx = rnd.Next(0, crestCount);
43-
newCrest = availableCrests[crestIdx];
54+
crestIdx = rnd.Next(0, count);
55+
newCrest = crestsList[crestIdx];
4456
}
4557
__instance.playerData.CurrentCrestID = newCrest.name;
4658
ToolItemManager.SendEquippedChangedEvent(force: true);
4759
}
60+
// sometimes ResetAllCrestState seems to remove silk from the player
61+
__instance.playerData.silk = currentSilk;
62+
4863
}
4964

5065
}

0 commit comments

Comments
 (0)