Skip to content

Commit

Permalink
Randomizer interop fixes
Browse files Browse the repository at this point in the history
- Fix artifacts spawning in vanilla locations even when custom locations was turned off in a randomizer
- Add new option for randomizers to set the artifact group number
  • Loading branch information
Hoo-Knows committed Feb 11, 2024
1 parent 3f9c7da commit 9a9f70c
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 72 deletions.
10 changes: 9 additions & 1 deletion LostArtifacts/LostArtifacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,15 @@ private void UIManagerStartNewGame(On.UIManager.orig_StartNewGame orig, UIManage
return;
}

if(!RandoSettings.Enabled) return;
if(ModHooks.GetMod("Randomizer 4") is Mod)
{
// If the save is a rando save and artifacts are randomized, let ArtifactRando handle placing the artifacts instead
// If we are not randomizing the artifacts but still enabling them, place them with PlaceArtifacts
if(ArtifactRando.isRandoSave)
{
if(!RandoSettings.EnableArtifacts || RandoSettings.RandomizeArtifacts) return;
}
}
PlaceArtifacts();
}

Expand Down
13 changes: 8 additions & 5 deletions LostArtifacts/LostArtifacts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<Product>LostArtifacts</Product>
<Description>A Hollow Knight Mod</Description>
<Copyright>Copyright © 2022</Copyright>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<FileVersion>1.1.1.0</FileVersion>
<OutputPath>bin\$(Configuration)\</OutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down Expand Up @@ -68,7 +68,7 @@
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\ItemChanger\ItemChanger.dll</HintPath>
</Reference>
<Reference Include="MenuChanger">
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\Disabled\MenuChanger\MenuChanger.dll</HintPath>
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\MenuChanger\MenuChanger.dll</HintPath>
</Reference>
<Reference Include="MMHOOK_Assembly-CSharp">
<HintPath>$(HollowKnightRefs)/MMHOOK_Assembly-CSharp.dll</HintPath>
Expand Down Expand Up @@ -98,10 +98,13 @@
<HintPath>$(HollowKnightRefs)/PlayMaker.dll</HintPath>
</Reference>
<Reference Include="RandomizerCore">
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\Disabled\RandomizerCore\RandomizerCore.dll</HintPath>
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\RandomizerCore\RandomizerCore.dll</HintPath>
</Reference>
<Reference Include="RandomizerCore.Json">
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\RandomizerCore.Json\RandomizerCore.Json.dll</HintPath>
</Reference>
<Reference Include="RandomizerMod">
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\Disabled\Randomizer 4\RandomizerMod.dll</HintPath>
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Hollow Knight\hollow_knight_Data\Managed\Mods\Randomizer 4\RandomizerMod.dll</HintPath>
</Reference>
<Reference Include="Satchel">
<HintPath>$(HollowKnightRefs)\Mods\Satchel\Satchel.dll</HintPath>
Expand Down
62 changes: 28 additions & 34 deletions LostArtifacts/RandoInterop/ArtifactRando.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using RandomizerCore.Logic;
using RandomizerCore.LogicItems;
using RandomizerCore.Json;
using RandomizerMod.Menu;
using RandomizerMod.RC;
using RandomizerMod.Settings;
using RandomizerMod.Logging;
using System.IO;
using System;
using Newtonsoft.Json;

