This commit is contained in:
Leon Friedrich
2022-10-25 13:06:00 +13:00
committed by GitHub
parent 4b5df9b0f7
commit 92e92dceb0
12 changed files with 74 additions and 32 deletions

View File

@@ -5,6 +5,7 @@ using Content.Shared.IdentityManagement.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Slippery;
using Content.Shared.Strip.Components;
using Content.Shared.Temperature;
namespace Content.Shared.Inventory;
@@ -19,19 +20,43 @@ public partial class InventorySystem
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, BeforeStripEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, SeeIdentityAttemptEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, ModifyChangedTemperatureEvent>(RelayInventoryEvent);
}
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);
while(containerEnumerator.MoveNext(out var container))
var ev = new InventoryRelayedEvent<T>(args);
while (containerEnumerator.MoveNext(out var container))
{
if(!container.ContainedEntity.HasValue) continue;
RaiseLocalEvent(container.ContainedEntity.Value, args, false);
if (!container.ContainedEntity.HasValue) continue;
RaiseLocalEvent(container.ContainedEntity.Value, ev, 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>