From 9e7d698145612ca02658e0ea218de4317db8bf6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= <6766154+Zumorica@users.noreply.github.com> Date: Thu, 20 Aug 2020 18:09:29 +0200 Subject: [PATCH] Allow specifying a text to be shown to players in the summary when ending the round. (#1818) * Allow specifying a text to be shown to players when ending the round. Also sets text * Fix comment --- .../GameTicking/ClientGameTicker.cs | 2 +- .../UserInterface/RoundEndSummaryWindow.cs | 10 +++++- Content.IntegrationTests/DummyGameTicker.cs | 2 +- .../GameTicking/GameRules/RuleSuspicion.cs | 36 +++++++++++++++---- Content.Server/GameTicking/GameTicker.cs | 3 +- .../Interfaces/GameTicking/IGameTicker.cs | 2 +- Content.Shared/SharedGameTicker.cs | 3 ++ 7 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Content.Client/GameTicking/ClientGameTicker.cs b/Content.Client/GameTicking/ClientGameTicker.cs index d618046255..1ae8bcd8a7 100644 --- a/Content.Client/GameTicking/ClientGameTicker.cs +++ b/Content.Client/GameTicking/ClientGameTicker.cs @@ -113,7 +113,7 @@ namespace Content.Client.GameTicking private void RoundEnd(MsgRoundEndMessage message) { //This is not ideal at all, but I don't see an immediately better fit anywhere else. - var roundEnd = new RoundEndSummaryWindow(message.GamemodeTitle, message.RoundDuration, message.AllPlayersEndInfo); + var roundEnd = new RoundEndSummaryWindow(message.GamemodeTitle, message.RoundEndText, message.RoundDuration, message.AllPlayersEndInfo); } } diff --git a/Content.Client/UserInterface/RoundEndSummaryWindow.cs b/Content.Client/UserInterface/RoundEndSummaryWindow.cs index 550c48032f..8d40c0b8ba 100644 --- a/Content.Client/UserInterface/RoundEndSummaryWindow.cs +++ b/Content.Client/UserInterface/RoundEndSummaryWindow.cs @@ -18,7 +18,7 @@ namespace Content.Client.UserInterface private TabContainer RoundEndWindowTabs { get; } protected override Vector2? CustomSize => (520, 580); - public RoundEndSummaryWindow(string gm, TimeSpan roundTimeSpan, List info) + public RoundEndSummaryWindow(string gm, string roundEnd, TimeSpan roundTimeSpan, List info) { Title = Loc.GetString("Round End Summary"); @@ -50,6 +50,14 @@ namespace Content.Client.UserInterface gamemodeLabel.SetMarkup(Loc.GetString("Round of [color=white]{0}[/color] has ended.", gm)); RoundEndSummaryTab.AddChild(gamemodeLabel); + //Round end text + if (!string.IsNullOrEmpty(roundEnd)) + { + var roundendLabel = new RichTextLabel(); + roundendLabel.SetMarkup(Loc.GetString(roundEnd)); + RoundEndSummaryTab.AddChild(roundendLabel); + } + //Duration var roundTimeLabel = new RichTextLabel(); roundTimeLabel.SetMarkup(Loc.GetString("It lasted for [color=yellow]{0} hours, {1} minutes, and {2} seconds.", diff --git a/Content.IntegrationTests/DummyGameTicker.cs b/Content.IntegrationTests/DummyGameTicker.cs index f135339c75..afe44ed8ff 100644 --- a/Content.IntegrationTests/DummyGameTicker.cs +++ b/Content.IntegrationTests/DummyGameTicker.cs @@ -41,7 +41,7 @@ namespace Content.IntegrationTests { } - public void EndRound() + public void EndRound(string roundEnd) { } diff --git a/Content.Server/GameTicking/GameRules/RuleSuspicion.cs b/Content.Server/GameTicking/GameRules/RuleSuspicion.cs index 553df745a2..026c11516a 100644 --- a/Content.Server/GameTicking/GameRules/RuleSuspicion.cs +++ b/Content.Server/GameTicking/GameRules/RuleSuspicion.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using Content.Server.GameObjects.Components.Suspicion; using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.GameTicking; using Content.Server.Mobs.Roles; @@ -50,7 +51,8 @@ namespace Content.Server.GameTicking.GameRules foreach (var playerSession in _playerManager.GetAllPlayers()) { if (playerSession.AttachedEntity == null - || !playerSession.AttachedEntity.TryGetComponent(out IDamageableComponent damageable)) + || !playerSession.AttachedEntity.TryGetComponent(out IDamageableComponent damageable) + || !playerSession.AttachedEntity.TryGetComponent(out SuspicionRoleComponent suspicionRole)) { continue; } @@ -69,24 +71,46 @@ namespace Content.Server.GameTicking.GameRules if ((innocentsAlive + traitorsAlive) == 0) { _chatManager.DispatchServerAnnouncement("Everybody is dead, it's a stalemate!"); - EndRound(); + EndRound(Victory.Stalemate); } else if (traitorsAlive == 0) { _chatManager.DispatchServerAnnouncement("The traitors are dead! The innocents win."); - EndRound(); + EndRound(Victory.Innocents); } else if (innocentsAlive == 0) { _chatManager.DispatchServerAnnouncement("The innocents are dead! The traitors win."); - EndRound(); + EndRound(Victory.Traitors); } } - private void EndRound() + private enum Victory { - _gameTicker.EndRound(); + Stalemate, + Innocents, + Traitors + } + + private void EndRound(Victory victory) + { + string text; + + switch (victory) + { + case Victory.Innocents: + text = "The innocents have won!"; + break; + case Victory.Traitors: + text = "The traitors have won!"; + break; + default: + text = "Nobody wins!"; + break; + } + + _gameTicker.EndRound(text); _chatManager.DispatchServerAnnouncement($"Restarting in 10 seconds."); _checkTimerCancel.Cancel(); Timer.Spawn(TimeSpan.FromSeconds(10), () => _gameTicker.RestartRound()); diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index 62d6dfa1a6..6ff0061c25 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -326,7 +326,7 @@ namespace Content.Server.GameTicking (HumanoidCharacterProfile) (await _prefsManager.GetPreferencesAsync(p.SessionId.Username)) .SelectedCharacter; - public void EndRound() + public void EndRound(string roundEndText = "") { DebugTools.Assert(RunLevel == GameRunLevel.InRound); Logger.InfoS("ticker", "Ending round!"); @@ -336,6 +336,7 @@ namespace Content.Server.GameTicking //Tell every client the round has ended. var roundEndMessage = _netManager.CreateNetMessage(); roundEndMessage.GamemodeTitle = MakeGamePreset(null).ModeTitle; + roundEndMessage.RoundEndText = roundEndText; //Get the timespan of the round. roundEndMessage.RoundDuration = IoCManager.Resolve().RealTime.Subtract(_roundStartTimeSpan); diff --git a/Content.Server/Interfaces/GameTicking/IGameTicker.cs b/Content.Server/Interfaces/GameTicking/IGameTicker.cs index 6ec11e8421..a4e045e2ee 100644 --- a/Content.Server/Interfaces/GameTicking/IGameTicker.cs +++ b/Content.Server/Interfaces/GameTicking/IGameTicker.cs @@ -22,7 +22,7 @@ namespace Content.Server.Interfaces.GameTicking void RestartRound(); void StartRound(bool force = false); - void EndRound(); + void EndRound(string roundEndText = ""); void Respawn(IPlayerSession targetPlayer); void MakeObserve(IPlayerSession player); diff --git a/Content.Shared/SharedGameTicker.cs b/Content.Shared/SharedGameTicker.cs index e180ddb198..d29cc0f84e 100644 --- a/Content.Shared/SharedGameTicker.cs +++ b/Content.Shared/SharedGameTicker.cs @@ -253,6 +253,7 @@ namespace Content.Shared #endregion public string GamemodeTitle; + public string RoundEndText; public TimeSpan RoundDuration; @@ -263,6 +264,7 @@ namespace Content.Shared public override void ReadFromBuffer(NetIncomingMessage buffer) { GamemodeTitle = buffer.ReadString(); + RoundEndText = buffer.ReadString(); var hours = buffer.ReadInt32(); var mins = buffer.ReadInt32(); @@ -289,6 +291,7 @@ namespace Content.Shared public override void WriteToBuffer(NetOutgoingMessage buffer) { buffer.Write(GamemodeTitle); + buffer.Write(RoundEndText); buffer.Write(RoundDuration.Hours); buffer.Write(RoundDuration.Minutes); buffer.Write(RoundDuration.Seconds);