Fix arrow visibility for ghosts.

metacomming bad
This commit is contained in:
Víctor Aguilera Puerto
2020-08-21 13:32:04 +02:00
parent 02b5632dac
commit c042b46220
2 changed files with 21 additions and 4 deletions

View File

@@ -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
/// </summary>
private readonly Dictionary<ICommonSession, TimeSpan> _pointers = new Dictionary<ICommonSession, TimeSpan>();
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<VisibilityComponent>();
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;