-
Notifications
You must be signed in to change notification settings - Fork 43
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
namespace Content.Shared._CorvaxNext.NextVars; | ||
|
||
/// <summary> | ||
/// Corvax modules console variables | ||
/// Corvax modules console variables | ||
/// </summary> | ||
[CVarDefs] | ||
// ReSharper disable once InconsistentNaming | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отступа слишком много, кажется. |
||
|
||
#endregion | ||
|
||
/// <summary> | ||
/// CorvaxNext Surgery cvars | ||
/// _CorvaxNext Surgery cvars | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лучше оставь. |
||
/// </summary> | ||
#region Surgery | ||
|
||
|
@@ -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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вызов пустого метода.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base должен вызывается всегда, считается хорошим тоном