ECS OnUseTimerTrigger (#6369)
This commit is contained in:
@@ -1,34 +1,11 @@
|
|||||||
using System;
|
using Robust.Shared.GameObjects;
|
||||||
using Content.Server.Explosion.EntitySystems;
|
|
||||||
using Content.Shared.Interaction;
|
|
||||||
using Content.Shared.Trigger;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
|
||||||
namespace Content.Server.Explosion.Components
|
namespace Content.Server.Explosion.Components
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent, ComponentProtoName("OnUseTimerTrigger")]
|
||||||
public class OnUseTimerTriggerComponent : Component, IUse
|
public class OnUseTimerTriggerComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "OnUseTimerTrigger";
|
[DataField("delay")] public float Delay = 0f;
|
||||||
|
|
||||||
[DataField("delay")]
|
|
||||||
private float _delay = 0f;
|
|
||||||
|
|
||||||
// TODO: Need to split this out so it's a generic "OnUseTimerTrigger" component.
|
|
||||||
public void Trigger(EntityUid user)
|
|
||||||
{
|
|
||||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent? appearance))
|
|
||||||
appearance.SetData(TriggerVisuals.VisualState, TriggerVisualState.Primed);
|
|
||||||
|
|
||||||
EntitySystem.Get<TriggerSystem>().HandleTimerTrigger(TimeSpan.FromSeconds(_delay), Owner, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
|
||||||
{
|
|
||||||
Trigger(eventArgs.User);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Server.Explosion.Components;
|
||||||
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Trigger;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Server.Explosion.EntitySystems;
|
||||||
|
|
||||||
|
public sealed partial class TriggerSystem
|
||||||
|
{
|
||||||
|
private void InitializeOnUse()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<OnUseTimerTriggerComponent, UseInHandEvent>(OnTimerUse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTimerUse(EntityUid uid, OnUseTimerTriggerComponent component, UseInHandEvent args)
|
||||||
|
{
|
||||||
|
if (args.Handled) return;
|
||||||
|
|
||||||
|
Trigger(uid, args.User, component);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Need to split this out so it's a generic "OnUseTimerTrigger" component.
|
||||||
|
private void Trigger(EntityUid uid, EntityUid user, OnUseTimerTriggerComponent component)
|
||||||
|
{
|
||||||
|
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
||||||
|
appearance.SetData(TriggerVisuals.VisualState, TriggerVisualState.Primed);
|
||||||
|
|
||||||
|
HandleTimerTrigger(TimeSpan.FromSeconds(component.Delay), uid, user);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ namespace Content.Server.Explosion.EntitySystems
|
|||||||
}
|
}
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class TriggerSystem : EntitySystem
|
public sealed partial class TriggerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly ExplosionSystem _explosions = default!;
|
[Dependency] private readonly ExplosionSystem _explosions = default!;
|
||||||
[Dependency] private readonly FlashSystem _flashSystem = default!;
|
[Dependency] private readonly FlashSystem _flashSystem = default!;
|
||||||
@@ -43,6 +43,9 @@ namespace Content.Server.Explosion.EntitySystems
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
InitializeOnUse();
|
||||||
|
|
||||||
SubscribeLocalEvent<TriggerOnCollideComponent, StartCollideEvent>(HandleCollide);
|
SubscribeLocalEvent<TriggerOnCollideComponent, StartCollideEvent>(HandleCollide);
|
||||||
|
|
||||||
SubscribeLocalEvent<DeleteOnTriggerComponent, TriggerEvent>(HandleDeleteTrigger);
|
SubscribeLocalEvent<DeleteOnTriggerComponent, TriggerEvent>(HandleDeleteTrigger);
|
||||||
|
|||||||
Reference in New Issue
Block a user