-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameData.cs
264 lines (243 loc) · 11.6 KB
/
GameData.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
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using BrokemiaHelper;
using Celeste;
using MadelineParty.Board;
using MadelineParty.Minigame;
using MadelineParty.Multiplayer;
using Microsoft.Xna.Framework;
using Monocle;
using MonoMod.Utils;
using static MadelineParty.Board.BoardController;
namespace MadelineParty
{
public class GameData
{
public static GameData Instance { get; private set; } = new GameData();
private GameData()
{
}
public static readonly IReadOnlyDictionary<string, Item> items = new Dictionary<string, Item>() {
{
"Double Dice",
new((player) => {
// Double dice are special
if(player != Instance.realPlayerID) {
return;
}
BoardController.Instance.RollDice(player, 2);
}) {
Name = "Double Dice",
Price = 3
}
},
{
"Triple Dice",
new((player) => {
// Triple dice are special
if(player != Instance.realPlayerID) {
return;
}
BoardController.Instance.RollDice(player, 3);
}) {
Name = "Triple Dice",
Price = 6
}
},
{
"eciD esreveR",
new((player) => {
BoardController.Instance.Add(new Coroutine(BoardController.Instance.DieRollAnimation(player, new[] { 0, -5, 0 }, ReverseDieRolled)));
}) {
Name = "eciD esreveR",
Price = 5
}
},
{
"Flip Flop",
new((player) => {
BoardController.Instance.SetLeftButtonStatus(player, LeftButton.Modes.Inactive);
BoardController.Instance.SetRightButtonStatus(player, RightButton.Modes.Inactive);
Level level = Engine.Scene as Level;
var swappable = Instance.players.Where(p => p != null && p.token.id != player).ToList();
if(swappable.Count == 0) {
swappable = new List<PlayerData>() { Instance.players[player] };
}
var swapping = swappable[Instance.Random.Next(swappable.Count())];
swappable.Remove(swapping);
Dialog.Language.Dialog["MadelineParty_Swappable_Players"] = swapping == Instance.players[player] ? Dialog.Get("MadelineParty_Yourself") : Instance.GetPlayerName(swapping.token.id);
if(swappable.Count > 0) {
Dialog.Language.Dialog["MadelineParty_Swappable_Players"] += "|" + string.Join("|", swappable.ConvertAll(p => Instance.GetPlayerName(p.token.id)));
}
var textbox = new PersistentMiniTextbox("MadelineParty_Item_FlipFlop_Who", pauseUpdate: true);
level.Add(textbox);
textbox.OnFinish += () => BoardController.Instance.Add(new Coroutine(FlipFlopCoroutine(textbox, Instance.players[player], swapping, swappable.Count == 0), true));
}) {
Name = "Flip Flop",
Price = 4
}
},
{
"Minigame Skip",
new((player) => {
Level level = Engine.Scene as Level;
if(level.Tracker.GetEntity<MinigameSelectUI>() is { } ui) {
ui.Reroll(player);
}
}) {
Name = "Minigame Skip",
Price = 7,
CanUseInTurn = false
}
},
{
"Heart Block",
new((player) => {
BoardController.Instance.SetLeftButtonStatus(player, LeftButton.Modes.Inactive);
BoardController.Instance.SetRightButtonStatus(player, RightButton.Modes.Inactive);
Instance.heartBlocks.Add(player);
Engine.Scene.Add(new HeartBlock(
BoardController.Instance.boardSpaces.Find(s => s.ID == Instance.heartSpaceID).screenPosition - new Vector2(48), 48, 48));
Alarm.Set(BoardController.Instance, 2, () => BoardController.Instance.SetDice(player));
}) {
Name = "Heart Block",
Price = 10
}
},
};
private static void ReverseDieRolled(int playerID, int roll) {
var board = BoardController.Instance;
board.SetLeftButtonStatus(playerID, LeftButton.Modes.Inactive);
board.SetRightButtonStatus(playerID, RightButton.Modes.Inactive);
board.Add(new Coroutine(board.RemoveDieRollsAnimation()));
// Get the past roll + 1 spaces
board.playerMovePath = Instance.players[playerID].pastBoardSpaceIDs.Take(-roll + 1).Reverse().Select(id => board.boardSpaces.Find(s => s.ID == id)).ToList();
board.movingPlayerID = playerID;
board.playerMoveDistance = board.playerMovePath.Count - 1;
board.playerMoveProgress = 0;
board.status = BoardStatus.PLAYERMOVE;
}
private static IEnumerator FlipFlopCoroutine(PersistentMiniTextbox textbox, PlayerData p1, PlayerData p2, bool oneOption) {
yield return oneOption ? 4f : 7f;
yield return DynamicData.For(textbox).Invoke("Close");
var vanishTween = Tween.Create(Tween.TweenMode.Oneshot, Ease.ElasticIn, 1.5f, true);
vanishTween.OnUpdate += t => p1.token.scaleModifier = p2.token.scaleModifier = new Vector2(1 - t.Eased);
BoardController.Instance.Add(vanishTween);
while(vanishTween.Percent < 1) {
yield return null;
}
// Swap the positions and spaces of the two players
var tempPos = p1.token.Position;
p1.token.Position = p2.token.Position;
p2.token.Position = tempPos;
var tempSpace = p1.token.currentSpace;
p1.token.currentSpace = p2.token.currentSpace;
p2.token.currentSpace = tempSpace;
p1.pastBoardSpaceIDs.Clear();
p2.pastBoardSpaceIDs.Clear();
yield return 1f;
var appearTween = Tween.Create(Tween.TweenMode.Oneshot, Ease.ElasticOut, 1.5f, true);
appearTween.OnUpdate += t => p1.token.scaleModifier = p2.token.scaleModifier = new Vector2(t.Eased);
BoardController.Instance.Add(appearTween);
while (appearTween.Percent < 1) {
yield return null;
}
// Have the player roll as normal
BoardController.Instance.SetDice(p1.token.id);
}
public class Item {
public string Name { get; set; }
public int Price { get; set; }
public bool CanUseInTurn { get; set; } = true;
private Action<int> Action { get; set; }
public Item(Action<int> action) {
Action = action;
}
public void UseItem(int playerID) {
if (!MadelinePartyModule.SaveData.ItemsUsed.ContainsKey(Name)) {
MadelinePartyModule.SaveData.ItemsUsed[Name] = 0;
}
if (playerID == Instance.realPlayerID) {
MadelinePartyModule.SaveData.ItemsUsed[Name]++;
}
Action?.Invoke(playerID);
}
}
public Random Random;
public const int START_BERRIES = 10;
public const int MAX_ITEMS = 3;
public int turn = 1;
public int maxTurns = 10;
public int playerNumber = -1;
public PlayerData[] players = { null, null, null, null };
// The ID of the player at this client
public int realPlayerID = -1;
public bool celesteNetHost = true;
public List<uint> celestenetIDs = new();
// Which playerSelectTrigger each player is in
public ConcurrentDictionary<uint, int> playerSelectTriggers = new();
public List<string> playedMinigames = new();
// Matches player token ID to number of minigames won
public Dictionary<int, uint> minigameWins = new();
// Matches player token ID to minigame status
public Dictionary<int, uint> minigameStatus = new();
// Matches player token ID to minigame results
public List<Tuple<int, uint>> minigameResults = new();
public int heartSpaceID = -1;
public List<int> heartBlocks = new();
public PlayerSelectTrigger currentPlayerSelection;
public int heartCost = 15;
public string minigame;
public string board;
public bool gameStarted;
private static List<string> earlyShop = new() { "Double Dice", "Minigame Skip", "Flip Flop", "eciD esreveR" };
private static List<string> lateShop = new() { "Double Dice", "Triple Dice", "Minigame Skip", "Heart Block" };
public List<string> shopContents
{
get
{
return turn <= maxTurns / 2 ? earlyShop : lateShop;
}
}
public PlayerData RealPlayer => players[realPlayerID];
public static void Reset()
{
Instance = new GameData();
BoardController.hackfixRespawn = false;
}
public string GetPlayerName(int id) {
if (MultiplayerSingleton.Instance.BackendConnected()) {
if(realPlayerID == id) {
return MultiplayerSingleton.Instance.GetPlayer(MultiplayerSingleton.Instance.CurrentPlayerID()).Name;
}
return MultiplayerSingleton.Instance.GetPlayer(Instance.playerSelectTriggers.First(kvp => kvp.Value == id).Key).Name;
} else {
return SaveData.Instance.Name;
}
}
public string GetRandomDialogID(string listID) {
return Random.Choose(Dialog.Clean(listID).Split(','));
}
private bool LevelMatchesSearch(LevelData level, MinigameSearchQuery query) {
if (query == null) return true;
if (level.Entities.Find(data => data.Name == MinigameMetadataController.EntityName) is not { } data) return true;
var meta = MinigameMetadataController.LoadMetadata(data);
if (meta.MinPlayers > query.PlayerCount || meta.MaxPlayers < query.PlayerCount) return false;
// Make sure minigame tags contains at least all the tags in query.Tags
if (!meta.MinigameTags.IsSupersetOf(query.Tags)) return false;
return true;
}
public List<LevelData> GetAllMinigames(Level level, MinigameSearchQuery query) {
return level.Session.MapData.Levels.FindAll((lvl) => lvl.Name.StartsWith("z_Minigame", StringComparison.InvariantCulture) && LevelMatchesSearch(lvl, query));
}
public List<LevelData> GetAllUnplayedMinigames(Level level, MinigameSearchQuery query) {
return GetAllMinigames(level, query).FindAll((lvl) => !playedMinigames.Contains(lvl.Name));
}
public static string GetMinigameMusic(string name) {
return "event:/madelineparty/music/minigame/chase_chiptune";
}
}
}