Skip to content

Commit 6842931

Browse files
committed
Add Cancel Lightning Remove Routine Trigger
1 parent 7941a4d commit 6842931

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module SpringCollab2020CancelLightningRemoveRoutineTrigger
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Trigger "SpringCollab2020/CancelLightningRemoveRoutineTrigger" CancelLightningRemoveRoutineTrigger(x::Integer, y::Integer, width::Integer=Maple.defaultTriggerWidth, height::Integer=Maple.defaultTriggerHeight)
6+
7+
const placements = Ahorn.PlacementDict(
8+
"Cancel Lightning Remove Routine Trigger (Spring Collab 2020)" => Ahorn.EntityPlacement(
9+
CancelLightningRemoveRoutineTrigger,
10+
"rectangle",
11+
),
12+
)
13+
14+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using Monocle;
4+
using System.Linq;
5+
using System.Reflection;
6+
7+
namespace Celeste.Mod.SpringCollab2020.Triggers {
8+
[CustomEntity("SpringCollab2020/CancelLightningRemoveRoutineTrigger")]
9+
class CancelLightningRemoveRoutineTrigger : Trigger {
10+
private static MethodInfo lightningSetBreakValue = typeof(Lightning).GetMethod("SetBreakValue", BindingFlags.Static | BindingFlags.NonPublic);
11+
12+
public CancelLightningRemoveRoutineTrigger(EntityData data, Vector2 offset) : base(data, offset) { }
13+
14+
public override void OnEnter(Player player) {
15+
base.OnEnter(player);
16+
17+
if (Scene.Entities.FirstOrDefault(entity => entity is LightningBreakerBox && entity.TagCheck(Tags.Persistent))
18+
is LightningBreakerBox box) {
19+
20+
// break routine is in progress! delete the box running it, and reset the "break value" to zero.
21+
box.Remove(box.Get<Coroutine>());
22+
box.RemoveSelf();
23+
lightningSetBreakValue.Invoke(null /* static method */, new object[] { Scene as Level, 0f });
24+
}
25+
26+
RemoveSelf();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)