forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathAutoVoteSystem.cs
54 lines (43 loc) · 1.58 KB
/
AutoVoteSystem.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
using Robust.Shared.Configuration;
using Content.Server.Voting.Managers;
using Content.Shared.GameTicking;
using Content.Shared.Voting;
using Content.Shared._CorvaxNext.NextVars;
using Robust.Server.Player;
using Content.Server.GameTicking;
namespace Content.Server._CorvaxNext.AutoVote;
public sealed class AutoVoteSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] public readonly IVoteManager _voteManager = default!;
[Dependency] public readonly IPlayerManager _playerManager = default!;
public bool _shouldVoteNextJoin = false;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnReturnedToLobby);
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(OnPlayerJoinedLobby);
}
public void OnReturnedToLobby(RoundRestartCleanupEvent ev) => CallAutovote();
public void OnPlayerJoinedLobby(PlayerJoinedLobbyEvent ev)
{
if (!_shouldVoteNextJoin)
return;
CallAutovote();
_shouldVoteNextJoin = false;
}
private void CallAutovote()
{
if (!_cfg.GetCVar(NextVars.AutoVoteEnabled))
return;
if (_playerManager.PlayerCount == 0)
{
_shouldVoteNextJoin = true;
return;
}
if (_cfg.GetCVar(NextVars.MapAutoVoteEnabled))
_voteManager.CreateStandardVote(null, StandardVoteType.Map);
if (_cfg.GetCVar(NextVars.PresetAutoVoteEnabled))
_voteManager.CreateStandardVote(null, StandardVoteType.Preset);
}
}