This repository has been archived by the owner on Aug 9, 2023. It is now read-only.
forked from Marco15453-Archived/UIURescueSquad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventHandlers.cs
217 lines (184 loc) · 8.16 KB
/
EventHandlers.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
namespace UIURescueSquad
{
#pragma warning disable SA1202
using System;
using System.Linq;
using Configs;
using Exiled.API.Extensions;
using Exiled.API.Features;
using Exiled.API.Features.Items;
using Exiled.CustomItems.API.Features;
using Exiled.Events.EventArgs;
using InventorySystem.Items;
using MEC;
using Respawning;
using UnityEngine;
using static API;
using Random = UnityEngine.Random;
/// <summary>
/// EventHandlers and Methods which UIURescueSquad uses.
/// </summary>
public partial class EventHandlers
{
/// <summary>
/// Is UIU spawnable in <see cref="Exiled.Events.Handlers.Server.OnRespawningTeam(RespawningTeamEventArgs)"/>.
/// </summary>
public static bool IsSpawnable;
/// <summary>
/// The maximum number of UIU players in next the respawn.
/// </summary>
public static uint MaxPlayers;
private static int respawns = 0;
/// <summary>
/// Handles UIU spawn chance with all other conditions.
/// </summary>
internal static void CalculateChance()
{
IsSpawnable = Random.Range(1, 101) <= Config.SpawnManager.Probability &&
respawns >= Config.SpawnManager.Respawns;
Log.Debug($"Is UIU spawnable: {IsSpawnable}", Config.Debug);
}
/// <inheritdoc cref="Exiled.Events.Handlers.Server.OnWaitingForPlayers"/>
internal static void OnWaitingForPlayers()
{
respawns = 0;
MaxPlayers = Config.SpawnManager.MaxSquad;
}
/// <inheritdoc cref="Exiled.Events.Handlers.Server.OnRoundStarted"/>
internal static void OnRoundStart()
{
if (!string.IsNullOrEmpty(Config.TeamColors.GuardUnitColor))
{
Map.ChangeUnitColor(0, Config.TeamColors.GuardUnitColor);
}
}
/// <inheritdoc cref="Exiled.Events.Handlers.Server.OnRespawningTeam(RespawningTeamEventArgs)"/>
internal static void OnTeamRespawn(RespawningTeamEventArgs ev)
{
if (ev.NextKnownTeam == SpawnableTeamType.NineTailedFox)
{
respawns++;
if (IsSpawnable)
{
bool prioritySpawn = RespawnManager.Singleton._prioritySpawn;
if (prioritySpawn)
{
ev.Players.OrderBy((x) => x.ReferenceHub.characterClassManager.DeathTime);
}
for (int i = ev.Players.Count; i > MaxPlayers; i--)
{
Player player = prioritySpawn ? ev.Players.Last() : ev.Players[Random.Range(0, ev.Players.Count)];
ev.Players.Remove(player);
}
Timing.CallDelayed(1.0f, () =>
{
foreach (Player player in ev.Players)
{
SpawnPlayer(player);
}
if (Config.SpawnManager.AnnouncementText != null)
{
Map.ClearBroadcasts();
Timing.CallDelayed(0.5f, () => Map.Broadcast(Config.SpawnManager.AnnouncementTime, Config.SpawnManager.AnnouncementText));
}
if (Config.SupplyDrop.DropEnabled)
{
foreach (var item in Config.SupplyDrop.DropItems)
{
Vector3 spawnPos = RoleType.NtfPrivate.GetRandomSpawnProperties().Item1;
if (Enum.TryParse(item.Key, out ItemType parsedItem))
{
Item item1 = Item.Create(parsedItem);
item1.Spawn(spawnPos, Random.rotation);
}
else
{
CustomItem.TrySpawn(item.Key, spawnPos, out Pickup _);
}
}
}
});
if (!string.IsNullOrEmpty(Config.TeamColors.UiuUnitColor))
{
Timing.CallDelayed(Timing.WaitUntilTrue(() => RespawnManager.Singleton.NamingManager.AllUnitNames.Count >= respawns), () =>
{
Map.ChangeUnitColor(respawns, Config.TeamColors.UiuUnitColor);
});
}
Timing.CallDelayed(1f, () => IsSpawnable = false);
}
else if (!string.IsNullOrEmpty(Config.TeamColors.NtfUnitColor))
{
Timing.CallDelayed(Timing.WaitUntilTrue(() => RespawnManager.Singleton.NamingManager.AllUnitNames.Count >= respawns), () =>
{
Map.ChangeUnitColor(respawns, Config.TeamColors.NtfUnitColor);
});
}
}
}
/// <inheritdoc cref="Exiled.Events.Handlers.Map.OnAnnouncingNtfEntrance(AnnouncingNtfEntranceEventArgs) />
internal static void OnAnnouncingNTF(AnnouncingNtfEntranceEventArgs ev)
{
string cassieMessage = string.Empty;
if (!IsSpawnable)
{
if (ev.ScpsLeft == 0 && !string.IsNullOrEmpty(Config.SpawnManager.NtfAnnouncmentCassieNoScp))
{
ev.IsAllowed = false;
cassieMessage = Config.SpawnManager.NtfAnnouncmentCassieNoScp;
}
else if (!string.IsNullOrEmpty(Config.SpawnManager.NtfAnnouncementCassie))
{
ev.IsAllowed = false;
cassieMessage = Config.SpawnManager.NtfAnnouncementCassie;
}
}
else
{
if (ev.ScpsLeft == 0 && !string.IsNullOrEmpty(Config.SpawnManager.UiuAnnouncmentCassieNoScp))
{
ev.IsAllowed = false;
cassieMessage = Config.SpawnManager.UiuAnnouncmentCassieNoScp;
}
else if (ev.ScpsLeft > 1 && !string.IsNullOrEmpty(Config.SpawnManager.UiuAnnouncementCassie))
{
ev.IsAllowed = false;
cassieMessage = Config.SpawnManager.UiuAnnouncementCassie;
}
}
cassieMessage = cassieMessage.Replace("{scpnum}", $"{ev.ScpsLeft} scpsubject");
if (ev.ScpsLeft > 1)
{
cassieMessage = cassieMessage.Replace("scpsubject", "scpsubjects");
}
cassieMessage = cassieMessage.Replace("{designation}", $"nato_{ev.UnitName[0]} {ev.UnitNumber}");
if (!string.IsNullOrEmpty(cassieMessage))
Cassie.GlitchyMessage(cassieMessage, Config.SpawnManager.GlitchChance, Config.SpawnManager.JamChance);
}
/// <inheritdoc cref="Exiled.Events.Handlers.Player.OnDestroying(DestroyingEventArgs)"/>
internal static void OnDestroy(DestroyingEventArgs ev)
{
if (IsUiu(ev.Player))
{
DestroyUIU(ev.Player);
}
}
/// <inheritdoc cref="Exiled.Events.Handlers.Player.OnDied(DiedEventArgs)"/>
internal static void OnDied(DiedEventArgs ev)
{
if (IsUiu(ev.Target))
{
DestroyUIU(ev.Target);
}
}
/// <inheritdoc cref="Exiled.Events.Handlers.Player.OnChangingRole(ChangingRoleEventArgs)"/>
internal static void OnChanging(ChangingRoleEventArgs ev)
{
if (IsUiu(ev.Player) && ev.NewRole.GetTeam() != Team.MTF)
{
DestroyUIU(ev.Player);
}
}
private static readonly Config Config = UIURescueSquad.Instance.Config;
}
}