2021-01-01 19:04:10 -06:00
|
|
|
using System.Collections.Generic;
|
2021-07-04 18:11:52 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-04-28 10:49:37 -07:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Map;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.NodeContainer.Nodes
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
|
|
|
|
/// <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
|
|
|
|
|
{
|
2021-07-04 18:11:52 +02:00
|
|
|
public override IEnumerable<Node> GetReachableNodes()
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
if (!IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Anchored)
|
2021-03-02 11:58:19 -07:00
|
|
|
yield break;
|
|
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
2021-12-03 15:53:09 +01:00
|
|
|
var grid = IoCManager.Resolve<IMapManager>().GetGrid(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).GridID);
|
|
|
|
|
var gridIndex = grid.TileIndicesFor(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
|
2021-04-09 20:47:31 +02:00
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
foreach (var (_, node) in NodeHelpers.GetCardinalNeighborNodes(entMan, grid, gridIndex))
|
2021-07-04 18:11:52 +02:00
|
|
|
{
|
|
|
|
|
if (node != this)
|
|
|
|
|
yield return node;
|
2021-01-01 19:04:10 -06:00
|
|
|
}
|
2020-06-28 09:23:26 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|