-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathPlumbingOutputSystem.cs
More file actions
74 lines (60 loc) · 2.82 KB
/
Copy pathPlumbingOutputSystem.cs
File metadata and controls
74 lines (60 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Linq;
using Content.Server.Popups;
using Content.Shared._Starlight.Chemistry.Components;
using Content.Shared._Starlight.Plumbing.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using JetBrains.Annotations;
using NetCord;
namespace Content.Server._Starlight.Plumbing.EntitySystems;
/// <summary>
/// Handles plumbing output machine behavior: A small tank that players can draw reagents from.
/// Pulling from the network is handled by <see cref="PlumbingInletSystem"/> via <see cref="PlumbingInletComponent"/>.
/// </summary>
[UsedImplicitly]
public sealed partial class PlumbingOutputSystem : EntitySystem
{
[Dependency] private SharedSolutionContainerSystem _solutionSystem = default!;
[Dependency] private PopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlumbingOutputComponent, InteractUsingEvent>(OnOutputInteractUsing);
}
private void OnOutputInteractUsing(Entity<PlumbingOutputComponent> ent, ref InteractUsingEvent args)
{
if (args.Handled)
return;
if (!_solutionSystem.TryGetRefillableSolution(args.Used, out var refillableSolutionEnt, out var refillableSolution))
return;
if (!_solutionSystem.TryGetSolution(ent.Owner, ent.Comp.SolutionName, out var outputSolutionEnt, out var outputSolution))
return;
// Starlight Start
if (TryComp<RefillReagentFilterComponent>(args.Used, out var filter)
&& outputSolution.Contents.Any(sol => !filter.Reagents.Contains(sol.Reagent.Prototype)))
{
// Incorrect reagents being put into our lovely automenders (and anything with filters)!
if (args.User is { Valid: true })
_popup.PopupEntity(Loc.GetString(filter.Popup), ent.Owner, args.User);
args.Handled = true;
return;
}
// Starlight End
var transferAmount = outputSolution.Volume;
if (TryComp<SolutionTransferComponent>(args.Used, out var transferComp))
transferAmount = FixedPoint2.Min(transferAmount, transferComp.TransferAmount);
var space = refillableSolution.AvailableVolume;
var toTransfer = FixedPoint2.Min(transferAmount, space);
if (toTransfer <= 0)
{
_popup.PopupEntity(Loc.GetString("plumbing-output-empty"), ent.Owner, args.User);
return;
}
var split = _solutionSystem.SplitSolution(outputSolutionEnt.Value, toTransfer);
_solutionSystem.TryAddSolution(refillableSolutionEnt.Value, split);
_popup.PopupEntity(Loc.GetString("plumbing-output-filled", ("amount", toTransfer)), ent.Owner, args.User);
args.Handled = true;
}
}