Radiation pulse ECS (#10641)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Content.Shared.Radiation.Systems;
|
||||
using Content.Shared.Spawners.Components;
|
||||
|
||||
namespace Content.Shared.Radiation.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Create circle pulse animation of radiation around object.
|
||||
/// Drawn on client after creation only once per component lifetime.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(RadiationPulseSystem))]
|
||||
public sealed class RadiationPulseComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Timestamp when component was assigned to this entity.
|
||||
/// </summary>
|
||||
public TimeSpan StartTime;
|
||||
|
||||
/// <summary>
|
||||
/// How long will animation play in seconds.
|
||||
/// Can be overridden by <see cref="TimedDespawnComponent"/>.
|
||||
/// </summary>
|
||||
public float VisualDuration = 2f;
|
||||
|
||||
/// <summary>
|
||||
/// The range of animation.
|
||||
/// Can be overridden by <see cref="RadiationSourceComponent"/>.
|
||||
/// </summary>
|
||||
public float VisualRange = 5f;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/// <summary>
|
||||
/// Irradiate all objects in range.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class RadiationSourceComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// How many rads per second receive irradiated object.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("radsPerSecond")]
|
||||
public float RadsPerSecond = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Radius of radiation source.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("range")]
|
||||
public float Range = 5f;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Radiation
|
||||
{
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedRadiationPulseComponent : Component
|
||||
{
|
||||
[DataField("radsPerSecond")]
|
||||
public float RadsPerSecond { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Radius of the pulse from its position
|
||||
/// </summary>
|
||||
public virtual float Range { get; set; }
|
||||
|
||||
public virtual bool Decay { get; set; }
|
||||
public virtual bool Draw { get; set; }
|
||||
|
||||
public virtual TimeSpan StartTime { get; }
|
||||
public virtual TimeSpan EndTime { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For syncing the pulse's lifespan between client and server for the overlay
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class RadiationPulseState : ComponentState
|
||||
{
|
||||
// not networking RadsPerSecond because damage is only ever dealt by server-side systems.
|
||||
|
||||
public readonly float Range;
|
||||
public readonly bool Draw;
|
||||
public readonly bool Decay;
|
||||
public readonly TimeSpan StartTime;
|
||||
public readonly TimeSpan EndTime;
|
||||
|
||||
public RadiationPulseState(float range, bool draw, bool decay, TimeSpan startTime, TimeSpan endTime)
|
||||
{
|
||||
Range = range;
|
||||
Draw = draw;
|
||||
Decay = decay;
|
||||
StartTime = startTime;
|
||||
EndTime = endTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Content.Shared/Radiation/Systems/RadiationPulseSystem.cs
Normal file
32
Content.Shared/Radiation/Systems/RadiationPulseSystem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Content.Shared.Radiation.Components;
|
||||
using Content.Shared.Spawners.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Radiation.Systems;
|
||||
|
||||
public sealed class RadiationPulseSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RadiationPulseComponent, ComponentStartup>(OnStartup);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, RadiationPulseComponent component, ComponentStartup args)
|
||||
{
|
||||
component.StartTime = _timing.RealTime;
|
||||
|
||||
// try to get despawn time or keep default duration time
|
||||
if (TryComp<TimedDespawnComponent>(uid, out var despawn))
|
||||
{
|
||||
component.VisualDuration = despawn.Lifetime;
|
||||
}
|
||||
// try to get radiation range or keep default visual range
|
||||
if (TryComp<RadiationSourceComponent>(uid, out var radSource))
|
||||
{
|
||||
component.VisualRange = radSource.Range;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user