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

[Port] Autovote System #62

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вызов пустого метода.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base должен вызывается всегда, считается хорошим тоном


SubscribeLocalEvent<RoundRestartCleanupEvent>(OnReturnedToLobby);
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(OnPlayerJoinedLobby);
}

public void OnReturnedToLobby(RoundRestartCleanupEvent ev) => CallAutovote();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ванлайнеры делают только на свойствах.


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>
Tornado-Technology marked this conversation as resolved.
Show resolved Hide resolved
/// 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
Loading