Ghosts now make use of the new "entity visibility" engine functionality

This commit is contained in:
zumorica
2020-04-10 16:28:14 +02:00
parent aff9f18bc8
commit 683644eec5
3 changed files with 24 additions and 3 deletions

View File

@@ -34,7 +34,6 @@ namespace Content.Client.GameObjects.Components.Observer
private void SetGhostVisibility(bool visibility) private void SetGhostVisibility(bool visibility)
{ {
// So, for now this is a client-side hack... Please, PLEASE someone make this work server-side.
foreach (var ghost in _componentManager.GetAllComponents(typeof(GhostComponent))) foreach (var ghost in _componentManager.GetAllComponents(typeof(GhostComponent)))
{ {
if (ghost.Owner.TryGetComponent(out SpriteComponent component)) if (ghost.Owner.TryGetComponent(out SpriteComponent component))

View File

@@ -2,6 +2,7 @@ using Content.Server.GameObjects.EntitySystems;
using Content.Server.Players; using Content.Server.Players;
using Content.Shared.GameObjects.Components.Observer; using Content.Shared.GameObjects.Components.Observer;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
@@ -28,6 +29,13 @@ namespace Content.Server.GameObjects.Components.Observer
} }
} }
public override void Initialize()
{
base.Initialize();
Owner.EnsureComponent<VisibilityComponent>().Layer = (int)VisibilityFlags.Ghost;
}
public override ComponentState GetComponentState() => new GhostComponentState(CanReturnToBody); public override ComponentState GetComponentState() => new GhostComponentState(CanReturnToBody);
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null,
@@ -44,10 +52,12 @@ namespace Content.Server.GameObjects.Components.Observer
actor.playerSession.ContentData().Mind.UnVisit(); actor.playerSession.ContentData().Mind.UnVisit();
} }
break; break;
case PlayerAttachedMsg _: case PlayerAttachedMsg msg:
msg.NewPlayer.VisibilityMask |= (int)VisibilityFlags.Ghost;
Dirty(); Dirty();
break; break;
case PlayerDetachedMsg _: case PlayerDetachedMsg msg:
msg.OldPlayer.VisibilityMask &= ~(int)VisibilityFlags.Ghost;
Timer.Spawn(100, Owner.Delete); Timer.Spawn(100, Owner.Delete);
break; break;
default: default:

View File

@@ -0,0 +1,12 @@
using System;
namespace Content.Server.GameObjects
{
[Flags]
public enum VisibilityFlags
{
None = 0,
Normal = 1,
Ghost = 2,
}
}