Map vote & forcemap command (#5278)

This commit is contained in:
mirrorcult
2021-11-11 23:25:57 -07:00
committed by GitHub
parent 0b182f2d11
commit 03f766577a
7 changed files with 107 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ using Content.Shared.CCVar;
using Content.Shared.Voting;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Random;
@@ -23,6 +24,9 @@ namespace Content.Server.Voting.Managers
case StandardVoteType.Preset:
CreatePresetVote(initiator);
break;
case StandardVoteType.Map:
CreateMapVote(initiator);
break;
default:
throw new ArgumentOutOfRangeException(nameof(voteType), voteType, null);
}
@@ -140,6 +144,55 @@ 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 alone = _playerManager.PlayerCount == 1 && initiator != null;
var options = new VoteOptions
{
Title = Loc.GetString("ui-vote-map-title"),
Duration = alone
? TimeSpan.FromSeconds(10)
: TimeSpan.FromSeconds(180)
};
if (alone)
options.InitiatorTimeout = TimeSpan.FromSeconds(10);
foreach (var (k, v) in maps)
{
options.Options.Add((v, k));
}
WirePresetVoteInitiator(options, initiator);
var vote = CreateVote(options);
vote.OnFinished += (_, args) =>
{
string picked;
if (args.Winner == null)
{
picked = (string) _random.Pick(args.Winners);
_chatManager.DispatchServerAnnouncement(
Loc.GetString("ui-vote-map-tie", ("picked", maps[picked])));
}
else
{
picked = (string) args.Winner;
_chatManager.DispatchServerAnnouncement(
Loc.GetString("ui-vote-map-win", ("winner", maps[picked])));
}
_cfg.SetCVar(CCVars.GameMap, picked);
};
}
private void TimeoutStandardVote(StandardVoteType type)
{
var timeout = TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.VoteSameTypeTimeout));