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 all commits
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 @@ -3,7 +3,7 @@
namespace Content.Shared._CorvaxNext.NextVars;

/// <summary>
/// Corvax modules console variables
/// Corvax modules console variables
/// </summary>
[CVarDefs]
// ReSharper disable once InconsistentNaming
Expand All @@ -15,8 +15,35 @@ public sealed class NextVars
public static readonly CVarDef<bool> OfferModeIndicatorsPointShow =
CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);

/*
* AUTOVOTE SYSTEM
*/
#region Autovote

/// <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);
Comment on lines +23 to +41
Copy link
Collaborator

Choose a reason for hiding this comment

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

Отступа слишком много, кажется.


#endregion

/// <summary>
/// CorvaxNext Surgery cvars
/// _CorvaxNext Surgery cvars
Copy link
Collaborator

Choose a reason for hiding this comment

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

Лучше оставь.

/// </summary>
#region Surgery

Expand All @@ -38,7 +65,4 @@ public sealed class NextVars
/// </summary>
public static readonly CVarDef<bool> CrawlUnderTables =
CVarDef.Create("laying.crawlundertables", false, CVar.REPLICATED);

// public static readonly CVarDef<bool> OfferModeIndicatorsPointShow =
// CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
}
Loading