mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 21:48:58 +03:00
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using Robust.Shared.Configuration;
|
|
using Content.Server.Voting.Managers;
|
|
using Content.Shared.GameTicking;
|
|
using Content.Shared.Voting;
|
|
using Content.Shared.CCVar;
|
|
using Robust.Server.Player;
|
|
using Content.Server.GameTicking;
|
|
|
|
namespace Content.Server.AutoVote;
|
|
|
|
public sealed class AutoVoteSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IVoteManager _voteManager = default!;
|
|
|
|
private bool _shouldVoteNextJoin;
|
|
|
|
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 (_playerManager.PlayerCount == 0)
|
|
{
|
|
_shouldVoteNextJoin = true;
|
|
return;
|
|
}
|
|
|
|
if (_cfgManager.GetCVar(CCVars.MapAutoVoteEnabled))
|
|
_voteManager.CreateStandardVote(null, StandardVoteType.Map);
|
|
if (_cfgManager.GetCVar(CCVars.PresetAutoVoteEnabled))
|
|
_voteManager.CreateStandardVote(null, StandardVoteType.Preset);
|
|
}
|
|
}
|