private void VoiceTriggered(Entity<StorageVoiceControlComponent> ent, ref VoiceTriggeredEvent args)
{
- // Check if the component has any slot restrictions via AllowedSlots
// If it has slot restrictions, check if the item is in a slot that is allowed
- if (ent.Comp.AllowedSlots != null && _inventory.TryGetContainingSlot(ent.Owner, out var itemSlot) &&
- (itemSlot.SlotFlags & ent.Comp.AllowedSlots) == 0)
+ if (ent.Comp.AllowedSlots is { } allowedSlots
+ && !_inventory.InSlotWithAnyFlags(ent.Owner, allowedSlots))
return;
// Get the storage component
}
/// <summary>
- /// Returns true if the given entity is equipped to an inventory slot with the given inventory slot flags.
+ /// Returns true if the given entity is equipped to an inventory slot with exactly matching inventory slot flags.
/// </summary>
+ /// <seealso cref="InSlotWithAnyFlags" />
public bool InSlotWithFlags(Entity<TransformComponent?, MetaDataComponent?> entity, SlotFlags flags)
{
return TryGetContainingSlot(entity, out var slot)
&& (slot.SlotFlags & flags) == flags;
}
+ /// <summary>
+ /// Returns true if the given entity is equipped to an inventory slot that
+ /// has any flags in common with the given ones.
+ /// </summary>
+ /// <seealso cref="InSlotWithFlags" />
+ public bool InSlotWithAnyFlags(Entity<TransformComponent?, MetaDataComponent?> ent, SlotFlags flags)
+ {
+ return TryGetContainingSlot(ent, out var slot)
+ && (slot.SlotFlags & flags) != 0;
+ }
+
public bool SpawnItemInSlot(EntityUid uid, string slot, string prototype, bool silent = false, bool force = false, InventoryComponent? inventory = null)
{
if (!Resolve(uid, ref inventory, false))