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
This commit is contained in:
DrSmugleaf
2021-06-18 09:56:23 +02:00
committed by GitHub
parent 86ff812428
commit 4f4d203d2e
10 changed files with 481 additions and 401 deletions

View File

@@ -1,19 +0,0 @@
#nullable enable
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Ghost
{
[Serializable, NetSerializable]
public class GhostWarpToLocationRequestMessage : ComponentMessage
{
public string Name { get; }
public GhostWarpToLocationRequestMessage(string name)
{
Name = name;
Directed = true;
}
}
}

View File

@@ -1,18 +0,0 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Ghost
{
[Serializable, NetSerializable]
public class GhostWarpToTargetRequestMessage : ComponentMessage
{
public EntityUid Target { get; }
public GhostWarpToTargetRequestMessage(EntityUid target)
{
Target = target;
Directed = true;
}
}
}

View File

@@ -3,7 +3,10 @@ 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
{
@@ -12,6 +15,30 @@ namespace Content.Shared.Ghost
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;
@@ -26,60 +53,19 @@ namespace Content.Shared.Ghost
{
public bool CanReturnToBody { get; }
public GhostComponentState(bool canReturnToBody) : base(ContentNetIDs.GHOST)
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;
}
}
[Serializable, NetSerializable]
public class ReturnToBodyComponentMessage : ComponentMessage
{
public ReturnToBodyComponentMessage()
{
Directed = true;
}
}
[Serializable, NetSerializable]
public class GhostRequestWarpPointData : ComponentMessage
{
public GhostRequestWarpPointData()
{
Directed = true;
}
}
[Serializable, NetSerializable]
public class GhostRequestPlayerNameData : ComponentMessage
{
public GhostRequestPlayerNameData()
{
Directed = true;
}
}
[Serializable, NetSerializable]
public class GhostReplyWarpPointData : ComponentMessage
{
public List<string> WarpName;
public GhostReplyWarpPointData(List<string> warpName)
{
WarpName = warpName;
Directed = true;
}
}
[Serializable, NetSerializable]
public class GhostReplyPlayerNameData : ComponentMessage
{
public Dictionary<EntityUid,string> PlayerNames;
public GhostReplyPlayerNameData(Dictionary<EntityUid, string> playerNameDict)
{
PlayerNames = playerNameDict;
Directed = true;
LocationWarps = locationWarps;
PlayerWarps = playerWarps;
}
}
}

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Ghost
{
public abstract class SharedGhostSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedGhostComponent, GhostChangeCanReturnToBodyEvent>(OnGhostChangeCanReturnToBody);
}
private void OnGhostChangeCanReturnToBody(EntityUid uid, SharedGhostComponent component, GhostChangeCanReturnToBodyEvent args)
{
if (component.CanReturnToBody == args.CanReturnToBody)
{
return;
}
component.CanReturnToBody = args.CanReturnToBody;
component.Dirty();
}
}
/// <summary>
/// Raised to change the value of <see cref="SharedGhostComponent.CanReturnToBody"/>
/// </summary>
[Serializable, NetSerializable]
public class GhostChangeCanReturnToBodyEvent : EntityEventArgs
{
public GhostChangeCanReturnToBodyEvent(bool canReturnToBody)
{
CanReturnToBody = canReturnToBody;
}
public bool CanReturnToBody { get; }
}
[Serializable, NetSerializable]
public class GhostWarpsRequestEvent : EntityEventArgs
{
}
[Serializable, NetSerializable]
public class GhostWarpsResponseEvent : EntityEventArgs
{
public GhostWarpsResponseEvent(List<string> locations, Dictionary<EntityUid, string> players)
{
Locations = locations;
Players = players;
}
public List<string> Locations { get; }
public Dictionary<EntityUid, string> Players { get; }
}
[Serializable, NetSerializable]
public class GhostWarpToLocationRequestEvent : EntityEventArgs
{
public string Name { get; }
public GhostWarpToLocationRequestEvent(string name)
{
Name = name;
}
}
[Serializable, NetSerializable]
public class GhostWarpToTargetRequestEvent : EntityEventArgs
{
public EntityUid Target { get; }
public GhostWarpToTargetRequestEvent(EntityUid target)
{
Target = target;
}
}
[Serializable, NetSerializable]
public class GhostReturnToBodyRequest : EntityEventArgs
{
}
}