]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix(contraband): Make contraband work with chameleon items (#30986)
authorBrandon Hu <103440971+Brandon-Huu@users.noreply.github.com>
Mon, 23 Sep 2024 20:19:15 +0000 (20:19 +0000)
committerGitHub <noreply@github.com>
Mon, 23 Sep 2024 20:19:15 +0000 (22:19 +0200)
* formatting

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs
Content.Shared/Contraband/ContrabandSystem.cs

index f5df04037ee6505b90ed3ad175335ba50bc18a56..2b10b41fee8da09bed4495899a5ed45412b2b5ca 100644 (file)
@@ -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 @@ public abstract class SharedChameleonClothingSystem : EntitySystem
         {
             _clothingSystem.CopyVisuals(uid, otherClothing, clothing);
         }
+
+        // properly mark contraband
+        if (proto.TryGetComponent("Contraband", out ContrabandComponent? contra))
+        {
+            EnsureComp<ContrabandComponent>(uid, out var current);
+            _contraband.CopyDetails(uid, contra, current);
+        }
+        else
+        {
+            RemComp<ContrabandComponent>(uid);
+        }
     }
 
     protected virtual void UpdateSprite(EntityUid uid, EntityPrototype proto) { }
index 22181ce99ada2af5d622930f7cf0356f5cbdf1aa..e6931f2860a1793e7507579ed1dbee02fa1e1eba 100644 (file)
@@ -33,6 +33,16 @@ public sealed class ContrabandSystem : EntitySystem
         _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<ContrabandComponent> ent, ref ExaminedEvent args)
     {
         if (!_contrabandExamineEnabled)
@@ -45,7 +55,7 @@ public sealed class ContrabandSystem : EntitySystem
         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());