-
Notifications
You must be signed in to change notification settings - Fork 1
/
Extensions.cs
64 lines (58 loc) · 2.09 KB
/
Extensions.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
using Celeste;
using MadelineParty.Minigame;
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MadelineParty {
static class Extensions {
public static void Teleport(this Level self, string levelName, Vector2? spawnPoint = null) {
self.Teleport(levelName, () => spawnPoint);
}
public static void Teleport(this Level self, string levelName, Func<Vector2?> spawnPointFunc) {
Glitch.Value = 0f;
Engine.TimeRate = 1f;
Distort.Anxiety = 0f;
Distort.GameRate = 1f;
Audio.SetMusicParam("fade", 1f);
self.ParticlesBG.Clear();
self.Particles.Clear();
self.ParticlesFG.Clear();
TrailManager.Clear();
if(self.Tracker.GetEntity<Player>() is Player player) {
self.Remove(player);
}
self.UnloadLevel();
GC.Collect();
GC.WaitForPendingFinalizers();
self.Session.Level = levelName;
Vector2 spawnPoint = spawnPointFunc.Invoke() ?? self.GetSpawnPoint(new Vector2(self.Bounds.Left, self.Bounds.Top));
self.Session.RespawnPoint = spawnPoint;
self.LoadLevel(Player.IntroTypes.None);
self.strawberriesDisplay.DrawLerp = 0f;
WindController windController = self.Entities.FindFirst<WindController>();
if (windController != null) {
windController.SnapWind();
} else {
self.Wind = Vector2.Zero;
}
}
public static Vector2 GetMinigameSpawnPoint(this Level level, MinigamePersistentData data, int playerID) {
// Get spawnpoints for the player's role
var roles = data.GetRoles(playerID);
List<Vector2> possibleSpawns = [];
foreach (MinigameSpawnpoint spawn in level.Tracker.GetEntities<MinigameSpawnpoint>()) {
if (spawn.Roles.Intersect(roles).Any()) {
possibleSpawns.Add(spawn.Position);
}
}
// Default back to using normal spawnpoints
if (!possibleSpawns.Any()) {
possibleSpawns = level.Session.LevelData.Spawns;
}
// Try to space out players. This is kind of janky for spawn points with roles
return possibleSpawns[playerID % possibleSpawns.Count];
}
}
}