]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
rev roundend shows converted count (#21854)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Mon, 27 Nov 2023 21:43:48 +0000 (21:43 +0000)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 21:43:48 +0000 (14:43 -0700)
* add ConvertedCount field to role

* make objectives roundend title logic reusable

* change rev system + use GetTitle

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs
Content.Server/Objectives/ObjectivesSystem.cs
Content.Server/Roles/RevolutionaryRoleComponent.cs
Resources/Locale/en-US/game-ticking/game-presets/preset-revolutionary.ftl

index 13369ff8d0857db3c15d6361c2df0ce1ce8d1052..2759e931181f194f8b4bbe20950d1b3a612ff9e6 100644 (file)
@@ -7,6 +7,7 @@ using Content.Server.GameTicking.Rules.Components;
 using Content.Server.Mind;
 using Content.Server.NPC.Components;
 using Content.Server.NPC.Systems;
+using Content.Server.Objectives;
 using Content.Server.Popups;
 using Content.Server.Revolutionary.Components;
 using Content.Server.Roles;
@@ -42,6 +43,7 @@ public sealed class RevolutionaryRuleSystem : GameRuleSystem<RevolutionaryRuleCo
     [Dependency] private readonly MindSystem _mind = default!;
     [Dependency] private readonly MobStateSystem _mobState = default!;
     [Dependency] private readonly NpcFactionSystem _npcFaction = default!;
+    [Dependency] private readonly ObjectivesSystem _objectives = default!;
     [Dependency] private readonly PopupSystem _popup = default!;
     [Dependency] private readonly RoleSystem _role = default!;
     [Dependency] private readonly SharedStunSystem _stun = default!;
@@ -101,24 +103,19 @@ public sealed class RevolutionaryRuleSystem : GameRuleSystem<RevolutionaryRuleCo
             var index = (commandLost ? 1 : 0) | (revsLost ? 2 : 0);
             ev.AddLine(Loc.GetString(Outcomes[index]));
 
-            ev.AddLine(Loc.GetString("head-rev-initial-count", ("initialCount", headrev.HeadRevs.Count)));
-            foreach (var player in headrev.HeadRevs)
+            ev.AddLine(Loc.GetString("rev-headrev-count", ("initialCount", headrev.HeadRevs.Count)));
+            foreach (var player in headrev.HeadRevs.Values)
             {
-                _mind.TryGetSession(player.Value, out var session);
-                var username = session?.Name;
-                if (username != null)
-                {
-                    ev.AddLine(Loc.GetString("head-rev-initial-name-user",
-                    ("name", player.Key),
-                    ("username", username)));
-                }
-                else
-                {
-                    ev.AddLine(Loc.GetString("head-rev-initial-name",
-                    ("name", player.Key)));
-                }
+                var title = _objectives.GetTitle(player);
+                if (title == null)
+                    continue;
+
+                // TODO: when role entities are a thing this has to change
+                var count = CompOrNull<RevolutionaryRoleComponent>(player)?.ConvertedCount ?? 0;
+                ev.AddLine(Loc.GetString("rev-headrev-player", ("title", title), ("count", count)));
+
+                // TODO: someone suggested listing all alive? revs maybe implement at some point
             }
-            break;
         }
     }
 
@@ -208,6 +205,9 @@ public sealed class RevolutionaryRuleSystem : GameRuleSystem<RevolutionaryRuleCo
         if (ev.User != null)
         {
             _adminLogManager.Add(LogType.Mind, LogImpact.Medium, $"{ToPrettyString(ev.User.Value)} converted {ToPrettyString(ev.Target)} into a Revolutionary");
+
+            if (_mind.TryGetRole<RevolutionaryRoleComponent>(ev.User.Value, out var headrev))
+                headrev.ConvertedCount++;
         }
 
         if (mindId == default || !_role.MindHasRole<RevolutionaryRoleComponent>(mindId))
