From 66ccbef8245ba0d1224e670fc9a089f1f715dbaa Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:41:28 +0200 Subject: [PATCH] Give detectives TC when killing traitors and give them the remaining TC when examining a Traitor body --- .../SuspicionRuleSystem.Rules.cs | 79 ++++++++++++------- .../SuspicionRuleSystem.Spawning.cs | 2 +- .../SuspicionRuleSystem.Utility.cs | 52 ++++++++++++ Resources/Locale/en-US/_SSS/suspicion.ftl | 1 + 4 files changed, 103 insertions(+), 31 deletions(-) diff --git a/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Rules.cs b/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Rules.cs index 13d74cb5a2..fcb274334d 100644 --- a/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Rules.cs +++ b/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Rules.cs @@ -1,4 +1,5 @@ -using Content.Server._SSS.GridMarker; +using System.Linq; +using Content.Server._SSS.GridMarker; using Content.Server._SSS.SuspicionGameRule.Components; using Content.Server.Communications; using Content.Server.Ghost; @@ -67,36 +68,8 @@ private void OnMobStateChanged(EntityUid uid, SuspicionPlayerComponent component // Ok this is fucking horrible foreach (var traitor in allTraitors) { - var implantedComponent = CompOrNull(traitor.body); - if (implantedComponent == null) - continue; - - foreach (var implant in implantedComponent.ImplantContainer.ContainedEntities) - { - var storeComp = CompOrNull(implant); - if (storeComp == null) - continue; - - _storeSystem.TryAddCurrency(new Dictionary() - { - { "Telecrystal", sus.AmountAddedPerKill }, - }, - implant, - storeComp - ); - } - } - - var message = Loc.GetString("tc-added-sus", ("tc", sus.AmountAddedPerKill)); - - var channels = new List(); - foreach (var traitor in allTraitors) - { - var found = _playerManager.TryGetSessionByEntity(traitor.body, out var channel); - if (found) - channels.Add(channel!.Channel); + AddTcToPlayer(traitor.body, sus.AmountAddedPerKill); } - _chatManager.ChatMessageToMany(ChatChannel.Server, message, message, EntityUid.Invalid, false, true, channels); var allInnocents = FindAllOfType(SuspicionRole.Innocent); var allDetectives = FindAllOfType(SuspicionRole.Detective); @@ -148,6 +121,7 @@ private void OnExamine(EntityUid uid, SuspicionPlayerComponent component, ref Ex } var mind = _mindSystem.GetMind(args.Examined); + var examinerMind = _mindSystem.GetMind(args.Examiner); if (mind == null) return; @@ -158,6 +132,42 @@ private void OnExamine(EntityUid uid, SuspicionPlayerComponent component, ref Ex if (role.Value.Comp2.Role == SuspicionRole.Pending) return; + if (examinerMind.HasValue) // I apologize for this being so nested. Can't use early returns with the other stuff below. + { + // If the examined is a traitor and the examinor is a detective, we give the detective any TC the traitor had. + if (role.Value.Comp2.Role == SuspicionRole.Traitor) + { + if (_roleSystem.MindHasRole(examinerMind.Value, out var examinerRole)) + { + if (examinerRole.Value.Comp2.Role == SuspicionRole.Detective) + { + var implantT = GetUplinkImplant(args.Examined); + var implantD = GetUplinkImplant(args.Examiner); + if (implantT.HasValue && implantD.HasValue) + { + var tc = implantT.Value.Comp.Balance.Values.Sum(x => x.Int()); + AddTcToPlayer(args.Examiner, tc); + implantT.Value.Comp.Balance.Clear(); + + if (_playerManager.TryGetSessionByEntity(args.Examiner, out var session)) + { + var msgFound = Loc.GetString("suspicion-found-tc", ("tc", tc)); + _chatManager.ChatMessageToOne( + ChatChannel.Server, + msgFound, + msgFound, + EntityUid.Invalid, + false, + client: session.Channel, + recordReplay:true + ); + } + } + } + } + } + } + args.PushMarkup(Loc.GetString( "suspicion-examination", ("ent", args.Examined), @@ -175,6 +185,15 @@ private void OnExamine(EntityUid uid, SuspicionPlayerComponent component, ref Ex if (component.Revealed) return; + if (role.Value.Comp2.Role == SuspicionRole.Traitor) + { + var allDetectives = FindAllOfType(SuspicionRole.Detective); + foreach (var det in allDetectives) // Once a Traitor is found, all detectives get 1 TC. + { + AddTcToPlayer(det.body, 1, false); + } + } + component.Revealed = true; var trans = Comp(args.Examined); var loc = _transformSystem.GetMapCoordinates(trans); diff --git a/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Spawning.cs b/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Spawning.cs index 22c06c5fc8..6bb2ca4ffa 100644 --- a/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Spawning.cs +++ b/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Spawning.cs @@ -77,7 +77,7 @@ private void StartRound(EntityUid uid, SuspicionRuleComponent component, GameRul } var traitorCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.TraitorPercentage), 1, allPlayerData.Count); - var detectiveCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.DetectivePercentage), 0, allPlayerData.Count); + var detectiveCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.DetectivePercentage), 1, allPlayerData.Count); RobustRandom.Shuffle(participatingPlayers); // Shuffle the list so we can just take the first N players RobustRandom.Shuffle(participatingPlayers); diff --git a/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Utility.cs b/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Utility.cs index eeb4452ad7..c95fea4ee7 100644 --- a/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Utility.cs +++ b/Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Utility.cs @@ -1,9 +1,12 @@ using Content.Server._SSS.SuspicionGameRule.Components; using Content.Shared.Chat; +using Content.Shared.FixedPoint; using Content.Shared.Humanoid; +using Content.Shared.Implants.Components; using Content.Shared.Mind; using Content.Shared.Mind.Components; using Content.Shared.Roles; +using Content.Shared.Store.Components; using Robust.Server.Containers; using Robust.Shared.Map; using Robust.Shared.Physics.Components; @@ -27,6 +30,55 @@ private void SendAnnouncement(string message, Color? colorOverride = null) colorOverride: colorOverride); } + private void AddTcToPlayer(EntityUid player, int amount, bool displayMessage = true) + { + var implantedComponent = CompOrNull(player); + if (implantedComponent == null) + return; + + foreach (var implant in implantedComponent.ImplantContainer.ContainedEntities) + { + var storeComp = CompOrNull(implant); + if (storeComp == null) + continue; + + _storeSystem.TryAddCurrency(new Dictionary() + { + { "Telecrystal", FixedPoint2.New(amount)}, + }, + implant, + storeComp + ); + } + + if (!_playerManager.TryGetSessionByEntity(player, out var session)) + return; + + if (!displayMessage) + return; + + var message = Loc.GetString("tc-added-sus", ("tc", amount)); + _chatManager.ChatMessageToOne(ChatChannel.Server, message, message, EntityUid.Invalid, false, session.Channel); + } + + private Entity? GetUplinkImplant(EntityUid player) + { + var implantedComponent = CompOrNull(player); + if (implantedComponent == null) + return null; + + foreach (var implant in implantedComponent.ImplantContainer.ContainedEntities) + { + var storeComp = CompOrNull(implant); + if (storeComp == null) + continue; + + return (implant, storeComp); + } + + return null; + } + /// /// Finds all players with a specific role. /// diff --git a/Resources/Locale/en-US/_SSS/suspicion.ftl b/Resources/Locale/en-US/_SSS/suspicion.ftl index c046dacbef..87fc82ad75 100644 --- a/Resources/Locale/en-US/_SSS/suspicion.ftl +++ b/Resources/Locale/en-US/_SSS/suspicion.ftl @@ -6,6 +6,7 @@ suspicion-detective-uplink = Detective Uplink tc-added-sus = You have been given {$tc} TC for your performance. suspicion-examination = { SUBJECT($ent) } were [color={$col}]{ $role }[/color] suspicion-examination-chat = [italic]{ $finder }[/italic] found the body of [italic]{ $found }[/italic] { $where } and discovered { SUBJECT($found) } { CONJUGATE-BASIC($found, "were", "was") } { INDEFINITE($role) } [bold][color={ $col }]{ $role }[/color][/bold]. +suspicion-found-tc = You found [bold]{$tc} TC[/bold] on the body. They have been added to your uplink. roles-antag-suspicion-traitor-name = Traitor roles-antag-suspicion-traitor-objective = Kill the innocents while avoiding detection.