|
| 1 | +using Celeste.Mod.Entities; |
| 2 | +using Microsoft.Xna.Framework; |
| 3 | +using Monocle; |
| 4 | +using System; |
| 5 | +using System.Reflection; |
| 6 | + |
| 7 | +namespace Celeste.Mod.SpringCollab2020.Entities { |
| 8 | + [CustomEntity("SpringCollab2020/NoDashRefillSpring", "SpringCollab2020/NoDashRefillSpringLeft", "SpringCollab2020/NoDashRefillSpringRight")] |
| 9 | + class NoDashRefillSpring : Spring { |
| 10 | + private static MethodInfo bounceAnimate = typeof(Spring).GetMethod("BounceAnimate", BindingFlags.NonPublic | BindingFlags.Instance); |
| 11 | + private static object[] noParams = new object[0]; |
| 12 | + |
| 13 | + public NoDashRefillSpring(EntityData data, Vector2 offset) |
| 14 | + : base(data.Position + offset, GetOrientationFromName(data.Name), data.Bool("playerCanUse", true)) { |
| 15 | + |
| 16 | + // remove the vanilla player collider. this is the one thing we want to mod here. |
| 17 | + foreach (Component component in this) { |
| 18 | + if (component.GetType() == typeof(PlayerCollider)) { |
| 19 | + Remove(component); |
| 20 | + break; |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + // replace it with our own collider. |
| 25 | + if (data.Bool("playerCanUse", true)) { |
| 26 | + Add(new PlayerCollider(OnCollide)); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + private static Orientations GetOrientationFromName(string name) { |
| 31 | + switch (name) { |
| 32 | + case "SpringCollab2020/NoDashRefillSpring": |
| 33 | + return Orientations.Floor; |
| 34 | + case "SpringCollab2020/NoDashRefillSpringRight": |
| 35 | + return Orientations.WallRight; |
| 36 | + case "SpringCollab2020/NoDashRefillSpringLeft": |
| 37 | + return Orientations.WallLeft; |
| 38 | + default: |
| 39 | + throw new Exception("No Dash Refill Spring name doesn't correlate to a valid Orientation!"); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + private void OnCollide(Player player) { |
| 45 | + if (player.StateMachine.State == 9) { |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + // Save dash count. Dashes are reloaded by SideBounce and SuperBounce. |
| 50 | + int originalDashCount = player.Dashes; |
| 51 | + |
| 52 | + if (Orientation == Orientations.Floor) { |
| 53 | + if (player.Speed.Y >= 0f) { |
| 54 | + bounceAnimate.Invoke(this, noParams); |
| 55 | + player.SuperBounce(Top); |
| 56 | + } |
| 57 | + } else if (Orientation == Orientations.WallLeft) { |
| 58 | + if (player.SideBounce(1, Right, CenterY)) { |
| 59 | + bounceAnimate.Invoke(this, noParams); |
| 60 | + } |
| 61 | + } else if (Orientation == Orientations.WallRight) { |
| 62 | + if (player.SideBounce(-1, Left, CenterY)) { |
| 63 | + bounceAnimate.Invoke(this, noParams); |
| 64 | + } |
| 65 | + } else { |
| 66 | + throw new Exception("Orientation not supported!"); |
| 67 | + } |
| 68 | + |
| 69 | + // Restore original dash count. |
| 70 | + player.Dashes = originalDashCount; |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments