Files
tbd-station-14/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/BaseSiphonComponent.cs
ColdAutumnRain f5dc62b533 Removed EntityManager member variable from Components and EntitySystems (#2502)
* Removed EntityManager member variable from Components and EntitySystems

* Removed EntityManager with minor corecctions

* Update PathfindingSystem.cs

* Update InteractionSystem.cs

* Update Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>

* Update Content.Client/GameObjects/Components/Suspicion/SuspicionRoleComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Client/GameObjects/Components/Suspicion/TraitorOverlay.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/PDA/PDAComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Singularity/SingularityComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Singularity/SingularityComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/AI/Pathfinding/PathfindingSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/Click/ExamineSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

* Update Content.Server/GameObjects/Components/Stack/StackComponent.cs

Co-authored-by: Clyybber <darkmine956@gmail.com>

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: Clyybber <darkmine956@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
2020-11-18 15:45:53 +01:00

82 lines
2.8 KiB
C#

using System.Linq;
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers
{
/// <summary>
/// Transfers gas from the tile it is on to a <see cref="PipeNode"/>.
/// </summary>
public abstract class BaseSiphonComponent : PipeNetDeviceComponent
{
[ViewVariables]
private PipeNode _scrubberOutlet;
private AtmosphereSystem _atmosSystem;
[ViewVariables(VVAccess.ReadWrite)]
public bool SiphonEnabled
{
get => _siphonEnabled;
set
{
_siphonEnabled = value;
UpdateAppearance();
}
}
private bool _siphonEnabled = true;
private AppearanceComponent _appearance;
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;
}
Owner.TryGetComponent(out _appearance);
UpdateAppearance();
}
public override void Update()
{
if (!SiphonEnabled)
return;
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager);
if (tileAtmos == null)
return;
ScrubGas(tileAtmos.Air, _scrubberOutlet.Air);
_atmosSystem.GetGridAtmosphere(Owner.Transform.GridID)?.Invalidate(tileAtmos.GridIndices);
}
protected abstract void ScrubGas(GasMixture inletGas, GasMixture outletGas);
private void UpdateAppearance()
{
_appearance?.SetData(SiphonVisuals.VisualState, new SiphonVisualState(SiphonEnabled));
}
}
}