StealthComponent.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Robust.Shared.GameStates;
  2. using Robust.Shared.Serialization;
  3. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  4. namespace Content.Shared.Stealth.Components;
  5. /// <summary>
  6. /// Add this component to an entity that you want to be cloaked.
  7. /// It overlays a shader on the entity to give them an invisibility cloaked effect.
  8. /// It also turns the entity invisible.
  9. /// Use other components (like StealthOnMove) to modify this component's visibility based on certain conditions.
  10. /// </summary>
  11. [RegisterComponent, NetworkedComponent]
  12. [Access(typeof(SharedStealthSystem))]
  13. public sealed partial class StealthComponent : Component
  14. {
  15. /// <summary>
  16. /// Whether or not the stealth effect should currently be applied.
  17. /// </summary>
  18. [DataField("enabled")]
  19. public bool Enabled = true;
  20. /// <summary>
  21. /// The creature will continue invisible at death.
  22. /// </summary>
  23. [DataField("enabledOnDeath")]
  24. public bool EnabledOnDeath = true;
  25. /// <summary>
  26. /// Whether or not the entity previously had an interaction outline prior to cloaking.
  27. /// </summary>
  28. [DataField("hadOutline")]
  29. public bool HadOutline;
  30. /// <summary>
  31. /// Minimum visibility before the entity becomes unexaminable (and thus no longer appears on context menus).
  32. /// </summary>
  33. [DataField("examineThreshold")]
  34. public float ExamineThreshold = 0.5f;
  35. /// <summary>
  36. /// Last set level of visibility. The visual effect ranges from 1 (fully visible) and -1 (fully hidden). Values
  37. /// outside of this range simply act as a buffer for the visual effect (i.e., a delay before turning invisible). To
  38. /// get the actual current visibility, use <see cref="SharedStealthSystem.GetVisibility(EntityUid, StealthComponent?)"/>
  39. /// If you don't have anything else updating the stealth, this will just stay at a constant value, which can be useful.
  40. /// </summary>
  41. [DataField("lastVisibility")]
  42. [Access(typeof(SharedStealthSystem), Other = AccessPermissions.None)]
  43. public float LastVisibility = 1;
  44. /// <summary>
  45. /// Time at which <see cref="LastVisibility"/> was set. Null implies the entity is currently paused and not
  46. /// accumulating any visibility change.
  47. /// </summary>
  48. [DataField("lastUpdate", customTypeSerializer:typeof(TimeOffsetSerializer))]
  49. public TimeSpan? LastUpdated;
  50. /// <summary>
  51. /// Minimum visibility. Note that the visual effect caps out at -1, but this value is allowed to be larger or smaller.
  52. /// </summary>
  53. [DataField("minVisibility")]
  54. public float MinVisibility = -1f;
  55. /// <summary>
  56. /// Maximum visibility. Note that the visual effect caps out at +1, but this value is allowed to be larger or smaller.
  57. /// </summary>
  58. [DataField("maxVisibility")]
  59. public float MaxVisibility = 1.5f;
  60. /// <summary>
  61. /// Localization string for how you'd like to describe this effect.
  62. /// </summary>
  63. [DataField("examinedDesc")]
  64. public string ExaminedDesc = "stealth-visual-effect";
  65. }
  66. [Serializable, NetSerializable]
  67. public sealed class StealthComponentState : ComponentState
  68. {
  69. public readonly float Visibility;
  70. public readonly TimeSpan? LastUpdated;
  71. public readonly bool Enabled;
  72. public StealthComponentState(float stealthLevel, TimeSpan? lastUpdated, bool enabled)
  73. {
  74. Visibility = stealthLevel;
  75. LastUpdated = lastUpdated;
  76. Enabled = enabled;
  77. }
  78. }