From 888f77caf60c6c2e56d9c61767c414e4f168a4f3 Mon Sep 17 00:00:00 2001 From: PuroSlavKing Date: Fri, 15 Nov 2024 22:59:35 +0300 Subject: [PATCH 1/2] [Port] Autovote System Co-Authored-By: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> --- .../_CorvaxNext/AutoVote/AutoVoteSystem.cs | 54 +++++++++++++++++++ Content.Shared/_CorvaxNext/NextVars.cs | 34 ++++++++++-- Resources/ConfigPresets/Corvax/mrp.toml | 1 + 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 Content.Server/_CorvaxNext/AutoVote/AutoVoteSystem.cs diff --git a/Content.Server/_CorvaxNext/AutoVote/AutoVoteSystem.cs b/Content.Server/_CorvaxNext/AutoVote/AutoVoteSystem.cs new file mode 100644 index 00000000000..12b5a1712fd --- /dev/null +++ b/Content.Server/_CorvaxNext/AutoVote/AutoVoteSystem.cs @@ -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(OnReturnedToLobby); + SubscribeLocalEvent(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); + } +} diff --git a/Content.Shared/_CorvaxNext/NextVars.cs b/Content.Shared/_CorvaxNext/NextVars.cs index 5d232025ae7..bb60bc4c450 100644 --- a/Content.Shared/_CorvaxNext/NextVars.cs +++ b/Content.Shared/_CorvaxNext/NextVars.cs @@ -9,9 +9,33 @@ namespace Content.Shared._CorvaxNext.NextVars; // ReSharper disable once InconsistentNaming public sealed class NextVars { - /// - /// Offer item. - /// - public static readonly CVarDef OfferModeIndicatorsPointShow = - CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY); + /// + /// Offer item. + /// + public static readonly CVarDef OfferModeIndicatorsPointShow = + CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY); + + /* + * AUTOVOTE SYSTEM + */ + + /// + /// Enables the automatic voting system. + /// + public static readonly CVarDef 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 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 PresetAutoVoteEnabled = + CVarDef.Create("vote.preset_autovote_enabled", true, CVar.SERVERONLY); } diff --git a/Resources/ConfigPresets/Corvax/mrp.toml b/Resources/ConfigPresets/Corvax/mrp.toml index f5ce55298fc..bc233b5ce36 100644 --- a/Resources/ConfigPresets/Corvax/mrp.toml +++ b/Resources/ConfigPresets/Corvax/mrp.toml @@ -26,3 +26,4 @@ same_type_timeout = 300.0 timerrestart = 30 preset_enabled = false restart_enabled = false +autovote_enabled = true From b244ededd5b36db91142fb26b51a14881b10789e Mon Sep 17 00:00:00 2001 From: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:04:14 +1000 Subject: [PATCH 2/2] Developer = Sosat --- Resources/ConfigPresets/Corvax/mrp.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Resources/ConfigPresets/Corvax/mrp.toml b/Resources/ConfigPresets/Corvax/mrp.toml index bc233b5ce36..f5ce55298fc 100644 --- a/Resources/ConfigPresets/Corvax/mrp.toml +++ b/Resources/ConfigPresets/Corvax/mrp.toml @@ -26,4 +26,3 @@ same_type_timeout = 300.0 timerrestart = 30 preset_enabled = false restart_enabled = false -autovote_enabled = true