using Content.Shared.Actions; using Content.Shared.Clothing; using Content.Shared.Clothing.Components; using Content.Shared.Inventory; using Content.Shared.Item.ItemToggle; using Content.Shared.Toggleable; namespace Content.Shared.Clothing.EntitySystems; /// /// Handles adding and using a toggle action for . /// public sealed class ToggleClothingSystem : EntitySystem { [Dependency] private readonly SharedActionsSystem _actions = default!; [Dependency] private readonly ItemToggleSystem _toggle = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnGetActions); SubscribeLocalEvent(OnToggleAction); SubscribeLocalEvent(OnUnequipped); } private void OnMapInit(Entity ent, ref MapInitEvent args) { var (uid, comp) = ent; // test funny if (string.IsNullOrEmpty(comp.Action)) return; _actions.AddAction(uid, ref comp.ActionEntity, comp.Action); _actions.SetToggled(comp.ActionEntity, _toggle.IsActivated(ent.Owner)); Dirty(uid, comp); } private void OnGetActions(Entity ent, ref GetItemActionsEvent args) { if (args.InHands && ent.Comp.MustEquip) return; var ev = new ToggleClothingCheckEvent(args.User); RaiseLocalEvent(ent, ref ev); if (!ev.Cancelled) args.AddAction(ent.Comp.ActionEntity); } private void OnToggleAction(Entity ent, ref ToggleActionEvent args) { args.Handled = _toggle.Toggle(ent.Owner, args.Performer); } private void OnUnequipped(Entity ent, ref ClothingGotUnequippedEvent args) { if (ent.Comp.DisableOnUnequip) _toggle.TryDeactivate(ent.Owner, args.Wearer); } }