Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent storing liquids in equipped buckets #24412

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Content.Server/Fluids/EntitySystems/PuddleSystem.Spillable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected override void InitializeSpillable()
SubscribeLocalEvent<SpillableComponent, MeleeHitEvent>(SplashOnMeleeHit, after: [typeof(OpenableSystem)]);
SubscribeLocalEvent<SpillableComponent, GetVerbsEvent<Verb>>(AddSpillVerb);
SubscribeLocalEvent<SpillableComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<SpillableComponent, GotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<SpillableComponent, SolutionContainerOverflowEvent>(OnOverflow);
SubscribeLocalEvent<SpillableComponent, SpillDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<SpillableComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
Expand Down Expand Up @@ -121,6 +122,9 @@ private void OnGotEquipped(Entity<SpillableComponent> 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<BlockSolutionAccessComponent>(entity);

if (solution.Volume == 0)
return;

Expand All @@ -129,6 +133,14 @@ private void OnGotEquipped(Entity<SpillableComponent> entity, ref GotEquippedEve
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))
Expand Down
4 changes: 4 additions & 0 deletions Content.Server/Nutrition/EntitySystems/DrinkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ private void AddDrinkVerb(Entity<DrinkComponent> entity, ref GetVerbsEvent<Alter
!_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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public bool TryGetSolution(Entity<SolutionContainerManagerComponent?> container,
/// <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;
Expand Down Expand Up @@ -178,6 +184,9 @@ public bool TryGetSolution(SolutionContainerManagerComponent container, string n
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)
Expand Down
Loading