Skip to content

Commit 396610a

Browse files
committed
Client support for grub hunt goal
1 parent f64009e commit 396610a

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

Archipelago.HollowKnight/Archipelago.HollowKnight.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Description>The Archipelago Multiworld client for Hollow Knight</Description>
99
<Copyright>
1010
</Copyright>
11-
<Version>0.4.1</Version>
11+
<Version>0.4.2</Version>
1212
<OutputPath>bin\$(Configuration)\</OutputPath>
1313
<LangVersion>latest</LangVersion>
1414
<Company>The Archipelago Community</Company>

Archipelago.HollowKnight/Archipelago.cs

+12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public override string GetVersion()
5151
public static Archipelago Instance;
5252
public ArchipelagoSession session { get; private set; }
5353
public SlotOptions SlotOptions { get; set; }
54+
public int GrubHuntRequiredGrubs { get; set; }
5455
public bool ArchipelagoEnabled { get; set; }
5556

5657
public int Slot { get; private set; }
@@ -111,6 +112,17 @@ public void StartOrResumeGame(bool randomize)
111112
LogDebug("StartOrResumeGame: This is an Archipelago Game.");
112113

113114
LoginSuccessful loginResult = ConnectToArchipelago();
115+
if (loginResult.SlotData.TryGetValue("grub_count", out object objGrubsRequired))
116+
{
117+
GrubHuntRequiredGrubs = (int)((long) objGrubsRequired);
118+
}
119+
else
120+
{
121+
// if not present, it's an older world version so make the goal functionally impossible
122+
// (e.g. for Any goal)
123+
GrubHuntRequiredGrubs = int.MaxValue;
124+
}
125+
114126
if (randomize)
115127
{
116128
LogDebug("StartOrResumeGame: Beginning first time randomization.");

Archipelago.HollowKnight/Goals.cs

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Archipelago.HollowKnight.IC.Modules;
22
using Archipelago.MultiClient.Net.Exceptions;
33
using ItemChanger;
4+
using MonoMod.RuntimeDetour;
45
using System;
56
using System.Collections.Generic;
67
using System.Linq;
8+
using System.Reflection;
79
using System.Threading.Tasks;
810

911
namespace Archipelago.HollowKnight
@@ -16,7 +18,8 @@ public enum GoalsLookup
1618
Radiance = 3,
1719
Godhome = 4,
1820
GodhomeFlower = 5,
19-
MAX = GodhomeFlower
21+
GrubHunt = 6,
22+
MAX = GrubHunt
2023
}
2124

2225
public abstract class Goal
@@ -30,7 +33,8 @@ public abstract class Goal
3033
[GoalsLookup.SealedSiblings] = new SealedSiblingsGoal(),
3134
[GoalsLookup.Radiance] = new RadianceGoal(),
3235
[GoalsLookup.Godhome] = new GodhomeGoal(),
33-
[GoalsLookup.GodhomeFlower] = new GodhomeFlowerGoal()
36+
[GoalsLookup.GodhomeFlower] = new GodhomeFlowerGoal(),
37+
[GoalsLookup.GrubHunt] = new GrubHuntGoal(),
3438
};
3539

3640
static Goal()
@@ -206,4 +210,45 @@ public class GodhomeFlowerGoal : EndingGoal
206210
public override string Description => "Defeat Absolute Radiance in Pantheon 5<br>after delivering the flower to the Godseeker.";
207211
public override string MinimumGoalScene => SceneNames.Cinematic_Ending_E;
208212
}
213+
214+
public class GrubHuntGoal : Goal
215+
{
216+
public override string Name => "Grub Hunt";
217+
218+
public override string Description => $"Save {Archipelago.Instance.GrubHuntRequiredGrubs} of your Grubs.";
219+
220+
private static readonly MethodInfo setIntInternal = typeof(PlayerData).GetMethod("SetIntInternal");
221+
private Hook onSetIntInternal;
222+
223+
public override void OnSelected()
224+
{
225+
if (onSetIntInternal == null)
226+
{
227+
onSetIntInternal = new Hook(setIntInternal, OnSetPlayerInt);
228+
}
229+
else
230+
{
231+
onSetIntInternal.Apply();
232+
}
233+
}
234+
235+
public override void OnDeselected()
236+
{
237+
onSetIntInternal.Undo();
238+
}
239+
240+
protected override bool VictoryCondition()
241+
{
242+
return PlayerData.instance.grubsCollected >= Archipelago.Instance.GrubHuntRequiredGrubs;
243+
}
244+
245+
private async void OnSetPlayerInt(On.PlayerData.orig_SetInt orig, PlayerData self, string intName, int value)
246+
{
247+
orig(self, intName, value);
248+
if (intName == nameof(PlayerData.grubsCollected))
249+
{
250+
await CheckForVictoryAsync();
251+
}
252+
}
253+
}
209254
}

0 commit comments

Comments
 (0)