index 511558216d5a2c7577fd0844751b315744a46dd0..bf5fe1d4d40c61bc5d9e39a3f5e9f1eaf68ebd42 100644 (file)
@@ -110,26 +110,9 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
             if (!TryComp(mindId, out MindComponent? mind))
                 continue;
 
-            var name = mind.CharacterName;
-            _mind.TryGetSession(mindId, out var session);
-            var username = session?.Name;
-
-            string title;
-            if (username != null)
-            {
-                if (name != null)
-                    title = Loc.GetString("objectives-player-user-named", ("user", username), ("name", name));
-                else
-                    title = Loc.GetString("objectives-player-user", ("user", username));
-            }
-            else
-            {
-                // nothing to identify the player by, just give up
-                if (name == null)
-                    continue;
-
-                title = Loc.GetString("objectives-player-named", ("name", name));
-            }
+            var title = GetTitle(mindId, mind);
+            if (title == null)
+                continue;
 
             result += "\n";
 
@@ -230,6 +213,33 @@ public sealed class ObjectivesSystem : SharedObjectivesSystem
         return originalEntityInCustody || (TryComp<CuffableComponent>(mind.OwnedEntity, out var cuffed) && cuffed.CuffedHandCount > 0
                && _emergencyShuttle.IsTargetEscaping(mind.OwnedEntity.Value));
     }
+
+    /// <summary>
+    /// Get the title for a player's mind used in round end.
+    /// </summary>
+    public string? GetTitle(EntityUid mindId, MindComponent? mind = null)
+    {
+        if (!Resolve(mindId, ref mind))
+            return null;
+
+        var name = mind.CharacterName;
+        _mind.TryGetSession(mindId, out var session);
+        var username = session?.Name;
+
+        if (username != null)
+        {
+            if (name != null)
+                return Loc.GetString("objectives-player-user-named", ("user", username), ("name", name));
+
+            return Loc.GetString("objectives-player-user", ("user", username));
+        }
+
+        // nothing to identify the player by, just give up
+        if (name == null)
+            return null;
+
+        return Loc.GetString("objectives-player-named", ("name", name));
+    }
 }
 
 /// <summary>
index fa06cc319180fa081436a6b85ac431134146a426..821364c7389083ffe6ad79501fa91a5be59a8cc7 100644 (file)
@@ -8,5 +8,9 @@ namespace Content.Server.Roles;
 [RegisterComponent]
 public sealed partial class RevolutionaryRoleComponent : AntagonistRoleComponent
 {
-
+    /// <summary>
+    /// For headrevs, how many people you have converted.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public uint ConvertedCount = 0;
 }
index c6e925d0c46e24cbdd854539dc5fed79e2d94c9d..ba2e3e554a88b5e78c21a456830a8b9af1d9180f 100644 (file)
@@ -14,14 +14,6 @@ head-rev-briefing =
     Use flashes to convert people to your cause.
     Kill all heads to take over the station.
 
-head-rev-initial-name = [color=#5e9cff]{$name}[/color] was one of the Head Revolutionaries.
-head-rev-initial-name-user = [color=#5e9cff]{$name}[/color] ([color=gray]{$username}[/color]) was one of the Head Revolutionaries.
-
-head-rev-initial-count = {$initialCount ->
-    [one] There was one Head Revolutionary:
-    *[other] There were {$initialCount} Head Revolutionaries:
-}
-
 head-rev-break-mindshield = The Mindshield was destroyed!
 
 ## Rev
@@ -58,4 +50,12 @@ rev-stalemate = All of the Head Revs and Command died. It's a draw.
 
 rev-reverse-stalemate = Both Command and Head Revs survived.
 
+rev-headrev-count = {$initialCount ->
+    [one] There was one Head Revolutionary:
+    *[other] There were {$initialCount} Head Revolutionaries:
+}
 
+rev-headrev-player = {$title} converted {$count} {$count ->
+    [one] person
+    *[other] people
+}.