From 1cae861f40e87fa912e9ec34666a69afe13a99d4 Mon Sep 17 00:00:00 2001 From: Alex Evgrashin Date: Thu, 24 Nov 2022 03:02:54 +0100 Subject: [PATCH] Chameleon clothing hides identity (#12642) --- .../Systems/ChameleonClothingSystem.cs | 19 ++++++++++++++++++- .../Components/ChameleonClothingComponent.cs | 6 ++++++ .../SharedChameleonClothingSystem.cs | 18 ++++++++++++++++++ .../Entities/Clothing/Masks/specific.yml | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs b/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs index 862f41dd0f..33c4a44098 100644 --- a/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs +++ b/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs @@ -1,5 +1,8 @@ -using Content.Shared.Clothing.Components; +using Content.Server.IdentityManagement; +using Content.Shared.Clothing.Components; using Content.Shared.Clothing.EntitySystems; +using Content.Shared.IdentityManagement.Components; +using Content.Shared.Prototypes; using Content.Shared.Verbs; using Robust.Server.GameObjects; using Robust.Shared.GameStates; @@ -11,6 +14,8 @@ public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem { [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; + [Dependency] private readonly IComponentFactory _factory = default!; + [Dependency] private readonly IdentitySystem _identity = default!; public override void Initialize() { @@ -91,8 +96,20 @@ public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem return; component.SelectedId = protoId; + UpdateIdentityBlocker(uid, component, proto); UpdateVisuals(uid, component); UpdateUi(uid, component); Dirty(component); } + + private void UpdateIdentityBlocker(EntityUid uid, ChameleonClothingComponent component, EntityPrototype proto) + { + if (proto.HasComponent(_factory)) + EnsureComp(uid); + else + RemComp(uid); + + if (component.User != null) + _identity.QueueIdentityUpdate(component.User.Value); + } } diff --git a/Content.Shared/Clothing/Components/ChameleonClothingComponent.cs b/Content.Shared/Clothing/Components/ChameleonClothingComponent.cs index 567a23a8f5..6ecd7cba33 100644 --- a/Content.Shared/Clothing/Components/ChameleonClothingComponent.cs +++ b/Content.Shared/Clothing/Components/ChameleonClothingComponent.cs @@ -27,6 +27,12 @@ public sealed class ChameleonClothingComponent : Component [ViewVariables(VVAccess.ReadOnly)] [DataField("default", required: true, customTypeSerializer: typeof(PrototypeIdSerializer))] public string? SelectedId; + + /// + /// Current user that wears chameleon clothing. + /// + [ViewVariables] + public EntityUid? User; } [Serializable, NetSerializable] diff --git a/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs b/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs index ce823166ba..1484d74963 100644 --- a/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs +++ b/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs @@ -1,5 +1,6 @@ using Content.Shared.Clothing.Components; using Content.Shared.Inventory; +using Content.Shared.Inventory.Events; using Content.Shared.Item; using Content.Shared.Tag; using Robust.Shared.Prototypes; @@ -13,6 +14,23 @@ public abstract class SharedChameleonClothingSystem : EntitySystem [Dependency] private readonly SharedItemSystem _itemSystem = default!; [Dependency] private readonly ClothingSystem _clothingSystem = default!; + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); + } + + private void OnGotEquipped(EntityUid uid, ChameleonClothingComponent component, GotEquippedEvent args) + { + component.User = args.Equipee; + } + + private void OnGotUnequipped(EntityUid uid, ChameleonClothingComponent component, GotUnequippedEvent args) + { + component.User = null; + } + // Updates chameleon visuals and meta information. // This function is called on a server after user selected new outfit. // And after that on a client after state was updated. diff --git a/Resources/Prototypes/Entities/Clothing/Masks/specific.yml b/Resources/Prototypes/Entities/Clothing/Masks/specific.yml index a30f1fcb22..e0ca259d98 100644 --- a/Resources/Prototypes/Entities/Clothing/Masks/specific.yml +++ b/Resources/Prototypes/Entities/Clothing/Masks/specific.yml @@ -15,6 +15,7 @@ - type: ChameleonClothing slot: [mask] default: ClothingMaskGas + - type: IdentityBlocker # need that for default ClothingMaskGas - type: UserInterface interfaces: - key: enum.ChameleonUiKey.Key