From: DrSmugleaf Date: Wed, 6 Dec 2023 07:01:31 +0000 (-0700) Subject: Add public methods to relay inventory events (#22165) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=abfea8db5fdfba03ab2a8f955a305eb17b3e8562;p=space-station-14.git Add public methods to relay inventory events (#22165) --- 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); + } + + 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 + // 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); } }