1
0

TriggerOnProximityComponent.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Content.Server.Explosion.EntitySystems;
  2. using Content.Shared.Explosion;
  3. using Content.Shared.Explosion.Components;
  4. using Content.Shared.Physics;
  5. using Robust.Shared.Physics.Collision.Shapes;
  6. using Robust.Shared.Physics.Components;
  7. using Robust.Shared.Physics.Dynamics;
  8. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  9. namespace Content.Server.Explosion.Components
  10. {
  11. /// <summary>
  12. /// Raises a <see cref="TriggerEvent"/> whenever an entity collides with a fixture attached to the owner of this component.
  13. /// </summary>
  14. [RegisterComponent, AutoGenerateComponentPause]
  15. public sealed partial class TriggerOnProximityComponent : SharedTriggerOnProximityComponent
  16. {
  17. public const string FixtureID = "trigger-on-proximity-fixture";
  18. [ViewVariables]
  19. public readonly Dictionary<EntityUid, PhysicsComponent> Colliding = new();
  20. /// <summary>
  21. /// What is the shape of the proximity fixture?
  22. /// </summary>
  23. [ViewVariables]
  24. [DataField("shape")]
  25. public IPhysShape Shape = new PhysShapeCircle(2f);
  26. /// <summary>
  27. /// How long the the proximity trigger animation plays for.
  28. /// </summary>
  29. [ViewVariables(VVAccess.ReadWrite)]
  30. [DataField("animationDuration")]
  31. public TimeSpan AnimationDuration = TimeSpan.FromSeconds(0.6f);
  32. /// <summary>
  33. /// Whether the entity needs to be anchored for the proximity to work.
  34. /// </summary>
  35. [ViewVariables(VVAccess.ReadWrite)]
  36. [DataField("requiresAnchored")]
  37. public bool RequiresAnchored = true;
  38. [ViewVariables(VVAccess.ReadWrite)]
  39. [DataField("enabled")]
  40. public bool Enabled = true;
  41. /// <summary>
  42. /// The minimum delay between repeating triggers.
  43. /// </summary>
  44. [ViewVariables(VVAccess.ReadWrite)]
  45. [DataField("cooldown")]
  46. public TimeSpan Cooldown = TimeSpan.FromSeconds(5);
  47. /// <summary>
  48. /// When can the trigger run again?
  49. /// </summary>
  50. [ViewVariables(VVAccess.ReadWrite)]
  51. [DataField("nextTrigger", customTypeSerializer: typeof(TimeOffsetSerializer))]
  52. [AutoPausedField]
  53. public TimeSpan NextTrigger = TimeSpan.Zero;
  54. /// <summary>
  55. /// When will the visual state be updated again after activation?
  56. /// </summary>
  57. [ViewVariables(VVAccess.ReadWrite)]
  58. [DataField("nextVisualUpdate", customTypeSerializer: typeof(TimeOffsetSerializer))]
  59. [AutoPausedField]
  60. public TimeSpan NextVisualUpdate = TimeSpan.Zero;
  61. /// <summary>
  62. /// What speed should the other object be moving at to trigger the proximity fixture?
  63. /// </summary>
  64. [ViewVariables(VVAccess.ReadWrite)]
  65. [DataField("triggerSpeed")]
  66. public float TriggerSpeed = 3.5f;
  67. /// <summary>
  68. /// If this proximity is triggered should we continually repeat it?
  69. /// </summary>
  70. [ViewVariables(VVAccess.ReadWrite)]
  71. [DataField("repeating")]
  72. public bool Repeating = true;
  73. /// <summary>
  74. /// What layer is the trigger fixture on?
  75. /// </summary>
  76. [ViewVariables]
  77. [DataField("layer", customTypeSerializer: typeof(FlagSerializer<CollisionLayer>))]
  78. public int Layer = (int) (CollisionGroup.MidImpassable | CollisionGroup.LowImpassable | CollisionGroup.HighImpassable);
  79. }
  80. }