Disable gamemode vote if only one available (#11915)
* disable vote on condition * move to new method * still allow vote if current mode is different from available
This commit is contained in:
@@ -103,21 +103,7 @@ namespace Content.Server.Voting.Managers
|
||||
|
||||
private void CreatePresetVote(IPlayerSession? initiator)
|
||||
{
|
||||
var presets = new Dictionary<string, string>();
|
||||
|
||||
foreach (var preset in _prototypeManager.EnumeratePrototypes<GamePresetPrototype>())
|
||||
{
|
||||
if(!preset.ShowInVote)
|
||||
continue;
|
||||
|
||||
if(_playerManager.PlayerCount < (preset.MinPlayers ?? int.MinValue))
|
||||
continue;
|
||||
|
||||
if(_playerManager.PlayerCount > (preset.MaxPlayers ?? int.MaxValue))
|
||||
continue;
|
||||
|
||||
presets[preset.ID] = preset.ModeTitle;
|
||||
}
|
||||
var presets = GetGamePresets();
|
||||
|
||||
var alone = _playerManager.PlayerCount == 1 && initiator != null;
|
||||
var options = new VoteOptions
|
||||
@@ -211,5 +197,25 @@ namespace Content.Server.Voting.Managers
|
||||
_standardVoteTimeout[type] = _timing.RealTime + timeout;
|
||||
DirtyCanCallVoteAll();
|
||||
}
|
||||
|
||||
private Dictionary<string, string> GetGamePresets()
|
||||
{
|
||||
var presets = new Dictionary<string, string>();
|
||||
|
||||
foreach (var preset in _prototypeManager.EnumeratePrototypes<GamePresetPrototype>())
|
||||
{
|
||||
if(!preset.ShowInVote)
|
||||
continue;
|
||||
|
||||
if(_playerManager.PlayerCount < (preset.MinPlayers ?? int.MinValue))
|
||||
continue;
|
||||
|
||||
if(_playerManager.PlayerCount > (preset.MaxPlayers ?? int.MaxValue))
|
||||
continue;
|
||||
|
||||
presets[preset.ID] = preset.ModeTitle;
|
||||
}
|
||||
return presets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.Administration;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Afk;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Maps;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.CCVar;
|
||||
@@ -326,6 +327,15 @@ namespace Content.Server.Voting.Managers
|
||||
if (voteType == StandardVoteType.Restart && _cfg.GetCVar(CCVars.VoteRestartNotAllowedWhenAdminOnline) && _adminMgr.ActiveAdmins.Count() != 0)
|
||||
return false;
|
||||
|
||||
// If only one Preset available thats not really a vote
|
||||
// Still allow vote if availbable one is different from current one
|
||||
if (voteType == StandardVoteType.Preset)
|
||||
{
|
||||
var presets = GetGamePresets();
|
||||
if (presets.Count() == 1 && presets.Select(x => x.Key).Single() == EntitySystem.Get<GameTicker>().Preset?.ID)
|
||||
return false;
|
||||
}
|
||||
|
||||
return !_voteTimeout.TryGetValue(initiator.UserId, out timeSpan);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user