]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Prevent storing liquids in equipped buckets (#24412)
authorTayrtahn <tayrtahn@gmail.com>
Sun, 31 Mar 2024 04:40:22 +0000 (00:40 -0400)
committerGitHub <noreply@github.com>
Sun, 31 Mar 2024 04:40:22 +0000 (15:40 +1100)
* Block access to solutions in equipped spillables.

* Stop Drink verb appearing if the solution can't be accessed.

Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs
Content.Server/Nutrition/EntitySystems/DrinkSystem.cs
Content.Shared/Chemistry/Components/BlockSolutionAccessComponent.cs [new file with mode: 0644]
Content.Shared/Chemistry/EntitySystems/SharedSolutionContainerSystem.cs

index ce5b5b363782ba1b939459ef17ecb9c01b17e3c2..a365b8d0a45266ffa3d3350610da2395ed0bb412 100644 (file)
@@ -29,6 +29,7 @@ public sealed partial class PuddleSystem
         // Openable handles the event if it's closed
         SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: [typeof(OpenableSystem)]);
         SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
+        SubscribeLocalEvent<SpillableComponent, GotUnequippedEvent>(OnGotUnequipped);
         SubscribeLocalEvent<SpillableComponent, SolutionContainerOverflowEvent>(OnOverflow);
         SubscribeLocalEvent<SpillableComponent, SpillDoAfterEvent>(OnDoAfter);
         SubscribeLocalEvent<SpillableComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
@@ -114,6 +115,9 @@ public sealed partial class PuddleSystem
         if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution))
             return;
 
+        // block access to the solution while worn
+        AddComp<BlockSolutionAccessComponent>(entity);
+
         if (solution.Volume == 0)
             return;
 
@@ -122,6 +126,14 @@ public sealed partial class PuddleSystem
         TrySplashSpillAt(entity.Owner, Transform(args.Equipee).Coordinates, drainedSolution, out _);
     }
 
+    private void OnGotUnequipped(Entity<SpillableComponent> entity, ref GotUnequippedEvent args)
+    {
+        if (!entity.Comp.SpillWorn)
+            return;
+
+        RemCompDeferred<BlockSolutionAccessComponent>(entity);
+    }
+
     private void SpillOnLand(Entity<SpillableComponent> entity, ref LandEvent args)
     {
         if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution))
index 5fb090087a75e51eebf81a1309294143a52c35b8..036c855dbbac1ec2d481c70a768e26416b217cd1 100644 (file)
@@ -410,6 +410,10 @@ public sealed class DrinkSystem : EntitySystem
             !_body.TryGetBodyOrganComponents<StomachComponent>(ev.User, out var stomachs, body))
             return;
 
+        // Make sure the solution exists
+        if (!_solutionContainer.TryGetSolution(entity.Owner, entity.Comp.Solution, out var solution))
+            return;
+
         // no drinking from living drinks, have to kill them first.
         if (_mobState.IsAlive(entity))
             return;
diff --git a/Content.Shared/Chemistry/Components/BlockSolutionAccessComponent.cs b/Content.Shared/Chemistry/Components/BlockSolutionAccessComponent.cs
new file mode 100644 (file)
index 0000000..182f92d
--- /dev/null
@@ -0,0 +1,11 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Chemistry.Components;
+
+/// <summary>
+/// Blocks all attempts to access solutions contained by this entity.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class BlockSolutionAccessComponent : Component
+{
+}
index 6e762aa59843745fc320cb3be3414a89362fe24e..d71fffcdee675cc1b9020b541b5261b473737b82 100644 (file)
@@ -133,6 +133,12 @@ public abstract partial class SharedSolutionContainerSystem : EntitySystem
     /// <inheritdoc cref="TryGetSolution"/>
     public bool TryGetSolution(Entity<SolutionContainerManagerComponent?> container, string? name, [NotNullWhen(true)] out Entity<SolutionComponent>? entity)
     {
+        if (TryComp(container, out BlockSolutionAccessComponent? blocker))
+        {
+            entity = null;
+            return false;
+        }
+
         EntityUid uid;
         if (name is null)
             uid = container;
@@ -178,6 +184,9 @@ public abstract partial class SharedSolutionContainerSystem : EntitySystem
         if (!Resolve(container, ref container.Comp, logMissing: false))
             yield break;
 
+        if (HasComp<BlockSolutionAccessComponent>(container))
+            yield break;
+
         foreach (var name in container.Comp.Containers)
         {
             if (ContainerSystem.GetContainer(container, $"solution@{name}") is ContainerSlot slot && slot.ContainedEntity is { } solutionId)