2019-06-07 16:15:20 +05:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-02-18 20:45:45 -08:00
|
|
|
|
using Robust.Shared.Timing;
|
2019-06-07 16:15:20 +05:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Explosion
|
2019-06-07 16:15:20 +05:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This interface gives components behavior when being "triggered" by timer or other conditions
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public interface ITimerTrigger
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Called when one object is triggering some event
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
bool Trigger(TimerTriggerEventArgs eventArgs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class TimerTriggerEventArgs : EventArgs
|
|
|
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
|
public TimerTriggerEventArgs(IEntity user, IEntity source)
|
|
|
|
|
|
{
|
|
|
|
|
|
User = user;
|
|
|
|
|
|
Source = source;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-07 16:15:20 +05:00
|
|
|
|
public IEntity User { get; set; }
|
|
|
|
|
|
public IEntity Source { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
|
public sealed class TriggerSystem : EntitySystem
|
|
|
|
|
|
{
|
|
|
|
|
|
public void HandleTimerTrigger(TimeSpan delay, IEntity user, IEntity trigger)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Timer.Spawn(delay, () =>
|
|
|
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
|
var timerTriggerEventArgs = new TimerTriggerEventArgs(user, trigger);
|
2019-06-07 16:15:20 +05:00
|
|
|
|
var timerTriggers = trigger.GetAllComponents<ITimerTrigger>().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var timerTrigger in timerTriggers)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (timerTrigger.Trigger(timerTriggerEventArgs))
|
|
|
|
|
|
{
|
|
|
|
|
|
// If an IOnTimerTrigger returns a status completion we finish our trigger
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
|
}
|