]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make Droppers Respect Closed/Sealed Containers (#33011)
authorPreston Smith <92108534+thetolbean@users.noreply.github.com>
Tue, 12 Nov 2024 12:06:43 +0000 (06:06 -0600)
committerGitHub <noreply@github.com>
Tue, 12 Nov 2024 12:06:43 +0000 (19:06 +0700)
* Make droppers respect closed/sealed

* Combine nested

* Optimize conditions a bit

Content.Server/Chemistry/EntitySystems/InjectorSystem.cs
Content.Shared/Chemistry/Components/InjectorComponent.cs
Resources/Prototypes/Entities/Objects/Specific/chemistry.yml

index c5c45daa5bd5818d07ee5eb280221b792b5f9131..eb2039604afdabfd575a3158947b8a6d53d6de65 100644 (file)
@@ -13,6 +13,7 @@ using Content.Shared.IdentityManagement;
 using Content.Shared.Interaction;
 using Content.Shared.Mobs.Components;
 using Content.Shared.Stacks;
+using Content.Shared.Nutrition.EntitySystems;
 
 namespace Content.Server.Chemistry.EntitySystems;
 
@@ -20,6 +21,7 @@ public sealed class InjectorSystem : SharedInjectorSystem
 {
     [Dependency] private readonly BloodstreamSystem _blood = default!;
     [Dependency] private readonly ReactiveSystem _reactiveSystem = default!;
+    [Dependency] private readonly OpenableSystem _openable = default!;
 
     public override void Initialize()
     {
@@ -31,13 +33,14 @@ public sealed class InjectorSystem : SharedInjectorSystem
 
     private bool TryUseInjector(Entity<InjectorComponent> injector, EntityUid target, EntityUid user)
     {
+        var isOpenOrIgnored = injector.Comp.IgnoreClosed || !_openable.IsClosed(target);
         // Handle injecting/drawing for solutions
         if (injector.Comp.ToggleState == InjectorToggleMode.Inject)
         {
-            if (SolutionContainers.TryGetInjectableSolution(target, out var injectableSolution, out _))
+            if (isOpenOrIgnored && SolutionContainers.TryGetInjectableSolution(target, out var injectableSolution, out _))
                 return TryInject(injector, target, injectableSolution.Value, user, false);
 
-            if (SolutionContainers.TryGetRefillableSolution(target, out var refillableSolution, out _))
+            if (isOpenOrIgnored && SolutionContainers.TryGetRefillableSolution(target, out var refillableSolution, out _))
                 return TryInject(injector, target, refillableSolution.Value, user, true);
 
             if (TryComp<BloodstreamComponent>(target, out var bloodstream))
@@ -58,7 +61,7 @@ public sealed class InjectorSystem : SharedInjectorSystem
             }
 
             // Draw from an object (food, beaker, etc)
-            if (SolutionContainers.TryGetDrawableSolution(target, out var drawableSolution, out _))
+            if (isOpenOrIgnored && SolutionContainers.TryGetDrawableSolution(target, out var drawableSolution, out _))
                 return TryDraw(injector, target, drawableSolution.Value, user);
 
             Popup.PopupEntity(Loc.GetString("injector-component-cannot-draw-message",
index 17a65ef1c179cf93f129c6c898ffd872b9758721..ebd6654d9f5ca3af54bdd984b4bc6eb552210760 100644 (file)
@@ -45,6 +45,15 @@ public sealed partial class InjectorComponent : Component
     [DataField]
     public bool IgnoreMobs;
 
+    /// <summary>
+    /// Whether or not the injector is able to draw from or inject into containers that are closed/sealed
+    /// </summary>
+    /// <remarks>
+    ///     for example: droppers can not inject into cans, but syringes can
+    /// </remarks>
+    [DataField]
+    public bool IgnoreClosed = true;
+
     /// <summary>
     ///     The minimum amount of solution that can be transferred at once from this solution.
     /// </summary>
index 527b0ba5e620cce5b18d3600bee5712c4203b5ef..edaa8288145ebd905af0f6e57c2a45e25b58652a 100644 (file)
   - type: Injector
     injectOnly: false
     ignoreMobs: true
+    ignoreClosed: false
     minTransferAmount: 1
     maxTransferAmount: 5
     transferAmount: 1