diff --git a/Content.Server/GameObjects/Components/Suspicion/SuspicionRoleComponent.cs b/Content.Server/GameObjects/Components/Suspicion/SuspicionRoleComponent.cs new file mode 100644 index 0000000000..833169a223 --- /dev/null +++ b/Content.Server/GameObjects/Components/Suspicion/SuspicionRoleComponent.cs @@ -0,0 +1,42 @@ +using Content.Server.GameObjects.Components.Mobs; +using Content.Server.Mobs.Roles; +using Content.Shared.GameObjects.EntitySystems; +using Robust.Shared.GameObjects; +using Robust.Shared.Localization; +using Robust.Shared.Utility; + +namespace Content.Server.GameObjects.Components.Suspicion +{ + [RegisterComponent] + public class SuspicionRoleComponent : Component, IExamine + { + public override string Name => "SuspicionRole"; + + public bool IsDead() + { + return Owner.TryGetComponent(out SpeciesComponent species) && + species.CurrentDamageState is DeadState; + } + + public bool IsTraitor() + { + return Owner.TryGetComponent(out MindComponent mind) && + mind.HasMind && + mind.Mind!.HasRole(); + } + + void IExamine.Examine(FormattedMessage message, bool inDetailsRange) + { + if (!IsDead()) + { + return; + } + + var tooltip = IsTraitor() + ? Loc.GetString($"They were a [color=red]traitor[/color]!") + : Loc.GetString($"They were an [color=green]innocent[/color]!"); + + message.AddMarkup(tooltip); + } + } +} diff --git a/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs b/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs index bd2f43a13d..1f6e0437ca 100644 --- a/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs +++ b/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs @@ -10,11 +10,12 @@ using Robust.Shared.Prototypes; using Robust.Shared.Random; using System.Collections.Generic; using System.Linq; +using Content.Server.GameObjects.Components.Suspicion; using Content.Shared.Roles; +using Robust.Shared.GameObjects; using Robust.Shared.Log; using Robust.Shared.Maths; - namespace Content.Server.GameTicking.GamePresets { public class PresetSuspicion : GamePreset @@ -54,6 +55,8 @@ namespace Content.Server.GameTicking.GamePresets { prefList.Add(player); } + + player.AttachedEntity?.EnsureComponent(); } var numTraitors = FloatMath.Clamp(readyPlayers.Count % PlayersPerTraitor, diff --git a/Content.Server/GameTicking/GameRules/RuleSuspicion.cs b/Content.Server/GameTicking/GameRules/RuleSuspicion.cs index 34ddc50f78..a3d830412e 100644 --- a/Content.Server/GameTicking/GameRules/RuleSuspicion.cs +++ b/Content.Server/GameTicking/GameRules/RuleSuspicion.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using Content.Server.GameObjects.Components.Mobs; using Content.Server.Interfaces.Chat; @@ -7,7 +7,6 @@ using Content.Server.Mobs.Roles; using Content.Server.Players; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; -using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Timer = Robust.Shared.Timers.Timer; @@ -24,7 +23,6 @@ namespace Content.Server.GameTicking.GameRules #pragma warning disable 649 [Dependency] private readonly IPlayerManager _playerManager; [Dependency] private readonly IChatManager _chatManager; - [Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly IGameTicker _gameTicker; #pragma warning restore 649 @@ -32,28 +30,9 @@ namespace Content.Server.GameTicking.GameRules public override void Added() { - _entityManager.EventBus.SubscribeEvent(EventSource.Local, this, _onMobDamageStateChanged); - Timer.SpawnRepeating(DeadCheckDelay, _checkWinConditions, _checkTimerCancel.Token); } - private void _onMobDamageStateChanged(MobDamageStateChangedMessage message) - { - var owner = message.Species.Owner; - - if (!(message.Species.CurrentDamageState is DeadState)) - return; - - if (!owner.TryGetComponent(out var mind)) - return; - - if (!mind.HasMind) - return; - - message.Species.Owner.Description += - mind.Mind.HasRole() ? "\nThey were a traitor!" : "\nThey were an innocent!"; - } - public override void Removed() { base.Removed(); @@ -78,6 +57,7 @@ namespace Content.Server.GameTicking.GameRules { continue; } + if (playerSession.ContentData().Mind.HasRole()) traitorsAlive++; else