Skip to content

Commit

Permalink
[Port] Autovote System
Browse files Browse the repository at this point in the history
Co-Authored-By: sleepyyapril <[email protected]>
  • Loading branch information
PuroSlavKing and sleepyyapril committed Nov 15, 2024
1 parent 828bc25 commit 888f77c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
54 changes: 54 additions & 0 deletions Content.Server/_CorvaxNext/AutoVote/AutoVoteSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
34 changes: 29 additions & 5 deletions Content.Shared/_CorvaxNext/NextVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,33 @@ namespace Content.Shared._CorvaxNext.NextVars;
// ReSharper disable once InconsistentNaming
public sealed class NextVars
{
/// <summary>
/// Offer item.
/// </summary>
public static readonly CVarDef<bool> OfferModeIndicatorsPointShow =
CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
/// <summary>
/// Offer item.
/// </summary>
public static readonly CVarDef<bool> OfferModeIndicatorsPointShow =
CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);

/*
* AUTOVOTE SYSTEM
*/

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

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

/// <summary>
/// Automatically starts a gamemode vote when returning to the lobby.
/// Requires auto voting to be enabled.
/// <summary>
public static readonly CVarDef<bool> PresetAutoVoteEnabled =
CVarDef.Create("vote.preset_autovote_enabled", true, CVar.SERVERONLY);
}
1 change: 1 addition & 0 deletions Resources/ConfigPresets/Corvax/mrp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ same_type_timeout = 300.0
timerrestart = 30
preset_enabled = false
restart_enabled = false
autovote_enabled = true

0 comments on commit 888f77c

Please sign in to comment.