// 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 Piras314 // SPDX-FileCopyrightText: 2025 gus // // SPDX-License-Identifier: AGPL-3.0-or-later using Content.Shared._Shitmed.DoAfter; using Content.Shared.Body.Components; using Content.Shared.Body.Part; namespace Content.Shared.Body.Systems; public partial class SharedBodySystem { private void InitializeRelay() { SubscribeLocalEvent(RelayBodyPartEvent); } protected void RefRelayBodyPartEvent(EntityUid uid, BodyComponent component, ref T args) where T : IBodyPartRelayEvent { RelayEvent((uid, component), ref args); } protected void RelayBodyPartEvent(EntityUid uid, BodyComponent component, T args) where T : IBodyPartRelayEvent { RelayEvent((uid, component), args); } public void RelayEvent(Entity body, ref T args) where T : IBodyPartRelayEvent { // this copies the by-ref event if it is a struct var ev = new BodyPartRelayedEvent(args); foreach (var part in GetBodyChildrenOfType(body.Owner, args.TargetBodyPart, body.Comp)) { RaiseLocalEvent(part.Id, ev); } // and now we copy it back args = ev.Args; } public void RelayEvent(Entity body, T args) where T : IBodyPartRelayEvent { var ev = new BodyPartRelayedEvent(args); foreach (var part in GetBodyChildrenOfType(body.Owner, args.TargetBodyPart, body.Comp)) { RaiseLocalEvent(part.Id, ev); } } } public sealed class BodyPartRelayedEvent : EntityEventArgs { public TEvent Args; public BodyPartRelayedEvent(TEvent args) { Args = args; } } /// /// Events that should be relayed to body parts should implement this interface. /// public interface IBodyPartRelayEvent { /// /// What body part should this event be relayed to, if any? /// public BodyPartType TargetBodyPart { get; } }