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
This commit is contained in:
Víctor Aguilera Puerto
2020-08-20 18:09:29 +02:00
committed by GitHub
parent de61a01703
commit 9e7d698145
7 changed files with 47 additions and 11 deletions

View File

@@ -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());

View File

@@ -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<MsgRoundEndMessage>();
roundEndMessage.GamemodeTitle = MakeGamePreset(null).ModeTitle;
roundEndMessage.RoundEndText = roundEndText;
//Get the timespan of the round.
roundEndMessage.RoundDuration = IoCManager.Resolve<IGameTiming>().RealTime.Subtract(_roundStartTimeSpan);