-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #47 from aonkeeper4/bettertemplegateallswitches
Rework `TempleGateAllSwitches` to use the `DashSwitch`'s `OnDashCollide` instead of default `OnDashed`
Showing
1 changed file
with
28 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,49 @@ | ||
using Celeste; | ||
using Celeste.Mod.Entities; | ||
using MonoMod.Utils; | ||
using Microsoft.Xna.Framework; | ||
using Monocle; | ||
|
||
namespace vitmod | ||
{ | ||
namespace vitmod { | ||
[Tracked()] | ||
[CustomEntity("vitellary/templegateall")] | ||
public class TempleGateAllSwitches : TempleGate | ||
{ | ||
public TempleGateAllSwitches(EntityData data, Vector2 offset) : base(data.Position + offset, 48, Types.NearestSwitch, data.Attr("sprite", "default"), data.Level.Name) | ||
{ | ||
public class TempleGateAllSwitches : TempleGate { | ||
public TempleGateAllSwitches(EntityData data, Vector2 offset) : base(data.Position + offset, 48, Types.NearestSwitch, data.Attr("sprite", "default"), data.Level.Name) { | ||
ClaimedByASwitch = true; | ||
} | ||
|
||
public static void Load() | ||
{ | ||
On.Celeste.DashSwitch.OnDashed += DashSwitch_OnDashed; | ||
public static void Load() { | ||
On.Celeste.DashSwitch.Awake += DashSwitch_Awake; | ||
} | ||
|
||
public static void Unload() | ||
{ | ||
On.Celeste.DashSwitch.OnDashed -= DashSwitch_OnDashed; | ||
public static void Unload() { | ||
On.Celeste.DashSwitch.Awake -= DashSwitch_Awake; | ||
} | ||
|
||
private static DashCollisionResults DashSwitch_OnDashed(On.Celeste.DashSwitch.orig_OnDashed orig, DashSwitch self, Player player, Vector2 direction) | ||
{ | ||
DashCollisionResults result = orig(self, player, direction); | ||
bool finalswitch = true; | ||
if (self.pressed) | ||
{ | ||
foreach (Solid solid in self.SceneAs<Level>().Tracker.GetEntities<Solid>()) | ||
{ | ||
if (solid is DashSwitch dashSwitch) | ||
{ | ||
if (!dashSwitch.pressed) | ||
{ | ||
finalswitch = false; | ||
break; | ||
private static void DashSwitch_Awake(On.Celeste.DashSwitch.orig_Awake orig, DashSwitch self, Scene scene) { | ||
orig(self, scene); | ||
DashCollision orig_OnDashCollide = self.OnDashCollide; | ||
self.OnDashCollide = (Player player, Vector2 direction) => { | ||
DashCollisionResults result = orig_OnDashCollide(player, direction); | ||
bool finalswitch = true; | ||
if (self.pressed) { | ||
foreach (Solid solid in self.SceneAs<Level>().Tracker.GetEntities<Solid>()) { | ||
if (solid is DashSwitch dashSwitch) { | ||
if (!dashSwitch.pressed) { | ||
finalswitch = false; | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
finalswitch = false; | ||
} | ||
} | ||
else | ||
{ | ||
finalswitch = false; | ||
} | ||
if (finalswitch) | ||
{ | ||
foreach (TempleGateAllSwitches gate in self.SceneAs<Level>().Tracker.GetEntities<TempleGateAllSwitches>()) | ||
{ | ||
gate.Open(); | ||
if (finalswitch) { | ||
foreach (TempleGateAllSwitches gate in self.SceneAs<Level>().Tracker.GetEntities<TempleGateAllSwitches>()) { | ||
gate.Open(); | ||
} | ||
} | ||
} | ||
return result; | ||
return result; | ||
}; | ||
} | ||
} | ||
} |