SelfUnremovableClothingSystem.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Content.Shared.Clothing.Components;
  2. using Content.Shared.Examine;
  3. using Content.Shared.Inventory;
  4. using Content.Shared.Inventory.Events;
  5. namespace Content.Shared.Clothing.EntitySystems;
  6. /// <summary>
  7. /// A system for the operation of a component that prohibits the player from taking off his own clothes that have this component.
  8. /// </summary>
  9. public sealed class SelfUnremovableClothingSystem : EntitySystem
  10. {
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<SelfUnremovableClothingComponent, BeingUnequippedAttemptEvent>(OnUnequip);
  15. SubscribeLocalEvent<SelfUnremovableClothingComponent, ExaminedEvent>(OnUnequipMarkup);
  16. }
  17. private void OnUnequip(Entity<SelfUnremovableClothingComponent> selfUnremovableClothing, ref BeingUnequippedAttemptEvent args)
  18. {
  19. if (TryComp<ClothingComponent>(selfUnremovableClothing, out var clothing) && (clothing.Slots & args.SlotFlags) == SlotFlags.NONE)
  20. return;
  21. if (args.UnEquipTarget == args.Unequipee)
  22. {
  23. args.Cancel();
  24. }
  25. }
  26. private void OnUnequipMarkup(Entity<SelfUnremovableClothingComponent> selfUnremovableClothing, ref ExaminedEvent args)
  27. {
  28. args.PushMarkup(Loc.GetString("comp-self-unremovable-clothing"));
  29. }
  30. }