Refactor TriggerSystem.Proximity (#17554)

This commit is contained in:
Vordenburg
2023-06-27 21:17:06 -04:00
committed by GitHub
parent 72607f3066
commit fb126d2044
4 changed files with 103 additions and 76 deletions

View File

@@ -1,7 +1,10 @@
using Content.Server.Explosion.EntitySystems;
using Content.Shared.Explosion;
using Content.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Explosion.Components
{
@@ -12,49 +15,76 @@ namespace Content.Server.Explosion.Components
[RegisterComponent]
public sealed class TriggerOnProximityComponent : SharedTriggerOnProximityComponent
{
public const string FixtureID = "trigger-on-proximity-fixture";
public const string FixtureID = "trigger-on-proximity-fixture";
public readonly HashSet<PhysicsComponent> Colliding = new();
[ViewVariables]
public readonly Dictionary<EntityUid, PhysicsComponent> Colliding = new();
[DataField("shape", required: true)]
public IPhysShape Shape { get; set; } = new PhysShapeCircle(2f);
/// <summary>
/// What is the shape of the proximity fixture?
/// </summary>
[ViewVariables]
[DataField("shape")]
public IPhysShape Shape = new PhysShapeCircle(2f);
/// <summary>
/// How long the the proximity trigger animation plays for.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("animationDuration")]
public float AnimationDuration = 0.3f;
public TimeSpan AnimationDuration = TimeSpan.FromSeconds(0.6f);
/// <summary>
/// Whether the entity needs to be anchored for the proximity to work.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("requiresAnchored")]
public bool RequiresAnchored { get; set; } = true;
public bool RequiresAnchored = true;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("enabled")]
public bool Enabled = true;
/// <summary>
/// The minimum delay between repeating triggers.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("cooldown")]
public float Cooldown { get; set; } = 5f;
public TimeSpan Cooldown = TimeSpan.FromSeconds(5);
/// <summary>
/// How much cooldown has elapsed (if relevant).
/// When can the trigger run again?
/// </summary>
[DataField("accumulator")]
public float Accumulator = 0f;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("nextTrigger", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextTrigger = TimeSpan.Zero;
/// <summary>
/// When will the visual state be updated again after activation?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("nextVisualUpdate", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextVisualUpdate = TimeSpan.Zero;
/// <summary>
/// What speed should the other object be moving at to trigger the proximity fixture?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("triggerSpeed")]
public float TriggerSpeed { get; set; } = 3.5f;
public float TriggerSpeed = 3.5f;
/// <summary>
/// If this proximity is triggered should we continually repeat it?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("repeating")]
internal bool Repeating = true;
public bool Repeating = true;
/// <summary>
/// What layer is the trigger fixture on?
/// </summary>
[ViewVariables]
[DataField("layer", customTypeSerializer: typeof(FlagSerializer<CollisionLayer>))]
public readonly int Layer = (int) (CollisionGroup.MidImpassable | CollisionGroup.LowImpassable | CollisionGroup.HighImpassable);
}
}