Files
OldThink/Content.Server/Fluids/EntitySystems/PuddleSystem.Transfers.cs

72 lines
2.7 KiB
C#
Raw Permalink Normal View History

2023-04-10 15:37:03 +10:00
using Content.Shared.Chemistry.Components;
using Content.Shared.DragDrop;
using Content.Shared.FixedPoint;
using Content.Shared.Fluids;
namespace Content.Server.Fluids.EntitySystems;
public sealed partial class PuddleSystem
{
private void InitializeTransfers()
{
SubscribeLocalEvent<RefillableSolutionComponent, DragDropDraggedEvent>(OnRefillableDragged);
}
private void OnRefillableDragged(Entity<RefillableSolutionComponent> entity, ref DragDropDraggedEvent args)
2023-04-10 15:37:03 +10:00
{
if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.Solution, out var soln, out var solution) || solution.Volume == FixedPoint2.Zero)
2023-04-10 15:37:03 +10:00
{
_popups.PopupEntity(Loc.GetString("mopping-system-empty", ("used", entity.Owner)), entity, args.User);
2023-04-10 15:37:03 +10:00
return;
}
// Dump reagents into DumpableSolution
if (TryComp<DumpableSolutionComponent>(args.Target, out var dump))
2023-04-10 15:37:03 +10:00
{
if (!_solutionContainerSystem.TryGetDumpableSolution((args.Target, dump, null), out var dumpableSoln, out var dumpableSolution))
2023-04-10 15:37:03 +10:00
return;
bool success = true;
if (dump.Unlimited)
{
var split = _solutionContainerSystem.SplitSolution(soln.Value, solution.Volume);
dumpableSolution.AddSolution(split, _prototypeManager);
}
else
{
var split = _solutionContainerSystem.SplitSolution(soln.Value, dumpableSolution.AvailableVolume);
success = _solutionContainerSystem.TryAddSolution(dumpableSoln.Value, split);
}
2023-04-10 15:37:03 +10:00
if (success)
2023-04-10 15:37:03 +10:00
{
_audio.PlayPvs(AbsorbentComponent.DefaultTransferSound, args.Target);
}
else
{
_popups.PopupEntity(Loc.GetString("mopping-system-full", ("used", args.Target)), args.Target, args.User);
}
return;
}
// Take reagents from target
if (!TryComp<DrainableSolutionComponent>(args.Target, out var drainable))
2023-04-10 15:37:03 +10:00
{
if (!_solutionContainerSystem.TryGetDrainableSolution((args.Target, drainable, null), out var drainableSolution, out _))
2023-04-10 15:37:03 +10:00
return;
var split = _solutionContainerSystem.SplitSolution(drainableSolution.Value, solution.AvailableVolume);
2023-04-10 15:37:03 +10:00
if (_solutionContainerSystem.TryAddSolution(soln.Value, split))
2023-04-10 15:37:03 +10:00
{
_audio.PlayPvs(AbsorbentComponent.DefaultTransferSound, entity);
2023-04-10 15:37:03 +10:00
}
else
{
_popups.PopupEntity(Loc.GetString("mopping-system-full", ("used", entity.Owner)), entity, args.User);
2023-04-10 15:37:03 +10:00
}
}
}
}