30
Content.Server/IgnitionSource/IgniteOnTriggerComponent.cs
Normal file
30
Content.Server/IgnitionSource/IgniteOnTriggerComponent.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Server.IgnitionSource;
|
||||
|
||||
/// <summary>
|
||||
/// Ignites for a certain length of time when triggered.
|
||||
/// Requires <see cref="IgnitionSourceComponent"/> along with triggering components.
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(IgniteOnTriggerSystem))]
|
||||
public sealed partial class IgniteOnTriggerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Once ignited, the time it will unignite at.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan IgnitedUntil = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// How long the ignition source is active for after triggering.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan IgnitedTime = TimeSpan.FromSeconds(0.5);
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when igniting.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier IgniteSound = new SoundCollectionSpecifier("WelderOn");
|
||||
}
|
||||
55
Content.Server/IgnitionSource/IgniteOnTriggerSystem.cs
Normal file
55
Content.Server/IgnitionSource/IgniteOnTriggerSystem.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Content.Shared.Timing;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.IgnitionSource;
|
||||
|
||||
/// <summary>
|
||||
/// Handles igniting when triggered and stopping ignition after the delay.
|
||||
/// </summary>
|
||||
public sealed class IgniteOnTriggerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IgnitionSourceSystem _source = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<IgniteOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
var query = EntityQueryEnumerator<IgniteOnTriggerComponent, IgnitionSourceComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp, out var source))
|
||||
{
|
||||
if (!source.Ignited)
|
||||
continue;
|
||||
|
||||
if (_timing.CurTime < comp.IgnitedUntil)
|
||||
continue;
|
||||
|
||||
_source.SetIgnited(uid, false, source);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrigger(EntityUid uid, IgniteOnTriggerComponent comp, TriggerEvent args)
|
||||
{
|
||||
// prevent spamming sound and ignition
|
||||
TryComp<UseDelayComponent>(uid, out var delay);
|
||||
if (_useDelay.ActiveDelay(uid, delay))
|
||||
return;
|
||||
|
||||
_source.SetIgnited(uid);
|
||||
_audio.PlayPvs(comp.IgniteSound, uid);
|
||||
|
||||
_useDelay.BeginDelay(uid, delay);
|
||||
comp.IgnitedUntil = _timing.CurTime + comp.IgnitedTime;
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,18 @@ public sealed class IgnitionSourceSystem : EntitySystem
|
||||
|
||||
private void OnIsHot(EntityUid uid, IgnitionSourceComponent component, IsHotEvent args)
|
||||
{
|
||||
SetIgnited(uid,component,args.IsHot);
|
||||
SetIgnited(uid, args.IsHot, component);
|
||||
}
|
||||
|
||||
private void SetIgnited(EntityUid uid, IgnitionSourceComponent component, bool newState)
|
||||
/// <summary>
|
||||
/// Simply sets the ignited field to the ignited param.
|
||||
/// </summary>
|
||||
public void SetIgnited(EntityUid uid, bool ignited = true, IgnitionSourceComponent? comp = null)
|
||||
{
|
||||
component.Ignited = newState;
|
||||
if (!Resolve(uid, ref comp))
|
||||
return;
|
||||
|
||||
comp.Ignited = ignited;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
|
||||
Reference in New Issue
Block a user