Files
tbd-station-14/Content.Shared/Ghost/SharedGhostComponent.cs
DrSmugleaf 4f4d203d2e Make ghost component ECS (#4159)
* Make ghost component ECS

* Remove players and locations properties from ghost component

* Address reviews

* One more doc

* Fix client ghost component state method error
2021-06-18 09:56:23 +02:00

74 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using Content.Shared.ActionBlocker;
using Content.Shared.NetIDs;
using Robust.Shared.GameObjects;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Ghost
{
public class SharedGhostComponent : Component, IActionBlocker
{
public override string Name => "Ghost";
public override uint? NetID => ContentNetIDs.GHOST;
/// <summary>
/// Changed by <see cref="GhostChangeCanReturnToBodyEvent"/>
/// </summary>
[DataField("canReturnToBody")]
[ViewVariables(VVAccess.ReadWrite)]
public bool CanReturnToBody { get; set; }
public override ComponentState GetComponentState(ICommonSession player)
{
return new GhostComponentState(CanReturnToBody);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not GhostComponentState state)
{
return;
}
CanReturnToBody = state.CanReturnToBody;
}
public bool CanInteract() => false;
public bool CanUse() => false;
public bool CanThrow() => false;
public bool CanDrop() => false;
public bool CanPickup() => false;
public bool CanEmote() => false;
public bool CanAttack() => false;
}
[Serializable, NetSerializable]
public class GhostComponentState : ComponentState
{
public bool CanReturnToBody { get; }
public HashSet<string>? LocationWarps { get; }
public Dictionary<EntityUid, string>? PlayerWarps { get; }
public GhostComponentState(
bool canReturnToBody,
HashSet<string>? locationWarps = null,
Dictionary<EntityUid, string>? playerWarps = null)
: base(ContentNetIDs.GHOST)
{
CanReturnToBody = canReturnToBody;
LocationWarps = locationWarps;
PlayerWarps = playerWarps;
}
}
}