]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix remote solution injection (#23429)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 3 Jan 2024 07:57:36 +0000 (18:57 +1100)
committerGitHub <noreply@github.com>
Wed, 3 Jan 2024 07:57:36 +0000 (18:57 +1100)
Checks if its own fixture is hard so the fly-by fixture can't also proc it.

Content.Server/Chemistry/Components/SolutionInjectOnCollideComponent.cs
Content.Server/Chemistry/EntitySystems/SolutionInjectOnCollideSystem.cs

index 073bc1167c5167df39b5df39224e33b9c3a32226..c1d0fec05a77fab291e0c8fb9a4cd9bf4bb261fe 100644 (file)
@@ -1,29 +1,27 @@
 using Content.Shared.FixedPoint;
 using Content.Shared.Inventory;
 
-namespace Content.Server.Chemistry.Components
-{
-    /// <summary>
-    /// On colliding with an entity that has a bloodstream will dump its solution onto them.
-    /// </summary>
-    [RegisterComponent]
-    internal sealed partial class SolutionInjectOnCollideComponent : Component
-    {
+namespace Content.Server.Chemistry.Components;
 
-        [ViewVariables(VVAccess.ReadWrite)]
-        [DataField("transferAmount")]
-        public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(1);
+/// <summary>
+/// On colliding with an entity that has a bloodstream will dump its solution onto them.
+/// </summary>
+[RegisterComponent]
+public sealed partial class SolutionInjectOnCollideComponent : Component
+{
+    [ViewVariables(VVAccess.ReadWrite)]
+    [DataField("transferAmount")]
+    public FixedPoint2 TransferAmount = FixedPoint2.New(1);
 
-        [ViewVariables(VVAccess.ReadWrite)]
-        public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); }
+    [ViewVariables(VVAccess.ReadWrite)]
+    public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); }
 
-        [DataField("transferEfficiency")]
-        private float _transferEfficiency = 1f;
+    [DataField("transferEfficiency")]
+    private float _transferEfficiency = 1f;
 
-        /// <summary>
-        /// If anything covers any of these slots then the injection fails.
-        /// </summary>
-        [DataField("blockSlots"), ViewVariables(VVAccess.ReadWrite)]
-        public SlotFlags BlockSlots = SlotFlags.MASK;
-    }
+    /// <summary>
+    /// If anything covers any of these slots then the injection fails.
+    /// </summary>
+    [DataField("blockSlots"), ViewVariables(VVAccess.ReadWrite)]
+    public SlotFlags BlockSlots = SlotFlags.MASK;
 }
index f881240a09cfce3772721fe1ff96bf209534a45c..446be0ca772b854e8f5082e75d14cf266c40d378 100644 (file)
@@ -6,48 +6,47 @@ using Content.Shared.Inventory;
 using JetBrains.Annotations;
 using Robust.Shared.Physics.Events;
 
-namespace Content.Server.Chemistry.EntitySystems
+namespace Content.Server.Chemistry.EntitySystems;
+
+public sealed class SolutionInjectOnCollideSystem : EntitySystem
 {
-    [UsedImplicitly]
-    internal sealed class SolutionInjectOnCollideSystem : EntitySystem
+    [Dependency] private readonly SolutionContainerSystem _solutionContainersSystem = default!;
+    [Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
+    [Dependency] private readonly InventorySystem _inventorySystem = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<SolutionInjectOnCollideComponent, StartCollideEvent>(HandleInjection);
+    }
+
+    private void HandleInjection(Entity<SolutionInjectOnCollideComponent> ent, ref StartCollideEvent args)
     {
-        [Dependency] private readonly SolutionContainerSystem _solutionContainersSystem = default!;
-        [Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
-        [Dependency] private readonly InventorySystem _inventorySystem = default!;
+        var component = ent.Comp;
+        var target = args.OtherEntity;
 
-        public override void Initialize()
+        if (!args.OtherBody.Hard ||
+            !args.OurBody.Hard ||
+            !EntityManager.TryGetComponent<BloodstreamComponent>(target, out var bloodstream) ||
+            !_solutionContainersSystem.TryGetInjectableSolution(ent.Owner, out var solution, out _))
         {
-            base.Initialize();
-            SubscribeLocalEvent<SolutionInjectOnCollideComponent, StartCollideEvent>(HandleInjection);
+            return;
         }
 
-        private void HandleInjection(Entity<SolutionInjectOnCollideComponent> ent, ref StartCollideEvent args)
+        if (component.BlockSlots != 0x0)
         {
-            var component = ent.Comp;
-            var target = args.OtherEntity;
+            var containerEnumerator = _inventorySystem.GetSlotEnumerator(target, component.BlockSlots);
 
-            if (!args.OtherBody.Hard ||
-                !EntityManager.TryGetComponent<BloodstreamComponent>(target, out var bloodstream) ||
-                !_solutionContainersSystem.TryGetInjectableSolution(ent.Owner, out var solution, out _))
-            {
+            // TODO add a helper method for this?
+            if (containerEnumerator.MoveNext(out _))
                 return;
-            }
-
-            if (component.BlockSlots != 0x0)
-            {
-                var containerEnumerator = _inventorySystem.GetSlotEnumerator(target, component.BlockSlots);
-
-                // TODO add a helper method for this?
-                if (containerEnumerator.MoveNext(out _))
-                    return;
-            }
+        }
 
-            var solRemoved = _solutionContainersSystem.SplitSolution(solution.Value, component.TransferAmount);
-            var solRemovedVol = solRemoved.Volume;
+        var solRemoved = _solutionContainersSystem.SplitSolution(solution.Value, component.TransferAmount);
+        var solRemovedVol = solRemoved.Volume;
 
-            var solToInject = solRemoved.SplitSolution(solRemovedVol * component.TransferEfficiency);
+        var solToInject = solRemoved.SplitSolution(solRemovedVol * component.TransferEfficiency);
 
-            _bloodstreamSystem.TryAddToChemicals(target, solToInject, bloodstream);
-        }
+        _bloodstreamSystem.TryAddToChemicals(target, solToInject, bloodstream);
     }
 }