2020-09-02 06:07:54 -04:00
|
|
|
|
using Content.Server.GameObjects.Components.Mobs;
|
|
|
|
|
|
using Content.Server.Mobs;
|
|
|
|
|
|
using Content.Server.Players;
|
2020-04-05 02:29:04 +02:00
|
|
|
|
using Content.Shared.GameObjects.Components.Observer;
|
2020-03-03 19:10:07 +01:00
|
|
|
|
using Robust.Server.GameObjects;
|
2020-04-10 16:28:14 +02:00
|
|
|
|
using Robust.Server.GameObjects.Components;
|
2020-03-03 19:10:07 +01:00
|
|
|
|
using Robust.Server.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Interfaces.Network;
|
2020-04-20 10:36:02 +01:00
|
|
|
|
using Robust.Shared.Players;
|
2020-03-03 19:10:07 +01:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
|
2020-04-05 02:29:04 +02:00
|
|
|
|
namespace Content.Server.GameObjects.Components.Observer
|
2020-03-03 19:10:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
2020-06-24 02:21:20 +02:00
|
|
|
|
public class GhostComponent : SharedGhostComponent
|
2020-03-03 19:10:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
private bool _canReturnToBody = true;
|
|
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2020-04-09 03:01:56 +02:00
|
|
|
|
public bool CanReturnToBody
|
2020-03-03 19:10:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
get => _canReturnToBody;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
_canReturnToBody = value;
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-10 16:28:14 +02:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
2020-09-02 06:07:54 -04:00
|
|
|
|
Owner.EnsureComponent<VisibilityComponent>().Layer = (int) VisibilityFlags.Ghost;
|
2020-04-10 16:28:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 19:10:07 +01:00
|
|
|
|
public override ComponentState GetComponentState() => new GhostComponentState(CanReturnToBody);
|
|
|
|
|
|
|
2020-04-20 10:36:02 +01:00
|
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent component)
|
2020-03-03 19:10:07 +01:00
|
|
|
|
{
|
2020-04-20 10:36:02 +01:00
|
|
|
|
base.HandleMessage(message, component);
|
|
|
|
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
|
|
{
|
|
|
|
|
|
case PlayerAttachedMsg msg:
|
2020-09-02 06:07:54 -04:00
|
|
|
|
msg.NewPlayer.VisibilityMask |= (int) VisibilityFlags.Ghost;
|
2020-04-20 10:36:02 +01:00
|
|
|
|
Dirty();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case PlayerDetachedMsg msg:
|
2020-09-02 06:07:54 -04:00
|
|
|
|
msg.OldPlayer.VisibilityMask &= ~(int) VisibilityFlags.Ghost;
|
2020-04-20 10:36:02 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-02 06:07:54 -04:00
|
|
|
|
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel,
|
|
|
|
|
|
ICommonSession session = null)
|
2020-04-20 10:36:02 +01:00
|
|
|
|
{
|
|
|
|
|
|
base.HandleNetworkMessage(message, netChannel, session);
|
2020-03-03 19:10:07 +01:00
|
|
|
|
|
|
|
|
|
|
switch (message)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ReturnToBodyComponentMessage reenter:
|
|
|
|
|
|
if (!Owner.TryGetComponent(out IActorComponent actor) || !CanReturnToBody) break;
|
|
|
|
|
|
if (netChannel == null || netChannel == actor.playerSession.ConnectedClient)
|
|
|
|
|
|
{
|
|
|
|
|
|
actor.playerSession.ContentData().Mind.UnVisit();
|
2020-04-17 19:23:06 +02:00
|
|
|
|
Owner.Delete();
|
2020-03-03 19:10:07 +01:00
|
|
|
|
}
|
2020-09-02 06:07:54 -04:00
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ReturnToCloneComponentMessage reenter:
|
|
|
|
|
|
|
|
|
|
|
|
if (Owner.TryGetComponent(out VisitingMindComponent mind))
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new GhostReturnMessage(mind.Mind));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 19:10:07 +01:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-02 06:07:54 -04:00
|
|
|
|
|
|
|
|
|
|
public class GhostReturnMessage : EntitySystemMessage
|
|
|
|
|
|
{
|
|
|
|
|
|
public GhostReturnMessage(Mind sender)
|
|
|
|
|
|
{
|
|
|
|
|
|
Sender = sender;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Mind Sender { get; }
|
|
|
|
|
|
}
|
2020-03-03 19:10:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|