namespace LostArtifacts.Rando
{
public static class ArtifactRando
{
public static bool isRandoSave => RandomizerMod.RandomizerMod.IsRandoSave;

public static void HookRando()
{
RCData.RuntimeLogicOverride.Subscribe(-498f, DefineLogicItem);
Expand All @@ -21,30 +23,23 @@ public static void HookRando()
SettingsLog.AfterLogSettings += AddSettingsToLog;
}

public static bool IsRandoActive()
{
RandomizerSettings rs = RandomizerMod.RandomizerMod.RS;
if(rs == null) return false;
if(rs.GenerationSettings == null) return false;
return true;
}

private static void DefineLogicItem(GenerationSettings gs, LogicManagerBuilder lmb)
{
if(!LostArtifacts.RandoSettings.Enabled || !LostArtifacts.RandoSettings.RandomizeArtifacts) return;
if(!LostArtifacts.RandoSettings.EnableArtifacts) return;

foreach(Artifact artifact in LostArtifacts.Instance.artifacts)
{
lmb.AddItem(new EmptyItem(artifact.InternalName()));
}

using Stream stream = typeof(LostArtifacts).Assembly.GetManifestResourceStream("LostArtifacts.Resources.logic.json");
lmb.DeserializeJson(LogicManagerBuilder.JsonType.Locations, stream);
JsonLogicFormat fmt = new();
lmb.DeserializeFile(LogicFileType.Locations, fmt, stream);
}

private static void DefineArtifacts(RequestBuilder rb)
{
if(!LostArtifacts.RandoSettings.Enabled || !LostArtifacts.RandoSettings.RandomizeArtifacts) return;
if(!LostArtifacts.RandoSettings.EnableArtifacts) return;

foreach(Artifact artifact in LostArtifacts.Instance.artifacts)
{
Expand All @@ -60,40 +55,39 @@ private static void DefineArtifacts(RequestBuilder rb)
});
}

ItemGroupBuilder artifactGroup = null;
foreach(ItemGroupBuilder igb in rb.EnumerateItemGroups())
// -1 or 0 means artifacts will be in the main item group, snippet from Flibber
if(LostArtifacts.RandoSettings.ArtifactGroup > 0)
{
if(igb.label == "Artifacts")
ItemGroupBuilder artifactGroup = null;
string label = RBConsts.SplitGroupPrefix + LostArtifacts.RandoSettings.ArtifactGroup;
foreach(ItemGroupBuilder igb in rb.EnumerateItemGroups())
{
artifactGroup = igb;
break;
if(igb.label == label)
{
artifactGroup = igb;
break;
}
}
}
artifactGroup ??= rb.MainItemStage.AddItemGroup("Artifacts");
artifactGroup ??= rb.MainItemStage.AddItemGroup("Artifacts");

rb.OnGetGroupFor.Subscribe(0.01f, ResolveGroup);
bool ResolveGroup(RequestBuilder rb, string item, RequestBuilder.ElementType type, out GroupBuilder gb)
{
if(type == RequestBuilder.ElementType.Transition)
rb.OnGetGroupFor.Subscribe(0.01f, ResolveGroup);
bool ResolveGroup(RequestBuilder rb, string item, RequestBuilder.ElementType type, out GroupBuilder gb)
{
gb = default;
return false;
}
if(!LostArtifacts.Instance.artifactNames.Contains(item))
{
gb = default;
return false;
}

if(!LostArtifacts.Instance.artifactNames.Contains(item) || LostArtifacts.RandoSettings.UseMainItemGroup)
{
gb = default;
return false;
gb = artifactGroup;
return true;
}

gb = artifactGroup;
return true;
}
}

private static void AddArtifacts(RequestBuilder rb)
{
if(!LostArtifacts.RandoSettings.Enabled || !LostArtifacts.RandoSettings.RandomizeArtifacts) return;
if(!LostArtifacts.RandoSettings.RandomizeArtifacts) return;

foreach(Artifact artifact in LostArtifacts.Instance.artifacts)
{
Expand Down
77 changes: 52 additions & 25 deletions LostArtifacts/RandoInterop/RandoMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public static class RandoMenu
{
private static MenuPage SettingsPage;
private static SmallButton pageRootButton;
private static ToggleButton enabledButton;
private static ToggleButton randomizedButton;
private static ToggleButton useMainItemGroupButton;
private static ToggleButton placeInWorldButton;
private static ToggleButton enableArtifactsToggle;
private static ToggleButton randomizeArtifactsToggle;
private static ToggleButton useCustomLocations;
private static NumericEntryField<int> artifactGroupField;

public static bool HandleButton(MenuPage landingPage, out SmallButton button)
{
Expand All @@ -27,53 +27,80 @@ public static bool HandleButton(MenuPage landingPage, out SmallButton button)
public static void ConstructMenu(MenuPage landingPage)
{
SettingsPage = new MenuPage(LostArtifacts.Instance.GetName(), landingPage);
MenuElementFactory<RandoSettings> factory =
new MenuElementFactory<RandoSettings>(SettingsPage, LostArtifacts.RandoSettings);
MenuElementFactory<RandoSettings> factory = new MenuElementFactory<RandoSettings>(SettingsPage, LostArtifacts.RandoSettings);
IMenuElement[] elements = factory.Elements;
new VerticalItemPanel(SettingsPage, new Vector2(0f, 300f), 75f, true, elements);

enabledButton = (ToggleButton)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.Enabled)];
randomizedButton = (ToggleButton)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.RandomizeArtifacts)];
useMainItemGroupButton = (ToggleButton)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.UseMainItemGroup)];
placeInWorldButton = (ToggleButton)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.UseCustomLocations)];
enabledButton.SelfChanged += EnabledChanged;
randomizedButton.SelfChanged += RandomizedChanged;
useMainItemGroupButton.SelfChanged += UseMainItemGroupChanged;
placeInWorldButton.SelfChanged += PlaceInWorldButtonChanged;
enableArtifactsToggle = (ToggleButton)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.EnableArtifacts)];
randomizeArtifactsToggle = (ToggleButton)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.RandomizeArtifacts)];
artifactGroupField = (NumericEntryField<int>)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.ArtifactGroup)];
useCustomLocations = (ToggleButton)factory.ElementLookup[nameof(LostArtifacts.RandoSettings.UseCustomLocations)];
enableArtifactsToggle.SelfChanged += EnableArtifactsChanged;
randomizeArtifactsToggle.SelfChanged += RandomizeArtifactsChanged;
artifactGroupField.SelfChanged += ArtifactGroupChanged;
useCustomLocations.SelfChanged += UseCustomLocationsChanged;

