Добавлено голосование за вызов шаттла (#152)

* Добавлено голосование за вызов шаттла

* Minor locale fix
This commit is contained in:
Pupchansky
2025-06-05 16:35:51 +05:00
committed by GitHub
parent 566ff082e8
commit af01248a06
6 changed files with 117 additions and 6 deletions

View File

@@ -41,7 +41,10 @@ namespace Content.Client.Voting.UI
{ StandardVoteType.Restart, new CreateVoteOption("ui-vote-type-restart", new(), false, null) },
{ StandardVoteType.Preset, new CreateVoteOption("ui-vote-type-gamemode", new(), false, null) },
{ StandardVoteType.Map, new CreateVoteOption("ui-vote-type-map", new(), false, null) },
{ StandardVoteType.Votekick, new CreateVoteOption("ui-vote-type-votekick", new(), true, 0) }
{ StandardVoteType.Votekick, new CreateVoteOption("ui-vote-type-votekick", new(), true, 0) },
// WL-Changes-start
{ StandardVoteType.EvacuationShuttle, new CreateVoteOption("ui-vote-type-evac-shuttle", new(), false, null) }
//WL-Changes-end
};
public Dictionary<string, string> VotekickReasons = new Dictionary<string, string>()

View File

@@ -1,14 +1,13 @@
using System.Linq;
using System.Net;
using System.Net.Sockets;
using Content.Server.Administration;
using Content.Server.Administration.Managers;
using Content.Server.Construction.Conditions;
using Content.Server.Discord.WebhookMessages;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Presets;
using Content.Server.Maps;
using Content.Server.Roles;
using Content.Server.RoundEnd;
using Content.Shared._WL.CCVars;
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Database;
@@ -19,6 +18,9 @@ using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Player;
using Robust.Shared.Random;
using System.Linq;
using System.Net;
using System.Net.Sockets;
namespace Content.Server.Voting.Managers
{
@@ -38,7 +40,10 @@ namespace Content.Server.Voting.Managers
{StandardVoteType.Restart, CCVars.VoteRestartEnabled},
{StandardVoteType.Preset, CCVars.VotePresetEnabled},
{StandardVoteType.Map, CCVars.VoteMapEnabled},
{StandardVoteType.Votekick, CCVars.VotekickEnabled}
{StandardVoteType.Votekick, CCVars.VotekickEnabled},
// WL-Changes-start
{StandardVoteType.EvacuationShuttle, WLCVars.VoteShuttleEnabled},
// WL-Changes-end
};
public void CreateStandardVote(ICommonSession? initiator, StandardVoteType voteType, string[]? args = null)
@@ -69,6 +74,11 @@ namespace Content.Server.Voting.Managers
timeoutVote = false; // Allows the timeout to be updated manually in the create method
CreateVotekickVote(initiator, args);
break;
// WL-Changes-start
case StandardVoteType.EvacuationShuttle:
CreateVoteShuttleEvac(initiator);
break;
// WL-Changes-end
default:
throw new ArgumentOutOfRangeException(nameof(voteType), voteType, null);
}
@@ -77,6 +87,68 @@ namespace Content.Server.Voting.Managers
TimeoutStandardVote(voteType);
}
// WL-Changes-start
private void CreateVoteShuttleEvac(ICommonSession? initiator)
{
var ticker = _entityManager.EntitySysManager.GetEntitySystem<GameTicker>();
var roundEnd = _entityManager.EntitySysManager.GetEntitySystem<RoundEndSystem>();
if (ticker.RunLevel != GameRunLevel.InRound)
{
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"Evacuation shuttle vote canceled.");
_chatManager.DispatchServerAnnouncement(
Loc.GetString("ui-vote-shuttle-not-in-round"));
return;
}
var alone = _playerManager.PlayerCount == 1 && initiator != null;
var options = new VoteOptions
{
Title = Loc.GetString("ui-vote-shuttle-title"),
Duration = alone
? TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.VoteTimerAlone))
: TimeSpan.FromSeconds(_cfg.GetCVar(WLCVars.VoteShuttleTimer))
};
if (alone)
options.InitiatorTimeout = TimeSpan.FromSeconds(10);
var yes = Loc.GetString("ui-vote-shuttle-option1");
var no = Loc.GetString("ui-vote-shuttle-option2");
options.Options.Add((yes, true));
options.Options.Add((no, false));
WirePresetVoteInitiator(options, initiator);
var vote = CreateVote(options);
vote.OnFinished += (_, args) =>
{
var yesVotes = vote.VotesPerOption[true];
var noVotes = vote.VotesPerOption[false];
var total = yesVotes + noVotes;
var ratio = _cfg.GetCVar(WLCVars.VoteShuttlePlayersRatio);
var picked = total > 0 && (float)yesVotes / (float)total * 100f >= (float)ratio;
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"Evacuation shuttle vote finished: {picked}");
if (picked)
{
_chatManager.DispatchServerAnnouncement(Loc.GetString("ui-vote-shuttle-win"));
roundEnd.RequestRoundEnd(initiator?.AttachedEntity);
}
else
{
_chatManager.DispatchServerAnnouncement(Loc.GetString("ui-vote-shuttle-failed", ("ratio", ratio)));
}
};
}
// WL-Changes-end
private void CreateRestartVote(ICommonSession? initiator)
{

View File

@@ -23,7 +23,14 @@ public enum StandardVoteType : byte
/// <summary>
/// Vote to kick a player.
/// </summary>
Votekick
Votekick,
// WL-Changes-start
/// <summary>
/// Vote to call an evacuation shuttle.
/// </summary>
EvacuationShuttle
// WL-Changes-end
}
/// <summary>

View File

@@ -116,4 +116,26 @@ public sealed class WLCVars
/// </summary>
public static readonly CVarDef<int> CCMinResponseTime =
CVarDef.Create("central_command.min_response_time", 250, CVar.SERVERONLY); //It has normal distribution random where medium is 450 second (7.5 min)
/*
* Vote
*/
/// <summary>
/// Доступна ли игрокам возможность вызвать шаттл голосованием?
/// </summary>
public static readonly CVarDef<bool> VoteShuttleEnabled =
CVarDef.Create("vote.evacuation_shuttle_vote_enabled", true, CVar.SERVERONLY);
/// <summary>
/// Сколько требуется согласных игроков для вызова.
/// В процентах.
/// </summary>
public static readonly CVarDef<float> VoteShuttlePlayersRatio =
CVarDef.Create("vote.evacuation_shuttle_vote_ratio", 0.6f, CVar.SERVERONLY);
/// <summary>
/// Время голосования.
/// </summary>
public static readonly CVarDef<int> VoteShuttleTimer =
CVarDef.Create("vote.evacuation_shuttle_vote_time", 40, CVar.SERVERONLY);
}

View File

@@ -0,0 +1,6 @@
ui-vote-shuttle-title = Вызов шаттла эвакуации
ui-vote-shuttle-option1 = Да
ui-vote-shuttle-option2 = Нет
ui-vote-shuttle-win = Голосование о вызове шаттла эвакуации успешно.
ui-vote-shuttle-failed = Голосование о вызове шаттла эвакуации отклонено (требуется { TOSTRING($ratio, "P0") }).
ui-vote-shuttle-not-in-round = Голосование о вызове шаттла эвакуации действует только во время раунда!

View File

@@ -0,0 +1 @@
ui-vote-type-evac-shuttle = Вызов шаттла эвакуации