Skip to content

Commit

Permalink
Make Droppers Respect Closed/Sealed Containers (#33011)
Browse files Browse the repository at this point in the history
* Make droppers respect closed/sealed

* Combine nested

* Optimize conditions a bit
  • Loading branch information
thetolbean authored Nov 12, 2024
1 parent a1966d8 commit 70e3650
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Content.Server/Chemistry/EntitySystems/InjectorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
using Content.Shared.Interaction;
using Content.Shared.Mobs.Components;
using Content.Shared.Stacks;
using Content.Shared.Nutrition.EntitySystems;

namespace Content.Server.Chemistry.EntitySystems;

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()
{
Expand All @@ -31,13 +33,14 @@ public override void Initialize()

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))
Expand All @@ -58,7 +61,7 @@ private bool TryUseInjector(Entity<InjectorComponent> injector, EntityUid target
}

// 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",
Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/Chemistry/Components/InjectorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
- type: Injector
injectOnly: false
ignoreMobs: true
ignoreClosed: false
minTransferAmount: 1
maxTransferAmount: 5
transferAmount: 1
Expand Down

0 comments on commit 70e3650

Please sign in to comment.