Trigger Refactor (#39034)
This commit is contained in:
58
Content.Server/Trigger/Systems/IgniteOnTriggerSystem.cs
Normal file
58
Content.Server/Trigger/Systems/IgniteOnTriggerSystem.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Content.Shared.IgnitionSource;
|
||||
using Content.Shared.Trigger;
|
||||
using Content.Shared.Trigger.Components.Effects;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Trigger.Systems;
|
||||
|
||||
/// <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 SharedIgnitionSourceSystem _source = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<IgniteOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||
}
|
||||
|
||||
// TODO: move this into ignition source component
|
||||
// it already has an update loop
|
||||
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, source), false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrigger(Entity<IgniteOnTriggerComponent> ent, ref TriggerEvent args)
|
||||
{
|
||||
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||
return;
|
||||
|
||||
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
_source.SetIgnited(target.Value);
|
||||
ent.Comp.IgnitedUntil = _timing.CurTime + ent.Comp.IgnitedTime;
|
||||
Dirty(ent);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user