2022-10-09 18:17:53 -04:00
|
|
|
using Robust.Shared.GameStates;
|
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Stealth.Components;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add this component to an entity that you want to be cloaked.
|
2022-10-22 18:06:55 -04:00
|
|
|
/// It overlays a shader on the entity to give them an invisibility cloaked effect.
|
|
|
|
|
/// It also turns the entity invisible.
|
|
|
|
|
/// Use other components (like StealthOnMove) to modify this component's visibility based on certain conditions.
|
2022-10-09 18:17:53 -04:00
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent, NetworkedComponent]
|
|
|
|
|
[Access(typeof(SharedStealthSystem))]
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class StealthComponent : Component
|
2022-10-09 18:17:53 -04:00
|
|
|
{
|
2022-10-15 17:15:25 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether or not the stealth effect should currently be applied.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("enabled")]
|
|
|
|
|
public bool Enabled = true;
|
|
|
|
|
|
2023-12-07 03:25:57 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The creature will continue invisible at death.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("enabledOnDeath")]
|
|
|
|
|
public bool EnabledOnDeath = true;
|
|
|
|
|
|
2022-10-09 18:17:53 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether or not the entity previously had an interaction outline prior to cloaking.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("hadOutline")]
|
|
|
|
|
public bool HadOutline;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-10-15 17:15:25 +13:00
|
|
|
/// Minimum visibility before the entity becomes unexaminable (and thus no longer appears on context menus).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("examineThreshold")]
|
2023-08-22 18:14:33 -07:00
|
|
|
public float ExamineThreshold = 0.5f;
|
2022-10-15 17:15:25 +13:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Last set level of visibility. The visual effect ranges from 1 (fully visible) and -1 (fully hidden). Values
|
|
|
|
|
/// outside of this range simply act as a buffer for the visual effect (i.e., a delay before turning invisible). To
|
2023-01-19 03:56:45 +01:00
|
|
|
/// get the actual current visibility, use <see cref="SharedStealthSystem.GetVisibility(EntityUid, StealthComponent?)"/>
|
2022-10-22 18:06:55 -04:00
|
|
|
/// If you don't have anything else updating the stealth, this will just stay at a constant value, which can be useful.
|
2022-10-09 18:17:53 -04:00
|
|
|
/// </summary>
|
|
|
|
|
[DataField("lastVisibility")]
|
2023-01-19 03:56:45 +01:00
|
|
|
[Access(typeof(SharedStealthSystem), Other = AccessPermissions.None)]
|
2022-10-15 17:15:25 +13:00
|
|
|
public float LastVisibility = 1;
|
|
|
|
|
|
2022-10-09 18:17:53 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Time at which <see cref="LastVisibility"/> was set. Null implies the entity is currently paused and not
|
|
|
|
|
/// accumulating any visibility change.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("lastUpdate", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
|
|
|
|
public TimeSpan? LastUpdated;
|
|
|
|
|
|
2022-10-15 17:15:25 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Minimum visibility. Note that the visual effect caps out at -1, but this value is allowed to be larger or smaller.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("minVisibility")]
|
2023-08-22 18:14:33 -07:00
|
|
|
public float MinVisibility = -1f;
|
2022-10-15 17:15:25 +13:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maximum visibility. Note that the visual effect caps out at +1, but this value is allowed to be larger or smaller.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("maxVisibility")]
|
2023-08-22 18:14:33 -07:00
|
|
|
public float MaxVisibility = 1.5f;
|
2022-12-06 18:18:46 -05:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Localization string for how you'd like to describe this effect.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("examinedDesc")]
|
|
|
|
|
public string ExaminedDesc = "stealth-visual-effect";
|
2022-10-09 18:17:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class StealthComponentState : ComponentState
|
|
|
|
|
{
|
2022-10-15 17:15:25 +13:00
|
|
|
public readonly float Visibility;
|
|
|
|
|
public readonly TimeSpan? LastUpdated;
|
|
|
|
|
public readonly bool Enabled;
|
2022-10-09 18:17:53 -04:00
|
|
|
|
2022-10-15 17:15:25 +13:00
|
|
|
public StealthComponentState(float stealthLevel, TimeSpan? lastUpdated, bool enabled)
|
2022-10-09 18:17:53 -04:00
|
|
|
{
|
|
|
|
|
Visibility = stealthLevel;
|
|
|
|
|
LastUpdated = lastUpdated;
|
2022-10-15 17:15:25 +13:00
|
|
|
Enabled = enabled;
|
2022-10-09 18:17:53 -04:00
|
|
|
}
|
|
|
|
|
}
|