if(!LostArtifacts.RandoSettings.RandomizeArtifacts)
{
artifactGroupField.Hide();
useCustomLocations.Hide();
}
else
{
artifactGroupField.Show();
useCustomLocations.Show();
}
}

private static void EnabledChanged(IValueElement obj)
private static void EnableArtifactsChanged(IValueElement obj)
{
if(!(bool)obj.Value) randomizedButton.SetValue(false);
if(!(bool)obj.Value)
{
randomizeArtifactsToggle.SetValue(false);
}
ChangeTopLevelColor();
}

private static void RandomizedChanged(IValueElement obj)
private static void RandomizeArtifactsChanged(IValueElement obj)
{
if(!(bool)obj.Value)
{
useMainItemGroupButton.SetValue(false);
placeInWorldButton.SetValue(false);
artifactGroupField.Hide();
useCustomLocations.Hide();
}
else
{
enableArtifactsToggle.SetValue(true);
artifactGroupField.Show();
useCustomLocations.Show();
}
else enabledButton.SetValue(true);
ChangeTopLevelColor();
}

private static void UseMainItemGroupChanged(IValueElement obj)
private static void ArtifactGroupChanged(IValueElement obj)
{
if((bool)obj.Value) randomizedButton.SetValue(true);
// Randomizing artifacts within their own group requires adding custom locations
if((int)obj.Value > 0)
{
useCustomLocations.SetValue(true);
}
}

private static void PlaceInWorldButtonChanged(IValueElement obj)
private static void UseCustomLocationsChanged(IValueElement obj)
{
if((bool)obj.Value) randomizedButton.SetValue(true);
// Can't remove custom locations while still randomizing artifacts within their own group
if(!(bool)obj.Value)
{
artifactGroupField.SetValue(-1);
}
}

private static void ChangeTopLevelColor()
{
if(pageRootButton != null)
{
pageRootButton.Text.color = Colors.FALSE_COLOR;
if(LostArtifacts.RandoSettings.Enabled) pageRootButton.Text.color = Colors.DEFAULT_COLOR;
if(LostArtifacts.RandoSettings.EnableArtifacts) pageRootButton.Text.color = Colors.DEFAULT_COLOR;
if(LostArtifacts.RandoSettings.RandomizeArtifacts) pageRootButton.Text.color = Colors.TRUE_COLOR;
}
}
Expand Down
8 changes: 5 additions & 3 deletions LostArtifacts/RandoInterop/RandoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
{
public class RandoSettings
{
public bool Enabled { get; set; } = true;
public bool EnableArtifacts { get; set; } = true;
public bool RandomizeArtifacts { get; set; } = true;
public bool UseMainItemGroup { get; set; } = false;
public bool UseCustomLocations { get; set; } = false;
public bool UseCustomLocations { get; set; } = true;

[MenuChanger.Attributes.MenuRange(-1, 99)]
public int ArtifactGroup { get; set; } = -1;
}
}
10 changes: 7 additions & 3 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ A mod that adds **lost artifacts** scattered all across Hallownest. Obtaining an

## Integrations

If Randomizer 4 is installed alongside this mod, artifact locations can be randomized through Randomizer's Connections tab. If DebugMod is installed alongside this mod, artifacts or slots can be unlocked through the keybinds menu.
If Randomizer 4 is installed, artifact locations may be randomized through Randomizer's Connections tab. If DebugMod is installed alongside this mod, artifacts or slots can be unlocked through the keybinds menu.

### Randomizer Settings
- Randomize artifacts - whether or not to randomize artifacts
- Use main item group - whether or not to randomize the artifacts with other items
- Enable artifacts - Places artifacts in the rando save (but does not randomize them)
- Randomize artifacts - Randomizes the artifacts (requires enabling artifacts)
- Use custom locations - Adds the locations listed in SPOILERS.md as custom locations
- Artifact group - Determines which group the artifacts will be randomized into
- If -1 or 0, artifacts will be randomized with the main item group
- If above 1, requires using custom locations

### Debug Options
- Unlock all artifacts - unlocks all artifacts
Expand Down
2 changes: 1 addition & 1 deletion SPOILERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
- Hidden Memento (Path of Pain)
- Pogomaster - Pogoing makes the next attack deal increased damage

### Descriptions
### Locations
- Traveler’s Garment (Dirtmouth) - Next to the well
- Paving Stone (Forgotten Crossroads) - Next to the Stag
- Lush Moss (Greenpath) - Defeat the Massive Moss Charger
Expand Down

0 comments on commit 9a9f70c

Please sign in to comment.