Makes map vote and roundstart smart about player count. (#5418)

* Makes map vote and roundstart smart about player count.
No more Saltern with 30 players, or Knight Ship with 50.

* a typo

* Address reviews.

* Localized.
This commit is contained in:
Moony
2021-11-20 12:32:07 -06:00
committed by GitHub
parent 6487cd6d79
commit eb6d24abd0
18 changed files with 298 additions and 19 deletions

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameTicking;
using Content.Server.Maps;
using Content.Server.RoundEnd;
using Content.Shared.CCVar;
using Content.Shared.Voting;
@@ -146,11 +148,7 @@ namespace Content.Server.Voting.Managers
private void CreateMapVote(IPlayerSession? initiator)
{
var maps = new Dictionary<string, string>
{
["Maps/saltern.yml"] = "Saltern",
["Maps/packedstation.yml"] = "PackedStation",
};
var maps = _gameMapManager.CurrentlyEligibleMaps().ToDictionary(map => map, map => map.MapName);
var alone = _playerManager.PlayerCount == 1 && initiator != null;
var options = new VoteOptions
@@ -175,21 +173,21 @@ namespace Content.Server.Voting.Managers
vote.OnFinished += (_, args) =>
{
string picked;
GameMapPrototype picked;
if (args.Winner == null)
{
picked = (string) _random.Pick(args.Winners);
picked = (GameMapPrototype) _random.Pick(args.Winners);
_chatManager.DispatchServerAnnouncement(
Loc.GetString("ui-vote-map-tie", ("picked", maps[picked])));
}
else
{
picked = (string) args.Winner;
picked = (GameMapPrototype) args.Winner;
_chatManager.DispatchServerAnnouncement(
Loc.GetString("ui-vote-map-win", ("winner", maps[picked])));
}
_cfg.SetCVar(CCVars.GameMap, picked);
_gameMapManager.TrySelectMap(picked.ID);
};
}

View File

@@ -8,6 +8,7 @@ using Content.Server.Administration;
using Content.Server.Administration.Managers;
using Content.Server.Afk;
using Content.Server.Chat.Managers;
using Content.Server.Maps;
using Content.Shared.Administration;
using Content.Shared.Voting;
using Robust.Server.Player;
@@ -16,6 +17,7 @@ using Robust.Shared.Enums;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -33,6 +35,7 @@ namespace Content.Server.Voting.Managers
[Dependency] private readonly IAdminManager _adminMgr = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IAfkManager _afkManager = default!;
[Dependency] private readonly IGameMapManager _gameMapManager = default!;
private int _nextVoteId = 1;