Equipment verbs & admin inventory access. (#14315)
This commit is contained in:
@@ -1,11 +1,32 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Item;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Inventory;
|
||||
|
||||
public partial class InventorySystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the definition of the inventory slot that the given entity is currently in..
|
||||
/// </summary>
|
||||
public bool TryGetContainingSlot(EntityUid uid, [NotNullWhen(true)] out SlotDefinition? slot)
|
||||
{
|
||||
if (!_containerSystem.TryGetContainingContainer(uid, out var container))
|
||||
{
|
||||
slot = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryGetSlot(container.Owner, container.ID, out slot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the given entity is equipped to an inventory slot with the given inventory slot flags.
|
||||
/// </summary>
|
||||
public bool InSlotWithFlags(EntityUid uid, SlotFlags flags)
|
||||
{
|
||||
return TryGetContainingSlot(uid, out var slot) && ((slot.SlotFlags & flags) == flags);
|
||||
}
|
||||
|
||||
public bool SpawnItemInSlot(EntityUid uid, string slot, string prototype, bool silent = false, bool force = false, InventoryComponent? inventory = null)
|
||||
{
|
||||
if (!Resolve(uid, ref inventory, false))
|
||||
|
||||
@@ -7,6 +7,8 @@ using Content.Shared.Radio;
|
||||
using Content.Shared.Slippery;
|
||||
using Content.Shared.Strip.Components;
|
||||
using Content.Shared.Temperature;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Shared.Inventory;
|
||||
|
||||
@@ -23,6 +25,8 @@ public partial class InventorySystem
|
||||
SubscribeLocalEvent<InventoryComponent, SeeIdentityAttemptEvent>(RelayInventoryEvent);
|
||||
SubscribeLocalEvent<InventoryComponent, ModifyChangedTemperatureEvent>(RelayInventoryEvent);
|
||||
SubscribeLocalEvent<InventoryComponent, GetDefaultRadioChannelEvent>(RelayInventoryEvent);
|
||||
|
||||
SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetStrippingVerbs);
|
||||
}
|
||||
|
||||
protected void RelayInventoryEvent<T>(EntityUid uid, InventoryComponent component, T args) where T : EntityEventArgs, IInventoryRelayEvent
|
||||
@@ -38,6 +42,33 @@ public partial class InventorySystem
|
||||
RaiseLocalEvent(container.ContainedEntity.Value, ev, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetStrippingVerbs(EntityUid uid, InventoryComponent component, GetVerbsEvent<EquipmentVerb> args)
|
||||
{
|
||||
// Automatically relay stripping related verbs to all equipped clothing.
|
||||
|
||||
if (!_prototypeManager.TryIndex(component.TemplateId, out InventoryTemplatePrototype? proto))
|
||||
return;
|
||||
|
||||
if (!TryComp(uid, out ContainerManagerComponent? containers))
|
||||
return;
|
||||
|
||||
var ev = new InventoryRelayedEvent<GetVerbsEvent<EquipmentVerb>>(args);
|
||||
foreach (var slotDef in proto.Slots)
|
||||
{
|
||||
if (slotDef.StripHidden && args.User != uid)
|
||||
continue;
|
||||
|
||||
if (!containers.TryGetContainer(slotDef.Name, out var container))
|
||||
continue;
|
||||
|
||||
if (container is not ContainerSlot slot || slot.ContainedEntity is not { } ent)
|
||||
continue;
|
||||
|
||||
RaiseLocalEvent(ent, ev);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,7 +80,7 @@ public partial class InventorySystem
|
||||
/// 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 sealed class InventoryRelayedEvent<TEvent> : EntityEventArgs where TEvent : EntityEventArgs
|
||||
{
|
||||
public readonly TEvent Args;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user