// SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com> // SPDX-FileCopyrightText: 2025 Aviu00 <93730715+Aviu00@users.noreply.github.com> // SPDX-FileCopyrightText: 2025 Misandry // SPDX-FileCopyrightText: 2025 gus // // SPDX-License-Identifier: AGPL-3.0-or-later using System.Linq; using Content.Server._Shitcode.Wizard.Components; using Content.Shared._Shitcode.Wizard.Traps; using Content.Shared.Stunnable.Events; using Content.Shared.Timing; using Robust.Server.Audio; namespace Content.Server._Shitcode.Wizard.Systems; public sealed class UseDelayBlockKnockdownSystem : EntitySystem { [Dependency] private readonly UseDelaySystem _delay = default!; [Dependency] private readonly AudioSystem _audio = default!; [Dependency] private readonly SparksSystem _sparks = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnAttempt); SubscribeLocalEvent(OnSuccess); } private void OnSuccess(Entity ent, ref KnockdownOnHitSuccessEvent args) { var (uid, comp) = ent; if (comp.ResetDelayOnSuccess) _delay.TryResetDelay(uid, id: comp.Delay); _audio.PlayPvs(comp.KnockdownSound, Transform(uid).Coordinates); if (!comp.DoSparks) return; foreach (var coords in args.KnockedDown.Select(knocked => Transform(knocked).Coordinates)) { _sparks.DoSparks(coords, playSound: false); } } private void OnAttempt(Entity ent, ref KnockdownOnHitAttemptEvent args) { var (uid, comp) = ent; if (args.Cancelled || !TryComp(uid, out UseDelayComponent? delay)) return; if (_delay.IsDelayed((uid, delay), comp.Delay)) args.Cancelled = true; } }