Files
tbd-station-14/Content.Server/GameObjects/Components/Atmos/Piping/Pumps/VolumePumpComponent.cs
20kdc b9aa789bc4 Pressure & volume pumps can be toggled on/off now. (#3046)
This tidbit might or might not be suitable for a separate component.
Tell me in PR comments I guess.
2021-02-04 20:47:04 +11:00

48 lines
1.5 KiB
C#

#nullable enable
using System;
using Content.Server.Atmos;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Atmos.Piping.Pumps
{
[RegisterComponent]
[ComponentReference(typeof(BasePumpComponent))]
[ComponentReference(typeof(IActivate))]
public class VolumePumpComponent : BasePumpComponent
{
[ViewVariables(VVAccess.ReadWrite)]
public int VolumePumpRate
{
get => _volumePumpRate;
set => _volumePumpRate = Math.Clamp(value, 0, MaxVolumePumpRate);
}
private int _volumePumpRate;
[ViewVariables(VVAccess.ReadWrite)]
public int MaxVolumePumpRate
{
get => _maxVolumePumpRate;
set => Math.Max(value, 0);
}
private int _maxVolumePumpRate;
public override string Name => "VolumePump";
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _volumePumpRate, "startingVolumePumpRate", 0);
serializer.DataField(ref _maxVolumePumpRate, "maxVolumePumpRate", 100);
}
protected override void PumpGas(GasMixture inletGas, GasMixture outletGas)
{
var volumeRatio = Math.Clamp(VolumePumpRate / inletGas.Volume, 0, 1);
outletGas.Merge(inletGas.RemoveRatio(volumeRatio));
}
}
}