2020-08-27 09:45:27 -06:00
using Content.Server.Atmos ;
using Content.Server.GameObjects.Components.NodeContainer ;
using Content.Server.GameObjects.Components.NodeContainer.Nodes ;
using Content.Server.GameObjects.EntitySystems ;
using Robust.Shared.GameObjects.Systems ;
using Robust.Shared.Log ;
using Robust.Shared.ViewVariables ;
using System.Linq ;
2020-09-06 16:11:53 +02:00
using Robust.Shared.Interfaces.GameObjects ;
using Robust.Shared.IoC ;
2020-08-27 09:45:27 -06:00
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Transfers gas from the tile it is on to a <see cref="PipeNode"/>.
/// </summary>
public abstract class BaseSiphonComponent : PipeNetDeviceComponent
{
2020-09-06 16:11:53 +02:00
[Dependency] private readonly IEntityManager _entityManager = default ! ;
2020-08-27 09:45:27 -06:00
[ViewVariables]
private PipeNode _scrubberOutlet ;
private AtmosphereSystem _atmosSystem ;
public override void Initialize ( )
{
base . Initialize ( ) ;
_atmosSystem = EntitySystem . Get < AtmosphereSystem > ( ) ;
if ( ! Owner . TryGetComponent < NodeContainerComponent > ( out var container ) )
{
JoinedGridAtmos ? . RemovePipeNetDevice ( this ) ;
Logger . Error ( $"{typeof(BaseSiphonComponent)} on entity {Owner.Uid} did not have a {nameof(NodeContainerComponent)}." ) ;
return ;
}
_scrubberOutlet = container . Nodes . OfType < PipeNode > ( ) . FirstOrDefault ( ) ;
if ( _scrubberOutlet = = null )
{
JoinedGridAtmos ? . RemovePipeNetDevice ( this ) ;
Logger . Error ( $"{typeof(BaseSiphonComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}." ) ;
return ;
}
}
public override void Update ( )
{
2020-09-06 16:11:53 +02:00
var tileAtmos = Owner . Transform . Coordinates . GetTileAtmosphere ( _entityManager ) ;
2020-08-27 09:45:27 -06:00
if ( tileAtmos = = null )
return ;
ScrubGas ( tileAtmos . Air , _scrubberOutlet . Air ) ;
2020-09-06 16:11:53 +02:00
_atmosSystem . GetGridAtmosphere ( Owner . Transform . GridID ) ? . Invalidate ( tileAtmos . GridIndices ) ;
2020-08-27 09:45:27 -06:00
}
protected abstract void ScrubGas ( GasMixture inletGas , GasMixture outletGas ) ;
}
}