diff --git a/Content.Server/GameObjects/EntitySystems/PointingSystem.cs b/Content.Server/GameObjects/EntitySystems/PointingSystem.cs index 28efbd4f8a..301d55db95 100644 --- a/Content.Server/GameObjects/EntitySystems/PointingSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/PointingSystem.cs @@ -2,10 +2,13 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.Components.Pointing; +using Content.Server.Players; +using Content.Server.Utility; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Input; using Content.Shared.Interfaces; using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; using Robust.Server.GameObjects.Components; using Robust.Server.Interfaces.Player; using Robust.Server.Player; @@ -40,6 +43,8 @@ namespace Content.Server.GameObjects.EntitySystems /// private readonly Dictionary _pointers = new Dictionary(); + private const float PointingRange = 15f; + private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) { if (e.NewStatus != SessionStatus.Disconnected) @@ -79,7 +84,7 @@ namespace Content.Server.GameObjects.EntitySystems public bool TryPoint(ICommonSession? session, GridCoordinates coords, EntityUid uid) { - var player = session?.AttachedEntity; + var player = (session as IPlayerSession)?.ContentData().Mind.CurrentEntity; if (player == null) { return false; @@ -112,16 +117,27 @@ namespace Content.Server.GameObjects.EntitySystems } } - var viewers = _playerManager.GetPlayersInRange(player.Transform.GridPosition, 15); - var arrow = EntityManager.SpawnEntity("pointingarrow", coords); + var layer = (int)VisibilityFlags.Normal; if (player.TryGetComponent(out VisibilityComponent? playerVisibility)) { var arrowVisibility = arrow.EnsureComponent(); - arrowVisibility.Layer = playerVisibility.Layer; + layer = arrowVisibility.Layer = playerVisibility.Layer; } + // Get players that are in range and whose visibility layer matches the arrow's. + var viewers = _playerManager.GetPlayersBy((playerSession) => + { + if ((playerSession.VisibilityMask & layer) == 0) + return false; + + var ent = playerSession.ContentData().Mind.CurrentEntity; + + return ent != null + && ent.Transform.MapPosition.InRange(player.Transform.MapPosition, PointingRange); + }); + string selfMessage; string viewerMessage; string? viewerPointedAtMessage = null; diff --git a/Content.Server/GameObjects/VisibilityFlags.cs b/Content.Server/GameObjects/VisibilityFlags.cs index 4acb9c988a..bcd103ddfc 100644 --- a/Content.Server/GameObjects/VisibilityFlags.cs +++ b/Content.Server/GameObjects/VisibilityFlags.cs @@ -5,6 +5,7 @@ namespace Content.Server.GameObjects [Flags] public enum VisibilityFlags { + Normal = 1, Ghost = 2, } }