private void OnHandleState(EntityUid uid, SharedClothingComponent component, ref ComponentHandleState args)
 {
     if (args.Current is ClothingComponentState state)
     {
         component.EquippedPrefix = state.EquippedPrefix;
     }
 }
Exemple #2
0
    protected void QuickEquip(EntityUid uid, SharedClothingComponent component, UseInHandEvent args)
    {
        if (!TryComp(args.User, out InventoryComponent? inv) ||
            !TryComp(args.User, out SharedHandsComponent? hands) ||
            !_prototypeManager.TryIndex <InventoryTemplatePrototype>(inv.TemplateId, out var prototype))
        {
            return;
        }

        foreach (var slotDef in prototype.Slots)
        {
            if (!CanEquip(args.User, uid, slotDef.Name, out _, slotDef, inv))
            {
                continue;
            }

            if (TryGetSlotEntity(args.User, slotDef.Name, out var slotEntity, inv))
            {
                // Item in slot has to be quick equipable as well
                if (TryComp(slotEntity, out SharedClothingComponent? item) && !item.QuickEquip)
                {
                    continue;
                }

                if (!TryUnequip(args.User, slotDef.Name, true, inventory: inv))
                {
                    continue;
                }

                if (!TryEquip(args.User, uid, slotDef.Name, true, inventory: inv))
                {
                    continue;
                }

                _handsSystem.PickupOrDrop(args.User, slotEntity.Value);
            }
 private void OnGetState(EntityUid uid, SharedClothingComponent component, ref ComponentGetState args)
 {
     args.State = new ClothingComponentState(component.EquippedPrefix);
 }