diff --git a/Content.Shared/Inventory/InventorySystem.Relay.cs b/Content.Shared/Inventory/InventorySystem.Relay.cs index 20a98dc124..f6863c74e0 100644 --- a/Content.Shared/Inventory/InventorySystem.Relay.cs +++ b/Content.Shared/Inventory/InventorySystem.Relay.cs @@ -49,14 +49,26 @@ public partial class InventorySystem protected void RefRelayInventoryEvent(EntityUid uid, InventoryComponent component, ref T args) where T : IInventoryRelayEvent { - var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots); + RelayEvent((uid, component), args); + } - // this copies the by-ref event + protected void RelayInventoryEvent(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent + { + RelayEvent((uid, component), args); + } + + public void RelayEvent(Entity inventory, ref T args) where T : IInventoryRelayEvent + { + var containerEnumerator = new ContainerSlotEnumerator(inventory, inventory.Comp.TemplateId, _prototypeManager, this, args.TargetSlots); + + // this copies the by-ref event if it is a struct var ev = new InventoryRelayedEvent(args); while (containerEnumerator.MoveNext(out var container)) { - if (!container.ContainedEntity.HasValue) continue; + if (!container.ContainedEntity.HasValue) + continue; + RaiseLocalEvent(container.ContainedEntity.Value, ev); } @@ -64,16 +76,18 @@ public partial class InventorySystem args = ev.Args; } - protected void RelayInventoryEvent(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent + public void RelayEvent(Entity inventory, T args) where T : IInventoryRelayEvent { if (args.TargetSlots == SlotFlags.NONE) return; - var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots); + var containerEnumerator = new ContainerSlotEnumerator(inventory, inventory.Comp.TemplateId, _prototypeManager, this, args.TargetSlots); var ev = new InventoryRelayedEvent(args); while (containerEnumerator.MoveNext(out var container)) { - if (!container.ContainedEntity.HasValue) continue; + if (!container.ContainedEntity.HasValue) + continue; + RaiseLocalEvent(container.ContainedEntity.Value, ev); } }