From fb4dc39d97bcca8c00c51df3a46726e55cac5789 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Mon, 22 Jan 2024 15:45:34 -0500 Subject: [PATCH 1/2] Block access to solutions in equipped spillables. --- .../Fluids/EntitySystems/PuddleSystem.Spillable.cs | 12 ++++++++++++ .../Components/BlockSolutionAccessComponent.cs | 11 +++++++++++ .../EntitySystems/SharedSolutionContainerSystem.cs | 9 +++++++++ 3 files changed, 32 insertions(+) create mode 100644 Content.Shared/Chemistry/Components/BlockSolutionAccessComponent.cs diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs index 177391de22d280..227494aac35cb9 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs @@ -36,6 +36,7 @@ private void InitializeSpillable() SubscribeLocalEvent(SplashOnMeleeHit, after: new[] { typeof(OpenableSystem) }); SubscribeLocalEvent>(AddSpillVerb); SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); SubscribeLocalEvent(OnOverflow); SubscribeLocalEvent(OnDoAfter); SubscribeLocalEvent(OnAttemptPacifiedThrow); @@ -132,6 +133,9 @@ private void OnGotEquipped(Entity entity, ref GotEquippedEve if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution)) return; + // block access to the solution while worn + AddComp(entity); + if (solution.Volume == 0) return; @@ -140,6 +144,14 @@ private void OnGotEquipped(Entity entity, ref GotEquippedEve TrySplashSpillAt(entity.Owner, Transform(args.Equipee).Coordinates, drainedSolution, out _); } + private void OnGotUnequipped(Entity entity, ref GotUnequippedEvent args) + { + if (!entity.Comp.SpillWorn) + return; + + RemCompDeferred(entity); + } + private void SpillOnLand(Entity entity, ref LandEvent args) { if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln, out var solution)) diff --git a/Content.Shared/Chemistry/Components/BlockSolutionAccessComponent.cs b/Content.Shared/Chemistry/Components/BlockSolutionAccessComponent.cs new file mode 100644 index 00000000000000..182f92d7d33239 --- /dev/null +++ b/Content.Shared/Chemistry/Components/BlockSolutionAccessComponent.cs @@ -0,0 +1,11 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Chemistry.Components; + +/// +/// Blocks all attempts to access solutions contained by this entity. +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class BlockSolutionAccessComponent : Component +{ +} diff --git a/Content.Shared/Chemistry/EntitySystems/SharedSolutionContainerSystem.cs b/Content.Shared/Chemistry/EntitySystems/SharedSolutionContainerSystem.cs index 32ecdd4ba6fde0..acacf9d24e5cfb 100644 --- a/Content.Shared/Chemistry/EntitySystems/SharedSolutionContainerSystem.cs +++ b/Content.Shared/Chemistry/EntitySystems/SharedSolutionContainerSystem.cs @@ -133,6 +133,12 @@ public bool TryGetSolution(Entity container, /// public bool TryGetSolution(Entity container, string? name, [NotNullWhen(true)] out Entity? entity) { + if (TryComp(container, out BlockSolutionAccessComponent? blocker)) + { + entity = null; + return false; + } + EntityUid uid; if (name is null) uid = container; @@ -178,6 +184,9 @@ public bool TryGetSolution(SolutionContainerManagerComponent container, string n if (!Resolve(container, ref container.Comp, logMissing: false)) yield break; + if (HasComp(container)) + yield break; + foreach (var name in container.Comp.Containers) { if (ContainerSystem.GetContainer(container, $"solution@{name}") is ContainerSlot slot && slot.ContainedEntity is { } solutionId) From 1f62f9e62d2f0d7e2e271ffe3522a47eef61ed20 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 26 Mar 2024 12:30:09 -0400 Subject: [PATCH 2/2] Stop Drink verb appearing if the solution can't be accessed. --- Content.Server/Nutrition/EntitySystems/DrinkSystem.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs index f41ca44437b1e6..49de654e4ac9c1 100644 --- a/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/DrinkSystem.cs @@ -411,6 +411,10 @@ private void AddDrinkVerb(Entity entity, ref GetVerbsEvent(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;