Moved VisibilityFlags to EyeComponent (#3716)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Markers;
|
||||
@@ -40,32 +40,40 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
/// <inheritdoc />
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Initialize();
|
||||
base.Startup();
|
||||
|
||||
// Allow this entity to be seen by other ghosts.
|
||||
Owner.EnsureComponent<VisibilityComponent>().Layer = (int) VisibilityFlags.Ghost;
|
||||
|
||||
// Allows this entity to see other ghosts.
|
||||
Owner.EnsureComponent<EyeComponent>().VisibilityMask |= (uint) VisibilityFlags.Ghost;
|
||||
|
||||
_timeOfDeath = _gameTimer.RealTime;
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player) => new GhostComponentState(CanReturnToBody);
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
/// <inheritdoc />
|
||||
protected override void Shutdown()
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
|
||||
switch (message)
|
||||
//Perf: If the entity is deleting itself, no reason to change these back.
|
||||
if(Owner.LifeStage < EntityLifeStage.Terminating)
|
||||
{
|
||||
case PlayerAttachedMsg msg:
|
||||
msg.NewPlayer.VisibilityMask |= (int) VisibilityFlags.Ghost;
|
||||
Dirty();
|
||||
break;
|
||||
case PlayerDetachedMsg msg:
|
||||
msg.OldPlayer.VisibilityMask &= ~(int) VisibilityFlags.Ghost;
|
||||
break;
|
||||
// Entity can't be seen by ghosts anymore.
|
||||
if (Owner.TryGetComponent<VisibilityComponent>(out var visComp))
|
||||
visComp.Layer &= ~(int) VisibilityFlags.Ghost;
|
||||
|
||||
// Entity can't see ghosts anymore.
|
||||
if (Owner.TryGetComponent<EyeComponent>(out var eyeComp))
|
||||
eyeComp.VisibilityMask &= ~(uint) VisibilityFlags.Ghost;
|
||||
}
|
||||
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player) => new GhostComponentState(CanReturnToBody);
|
||||
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null!)
|
||||
{
|
||||
base.HandleNetworkMessage(message, netChannel, session);
|
||||
|
||||
@@ -131,13 +131,12 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
// 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);
|
||||
if (ent is null || (!ent.TryGetComponent<EyeComponent>(out var eyeComp) || (eyeComp.VisibilityMask & layer) != 0))
|
||||
return false;
|
||||
|
||||
return ent.Transform.MapPosition.InRange(player.Transform.MapPosition, PointingRange);
|
||||
});
|
||||
|
||||
string selfMessage;
|
||||
|
||||
@@ -3,9 +3,10 @@ using System;
|
||||
namespace Content.Server.GameObjects
|
||||
{
|
||||
[Flags]
|
||||
public enum VisibilityFlags
|
||||
public enum VisibilityFlags : uint
|
||||
{
|
||||
Normal = 1,
|
||||
Ghost = 2,
|
||||
None = 0,
|
||||
Normal = 1 << 0,
|
||||
Ghost = 1 << 1,
|
||||
}
|
||||
}
|
||||
|
||||
Submodule RobustToolbox updated: 4864096b2a...37fc0d0d2a
Reference in New Issue
Block a user