-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameEndController.cs
69 lines (59 loc) · 2.66 KB
/
GameEndController.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
using System;
using System.Collections;
using System.Linq;
using BrokemiaHelper;
using Celeste;
using MadelineParty.Multiplayer;
using Microsoft.Xna.Framework;
using Monocle;
namespace MadelineParty {
[Tracked(false)]
public class GameEndController : Entity {
private Level level;
public int winnerID;
public override void Added(Scene scene) {
base.Added(scene);
level = SceneAs<Level>();
Add(new Coroutine(GameEndRoutine()));
AddTag(Tags.PauseUpdate);
AddTag(Tags.FrozenUpdate);
if (GameData.Instance.RealPlayer.Strawberries > MadelinePartyModule.SaveData.BerryRecord) {
MadelinePartyModule.SaveData.BerryRecord = GameData.Instance.RealPlayer.Strawberries;
}
if (GameData.Instance.RealPlayer.Hearts > MadelinePartyModule.SaveData.HeartRecord) {
MadelinePartyModule.SaveData.HeartRecord = GameData.Instance.RealPlayer.Hearts;
}
}
private string GetWinnerText(int player) {
// First, set the name to use as a dialog entry
Dialog.Language.Dialog["MadelineParty_Winner_ID_Name"] = GameData.Instance.GetPlayerName(player);
return GameData.Instance.Random.Choose(Dialog.Clean("MadelineParty_Game_Winner_List").Split(','));
}
private IEnumerator GameEndRoutine() {
if(winnerID == GameData.Instance.realPlayerID) {
MadelinePartyModule.SaveData.GamesWon++;
}
MadelinePartyModule.SaveData.GamesFinished++;
if (level.Wipe != null) {
Action onComplete = level.Wipe.OnComplete;
level.Wipe.OnComplete = delegate {
level.Add(new PersistentMiniTextbox(GetWinnerText(winnerID), FancyText.Anchors.Middle, pauseUpdate: true));
onComplete?.Invoke();
};
} else {
level.Add(new PersistentMiniTextbox(GetWinnerText(winnerID), FancyText.Anchors.Middle, pauseUpdate: true));
}
yield return 10f;
level.OnEndOfFrame += delegate {
Player player = level.Tracker.GetEntity<Player>();
Leader.StoreStrawberries(player.Leader);
level.Remove(player);
level.UnloadLevel();
level.Session.Level = MadelinePartyModule.START_ROOM;
level.Session.RespawnPoint = level.GetSpawnPoint(new Vector2(level.Bounds.Left, level.Bounds.Top));
level.LoadLevel(Player.IntroTypes.None);
Leader.RestoreStrawberries(player.Leader);
};
}
}
}