2021-01-28 20:21:08 -06:00
|
|
|
#nullable enable
|
2021-01-01 19:04:10 -06:00
|
|
|
using System.Collections.Generic;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A <see cref="Node"/> that can reach other <see cref="AdjacentNode"/>s that are directly adjacent to it.
|
|
|
|
|
/// </summary>
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
2020-06-28 09:23:26 -06:00
|
|
|
public class AdjacentNode : Node
|
|
|
|
|
{
|
|
|
|
|
protected override IEnumerable<Node> GetReachableNodes()
|
|
|
|
|
{
|
2021-04-09 20:47:31 +02:00
|
|
|
if (!Owner.TryGetComponent(out SnapGridComponent? snap))
|
2021-03-02 11:58:19 -07:00
|
|
|
yield break;
|
|
|
|
|
|
2021-04-09 20:47:31 +02:00
|
|
|
foreach (var cell in snap.GetCardinalNeighborCells())
|
|
|
|
|
foreach (var entity in cell.GetLocal())
|
2021-01-01 19:04:10 -06:00
|
|
|
{
|
2021-04-09 20:47:31 +02:00
|
|
|
if (!entity.TryGetComponent<NodeContainerComponent>(out var container)) continue;
|
|
|
|
|
|
|
|
|
|
foreach (var node in container.Nodes.Values)
|
2021-01-01 19:04:10 -06:00
|
|
|
{
|
2021-04-09 20:47:31 +02:00
|
|
|
if (node != null && node != this)
|
2021-01-01 19:04:10 -06:00
|
|
|
{
|
2021-04-09 20:47:31 +02:00
|
|
|
yield return node;
|
2021-01-01 19:04:10 -06:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-09 20:47:31 +02:00
|
|
|
|
2021-01-01 19:04:10 -06:00
|
|
|
}
|
2020-06-28 09:23:26 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|