From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Wed, 26 Mar 2025 15:30:14 +0000 (+0100) Subject: Show paradox clones in deadchat (#35940) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=9ff43f344eaf1d513d42e0d9a9720097b4af95aa;p=space-station-14.git Show paradox clones in deadchat (#35940) show clones in deadchat --- diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index 1ca96889cf..e7125ee4f2 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -24,6 +24,7 @@ using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Systems; using Content.Shared.Movement.Events; using Content.Shared.Movement.Systems; +using Content.Shared.NameModifier.EntitySystems; using Content.Shared.Popups; using Content.Shared.Storage.Components; using Content.Shared.Tag; @@ -66,6 +67,7 @@ namespace Content.Server.Ghost [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly TagSystem _tag = default!; + [Dependency] private readonly NameModifierSystem _nameMod = default!; private EntityQuery _ghostQuery; private EntityQuery _physicsQuery; @@ -495,6 +497,10 @@ namespace Content.Server.Ghost else _minds.TransferTo(mind.Owner, ghost, mind: mind.Comp); Log.Debug($"Spawned ghost \"{ToPrettyString(ghost)}\" for {mind.Comp.CharacterName}."); + + // we changed the entity name above + // we have to call this after the mind has been transferred since some mind roles modify the ghost's name + _nameMod.RefreshNameModifiers(ghost); return ghost; } diff --git a/Content.Server/Roles/ParadoxCloneRoleComponent.cs b/Content.Server/Roles/ParadoxCloneRoleComponent.cs index d55cd34da4..32ebb2fe2d 100644 --- a/Content.Server/Roles/ParadoxCloneRoleComponent.cs +++ b/Content.Server/Roles/ParadoxCloneRoleComponent.cs @@ -6,4 +6,12 @@ namespace Content.Server.Roles; /// Added to mind role entities to tag that they are a paradox clone. /// [RegisterComponent] -public sealed partial class ParadoxCloneRoleComponent : BaseMindRoleComponent; +public sealed partial class ParadoxCloneRoleComponent : BaseMindRoleComponent +{ + /// + /// Name modifer applied to the player when they turn into a ghost. + /// Needed to be able to keep the original and the clone apart in dead chat. + /// + [DataField] + public LocId? NameModifier = "paradox-clone-ghost-name-modifier"; +} diff --git a/Content.Server/Roles/ParadoxCloneRoleSystem.cs b/Content.Server/Roles/ParadoxCloneRoleSystem.cs new file mode 100644 index 0000000000..83e23fef91 --- /dev/null +++ b/Content.Server/Roles/ParadoxCloneRoleSystem.cs @@ -0,0 +1,32 @@ +using Content.Shared.Ghost; +using Content.Shared.Mind; +using Content.Shared.NameModifier.EntitySystems; +using Content.Shared.Roles; + +namespace Content.Server.Roles; + +/// +/// System responsible for giving a ghost of a paradox clone a name modifier. +/// +public sealed class ParadoxCloneRoleSystem : EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent>(OnRefreshNameModifiers); + } + + private void OnRefreshNameModifiers(Entity ent, ref MindRelayedEvent args) + { + if (!TryComp(ent.Owner, out var roleComp)) + return; + + // only show for ghosts + if (!HasComp(roleComp.Mind.Comp.OwnedEntity)) + return; + + if (ent.Comp.NameModifier != null) + args.Args.AddModifier(ent.Comp.NameModifier.Value, 50); + } +} diff --git a/Content.Shared/Mind/SharedMindSystem.Relay.cs b/Content.Shared/Mind/SharedMindSystem.Relay.cs new file mode 100644 index 0000000000..60ad2fc30a --- /dev/null +++ b/Content.Shared/Mind/SharedMindSystem.Relay.cs @@ -0,0 +1,48 @@ +using Content.Shared.NameModifier.EntitySystems; +using Content.Shared.Mind.Components; + +namespace Content.Shared.Mind; + +/// +/// Relays events raised on a mobs body to its mind and mind role entities. +/// Useful for events that should be raised both on the body and the mind. +/// +public abstract partial class SharedMindSystem : EntitySystem +{ + public void InitializeRelay() + { + // for name modifiers that depend on certain mind roles + SubscribeLocalEvent(RelayRefToMind); + } + + protected void RelayToMind(EntityUid uid, MindContainerComponent component, T args) where T : class + { + var ev = new MindRelayedEvent(args); + + if (TryGetMind(uid, out var mindId, out var mindComp, component)) + { + RaiseLocalEvent(mindId, ref ev); + + foreach (var role in mindComp.MindRoles) + RaiseLocalEvent(role, ref ev); + } + } + + protected void RelayRefToMind(EntityUid uid, MindContainerComponent component, ref T args) where T : class + { + var ev = new MindRelayedEvent(args); + + if (TryGetMind(uid, out var mindId, out var mindComp, component)) + { + RaiseLocalEvent(mindId, ref ev); + + foreach (var role in mindComp.MindRoles) + RaiseLocalEvent(role, ref ev); + } + + args = ev.Args; + } +} + +[ByRefEvent] +public record struct MindRelayedEvent(TEvent Args); diff --git a/Content.Shared/Mind/SharedMindSystem.cs b/Content.Shared/Mind/SharedMindSystem.cs index fc1be3f1ba..b2e053f5f1 100644 --- a/Content.Shared/Mind/SharedMindSystem.cs +++ b/Content.Shared/Mind/SharedMindSystem.cs @@ -19,7 +19,7 @@ using Robust.Shared.Utility; namespace Content.Shared.Mind; -public abstract class SharedMindSystem : EntitySystem +public abstract partial class SharedMindSystem : EntitySystem { [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly INetManager _net = default!; @@ -42,6 +42,8 @@ public abstract class SharedMindSystem : EntitySystem SubscribeLocalEvent(OnReset); SubscribeLocalEvent(OnMindStartup); SubscribeLocalEvent(OnRenamed); + + InitializeRelay(); } public override void Shutdown() diff --git a/Resources/Locale/en-US/paradox-clone/role.ftl b/Resources/Locale/en-US/paradox-clone/role.ftl index 0a73ab4c3b..869cd5e7d2 100644 --- a/Resources/Locale/en-US/paradox-clone/role.ftl +++ b/Resources/Locale/en-US/paradox-clone/role.ftl @@ -3,3 +3,5 @@ paradox-clone-round-end-agent-name = paradox clone objective-issuer-paradox = [color=lightblue]Paradox[/color] paradox-clone-role-greeting = A freak space-time anomaly has teleported you into another reality! Now you have to find your counterpart and kill and replace them. Only one of you two can survive. + +paradox-clone-ghost-name-modifier = {$baseName} (clone)