Files
tbd-station-14/Content.Shared/Inventory/SlotBlockSystem.cs
Winkarst 08d9d46b46 New Feature: Slot blockers (#35172)
* First commit

* More comments

* Update

* Update

* For Beloved Maintainers

* Beck T, my beloved

* Update

* Old stuff

* Update EquipAttemptEvents.cs

* Update UnequipAttemptEvent.cs

---------

Co-authored-by: beck-thompson <107373427+beck-thompson@users.noreply.github.com>
2025-05-12 10:35:42 -07:00

36 lines
1.3 KiB
C#

using Content.Shared.Inventory.Events;
namespace Content.Shared.Inventory;
/// <summary>
/// Handles prevention of items being unequipped and equipped from slots that are blocked by <see cref="SlotBlockComponent"/>.
/// </summary>
public sealed partial class SlotBlockSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SlotBlockComponent, InventoryRelayedEvent<IsEquippingTargetAttemptEvent>>(OnEquipAttempt);
SubscribeLocalEvent<SlotBlockComponent, InventoryRelayedEvent<IsUnequippingTargetAttemptEvent>>(OnUnequipAttempt);
}
private void OnEquipAttempt(Entity<SlotBlockComponent> ent, ref InventoryRelayedEvent<IsEquippingTargetAttemptEvent> args)
{
if (args.Args.Cancelled || (args.Args.SlotFlags & ent.Comp.Slots) == 0)
return;
args.Args.Reason = Loc.GetString("slot-block-component-blocked", ("item", ent));
args.Args.Cancel();
}
private void OnUnequipAttempt(Entity<SlotBlockComponent> ent, ref InventoryRelayedEvent<IsUnequippingTargetAttemptEvent> args)
{
if (args.Args.Cancelled || (args.Args.SlotFlags & ent.Comp.Slots) == 0)
return;
args.Args.Reason = Loc.GetString("slot-block-component-blocked", ("item", ent));
args.Args.Cancel();
}
}