Prevent inventory events from being relayed to pockets (#6074)

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2022-01-10 17:37:20 +13:00
committed by GitHub
parent 19b1c003e0
commit 013edcc545
9 changed files with 63 additions and 20 deletions

View File

@@ -16,9 +16,9 @@ public partial class InventorySystem
SubscribeLocalEvent<InventoryComponent, RefreshMovementSpeedModifiersEvent>(RelayInventoryEvent);
}
protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : EntityEventArgs
protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : EntityEventArgs, IInventoryRelayEvent
{
var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this);
var containerEnumerator = new ContainerSlotEnumerator(uid, component.TemplateId, _prototypeManager, this, args.TargetSlots);
while(containerEnumerator.MoveNext(out var container))
{
if(!container.ContainedEntity.HasValue) continue;
@@ -26,3 +26,18 @@ public partial class InventorySystem
}
}
}
/// <summary>
/// Events that should be relayed to inventory slots should implement this interface.
/// </summary>
public interface IInventoryRelayEvent
{
/// <summary>
/// What inventory slots should this event be relayed to, if any?
/// </summary>
/// <remarks>
/// In general you may want to exclude <see cref="SlotFlags.POCKET"/>, given that those items are not truly
/// "equipped" by the user.
/// </remarks>
public SlotFlags TargetSlots { get; }
}