Files
tbd-station-14/Content.Server/Power/Nodes/CableDeviceNode.cs
Vera Aguilera Puerto a5b57c8e10 Inline Transform
2021-12-03 14:20:34 +01:00

34 lines
1.2 KiB
C#

using System.Collections.Generic;
using Content.Server.NodeContainer.Nodes;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Power.Nodes
{
/// <summary>
/// Type of node that connects to a <see cref="CableNode"/> below it.
/// </summary>
[DataDefinition]
public class CableDeviceNode : Node
{
public override IEnumerable<Node> GetReachableNodes()
{
var entMan = IoCManager.Resolve<IEntityManager>();
// If we're in an invalid grid, such as grid 0, we cannot connect to anything.
if(!IoCManager.Resolve<IMapManager>().TryGetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner.Uid).GridID, out var grid))
yield break;
var gridIndex = grid.TileIndicesFor(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner.Uid).Coordinates);
foreach (var node in NodeHelpers.GetNodesInTile(entMan, grid, gridIndex))
{
if (node is CableNode)
yield return node;
}
}
}
}