Ejemplo n.º 1
0
    /// <summary>
    /// Mounts an item to the first open mount point.
    /// </summary>
    /// <param name="itemToMount">Item to mount to this character.</param>
    /// <returns>True if the item mounted successfully, otherwise false.</returns>
    public bool MountItem(RegularItem itemToMount)
    {
        // look for empty mount point
        MountPoint[] mountPoints = GetComponentsInChildren <MountPoint>();

        // if slots are full, return false!
        for (int i = 0; i < mountPoints.Length; ++i)
        {
            if (itemToMount.MountTo(mountPoints[i]) != null)
            {
                ItemIdle itemStateIdle = ScriptableObject.CreateInstance <ItemIdle>();
                itemStateIdle.Enter(this, itemToMount, mountPoints[i].BodyPartType);
                bodyPartStates[mountPoints[i].BodyPartType] = itemStateIdle;
                return(true);
            }
        }

        // return true, we did it reddit!
        return(false);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Mounts a given item to a provided body part type if that joint's mount
    /// point is empty.
    /// </summary>
    /// <param name="itemToMount">Item to mount to this character.</param>
    /// <param name="bodyPartType">Body part ID to mount this item to.</param>
    /// <returns>True if the item mounted successfully, otherwise false.</returns>
    public bool MountItem(RegularItem itemToMount, int bodyPartType)
    {
        // ensure joint exists
        if (!joints.ContainsKey(bodyPartType))
        {
            return(false);
        }

        // ensure body part is attached
        BodyPart attachedBodyPart;

        if ((attachedBodyPart = joints[bodyPartType].BodyPart) == null)
        {
            return(false);
        }

        // ensure mount point exists
        if (attachedBodyPart.MountPoint == null)
        {
            return(false);
        }

        // mount it
        if (itemToMount.MountTo(attachedBodyPart.MountPoint) == null)
        {
            return(false);
        }

        // call animator to equip
        ItemIdle itemStateIdle = ScriptableObject.CreateInstance <ItemIdle>();

        itemStateIdle.Enter(this, itemToMount, bodyPartType);
        bodyPartStates[bodyPartType] = itemStateIdle;

        return(true);
    }