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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.GameObjects.Components.Markers;
|
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;
|
Owner.EnsureComponent<VisibilityComponent>().Layer = (int) VisibilityFlags.Ghost;
|
||||||
|
|
||||||
|
// Allows this entity to see other ghosts.
|
||||||
|
Owner.EnsureComponent<EyeComponent>().VisibilityMask |= (uint) VisibilityFlags.Ghost;
|
||||||
|
|
||||||
_timeOfDeath = _gameTimer.RealTime;
|
_timeOfDeath = _gameTimer.RealTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Shutdown()
|
||||||
|
{
|
||||||
|
//Perf: If the entity is deleting itself, no reason to change these back.
|
||||||
|
if(Owner.LifeStage < EntityLifeStage.Terminating)
|
||||||
|
{
|
||||||
|
// 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 ComponentState GetComponentState(ICommonSession player) => new GhostComponentState(CanReturnToBody);
|
||||||
|
|
||||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
|
||||||
{
|
|
||||||
base.HandleMessage(message, component);
|
|
||||||
|
|
||||||
switch (message)
|
|
||||||
{
|
|
||||||
case PlayerAttachedMsg msg:
|
|
||||||
msg.NewPlayer.VisibilityMask |= (int) VisibilityFlags.Ghost;
|
|
||||||
Dirty();
|
|
||||||
break;
|
|
||||||
case PlayerDetachedMsg msg:
|
|
||||||
msg.OldPlayer.VisibilityMask &= ~(int) VisibilityFlags.Ghost;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null!)
|
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null!)
|
||||||
{
|
{
|
||||||
base.HandleNetworkMessage(message, netChannel, session);
|
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.
|
// Get players that are in range and whose visibility layer matches the arrow's.
|
||||||
var viewers = _playerManager.GetPlayersBy((playerSession) =>
|
var viewers = _playerManager.GetPlayersBy((playerSession) =>
|
||||||
{
|
{
|
||||||
if ((playerSession.VisibilityMask & layer) == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var ent = playerSession.ContentData()?.Mind?.CurrentEntity;
|
var ent = playerSession.ContentData()?.Mind?.CurrentEntity;
|
||||||
|
|
||||||
return ent != null
|
if (ent is null || (!ent.TryGetComponent<EyeComponent>(out var eyeComp) || (eyeComp.VisibilityMask & layer) != 0))
|
||||||
&& ent.Transform.MapPosition.InRange(player.Transform.MapPosition, PointingRange);
|
return false;
|
||||||
|
|
||||||
|
return ent.Transform.MapPosition.InRange(player.Transform.MapPosition, PointingRange);
|
||||||
});
|
});
|
||||||
|
|
||||||
string selfMessage;
|
string selfMessage;
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ using System;
|
|||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
{
|
{
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum VisibilityFlags
|
public enum VisibilityFlags : uint
|
||||||
{
|
{
|
||||||
Normal = 1,
|
None = 0,
|
||||||
Ghost = 2,
|
Normal = 1 << 0,
|
||||||
|
Ghost = 1 << 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule RobustToolbox updated: 4864096b2a...37fc0d0d2a
Reference in New Issue
Block a user