From dd308c6d2d514f072980e382384a4c05cb4b6d30 Mon Sep 17 00:00:00 2001 From: Verm <32827189+Vermidia@users.noreply.github.com> Date: Mon, 21 Apr 2025 13:25:22 -0500 Subject: [PATCH] Makes EventRole Ids properly set ID names. (#28958) * Add id binding system * Change so it activates when added too * Add to eventhumanoid * Add PDA binding, try to fix some things * Still not fixed, PDA is working right * Move to server, add on mind instead * Implement suggestions * Fix things * Finish review stuff * Messed up cluwne * Remove after only changing id too --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> --- .../Access/Components/IdBindComponent.cs | 14 +++++ Content.Server/Access/Systems/IdBindSystem.cs | 51 +++++++++++++++++++ .../RandomHumanoidSettingsPrototype.cs | 2 +- .../Entities/Mobs/Player/humanoid.yml | 4 +- 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 Content.Server/Access/Components/IdBindComponent.cs create mode 100644 Content.Server/Access/Systems/IdBindSystem.cs diff --git a/Content.Server/Access/Components/IdBindComponent.cs b/Content.Server/Access/Components/IdBindComponent.cs new file mode 100644 index 0000000000..9fcc7e2d56 --- /dev/null +++ b/Content.Server/Access/Components/IdBindComponent.cs @@ -0,0 +1,14 @@ +using Robust.Shared.GameStates; + +namespace Content.Server.Access.Components; + +[RegisterComponent] +public sealed partial class IdBindComponent : Component +{ + /// + /// If true, also tries to get the PDA and set the owner to the entity + /// + [DataField] + public bool BindPDAOwner = true; +} + diff --git a/Content.Server/Access/Systems/IdBindSystem.cs b/Content.Server/Access/Systems/IdBindSystem.cs new file mode 100644 index 0000000000..275a96f4f3 --- /dev/null +++ b/Content.Server/Access/Systems/IdBindSystem.cs @@ -0,0 +1,51 @@ +using Content.Server.Access.Components; +using Content.Server.PDA; +using Content.Shared.Inventory; +using Content.Shared.Mind.Components; +using Content.Shared.PDA; +using Content.Shared.Roles; + +namespace Content.Server.Access.Systems; + +public sealed class IdBindSystem : EntitySystem +{ + [Dependency] private readonly IdCardSystem _cardSystem = default!; + [Dependency] private readonly PdaSystem _pdaSystem = default!; + [Dependency] private readonly InventorySystem _inventory = default!; + + public override void Initialize() + { + base.Initialize(); + //Activate on mind being added + SubscribeLocalEvent(TryBind); + } + + private void TryBind(Entity ent, ref MindAddedMessage args) + { + if (!_cardSystem.TryFindIdCard(ent, out var cardId)) + return; + + var data = MetaData(ent); + + _cardSystem.TryChangeFullName(cardId, data.EntityName, cardId); + + if (!ent.Comp.BindPDAOwner) + { + //Remove after running once + RemCompDeferred(ent); + return; + } + + //Get PDA from main slot and set us as owner + if (!_inventory.TryGetSlotEntity(ent, "id", out var uPda)) + return; + + if (!TryComp(uPda, out var pDA)) + return; + + _pdaSystem.SetOwner(uPda.Value, pDA, ent, data.EntityName); + //Remove after running once + RemCompDeferred(ent); + } +} + diff --git a/Content.Shared/Humanoid/Prototypes/RandomHumanoidSettingsPrototype.cs b/Content.Shared/Humanoid/Prototypes/RandomHumanoidSettingsPrototype.cs index e31289db1e..3c350de68f 100644 --- a/Content.Shared/Humanoid/Prototypes/RandomHumanoidSettingsPrototype.cs +++ b/Content.Shared/Humanoid/Prototypes/RandomHumanoidSettingsPrototype.cs @@ -21,7 +21,7 @@ public sealed partial class RandomHumanoidSettingsPrototype : IPrototype, IInher /// /// Whether the humanoid's name should take from the randomized profile or not. /// - [DataField("randomizeName")] + [DataField] public bool RandomizeName { get; private set; } = true; /// diff --git a/Resources/Prototypes/Entities/Mobs/Player/humanoid.yml b/Resources/Prototypes/Entities/Mobs/Player/humanoid.yml index f92cf40e2e..a2b516d9e5 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/humanoid.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/humanoid.yml @@ -6,10 +6,12 @@ - type: RandomHumanoidAppearance randomizeName: false - type: GhostTakeoverAvailable + - type: IdBind - type: randomHumanoidSettings id: EventHumanoidMindShielded parent: EventHumanoid + randomizeName: false components: - type: MindShield - type: AntagImmune @@ -43,7 +45,6 @@ - type: randomHumanoidSettings id: DeathSquad parent: EventHumanoidCentcomm - randomizeName: false components: - type: GhostRole name: ghost-role-information-Death-Squad-name @@ -84,7 +85,6 @@ - type: randomHumanoidSettings id: ERTLeader parent: EventHumanoidCentcomm - randomizeName: false components: - type: GhostRole name: ghost-role-information-ert-leader-name