Show ghosts popups etc through walls (#8077)

* Show ghosts popups etc through walls

* Stage moment

* crashes
This commit is contained in:
metalgearsloth
2022-05-12 21:18:38 +10:00
committed by GitHub
parent 40361ec0ad
commit 6903209a31
4 changed files with 25 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ public sealed class ChatSystem : SharedChatSystem
{
[Dependency] private readonly IChatManager _manager = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly ExamineSystem _examineSystem = default!;
public override void FrameUpdate(float frameTime)
{
@@ -23,6 +24,8 @@ public sealed class ChatSystem : SharedChatSystem
var bubbles = _manager.GetSpeechBubbles();
var playerPos = player != null ? Transform(player.Value).MapPosition : MapCoordinates.Nullspace;
var occluded = player != null && _examineSystem.IsOccluded(player.Value);
foreach (var (ent, bubs) in bubbles)
{
if (ent == player)
@@ -33,7 +36,7 @@ public sealed class ChatSystem : SharedChatSystem
var otherPos = Transform(ent).MapPosition;
if (!ExamineSystemShared.InRangeUnOccluded(
if (occluded && !ExamineSystemShared.InRangeUnOccluded(
playerPos,
otherPos, 0f,
(ent, player), predicate))

View File

@@ -5,6 +5,7 @@ using Content.Shared.Examine;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.GameStates;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -27,19 +28,18 @@ namespace Content.Client.DoAfter
*/
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;
/// <summary>
/// We'll use an excess time so stuff like finishing effects can show.
/// </summary>
public const float ExcessTime = 0.5f;
private EntityUid? _attachedEntity;
public override void Initialize()
{
base.Initialize();
UpdatesOutsidePrediction = true;
SubscribeLocalEvent<PlayerAttachSysMessage>(HandlePlayerAttached);
SubscribeNetworkEvent<CancelledDoAfterMessage>(OnCancelledDoAfter);
SubscribeLocalEvent<DoAfterComponent, ComponentStartup>(OnDoAfterStartup);
SubscribeLocalEvent<DoAfterComponent, ComponentShutdown>(OnDoAfterShutdown);
@@ -111,11 +111,6 @@ namespace Content.Client.DoAfter
Cancel(doAfter, ev.ID);
}
private void HandlePlayerAttached(PlayerAttachSysMessage message)
{
_attachedEntity = message.AttachedEntity;
}
/// <summary>
/// For handling PVS so we dispose of controls if they go out of range
/// </summary>
@@ -196,17 +191,19 @@ namespace Content.Client.DoAfter
base.Update(frameTime);
var currentTime = _gameTiming.CurTime;
var attached = _player.LocalPlayer?.ControlledEntity;
// Can't see any I guess?
if (_attachedEntity is not {Valid: true} entity || Deleted(entity))
if (attached == null || Deleted(attached))
return;
// ReSharper disable once ConvertToLocalFunction
var predicate = static (EntityUid uid, (EntityUid compOwner, EntityUid? attachedEntity) data)
=> uid == data.compOwner || uid == data.attachedEntity;
var occluded = _examineSystem.IsOccluded(attached.Value);
var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f);
var entXform = Transform(entity);
var entXform = Transform(attached.Value);
var playerPos = entXform.MapPosition;
foreach (var (comp, xform) in EntityManager.EntityQuery<DoAfterComponent, TransformComponent>(true))
@@ -224,11 +221,12 @@ namespace Content.Client.DoAfter
var range = (compPos.Position - playerPos.Position).Length + 0.01f;
if (comp.Owner != _attachedEntity &&
if (occluded &&
comp.Owner != attached &&
!ExamineSystemShared.InRangeUnOccluded(
playerPos,
compPos, range,
(comp.Owner, _attachedEntity), predicate))
(comp.Owner, attached), predicate))
{
Disable(comp);
continue;

View File

@@ -20,6 +20,7 @@ namespace Content.Client.Popups
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;
private readonly List<PopupLabel> _aliveLabels = new();
@@ -141,6 +142,7 @@ namespace Content.Client.Popups
// ReSharper disable once ConvertToLocalFunction
var predicate = static (EntityUid uid, (EntityUid? compOwner, EntityUid? attachedEntity) data)
=> uid == data.compOwner || uid == data.attachedEntity;
var occluded = player != null && _examineSystem.IsOccluded(player.Value);
for (var i = _aliveLabels.Count - 1; i >= 0; i--)
{
@@ -161,7 +163,7 @@ namespace Content.Client.Popups
var otherPos = label.Entity != null ? Transform(label.Entity.Value).MapPosition : label.InitialPos;
if (!ExamineSystemShared.InRangeUnOccluded(
if (occluded && !ExamineSystemShared.InRangeUnOccluded(
playerPos,
otherPos, 0f,
(label.Entity, player), predicate))

View File

@@ -102,6 +102,14 @@ namespace Content.Shared.Examine
return ExamineRange;
}
/// <summary>
/// True if occluders are drawn for this entity, otherwise false.
/// </summary>
public bool IsOccluded(EntityUid uid)
{
return TryComp<SharedEyeComponent>(uid, out var eye) && eye.DrawFov;
}
public static bool InRangeUnOccluded(MapCoordinates origin, MapCoordinates other, float range, Ignored? predicate, bool ignoreInsideBlocker = true, IEntityManager? entMan = null)
{
// No, rider. This is better.