Files
tbd-station-14/Content.Shared/Chemistry/EntitySystems/ScoopableSolutionSystem.cs
SlamBamActionman c6352786f1 Add doafter to filling the hypopen (#40538)
* Initial commit

* Small QOL buff

* Review changes

* Ch-ch-ch-ch-chaaaanges

* Review changes

* oops

* Oh ya fix the fill thing

* cleanup warnings make a few more private methods

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-10-21 22:05:44 +00:00

57 lines
2.0 KiB
C#

using Content.Shared.Chemistry.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Robust.Shared.Network;
namespace Content.Shared.Chemistry.EntitySystems;
/// <summary>
/// Handles solution transfer when a beaker is used on a scoopable entity.
/// </summary>
public sealed class ScoopableSolutionSystem : EntitySystem
{
[Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
[Dependency] private readonly SolutionTransferSystem _solutionTransfer = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ScoopableSolutionComponent, InteractUsingEvent>(OnInteractUsing);
}
private void OnInteractUsing(Entity<ScoopableSolutionComponent> ent, ref InteractUsingEvent args)
{
if (args.Handled)
return;
args.Handled = TryScoop(ent, args.Used, args.User);
}
public bool TryScoop(Entity<ScoopableSolutionComponent> ent, EntityUid beaker, EntityUid user)
{
if (!_solution.TryGetSolution(ent.Owner, ent.Comp.Solution, out var src, out var srcSolution) ||
!_solution.TryGetRefillableSolution(beaker, out var target, out _))
return false;
var scooped = _solutionTransfer.Transfer(new SolutionTransferData(user, ent, src.Value, beaker, target.Value, srcSolution.Volume));
if (scooped == 0)
return false;
_popup.PopupClient(Loc.GetString(ent.Comp.Popup, ("scooped", ent.Owner), ("beaker", beaker)), user, user);
if (srcSolution.Volume == 0 && ent.Comp.Delete)
{
// deletion isnt predicted so do this to prevent spam clicking to see "the ash is empty!"
RemCompDeferred<ScoopableSolutionComponent>(ent);
if (!_netManager.IsClient)
QueueDel(ent);
}
return true;
}
}