Cuffable/Handcuff ECS (#14382)

This commit is contained in:
Nemanja
2023-03-13 19:34:26 -04:00
committed by GitHub
parent 59bf67ec8c
commit 49f7575298
25 changed files with 947 additions and 933 deletions

View File

@@ -0,0 +1,72 @@
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Cuffs.Components;
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedCuffableSystem))]
public sealed class CuffableComponent : Component
{
/// <summary>
/// The current RSI for the handcuff layer
/// </summary>
[DataField("currentRSI"), ViewVariables(VVAccess.ReadWrite)]
public string? CurrentRSI;
/// <summary>
/// How many of this entity's hands are currently cuffed.
/// </summary>
[ViewVariables]
public int CuffedHandCount => Container.ContainedEntities.Count * 2;
/// <summary>
/// The last pair of cuffs that was added to this entity.
/// </summary>
[ViewVariables]
public EntityUid LastAddedCuffs => Container.ContainedEntities[^1];
/// <summary>
/// Container of various handcuffs currently applied to the entity.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public Container Container = default!;
/// <summary>
/// Whether or not the entity can still interact (is not cuffed)
/// </summary>
[DataField("canStillInteract"), ViewVariables(VVAccess.ReadWrite)]
public bool CanStillInteract = true;
/// <summary>
/// Whether or not the entity is currently in the process of being uncuffed.
/// </summary>
[DataField("uncuffing"), ViewVariables(VVAccess.ReadWrite)]
public bool Uncuffing;
}
[Serializable, NetSerializable]
public sealed class CuffableComponentState : ComponentState
{
public readonly bool CanStillInteract;
public readonly bool Uncuffing;
public readonly int NumHandsCuffed;
public readonly string? RSI;
public readonly string? IconState;
public readonly Color? Color;
public CuffableComponentState(int numHandsCuffed, bool canStillInteract, bool uncuffing, string? rsiPath, string? iconState, Color? color)
{
NumHandsCuffed = numHandsCuffed;
CanStillInteract = canStillInteract;
Uncuffing = uncuffing;
RSI = rsiPath;
IconState = iconState;
Color = color;
}
}
[ByRefEvent]
public readonly record struct CuffedStateChangeEvent;

View File

@@ -0,0 +1,113 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility;
namespace Content.Shared.Cuffs.Components;
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedCuffableSystem))]
public sealed class HandcuffComponent : Component
{
/// <summary>
/// The time it takes to cuff an entity.
/// </summary>
[DataField("cuffTime"), ViewVariables(VVAccess.ReadWrite)]
public float CuffTime = 3.5f;
/// <summary>
/// The time it takes to uncuff an entity.
/// </summary>
[DataField("uncuffTime"), ViewVariables(VVAccess.ReadWrite)]
public float UncuffTime = 3.5f;
/// <summary>
/// The time it takes for a cuffed entity to uncuff itself.
/// </summary>
[DataField("breakoutTime"), ViewVariables(VVAccess.ReadWrite)]
public float BreakoutTime = 30f;
/// <summary>
/// If an entity being cuffed is stunned, this amount of time is subtracted from the time it takes to add/remove their cuffs.
/// </summary>
[DataField("stunBonus"), ViewVariables(VVAccess.ReadWrite)]
public float StunBonus = 2f;
/// <summary>
/// Will the cuffs break when removed?
/// </summary>
[DataField("breakOnRemove"), ViewVariables(VVAccess.ReadWrite)]
public bool BreakOnRemove;
/// <summary>
/// Will the cuffs break when removed?
/// </summary>
[DataField("brokenPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public string? BrokenPrototype;
/// <summary>
/// The path of the RSI file used for the player cuffed overlay.
/// </summary>
[DataField("cuffedRSI"), ViewVariables(VVAccess.ReadWrite)]
public string? CuffedRSI = "Objects/Misc/handcuffs.rsi";
/// <summary>
/// The iconstate used with the RSI file for the player cuffed overlay.
/// </summary>
[DataField("bodyIconState"), ViewVariables(VVAccess.ReadWrite)]
public string? OverlayIconState = "body-overlay";
/// <summary>
/// An opptional color specification for <see cref="OverlayIconState"/>
/// </summary>
[DataField("color"), ViewVariables(VVAccess.ReadWrite)]
public Color Color = Color.White;
[DataField("startCuffSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier StartCuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_start.ogg");
[DataField("endCuffSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier EndCuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_end.ogg");
[DataField("startBreakoutSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier StartBreakoutSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_breakout_start.ogg");
[DataField("startUncuffSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier StartUncuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_takeoff_start.ogg");
[DataField("endUncuffSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier EndUncuffSound = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_takeoff_end.ogg");
/// <summary>
/// Used to prevent DoAfter getting spammed.
/// </summary>
[DataField("cuffing"), ViewVariables(VVAccess.ReadWrite)]
public bool Cuffing;
}
[Serializable, NetSerializable]
public sealed class HandcuffComponentState : ComponentState
{
public readonly string? IconState;
public readonly bool Cuffing;
public HandcuffComponentState(string? iconState, bool cuffing)
{
IconState = iconState;
Cuffing = cuffing;
}
}
/// <summary>
/// Event fired on the User when the User attempts to cuff the Target.
/// Should generate popups on the User.
/// </summary>
[ByRefEvent]
public record struct UncuffAttemptEvent(EntityUid User, EntityUid Target)
{
public readonly EntityUid User = User;
public readonly EntityUid Target = Target;
public bool Cancelled = false;
}

View File

@@ -1,61 +0,0 @@
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Cuffs.Components
{
[ByRefEvent]
public readonly struct CuffedStateChangeEvent { }
[NetworkedComponent()]
public abstract class SharedCuffableComponent : Component
{
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
/// <summary>
/// How many of this entity's hands are currently cuffed.
/// </summary>
[ViewVariables]
public int CuffedHandCount => Container.ContainedEntities.Count * 2;
public EntityUid LastAddedCuffs => Container.ContainedEntities[^1];
public IReadOnlyList<EntityUid> StoredEntities => Container.ContainedEntities;
/// <summary>
/// Container of various handcuffs currently applied to the entity.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public Container Container { get; set; } = default!;
protected override void Initialize()
{
base.Initialize();
Container = _sysMan.GetEntitySystem<SharedContainerSystem>().EnsureContainer<Container>(Owner, _componentFactory.GetComponentName(GetType()));
}
[ViewVariables]
public bool CanStillInteract { get; set; } = true;
[Serializable, NetSerializable]
protected sealed class CuffableComponentState : ComponentState
{
public bool CanStillInteract { get; }
public int NumHandsCuffed { get; }
public string? RSI { get; }
public string IconState { get; }
public Color Color { get; }
public CuffableComponentState(int numHandsCuffed, bool canStillInteract, string? rsiPath, string iconState, Color color)
{
NumHandsCuffed = numHandsCuffed;
CanStillInteract = canStillInteract;
RSI = rsiPath;
IconState = iconState;
Color = color;
}
}
}
}

View File

@@ -1,20 +0,0 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Cuffs.Components
{
[NetworkedComponent()]
public abstract class SharedHandcuffComponent : Component
{
[Serializable, NetSerializable]
protected sealed class HandcuffedComponentState : ComponentState
{
public string? IconState { get; }
public HandcuffedComponentState(string? iconState)
{
IconState = iconState;
}
}
}
}