forked from Michal78900/RespawnTimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventHandler.cs
More file actions
123 lines (100 loc) · 3.86 KB
/
Copy pathEventHandler.cs
File metadata and controls
123 lines (100 loc) · 3.86 KB
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
namespace RespawnTimer
{
using System;
using System.Collections.Generic;
using System.Linq;
using MEC;
using API.Features;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Player;
public class EventHandler
{
private CoroutineHandle _timerCoroutine;
// private CoroutineHandle _hintsCoroutine;
internal void OnGenerated()
{
if (BetterUI.Singleton.Config.ReloadTimerEachRound)
BetterUI.Singleton.OnReloaded();
if (_timerCoroutine.IsRunning)
Timing.KillCoroutines(_timerCoroutine);
// if (_hintsCoroutine.IsRunning)
// Timing.KillCoroutines(_hintsCoroutine);
}
internal void OnRoundStart()
{
try
{
_timerCoroutine = Timing.RunCoroutine(TimerCoroutine());
// _hintsCoroutine = Timing.RunCoroutine(HintsCoroutine());
}
catch (Exception e)
{
Log.Error(e.ToString());
}
Log.Debug("BetterUI coroutine started successfully!");
}
internal void OnDying(DyingEventArgs ev)
{
if (BetterUI.Singleton.Config.TimerDelay < 0)
return;
if (PlayerDeathDictionary.ContainsKey(ev.Player))
{
Timing.KillCoroutines(PlayerDeathDictionary[ev.Player]);
PlayerDeathDictionary.Remove(ev.Player);
}
PlayerDeathDictionary.Add(ev.Player, Timing.CallDelayed(BetterUI.Singleton.Config.TimerDelay, () => PlayerDeathDictionary.Remove(ev.Player)));
}
private IEnumerator<float> TimerCoroutine()
{
yield return Timing.WaitForSeconds(1f);
while (true)
{
yield return Timing.WaitForSeconds(1f);
int specNum = Player.List.Count(x => !x.IsAlive || x.SessionVariables.ContainsKey("IsGhost"));
foreach (Player player in Player.List)
{
try
{
if (player.IsAlive && !player.SessionVariables.ContainsKey("IsGhost"))
continue;
if (player.IsOverwatchEnabled && BetterUI.Singleton.Config.HideTimerForOverwatch)
continue;
if (API.API.TimerHidden.Contains(player.UserId))
continue;
if (PlayerDeathDictionary.ContainsKey(player))
continue;
if (!TimerView.TryGetTimerForPlayer(player, out TimerView timerView))
continue;
string text = timerView.GetText(specNum);
if (RueiHelper.IsActive)
{
RueiHelper.Show(player.ReferenceHub, text, TimeSpan.FromSeconds(1.25f));
}
else
{
player.ShowHint(text, 1.25f);
}
}
catch (Exception e)
{
Log.Error(e.ToString());
}
}
if (RoundSummary.singleton._roundEnded)
break;
}
}
/* private IEnumerator<float> HintsCoroutine()
{
while (true)
{
yield return Timing.WaitForSeconds(1f);
foreach (TimerView timerView in TimerView.CachedTimers.Values)
timerView.IncrementHintInterval();
if (RoundSummary.singleton._roundEnded)
break;
}
} */
private readonly Dictionary<Player, CoroutineHandle> PlayerDeathDictionary = new(25);
}
}