Revert "Fix unintentional inventory relayed event handling " (#12182)

This commit is contained in:
Emisse
2022-10-24 09:06:04 -06:00
committed by GitHub
parent 145471be2d
commit 80fd37041f
9 changed files with 15 additions and 53 deletions

View File

@@ -23,38 +23,15 @@ public partial class InventorySystem
protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : EntityEventArgs, IInventoryRelayEvent
{
if (args.TargetSlots == SlotFlags.NONE)
return;
var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots);
var ev = new InventoryRelayedEvent<T>(args);
while (containerEnumerator.MoveNext(out var container))
while(containerEnumerator.MoveNext(out var container))
{
if (!container.ContainedEntity.HasValue) continue;
RaiseLocalEvent(container.ContainedEntity.Value, ev, false);
if(!container.ContainedEntity.HasValue) continue;
RaiseLocalEvent(container.ContainedEntity.Value, args, false);
}
}
}
/// <summary>
/// Event wrapper for relayed events.
/// </summary>
/// <remarks>
/// This avoids nested inventory relays, and makes it easy to have certain events only handled by the initial
/// target entity. E.g. health based movement speed modifiers should not be handled by a hat, even if that hat
/// happens to be a dead mouse. Clothing that wishes to modify movement speed must subscribe to
/// InventoryRelayedEvent<RefreshMovementSpeedModifiersEvent>
/// </remarks>
public sealed class InventoryRelayedEvent<TEvent> : EntityEventArgs where TEvent : EntityEventArgs, IInventoryRelayEvent
{
public readonly TEvent Args;
public InventoryRelayedEvent(TEvent args)
{
Args = args;
}
}
/// <summary>
/// Events that should be relayed to inventory slots should implement this interface.
/// </summary>