Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Voting System #1213

Merged
merged 9 commits into from
Nov 14, 2024
57 changes: 57 additions & 0 deletions Content.Server/AutoVote/AutoVoteSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 _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();
}
sleepyyapril marked this conversation as resolved.
Show resolved Hide resolved

public void OnPlayerJoinedLobby(PlayerJoinedLobbyEvent ev)
{
if (_shouldVoteNextJoin)
{
CallAutovote();
_shouldVoteNextJoin = false;
}
sleepyyapril marked this conversation as resolved.
Show resolved Hide resolved
}

private void CallAutovote()
{
if (!_cfg.GetCVar(CCVars.AutoVoteEnabled))
return;

if (_playerManager.PlayerCount == 0)
{
_shouldVoteNextJoin = true;
return;
}

if (_cfg.GetCVar(CCVars.MapAutoVoteEnabled))
_voteManager.CreateStandardVote(null, StandardVoteType.Map);
if (_cfg.GetCVar(CCVars.PresetAutoVoteEnabled))
_voteManager.CreateStandardVote(null, StandardVoteType.Preset);
}
}
18 changes: 18 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2640,5 +2640,23 @@ public static readonly CVarDef<float>
/// </summary>
public static readonly CVarDef<bool> DebugPow3rDisableParallel =
CVarDef.Create("debug.pow3r_disable_parallel", true, CVar.SERVERONLY);

/*
* AUTOVOTE SYSTEM
*/

/// Enables the automatic voting system.
public static readonly CVarDef<bool> AutoVoteEnabled =
CVarDef.Create("vote.autovote_enabled", false, CVar.SERVERONLY);

/// Automatically starts a map vote when returning to the lobby.
/// Requires auto voting to be enabled.
public static readonly CVarDef<bool> MapAutoVoteEnabled =
CVarDef.Create("vote.map_autovote_enabled", true, CVar.SERVERONLY);

/// Automatically starts a gamemode vote when returning to the lobby.
/// Requires auto voting to be enabled.
public static readonly CVarDef<bool> PresetAutoVoteEnabled =
CVarDef.Create("vote.preset_autovote_enabled", true, CVar.SERVERONLY);
}
}
Loading