-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathModule.cs
303 lines (239 loc) · 8.14 KB
/
Module.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Monocle;
using System;
namespace Celeste.Mod.IsaGrabBag
{
public class GrabBagModule : EverestModule
{
public static GrabBagMeta GrabBagMeta {
get {
if (gbMeta == null) {
AreaKey key;
Level level = Engine.Scene as Level;
if (level == null)
level = Engine.NextScene as Level;
if (level != null) {
key = level.Session.Area;
}
else {
var loader = Engine.Scene as LevelLoader;
key = loader.Level.Session.Area;
}
gbMeta = GrabBagMeta.Default(key);
};
return gbMeta;
}
}
private static GrabBagMeta gbMeta;
public static int ZipLineState { get; private set; }
public static int ArrowBlockState { get; private set; }
public override Type SessionType => typeof(IsaSession);
public static IsaSession Session => (IsaSession)Instance._Session;
public override Type SettingsType => typeof(IsaSettings);
public static IsaSettings Settings => (IsaSettings)Instance._Settings;
public static GrabBagModule Instance { get; private set; }
public static Player playerInstance { get; private set; }
public static SpriteBank sprites { get; private set; }
public GrabBagModule()
{
Instance = this;
}
public override void Initialize()
{
base.Initialize();
}
public override void Load()
{
ArrowBubble.Load();
DreamSpinnerBorder.OnLoad();
ForceVariants.Load();
RewindCrystal.Load();
Everest.Events.Level.OnTransitionTo += Level_OnTransitionTo;
Everest.Events.Level.OnEnter += Level_OnEnter;
Everest.Events.Level.OnExit += Level_OnExit;
Everest.Events.Level.OnLoadEntity += Level_OnLoadEntity;
Everest.Events.Player.OnSpawn += Player_OnSpawn;
On.Celeste.Player.ctor += PlayerInit;
On.Celeste.Player.UpdateSprite += UpdatePlayerVisuals;
On.Celeste.Player.Update += ZipLine.OnPlayerUpdate;
On.Celeste.BadelineBoost.Awake += BadelineBoostAwake;
On.Celeste.ChangeRespawnTrigger.OnEnter += OnChangeRespawn;
}
public override void Unload() {
ArrowBubble.Unload();
DreamSpinnerBorder.OnUnload();
ForceVariants.Unload();
RewindCrystal.Unload();
Everest.Events.Level.OnEnter -= Level_OnEnter;
Everest.Events.Level.OnExit -= Level_OnExit;
Everest.Events.Level.OnLoadEntity -= Level_OnLoadEntity;
Everest.Events.Player.OnSpawn -= Player_OnSpawn;
On.Celeste.Player.ctor -= PlayerInit;
On.Celeste.Player.UpdateSprite -= UpdatePlayerVisuals;
On.Celeste.Player.Update -= ZipLine.OnPlayerUpdate;
On.Celeste.BadelineBoost.Awake -= BadelineBoostAwake;
On.Celeste.ChangeRespawnTrigger.OnEnter -= OnChangeRespawn;
}
private void BadelineBoostAwake(On.Celeste.BadelineBoost.orig_Awake orig, BadelineBoost self, Scene scene)
{
orig(self, scene);
if ((scene as Level).Session.GetFlag(BadelineFollower.SESSION_FLAG))
self.Visible = false;
}
private void UpdatePlayerVisuals(On.Celeste.Player.orig_UpdateSprite orig, Player self)
{
if (self.StateMachine == ZipLineState)
{
self.Sprite.Scale.X = Calc.Approach(self.Sprite.Scale.X, 1f, 1.75f * Engine.DeltaTime);
self.Sprite.Scale.Y = Calc.Approach(self.Sprite.Scale.Y, 1f, 1.75f * Engine.DeltaTime);
if (ZipLine.GrabbingCoroutine)
return;
self.Sprite.PlayOffset("fallSlow_carry", .5f, false);
self.Sprite.Rate = 0.0f;
}
else
{
orig(self);
}
}
private void OnChangeRespawn(On.Celeste.ChangeRespawnTrigger.orig_OnEnter orig, ChangeRespawnTrigger self, Player player)
{
orig(self, player);
ForceVariants.SaveToSession();
}
private void PlayerInit(On.Celeste.Player.orig_ctor orig, Player self, Vector2 position, PlayerSpriteMode spriteMode)
{
orig(self, position, spriteMode);
ZipLineState = self.StateMachine.AddState(ZipLine.ZipLineUpdate, begin: ZipLine.ZipLineBegin, end: ZipLine.ZipLineEnd, coroutine: ZipLine.ZipLineCoroutine);
}
public override void LoadContent(bool firstLoad)
{
DreamSpinnerBorder.LoadTextures();
RewindCrystal.LoadGraphics();
sprites = new SpriteBank(GFX.Game, "Graphics/IsaGrabBag.xml");
}
private void Player_OnSpawn(Player obj)
{
Level lvl = obj.SceneAs<Level>();
playerInstance = obj;
ForceVariants.GetFromSession();
if (obj.Get<VariantEnforcer>() == null)
{
obj.Add(new VariantEnforcer());
}
if (lvl.Session.GetFlag(BadelineFollower.SESSION_FLAG))
{
foreach (BadelineBoost boost in lvl.Entities.FindAll<BadelineBoost>())
{
boost.Visible = false;
boost.Collidable = false;
}
if (lvl.Entities.FindFirst<BadelineFollower>() == null)
{
if (BadelineFollower.instance == null)
{
BadelineFollower follower = new BadelineFollower(lvl, obj.Position + new Vector2((int)playerInstance.Facing * -12, -20));
lvl.Add(follower);
obj.Leader.GainFollower(follower.follower);
}
else
{
BadelineFollower.instance.Readd(lvl, obj);
}
}
}
if (lvl.Session.GetFlag(BadelineFollower.SESSION_FLAG))
BadelineFollower.instance.dummy.Visible = true;
BadelineFollower.CheckBooster(lvl, false);
}
private void Level_OnExit(Level level, LevelExit exit, LevelExit.Mode mode, Session session, HiresSnow snow)
{
gbMeta = null;
ForceVariants.ResetSession();
if (BadelineFollower.instance != null)
BadelineFollower.instance.RemoveSelf();
BadelineFollower.instance = null;
}
private void Level_OnEnter(Session session, bool fromSaveData) {
try {
GrabBagWrapperMeta parsed;
gbMeta = null;
//string s = session.Area.GetSID();
if (session != null && session.Area != null && session.Area.SID != null) {
var get = Everest.Content.Get(session.Area.SID);
if (get != null && get.TryGetMeta(out parsed)) {
gbMeta = parsed.IsaGrabBag;
}
}
}
catch (Exception e) {
Logger.Log("IsaGrabBag", "Unable to properly get metadata");
Logger.LogDetailed(e);
}
if (gbMeta == null)
gbMeta = GrabBagMeta.Default(session.Area);
if (session.Area.LevelSet.StartsWith("SpringCollab2020")) {
GrabBagMeta.WaterBoost = true;
}
ForceVariants.GetDefaults();
ForceVariants.ReinforceSession();
}
private void Level_OnTransitionTo(Level level, LevelData next, Vector2 direction) {
ForceVariants.SaveToSession();
if (GrabBagMeta == null)
gbMeta = GrabBagMeta.Default(level.Session.Area);
if (level.Session.GetFlag(BadelineFollower.SESSION_FLAG)) {
if (BadelineFollower.instance == null) {
BadelineFollower follower = new BadelineFollower(level, playerInstance.Position);
level.Add(follower);
playerInstance.Leader.GainFollower(follower.follower);
BadelineFollower.CheckBooster(level, false);
}
BadelineFollower.Search();
if (level.Session.GetFlag(BadelineFollower.SESSION_FLAG))
BadelineFollower.instance.dummy.Visible = true;
}
}
private bool Level_OnLoadEntity(Level level, LevelData levelData, Vector2 offset, EntityData entityData)
{
switch (entityData.Name) {
case "isaBag/arrowBlock":
level.Add(new ArrowBlock(entityData, offset));
return true;
case "CoreHeatWindTrigger":
level.Add(new HotColdWind(entityData, offset));
return true;
case "isaBag/dreamSpinner":
level.Add(new DreamSpinner(entityData, offset, false));
return true;
case "isaBag/dreamSpinFake":
level.Add(new DreamSpinner(entityData, offset, true));
return true;
case "ForceVariantTrigger":
level.Add(new ForceVariantTrigger(entityData, offset));
return true;
case "isaBag/zipline":
level.Add(new ZipLine(entityData, offset));
return true;
case "isaBag/waterBoost":
level.Add(new WaterBoostMechanic(entityData));
return true;
case "isaBag/rewindCrystal":
level.Add(new RewindCrystal(entityData, offset));
return true;
case "isaBag/pauseCrystal":
level.Add(new UnpauseCrystal(entityData, offset));
return true;
case "isaBag/arrowBubble":
level.Add(new ArrowBubble(entityData, offset));
return true;
case "isaBag/baddyFollow":
if (!level.Session.GetFlag(BadelineFollower.SESSION_FLAG))
BadelineFollower.SpawnBadelineFriendo(level);
return true;
}
return false;
}
}
}