Skip to content

Commit 40353a6

Browse files
committed
Make seeker explosions trigger flag touch switches
1 parent e2aa598 commit 40353a6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Entities/FlagTouchSwitch.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using Microsoft.Xna.Framework;
33
using Monocle;
44
using System;
5+
using System.Collections;
56
using System.Collections.Generic;
67
using System.Linq;
8+
using System.Reflection;
79
using System.Text;
810
using System.Threading.Tasks;
911

@@ -20,6 +22,32 @@ namespace Celeste.Mod.SpringCollab2020.Entities {
2022
[CustomEntity("SpringCollab2020/FlagTouchSwitch")]
2123
[Tracked]
2224
class FlagTouchSwitch : Entity {
25+
private static FieldInfo seekerPushRadius = typeof(Seeker).GetField("pushRadius", BindingFlags.NonPublic | BindingFlags.Instance);
26+
private static FieldInfo seekerPhysicsHitbox = typeof(Seeker).GetField("physicsHitbox", BindingFlags.NonPublic | BindingFlags.Instance);
27+
28+
public static void Load() {
29+
On.Celeste.Seeker.RegenerateCoroutine += onSeekerRegenerateCoroutine;
30+
}
31+
32+
public static void Unload() {
33+
On.Celeste.Seeker.RegenerateCoroutine -= onSeekerRegenerateCoroutine;
34+
}
35+
36+
private static IEnumerator onSeekerRegenerateCoroutine(On.Celeste.Seeker.orig_RegenerateCoroutine orig, Seeker self) {
37+
IEnumerator origEnum = orig(self);
38+
while (origEnum.MoveNext()) {
39+
yield return origEnum.Current;
40+
}
41+
42+
// make the seeker check for flag touch switches as well.
43+
self.Collider = (Collider) seekerPushRadius.GetValue(self);
44+
foreach (FlagTouchSwitch touchSwitch in self.Scene.Tracker.GetEntities<FlagTouchSwitch>()) {
45+
if (self.CollideCheck(touchSwitch)) {
46+
touchSwitch.turnOn();
47+
}
48+
}
49+
self.Collider = (Collider) seekerPhysicsHitbox.GetValue(self);
50+
}
2351

2452
private ParticleType P_RecoloredFire;
2553

SpringCollab2020Module.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public override void Load() {
2121
BubbleReturnBerry.Load();
2222
SidewaysJumpThru.Load();
2323
CrystalBombDetonatorRenderer.Load();
24+
FlagTouchSwitch.Load();
2425
}
2526

2627
public override void LoadContent(bool firstLoad) {
@@ -40,6 +41,7 @@ public override void Unload() {
4041
BubbleReturnBerry.Unload();
4142
SidewaysJumpThru.Unload();
4243
CrystalBombDetonatorRenderer.Unload();
44+
FlagTouchSwitch.Unload();
4345
}
4446

4547
public override void PrepareMapDataProcessors(MapDataFixup context) {

0 commit comments

Comments
 (0)