Пример #1
0
 private void OnEquipAttempt(EntityUid uid, StunnedComponent stunned, IsEquippingAttemptEvent args)
 {
     // is this a self-equip, or are they being stripped?
     if (args.Equipee == uid)
     {
         args.Cancel();
     }
 }
Пример #2
0
 private void OnEquipAttempt(EntityUid uid, MobStateComponent component, IsEquippingAttemptEvent args)
 {
     // is this a self-equip, or are they being stripped?
     if (args.Equipee == uid)
     {
         CheckAct(uid, component, args);
     }
 }
    public bool CanEquip(EntityUid actor, EntityUid target, EntityUid itemUid, string slot, [NotNullWhen(false)] out string?reason, SlotDefinition?slotDefinition = null, InventoryComponent?inventory = null, SharedItemComponent?item = null)
    {
        reason = "inventory-component-can-equip-cannot";
        if (!Resolve(target, ref inventory, false) || !Resolve(itemUid, ref item, false))
        {
            return(false);
        }

        if (slotDefinition == null && !TryGetSlot(target, slot, out slotDefinition, inventory: inventory))
        {
            return(false);
        }

        if (slotDefinition.DependsOn != null && !TryGetSlotEntity(target, slotDefinition.DependsOn, out _, inventory))
        {
            return(false);
        }

        if (!item.SlotFlags.HasFlag(slotDefinition.SlotFlags) && (!slotDefinition.SlotFlags.HasFlag(SlotFlags.POCKET) || item.Size > (int)ReferenceSizes.Pocket))
        {
            reason = "inventory-component-can-equip-does-not-fit";
            return(false);
        }

        var attemptEvent = new IsEquippingAttemptEvent(actor, target, itemUid, slotDefinition);

        RaiseLocalEvent(target, attemptEvent);
        if (attemptEvent.Cancelled)
        {
            reason = attemptEvent.Reason ?? reason;
            return(false);
        }

        if (actor != target)
        {
            //reuse the event. this is gucci, right?
            attemptEvent.Reason = null;
            RaiseLocalEvent(actor, attemptEvent);
            if (attemptEvent.Cancelled)
            {
                reason = attemptEvent.Reason ?? reason;
                return(false);
            }
        }

        var itemAttemptEvent = new BeingEquippedAttemptEvent(actor, target, itemUid, slotDefinition);

        RaiseLocalEvent(itemUid, itemAttemptEvent);
        if (itemAttemptEvent.Cancelled)
        {
            reason = itemAttemptEvent.Reason ?? reason;
            return(false);
        }

        return(true);
    }