Add public methods to relay inventory events (#22165)
This commit is contained in:
@@ -49,14 +49,26 @@ public partial class InventorySystem
|
||||
|
||||
protected void RefRelayInventoryEvent<T>(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<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
|
||||
{
|
||||
RelayEvent((uid, component), args);
|
||||
}
|
||||
|
||||
public void RelayEvent<T>(Entity<InventoryComponent> 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<T>(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<T>(EntityUid uid, InventoryComponent component, T args) where T : IInventoryRelayEvent
|
||||
public void RelayEvent<T>(Entity<InventoryComponent> 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<T>(args);
|
||||
while (containerEnumerator.MoveNext(out var container))
|
||||
{
|
||||
if (!container.ContainedEntity.HasValue) continue;
|
||||
if (!container.ContainedEntity.HasValue)
|
||||
continue;
|
||||
|
||||
RaiseLocalEvent(container.ContainedEntity.Value, ev);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user