1
0

LockComponent.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using Content.Shared.DoAfter;
  2. using Robust.Shared.Audio;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Serialization;
  5. namespace Content.Shared.Lock;
  6. /// <summary>
  7. /// Allows locking/unlocking, with access determined by AccessReader
  8. /// </summary>
  9. [RegisterComponent, NetworkedComponent]
  10. [Access(typeof(LockSystem))]
  11. [AutoGenerateComponentState]
  12. public sealed partial class LockComponent : Component
  13. {
  14. /// <summary>
  15. /// Whether or not the lock is locked.
  16. /// </summary>
  17. [DataField("locked"), ViewVariables(VVAccess.ReadWrite)]
  18. [AutoNetworkedField]
  19. public bool Locked = true;
  20. /// <summary>
  21. /// Whether or not the lock is locked by simply clicking.
  22. /// </summary>
  23. [DataField("lockOnClick"), ViewVariables(VVAccess.ReadWrite)]
  24. [AutoNetworkedField]
  25. public bool LockOnClick;
  26. /// <summary>
  27. /// Whether or not the lock is unlocked by simply clicking.
  28. /// </summary>
  29. [DataField, AutoNetworkedField]
  30. public bool UnlockOnClick = true;
  31. /// <summary>
  32. /// The sound played when unlocked.
  33. /// </summary>
  34. [DataField("unlockingSound"), ViewVariables(VVAccess.ReadWrite)]
  35. public SoundSpecifier UnlockSound = new SoundPathSpecifier("/Audio/Machines/door_lock_off.ogg")
  36. {
  37. Params = AudioParams.Default.WithVolume(-5f),
  38. };
  39. /// <summary>
  40. /// The sound played when locked.
  41. /// </summary>
  42. [DataField("lockingSound"), ViewVariables(VVAccess.ReadWrite)]
  43. public SoundSpecifier LockSound = new SoundPathSpecifier("/Audio/Machines/door_lock_on.ogg")
  44. {
  45. Params = AudioParams.Default.WithVolume(-5f)
  46. };
  47. /// <summary>
  48. /// Whether or not an emag disables it.
  49. /// </summary>
  50. [DataField]
  51. [AutoNetworkedField]
  52. public bool BreakOnAccessBreaker = true;
  53. /// <summary>
  54. /// Amount of do-after time needed to lock the entity.
  55. /// </summary>
  56. /// <remarks>
  57. /// If set to zero, no do-after will be used.
  58. /// </remarks>
  59. [DataField]
  60. [AutoNetworkedField]
  61. public TimeSpan LockTime;
  62. /// <summary>
  63. /// Amount of do-after time needed to unlock the entity.
  64. /// </summary>
  65. /// <remarks>
  66. /// If set to zero, no do-after will be used.
  67. /// </remarks>
  68. [DataField]
  69. [AutoNetworkedField]
  70. public TimeSpan UnlockTime;
  71. }
  72. /// <summary>
  73. /// Event raised on the lock when a toggle is attempted.
  74. /// Can be cancelled to prevent it.
  75. /// </summary>
  76. [ByRefEvent]
  77. public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false);
  78. /// <summary>
  79. /// Event raised on the user when a toggle is attempted.
  80. /// Can be cancelled to prevent it.
  81. /// </summary>
  82. [ByRefEvent]
  83. public record struct UserLockToggleAttemptEvent(EntityUid Target, bool Silent = false, bool Cancelled = false);
  84. /// <summary>
  85. /// Event raised on a lock after it has been toggled.
  86. /// </summary>
  87. [ByRefEvent]
  88. public readonly record struct LockToggledEvent(bool Locked);
  89. /// <summary>
  90. /// Used to lock a lockable entity that has a lock time configured.
  91. /// </summary>
  92. /// <seealso cref="LockComponent"/>
  93. /// <seealso cref="LockSystem"/>
  94. [Serializable, NetSerializable]
  95. public sealed partial class LockDoAfter : DoAfterEvent
  96. {
  97. public override DoAfterEvent Clone()
  98. {
  99. return this;
  100. }
  101. }
  102. /// <summary>
  103. /// Used to unlock a lockable entity that has an unlock time configured.
  104. /// </summary>
  105. /// <seealso cref="LockComponent"/>
  106. /// <seealso cref="LockSystem"/>
  107. [Serializable, NetSerializable]
  108. public sealed partial class UnlockDoAfter : DoAfterEvent
  109. {
  110. public override DoAfterEvent Clone()
  111. {
  112. return this;
  113. }
  114. }
  115. [NetSerializable]
  116. [Serializable]
  117. public enum LockVisuals : byte
  118. {
  119. Locked
  120. }