diff --git a/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs b/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs index 379d639760..30bcfe89c8 100644 --- a/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs +++ b/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs @@ -13,6 +13,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Suspicion; using Content.Shared.Roles; using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Log; using Robust.Shared.Maths; @@ -24,20 +25,32 @@ namespace Content.Server.GameTicking.GamePresets [Dependency] private readonly IChatManager _chatManager; [Dependency] private readonly IGameTicker _gameTicker; [Dependency] private readonly IRobustRandom _random; + [Dependency] private readonly IConfigurationManager _cfg; [Dependency] private IPrototypeManager _prototypeManager; #pragma warning restore 649 - public int MinPlayers { get; set; } = 5; - public int MinTraitors { get; set; } = 2; - public int PlayersPerTraitor { get; set; } = 5; + public int MinPlayers { get; set; } + public int MinTraitors { get; set; } + public int PlayersPerTraitor { get; set; } public override bool DisallowLateJoin => true; private static string TraitorID = "SuspicionTraitor"; private static string InnocentID = "SuspicionInnocent"; + public static void RegisterCVars(IConfigurationManager cfg) + { + cfg.RegisterCVar("game.suspicion_min_players", 5); + cfg.RegisterCVar("game.suspicion_min_traitors", 2); + cfg.RegisterCVar("game.suspicion_players_per_traitor", 5); + } + public override bool Start(IReadOnlyList readyPlayers, bool force = false) { + MinPlayers = _cfg.GetCVar("game.suspicion_min_players"); + MinTraitors = _cfg.GetCVar("game.suspicion_min_traitors"); + PlayersPerTraitor = _cfg.GetCVar("game.suspicion_players_per_traitor"); + if (!force && readyPlayers.Count < MinPlayers) { _chatManager.DispatchServerAnnouncement($"Not enough players readied up for the game! There were {readyPlayers.Count} players readied up out of {MinPlayers} needed."); @@ -71,6 +84,8 @@ namespace Content.Server.GameTicking.GamePresets var numTraitors = MathHelper.Clamp(readyPlayers.Count / PlayersPerTraitor, MinTraitors, readyPlayers.Count); + var traitors = new List(); + for (var i = 0; i < numTraitors; i++) { IPlayerSession traitor; @@ -87,7 +102,9 @@ namespace Content.Server.GameTicking.GamePresets } var mind = traitor.Data.ContentData().Mind; var antagPrototype = _prototypeManager.Index(TraitorID); - mind.AddRole(new SuspicionTraitorRole(mind, antagPrototype)); + var traitorRole = new SuspicionTraitorRole(mind, antagPrototype); + mind.AddRole(traitorRole); + traitors.Add(traitorRole); } foreach (var player in list) @@ -97,6 +114,11 @@ namespace Content.Server.GameTicking.GamePresets mind.AddRole(new SuspicionInnocentRole(mind, antagPrototype)); } + foreach (var traitor in traitors) + { + traitor.GreetSuspicion(traitors, _chatManager); + } + _gameTicker.AddGameRule(); return true; } diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index 49fb6c7157..0df79eb51c 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -134,6 +134,8 @@ namespace Content.Server.GameTicking _configurationManager.RegisterCVar("game.defaultpreset", "Suspicion", CVar.ARCHIVE); _configurationManager.RegisterCVar("game.fallbackpreset", "Sandbox", CVar.ARCHIVE); + PresetSuspicion.RegisterCVars(_configurationManager); + _playerManager.PlayerStatusChanged += _handlePlayerStatusChanged; _netManager.RegisterNetMessage(nameof(MsgTickerJoinLobby)); diff --git a/Content.Server/Mobs/Roles/SuspicionTraitorRole.cs b/Content.Server/Mobs/Roles/SuspicionTraitorRole.cs index 5279fae886..8a834564fd 100644 --- a/Content.Server/Mobs/Roles/SuspicionTraitorRole.cs +++ b/Content.Server/Mobs/Roles/SuspicionTraitorRole.cs @@ -1,9 +1,8 @@ -using Content.Server.GameObjects.Components.Suspicion; +using System.Collections.Generic; +using System.Linq; using Content.Server.Interfaces.Chat; using Content.Shared.Roles; -using Robust.Shared.GameObjects; -using Robust.Shared.Interfaces.GameObjects; -using Robust.Shared.IoC; +using Robust.Shared.Localization; namespace Content.Server.Mobs.Roles { @@ -22,26 +21,25 @@ namespace Content.Server.Mobs.Roles public string Objective => Prototype.Objective; public override bool Antagonist { get; } - public override void Greet() + public void GreetSuspicion(List traitors, IChatManager chatMgr) { - base.Greet(); + chatMgr.DispatchServerMessage(Mind.Session, Loc.GetString("You're a {0}!", Name)); + chatMgr.DispatchServerMessage(Mind.Session, Loc.GetString("Objective: {0}", Objective)); - var chat = IoCManager.Resolve(); - chat.DispatchServerMessage(Mind.Session, $"You're a {Name}!"); - chat.DispatchServerMessage(Mind.Session, $"Objective: {Objective}"); - - var traitors = ""; - - foreach (var sus in IoCManager.Resolve().EntityQuery()) + if (traitors.Count == 1) { - if (!sus.IsTraitor()) continue; - if (traitors.Length > 0) - traitors += $", {sus.Owner.Name}"; - else - traitors += sus.Owner.Name; + // Only traitor. + chatMgr.DispatchServerMessage(Mind.Session, Loc.GetString("You're on your own. Good luck!")); + return; } - - chat.DispatchServerMessage(Mind.Session, $"The traitors are: {traitors}"); + + var text = string.Join(", ", traitors.Where(p => p != this).Select(p => p.Mind.CharacterName)); + + var pluralText = Loc.GetPluralString("Your partner in crime is: {0}", + "Your partners in crime are: {0}", + traitors.Count-1, text); + + chatMgr.DispatchServerMessage(Mind.Session, pluralText); } } }