* move SolutionTransfer to shared and predict as much as possible * fully move OpenableSystem to shared now that SolutionTransfer is * fix imports for everything * doc for solution transfer system * trolling * add scoopable system * make ash and foam scoopable * untroll * untroll real * make clickable it work * troll * the scooping room --------- Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
54 lines
1.9 KiB
C#
54 lines
1.9 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)
|
|
{
|
|
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(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;
|
|
}
|
|
}
|