using Content.Shared.Body.Events; using Content.Shared.Gibbing; using Content.Shared.Humanoid; using Content.Shared.Medical; using JetBrains.Annotations; namespace Content.Shared.Body; public sealed partial class BodySystem { // Refrain from adding an infinite block of relays here - consuming systems can use RelayEvent private void InitializeRelay() { SubscribeLocalEvent(RefRelayBodyEvent); SubscribeLocalEvent(RefRelayBodyEvent); SubscribeLocalEvent(RefRelayBodyEvent); SubscribeLocalEvent(RefRelayBodyEvent); SubscribeLocalEvent(RefRelayBodyEvent); SubscribeLocalEvent(RefRelayBodyEvent); SubscribeLocalEvent(RefRelayBodyEvent); } private void RefRelayBodyEvent(EntityUid uid, BodyComponent component, ref T args) where T : struct { RelayEvent((uid, component), ref args); } private void RelayBodyEvent(EntityUid uid, BodyComponent component, T args) where T : class { RelayEvent((uid, component), args); } /// /// Relays the given event to organs within a body. /// /// The body to relay the event within /// The event to relay /// The type of the event [PublicAPI] public void RelayEvent(Entity ent, ref T args) where T : struct { var ev = new BodyRelayedEvent(ent, args); foreach (var organ in ent.Comp.Organs?.ContainedEntities ?? []) { RaiseLocalEvent(organ, ref ev); } args = ev.Args; } /// /// Relays the given event to organs within a body. /// /// The body to relay the event within /// The event to relay /// The type of the event [PublicAPI] public void RelayEvent(Entity ent, T args) where T : class { var ev = new BodyRelayedEvent(ent, args); foreach (var organ in ent.Comp.Organs?.ContainedEntities ?? []) { RaiseLocalEvent(organ, ref ev); } } } /// /// Event wrapper for events being relayed to organs within a body. /// [ByRefEvent] public record struct BodyRelayedEvent(Entity Body, TEvent Args);