1
1
using Archipelago . HollowKnight . IC . Modules ;
2
2
using Archipelago . MultiClient . Net . Exceptions ;
3
3
using ItemChanger ;
4
+ using MonoMod . RuntimeDetour ;
4
5
using System ;
5
6
using System . Collections . Generic ;
6
7
using System . Linq ;
8
+ using System . Reflection ;
7
9
using System . Threading . Tasks ;
8
10
9
11
namespace Archipelago . HollowKnight
@@ -16,7 +18,8 @@ public enum GoalsLookup
16
18
Radiance = 3 ,
17
19
Godhome = 4 ,
18
20
GodhomeFlower = 5 ,
19
- MAX = GodhomeFlower
21
+ GrubHunt = 6 ,
22
+ MAX = GrubHunt
20
23
}
21
24
22
25
public abstract class Goal
@@ -30,7 +33,8 @@ public abstract class Goal
30
33
[ GoalsLookup . SealedSiblings ] = new SealedSiblingsGoal ( ) ,
31
34
[ GoalsLookup . Radiance ] = new RadianceGoal ( ) ,
32
35
[ GoalsLookup . Godhome ] = new GodhomeGoal ( ) ,
33
- [ GoalsLookup . GodhomeFlower ] = new GodhomeFlowerGoal ( )
36
+ [ GoalsLookup . GodhomeFlower ] = new GodhomeFlowerGoal ( ) ,
37
+ [ GoalsLookup . GrubHunt ] = new GrubHuntGoal ( ) ,
34
38
} ;
35
39
36
40
static Goal ( )
@@ -206,4 +210,45 @@ public class GodhomeFlowerGoal : EndingGoal
206
210
public override string Description => "Defeat Absolute Radiance in Pantheon 5<br>after delivering the flower to the Godseeker." ;
207
211
public override string MinimumGoalScene => SceneNames . Cinematic_Ending_E ;
208
212
}
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
+ }
209
254
}
0 commit comments