Exemplo n.º 1
0
    void UpdateInteractions()
    {
        if (!sight.enabled || sight.target == null || !sight.target.isAbleToInteract)
        {
            return;
        }

        InteractiveThing target = sight.target;
        var focusTimeSec        = target.hasItsOwnFocusTime ? target.focusTimeSec : defaultFocusTimeSec;

        if (itemInHand != null && itemInHand.isAbleToInteract)
        {
            if (target != null && target != itemInHand && sight.focusOnTargetWithoutInterruptionSec > focusTimeSec)
            {
                if (itemInHand.IsAbleToInteractWith(target))
                {
                    itemInHand.Interact(target);

                    /*
                     * itemInHand = null;
                     * sight.reticle.SetBody(0);
                     * sight.ResetTarget();
                     */
                    Drop(itemInHand);
                }

                if (target is InventorySpot)
                {
                    var inventorySpot = target as InventorySpot;
                    if (inventorySpot.item == null)
                    {
                        inventorySpot.Add(itemInHand);

                        /*
                         * itemInHand = null;
                         * sight.reticle.SetBody(0);
                         * sight.ResetTarget();
                         */
                        Drop(itemInHand);
                    }
                }
            }
        }
        else if (itemInHand == null)
        {
            if (target != null && sight.focusOnTargetWithoutInterruptionSec > focusTimeSec)
            {
                if (target is ObtainableItem)
                {
                    Take(target as ObtainableItem);
                }
                else if (target is InteractiveObject)
                {
                    var interactiveObject = target as InteractiveObject;
                    if (interactiveObject.isAbleToBeActivatedOnItsOwn)
                    {
                        //Debug.Log("Visitor activates "+target);
                        interactiveObject.Activate();
                    }
                }
            }
        }
    }