GasCanisterSystem cleanup, use EntityUid more.

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 13:00:08 +01:00
parent 11c63112d1
commit 5d66a08ac9

View File

@@ -29,6 +29,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
public override void Initialize()
{
@@ -53,7 +54,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
/// </summary>
public void PurgeContents(EntityUid uid, GasCanisterComponent? canister = null, TransformComponent? transform = null)
{
if (!Resolve(uid, ref canister, ref transform)) return;
if (!Resolve(uid, ref canister, ref transform))
return;
var environment = _atmosphereSystem.GetTileMixture(transform.Coordinates, true);
@@ -66,10 +68,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnCanisterStartup(EntityUid uid, GasCanisterComponent canister, ComponentStartup args)
{
// Ensure container manager.
if (!EntityManager.TryGetComponent(uid, out ContainerManagerComponent? containerManager))
{
containerManager = EntityManager.AddComponent<ContainerManagerComponent>(EntityManager.GetEntity(uid));
}
var containerManager = EntityManager.EnsureComponent<ContainerManagerComponent>(uid);
// Ensure container.
if (!containerManager.TryGetContainer(canister.ContainerName, out _))
@@ -80,9 +79,9 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private bool CheckInteract(ICommonSession session)
{
if (session.AttachedEntity is not {} entity
|| !Get<ActionBlockerSystem>().CanInteract(entity)
|| !Get<ActionBlockerSystem>().CanUse(entity))
if (session.AttachedEntityUid is not {} uid
|| !_actionBlockerSystem.CanInteract(uid)
|| !_actionBlockerSystem.CanUse(uid))
return false;
return true;
@@ -105,9 +104,9 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (containerManager.TryGetContainer(canister.ContainerName, out var tankContainer)
&& tankContainer.ContainedEntities.Count > 0)
{
var tank = tankContainer.ContainedEntities[0];
var tankComponent = tank.GetComponent<GasTankComponent>();
tankLabel = tank.Name;
var tank = tankContainer.ContainedEntities[0].Uid;
var tankComponent = EntityManager.GetComponent<GasTankComponent>(tank);
tankLabel = EntityManager.GetComponent<MetaDataComponent>(tank).EntityName;
tankPressure = tankComponent.Air.Pressure;
}
@@ -231,7 +230,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (!args.User.TryGetComponent(out ActorComponent? actor))
return;
component.Owner.GetUIOrNull(GasCanisterUiKey.Key)?.Open(actor.PlayerSession);
_userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession);
args.Handled = true;
}
@@ -241,7 +240,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (!args.User.TryGetComponent(out ActorComponent? actor))
return;
component.Owner.GetUIOrNull(GasCanisterUiKey.Key)?.Open(actor.PlayerSession);
_userInterfaceSystem.GetUiOrNull(uid, GasCanisterUiKey.Key)?.Open(actor.PlayerSession);
args.Handled = true;
}