From 20bb9ede110efcb6c8c2d804f0ec038d3dd0f831 Mon Sep 17 00:00:00 2001 From: Brandon Hu <103440971+Brandon-Huu@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:19:15 +0000 Subject: [PATCH] fix(contraband): Make contraband work with chameleon items (#30986) * formatting --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- .../EntitySystems/SharedChameleonClothingSystem.cs | 13 +++++++++++++ Content.Shared/Contraband/ContrabandSystem.cs | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs b/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs index f5df04037ee6..2b10b41fee8d 100644 --- a/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs +++ b/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs @@ -1,5 +1,6 @@ using Content.Shared.Access.Components; using Content.Shared.Clothing.Components; +using Content.Shared.Contraband; using Content.Shared.Inventory; using Content.Shared.Inventory.Events; using Content.Shared.Item; @@ -13,6 +14,7 @@ public abstract class SharedChameleonClothingSystem : EntitySystem [Dependency] private readonly IComponentFactory _factory = default!; [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly ClothingSystem _clothingSystem = default!; + [Dependency] private readonly ContrabandSystem _contraband = default!; [Dependency] private readonly MetaDataSystem _metaData = default!; [Dependency] private readonly SharedItemSystem _itemSystem = default!; [Dependency] private readonly TagSystem _tag = default!; @@ -68,6 +70,17 @@ protected void UpdateVisuals(EntityUid uid, ChameleonClothingComponent component { _clothingSystem.CopyVisuals(uid, otherClothing, clothing); } + + // properly mark contraband + if (proto.TryGetComponent("Contraband", out ContrabandComponent? contra)) + { + EnsureComp(uid, out var current); + _contraband.CopyDetails(uid, contra, current); + } + else + { + RemComp(uid); + } } protected virtual void UpdateSprite(EntityUid uid, EntityPrototype proto) { } diff --git a/Content.Shared/Contraband/ContrabandSystem.cs b/Content.Shared/Contraband/ContrabandSystem.cs index 22181ce99ada..e6931f2860a1 100644 --- a/Content.Shared/Contraband/ContrabandSystem.cs +++ b/Content.Shared/Contraband/ContrabandSystem.cs @@ -33,6 +33,16 @@ private void SetContrabandExamine(bool val) _contrabandExamineEnabled = val; } + public void CopyDetails(EntityUid uid, ContrabandComponent other, ContrabandComponent? contraband = null) + { + if (!Resolve(uid, ref contraband)) + return; + + contraband.Severity = other.Severity; + contraband.AllowedDepartments = other.AllowedDepartments; + Dirty(uid, contraband); + } + private void OnExamined(Entity ent, ref ExaminedEvent args) { if (!_contrabandExamineEnabled) @@ -45,7 +55,7 @@ private void OnExamined(Entity ent, ref ExaminedEvent args) using (args.PushGroup(nameof(ContrabandComponent))) { var severity = _proto.Index(ent.Comp.Severity); - if (severity.ShowDepartments && ent.Comp is { AllowedDepartments: not null }) + if (severity.ShowDepartments && ent.Comp is { AllowedDepartments: not null }) { // TODO shouldn't department prototypes have a localized name instead of just using the ID for this? var list = ContentLocalizationManager.FormatList(ent.Comp.AllowedDepartments.Select(p => Loc.GetString($"department-{p.Id}")).ToList());