AnchorableComponent.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Content.Shared.Construction.EntitySystems;
  2. using Content.Shared.Tools;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Prototypes;
  5. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  6. namespace Content.Shared.Construction.Components
  7. {
  8. [RegisterComponent, Access(typeof(AnchorableSystem)), NetworkedComponent, AutoGenerateComponentState]
  9. public sealed partial class AnchorableComponent : Component
  10. {
  11. [DataField]
  12. public ProtoId<ToolQualityPrototype> Tool { get; private set; } = "Anchoring";
  13. [DataField, AutoNetworkedField]
  14. public AnchorableFlags Flags = AnchorableFlags.Anchorable | AnchorableFlags.Unanchorable;
  15. [DataField]
  16. [ViewVariables(VVAccess.ReadWrite)]
  17. public bool Snap { get; private set; } = true;
  18. /// <summary>
  19. /// Base delay to use for anchoring.
  20. /// </summary>
  21. [ViewVariables(VVAccess.ReadWrite)]
  22. [DataField]
  23. public float Delay = 1f;
  24. }
  25. [Flags]
  26. public enum AnchorableFlags : byte
  27. {
  28. None = 0,
  29. Anchorable = 1 << 0,
  30. Unanchorable = 1 << 1,
  31. }
  32. public abstract class BaseAnchoredAttemptEvent : CancellableEntityEventArgs
  33. {
  34. public EntityUid User { get; }
  35. public EntityUid Tool { get; }
  36. /// <summary>
  37. /// Extra delay to add to the do_after.
  38. /// Add to this, don't replace it.
  39. /// Output parameter.
  40. /// </summary>
  41. public float Delay { get; set; } = 0f;
  42. protected BaseAnchoredAttemptEvent(EntityUid user, EntityUid tool)
  43. {
  44. User = user;
  45. Tool = tool;
  46. }
  47. }
  48. public sealed class AnchorAttemptEvent : BaseAnchoredAttemptEvent
  49. {
  50. public AnchorAttemptEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
  51. }
  52. public sealed class UnanchorAttemptEvent : BaseAnchoredAttemptEvent
  53. {
  54. public UnanchorAttemptEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
  55. }
  56. public abstract class BaseAnchoredEvent : EntityEventArgs
  57. {
  58. public EntityUid User { get; }
  59. public EntityUid Tool { get; }
  60. protected BaseAnchoredEvent(EntityUid user, EntityUid tool)
  61. {
  62. User = user;
  63. Tool = tool;
  64. }
  65. }
  66. /// <summary>
  67. /// Raised just before the entity's body type is changed.
  68. /// </summary>
  69. public sealed class BeforeAnchoredEvent : BaseAnchoredEvent
  70. {
  71. public BeforeAnchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
  72. }
  73. /// <summary>
  74. /// Raised when an entity with an anchorable component is anchored. Note that you may instead want the more
  75. /// general <see cref="AnchorStateChangedEvent"/>. This event has the benefit of having user & tool information,
  76. /// as a result of interactions mediated by the <see cref="AnchorableSystem"/>.
  77. /// </summary>
  78. public sealed class UserAnchoredEvent : BaseAnchoredEvent
  79. {
  80. public UserAnchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
  81. }
  82. /// <summary>
  83. /// Raised just before the entity's body type is changed.
  84. /// </summary>
  85. public sealed class BeforeUnanchoredEvent : BaseAnchoredEvent
  86. {
  87. public BeforeUnanchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
  88. }
  89. /// <summary>
  90. /// Raised when an entity with an anchorable component is unanchored. Note that you will probably also need to
  91. /// subscribe to the more general <see cref="AnchorStateChangedEvent"/>, which gets raised BEFORE this one. This
  92. /// event has the benefit of having user & tool information, whereas the more general event may be due to
  93. /// explosions or grid-destruction or other interactions not mediated by the <see cref="AnchorableSystem"/>.
  94. /// </summary>
  95. public sealed class UserUnanchoredEvent : BaseAnchoredEvent
  96. {
  97. public UserUnanchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
  98. }
  99. }