Exemple #1
0
    private void OnEquip(EntityUid uid, BlockingComponent component, GotEquippedHandEvent args)
    {
        component.User = args.User;

        //To make sure that this bodytype doesn't get set as anything but the original
        if (TryComp <PhysicsComponent>(args.User, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static &&
            !TryComp <BlockingUserComponent>(args.User, out var blockingUserComponent))
        {
            var userComp = EnsureComp <BlockingUserComponent>(args.User);
            userComp.BlockingItem     = uid;
            userComp.OriginalBodyType = physicsComponent.BodyType;
        }
    }
    /// <summary>
    ///     Puts an entity into the player's hand, assumes that the insertion is allowed. In general, you should not be calling this function directly.
    /// </summary>
    public virtual void DoPickup(EntityUid uid, Hand hand, EntityUid entity, SharedHandsComponent?hands = null)
    {
        if (!Resolve(uid, ref hands))
        {
            return;
        }

        var handContainer = hand.Container;

        if (handContainer == null || handContainer.ContainedEntity != null)
        {
            return;
        }

        if (!handContainer.Insert(entity, EntityManager))
        {
            Logger.Error($"{nameof(SharedHandsComponent)} on {uid} could not insert {entity} into {handContainer}.");
            return;
        }

        _adminLogger.Add(LogType.Pickup, LogImpact.Low, $"{ToPrettyString(uid):user} picked up {ToPrettyString(entity):entity}");

        Dirty(hands);

        var didEquip = new DidEquipHandEvent(uid, entity, hand);

        RaiseLocalEvent(uid, didEquip, false);

        var gotEquipped = new GotEquippedHandEvent(uid, entity, hand);

        RaiseLocalEvent(entity, gotEquipped, true);

        // TODO this should REALLY be a cancellable thing, not a handled event.
        // If one of the interactions resulted in the item being dropped, return early.
        if (gotEquipped.Handled)
        {
            return;
        }

        if (hand == hands.ActiveHand)
        {
            RaiseLocalEvent(entity, new HandSelectedEvent(uid), false);
        }
    }