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

81 lines
2.8 KiB
C#
Raw Normal View History

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