Example #1
0
    private void Interact()
    {
        // first check if something is held
        if (grabbedElement != null)
        {
            grabbedElement.Throw();
            grabbedElement = null;
            return;
        }

        // Next check if an interaction is available
        if (nearestInteraction != null)
        {
            GameElement elem = nearestInteraction;
            try
            {
                elem.Interact(this);
            }
            catch (Exception e)
            {
            }

            if (elem is GrabbableElement)
            {
                grabbedElement = elem as GrabbableElement;
                HideIndicator(true);
            }
            if (elem is CollectableElement)
            {
                if (heldElement == null)
                {
                    heldElement = elem as CollectableElement;
                    Socket.SendMessage(new UpdateItemMessage(heldElement.ItemID, heldElement.ItemDescription, heldElement.ItemName));
                }
                else
                {
                    (elem as CollectableElement).Throw();
                }
            }
            nearestInteraction = null;
            return;
        }
    }