Exemplo n.º 1
0
 private void OnUnequipAttempt(EntityUid uid, StunnedComponent stunned, IsUnequippingAttemptEvent args)
 {
     // is this a self-equip, or are they being stripped?
     if (args.Unequipee == uid)
     {
         args.Cancel();
     }
 }
Exemplo n.º 2
0
 private void OnUnequipAttempt(EntityUid uid, MobStateComponent component, IsUnequippingAttemptEvent args)
 {
     // is this a self-equip, or are they being stripped?
     if (args.Unequipee == uid)
     {
         CheckAct(uid, component, args);
     }
 }
    public bool CanUnequip(EntityUid actor, EntityUid target, string slot, [NotNullWhen(false)] out string?reason, ContainerSlot?containerSlot = null, SlotDefinition?slotDefinition = null, InventoryComponent?inventory = null)
    {
        reason = "inventory-component-can-unequip-cannot";
        if (!Resolve(target, ref inventory, false))
        {
            return(false);
        }

        if ((containerSlot == null || slotDefinition == null) && !TryGetSlotContainer(target, slot, out containerSlot, out slotDefinition, inventory))
        {
            return(false);
        }

        if (containerSlot.ContainedEntity == null)
        {
            return(false);
        }

        if (!containerSlot.ContainedEntity.HasValue || !containerSlot.CanRemove(containerSlot.ContainedEntity.Value))
        {
            return(false);
        }

        var itemUid = containerSlot.ContainedEntity.Value;

        var attemptEvent = new IsUnequippingAttemptEvent(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 BeingUnequippedAttemptEvent(actor, target, itemUid, slotDefinition);

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

        return(true);
    }