Trigger Refactor (#39034)

This commit is contained in:
slarticodefast
2025-08-03 21:20:37 +02:00
committed by GitHub
parent 777e89ab3e
commit 2c40a950f7
256 changed files with 3987 additions and 2892 deletions

View File

@@ -1,5 +1,8 @@
using Content.Shared.Explosion.Components;
using Content.Shared.Throwing;
using Content.Shared.Trigger;
using Content.Shared.Trigger.Systems;
using Content.Shared.Trigger.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.Map;
@@ -15,6 +18,7 @@ public sealed class ScatteringGrenadeSystem : SharedScatteringGrenadeSystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly TriggerSystem _trigger = default!;
public override void Initialize()
{
@@ -30,6 +34,9 @@ public sealed class ScatteringGrenadeSystem : SharedScatteringGrenadeSystem
/// </summary>
private void OnScatteringTrigger(Entity<ScatteringGrenadeComponent> entity, ref TriggerEvent args)
{
if (args.Key != entity.Comp.TriggerKey)
return;
entity.Comp.IsTriggered = true;
args.Handled = true;
}
@@ -76,13 +83,12 @@ public sealed class ScatteringGrenadeSystem : SharedScatteringGrenadeSystem
_throwingSystem.TryThrow(contentUid, direction, component.Velocity);
if (component.TriggerContents)
if (component.TriggerContents && TryComp<TimerTriggerComponent>(contentUid, out var contentTimer))
{
additionalIntervalDelay += _random.NextFloat(component.IntervalBetweenTriggersMin, component.IntervalBetweenTriggersMax);
var contentTimer = EnsureComp<ActiveTimerTriggerComponent>(contentUid);
contentTimer.TimeRemaining = component.DelayBeforeTriggerContents + additionalIntervalDelay;
var ev = new ActiveTimerTriggerEvent(contentUid, uid);
RaiseLocalEvent(contentUid, ref ev);
_trigger.SetDelay((contentUid, contentTimer), TimeSpan.FromSeconds(component.DelayBeforeTriggerContents + additionalIntervalDelay));
_trigger.ActivateTimerTrigger((contentUid, contentTimer));
}
}