ECS visibility (#5769)

This commit is contained in:
metalgearsloth
2021-12-29 05:12:28 +11:00
committed by GitHub
parent 28df88ef21
commit 404accb18f
2 changed files with 12 additions and 7 deletions

View File

@@ -26,6 +26,7 @@ namespace Content.Server.Ghost
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
public override void Initialize()
{
@@ -59,10 +60,11 @@ namespace Content.Server.Ghost
private void OnGhostStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
{
// Allow this entity to be seen by other ghosts.
var visibility = component.Owner.EnsureComponent<VisibilityComponent>();
var visibility = EntityManager.EnsureComponent<VisibilityComponent>(component.Owner);
visibility.Layer |= (int) VisibilityFlags.Ghost;
visibility.Layer &= ~(int) VisibilityFlags.Normal;
_visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Ghost, false);
_visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Normal, false);
_visibilitySystem.RefreshVisibility(visibility);
if (EntityManager.TryGetComponent(component.Owner, out EyeComponent? eye))
{
@@ -80,8 +82,9 @@ namespace Content.Server.Ghost
// Entity can't be seen by ghosts anymore.
if (EntityManager.TryGetComponent(component.Owner, out VisibilityComponent? visibility))
{
visibility.Layer &= ~(int) VisibilityFlags.Ghost;
visibility.Layer |= (int) VisibilityFlags.Normal;
_visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Ghost, false);
_visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Normal, false);
_visibilitySystem.RefreshVisibility(visibility);
}
// Entity can't see ghosts anymore.

View File

@@ -33,6 +33,7 @@ namespace Content.Server.Pointing.EntitySystems
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
private static readonly TimeSpan PointDelay = TimeSpan.FromSeconds(0.5f);
@@ -127,8 +128,9 @@ namespace Content.Server.Pointing.EntitySystems
var layer = (int) VisibilityFlags.Normal;
if (TryComp(player, out VisibilityComponent? playerVisibility))
{
var arrowVisibility = arrow.EnsureComponent<VisibilityComponent>();
layer = arrowVisibility.Layer = playerVisibility.Layer;
var arrowVisibility = EntityManager.EnsureComponent<VisibilityComponent>(arrow);
layer = playerVisibility.Layer;
_visibilitySystem.SetLayer(arrowVisibility, layer);
}
// Get players that are in range and whose visibility layer matches the arrow's.