コード例 #1
0
        /// <summary>
        /// Equip all items in the weapon set
        /// </summary>
        /// <param name="rIndex">Index of the weapon set whose items will be stored</param>
        protected virtual IEnumerator Internal_EquipWeaponsSet(int rIndex)
        {
            // First, find all the entries with no equip motions and spawn them first
            for (int i = 0; i < WeaponSets[rIndex].Items.Count; i++)
            {
                BasicInventoryItem lItem = GetInventoryItem(WeaponSets[rIndex].Items[i].ItemID);
                if (lItem != null && lItem.EquipMotion.Length == 0)
                {
                    BasicInventorySlot lSlot = GetInventorySlot(WeaponSets[rIndex].Items[i].SlotID);
                    if (lSlot != null)
                    {
                        if (WeaponSets[rIndex].Items[i].Instantiate)
                        {
                            GameObject lInstance = EquipItem(lItem.ID, lSlot.ID);
                            if (lInstance != null)
                            {
                                lSlot.ItemID = lItem.ID;
                            }
                        }
                        else
                        {
                            lSlot.ItemID = lItem.ID;
                        }
                    }
                }
            }

            // Now, find all the entries that do have an equip motion
            for (int i = 0; i < WeaponSets[rIndex].Items.Count; i++)
            {
                BasicInventoryItem lItem = GetInventoryItem(WeaponSets[rIndex].Items[i].ItemID);
                if (lItem != null && lItem.EquipMotion.Length > 0)
                {
                    BasicInventorySlot lSlot = GetInventorySlot(WeaponSets[rIndex].Items[i].SlotID);
                    if (lSlot != null && lSlot.ItemID.Length == 0)
                    {
                        // If we have a motion to equip, activate it
                        MotionControllerMotion lMotion = mMotionController.GetMotion(lItem.EquipMotion);
                        if (lMotion != null)
                        {
                            IEquipStoreMotion lEquipStoreMotion = lMotion as IEquipStoreMotion;
                            if (lEquipStoreMotion != null)
                            {
                                lEquipStoreMotion.OverrideItemID = lItem.ID;
                                lEquipStoreMotion.OverrideSlotID = lSlot.ID;
                            }

                            mMotionController.ActivateMotion(lMotion);
                            while (lMotion.IsActive || lMotion.QueueActivation)
                            {
                                yield return(null);
                            }

                            // Set the item
                            lSlot.ItemID = lItem.ID;
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Store all items in the weapon set
        /// </summary>
        /// <param name="rIndex">Index of the weapon set whose items will be stored</param>
        protected virtual IEnumerator Internal_StoreWeaponsSet(int rIndex)
        {
            mIsEquippingItem = true;

            // First, find all the entries that do have a store motion
            for (int i = 0; i < WeaponSets[rIndex].Items.Count; i++)
            {
                BasicInventorySlot lSlot = GetInventorySlot(WeaponSets[rIndex].Items[i].SlotID);
                if (lSlot != null && lSlot.ItemID.Length > 0)
                {
                    BasicInventoryItem lItem = GetInventoryItem(lSlot.ItemID);
                    if (lItem != null && lItem.StoreMotion.Length > 0)
                    {
                        // If we have a motion to unequip, activate it
                        MotionControllerMotion lMotion = mMotionController.GetMotion(lItem.StoreMotion);
                        if (lMotion != null)
                        {
                            // This is an extra test so we don't try to sheathe a weapons we just
                            // unsheathed... until we're totally done with the transitions
                            while (lMotion.MotionLayer._AnimatorTransitionID != 0)
                            {
                                yield return(null);
                            }

                            // Ensure we override the item and slot
                            IEquipStoreMotion lEquipStoreMotion = lMotion as IEquipStoreMotion;
                            if (lEquipStoreMotion != null)
                            {
                                lEquipStoreMotion.OverrideItemID = lItem.ID;
                                lEquipStoreMotion.OverrideSlotID = lSlot.ID;
                            }

                            // Now sheathe
                            mMotionController.ActivateMotion(lMotion);
                            while (lMotion.IsActive || lMotion.QueueActivation)
                            {
                                yield return(null);
                            }

                            // Clear the item
                            lSlot.ItemID = "";
                        }
                    }
                }
            }

            // Second, find all the entries with no store motions destroy them
            for (int i = 0; i < WeaponSets[rIndex].Items.Count; i++)
            {
                BasicInventorySlot lSlot = GetInventorySlot(WeaponSets[rIndex].Items[i].SlotID);
                if (lSlot != null && lSlot.ItemID.Length > 0)
                {
                    StoreItem(lSlot.ID);
                }
            }

            mIsEquippingItem = false;
        }
コード例 #3
0
        /// <summary>
        /// Swaps the current weapons set items out for a new set
        /// </summary>
        /// <param name="rIndex">New weapont set index</param>
        protected virtual IEnumerator SwapWeaponSet(int rIndex)
        {
            if (!mIsEquippingItem && WeaponSets != null && WeaponSets.Count > rIndex)
            {
                mIsEquippingItem = true;

                bool lEquipItems = false;

                // Cycle through each item in the set and store each item that isn't part of the new set
                for (int i = 0; i < WeaponSets[rIndex].Items.Count; i++)
                {
                    BasicInventorySlot lSlot = GetInventorySlot(WeaponSets[rIndex].Items[i].SlotID);
                    if (lSlot != null)
                    {
                        // If no weapon is equipped, we need to equip it
                        if (lSlot.ItemID.Length == 0 && WeaponSets[rIndex].Items[i].ItemID.Length > 0)
                        {
                            lEquipItems = true;
                        }
                        // If we are changing weapons, unequip the weapon
                        else if (lSlot.ItemID != WeaponSets[rIndex].Items[i].ItemID)
                        {
                            // Flag the fact that we want to equip the group
                            lEquipItems = true;

                            // Store the item in the slot
                            yield return(StartCoroutine(Internal_StoreItem(lSlot.ID)));

                            // Clear the item
                            lSlot.ItemID = "";
                        }
                    }
                }

                // Equip all the set items
                if (lEquipItems)
                {
                    yield return(StartCoroutine(Internal_EquipWeaponsSet(rIndex)));
                }
                // Store all the set items
                else
                {
                    yield return(StartCoroutine(Internal_StoreWeaponsSet(rIndex)));
                }

                mIsEquippingItem = false;

                _ActiveWeaponSet = rIndex;
            }
        }
コード例 #4
0
        /// <summary>
        /// Clears a slot by the storing the current item. We'll use the
        /// store motion if it exists
        /// </summary>
        /// <param name="rSlotID">Slot that is being cleared</param>
        /// <returns></returns>
        protected virtual IEnumerator Internal_StoreItem(string rSlotID)
        {
            BasicInventorySlot lSlot = GetInventorySlot(rSlotID);

            if (lSlot != null)
            {
                BasicInventoryItem lItem = GetInventoryItem(lSlot.ItemID);
                if (lItem != null)
                {
                    // Run the unequip motion
                    if (lItem.StoreMotion.Length > 0)
                    {
                        // If we have a motion to unequip, activate it
                        MotionControllerMotion lMotion = mMotionController.GetMotion(lItem.StoreMotion);
                        if (lMotion != null)
                        {
                            // This is an extra test so we don't try to sheathe a weapons we just
                            // unsheathed... until we're totally done with the transitions
                            while (lMotion.MotionLayer._AnimatorTransitionID != 0)
                            {
                                yield return(null);
                            }

                            IEquipStoreMotion lEquipStoreMotion = lMotion as IEquipStoreMotion;
                            if (lEquipStoreMotion != null)
                            {
                                lEquipStoreMotion.OverrideItemID = lItem.ID;
                                lEquipStoreMotion.OverrideSlotID = lSlot.ID;
                            }

                            // Now sheathe
                            mMotionController.ActivateMotion(lMotion);
                            while (lMotion.IsActive || lMotion.QueueActivation)
                            {
                                yield return(null);
                            }
                        }
                    }
                    // Otherwise, simply unequip
                    else
                    {
                        StoreItem(lSlot.ID);
                    }
                }

                // Clear the slot
                lSlot.ItemID = "";
            }
        }
コード例 #5
0
        /// <summary>
        /// Instantiates the specified item and equips it. We return the instantiated item.
        /// </summary>
        /// <param name="rItemID">String representing the name or ID of the item to equip</param>
        /// <param name="rSlotID">String representing the name or ID of the slot to equip</param>
        /// <param name="rResourcePath">Alternate resource path to override the ItemID's</param>
        /// <returns>GameObject that is the instance or null if it could not be created</returns>
        public virtual GameObject EquipItem(string rItemID, string rSlotID, string rResourcePath = "")
        {
            BasicInventoryItem lItem = GetInventoryItem(rItemID);

            if (lItem == null)
            {
                return(null);
            }

            string lResourcePath = rResourcePath;

            if (lResourcePath.Length == 0)
            {
                lResourcePath = lItem.ResourcePath;
            }

            if (lItem.Instance == null)
            {
                GameObject lGameObject = CreateAndMountItem(gameObject, lResourcePath, lItem.LocalPosition, lItem.LocalRotation, rSlotID);
                if (lGameObject != null)
                {
                    lItem.Instance = lGameObject;
                }
            }
            else
            {
                MountItem(gameObject, lItem.Instance, lItem.LocalPosition, lItem.LocalRotation, rSlotID);
            }

            if (lItem.Instance != null)
            {
                IItemCore lItemCore = lItem.Instance.GetComponent <IItemCore>();
                if (lItemCore != null)
                {
                    lItemCore.OnEquipped();
                }

                BasicInventorySlot lSlot = GetInventorySlot(rSlotID);
                if (lSlot != null)
                {
                    lSlot.ItemID = rItemID;
                }
            }

            return(lItem.Instance);
        }
コード例 #6
0
        /// <summary>
        /// Instantiates the specified item and equips it. We return the instantiated item.
        /// </summary>
        /// <param name="rSlotID">String representing the name or ID of the slot to clear</param>
        public virtual void StoreItem(string rSlotID)
        {
            int lSlotIndex = -1;

            for (int i = 0; i < Slots.Count; i++)
            {
                if (Slots[i].ID == rSlotID)
                {
                    lSlotIndex = i;
                    break;
                }
            }

            if (lSlotIndex < 0)
            {
                return;
            }

            BasicInventorySlot lSlot = Slots[lSlotIndex];

            if (lSlot == null)
            {
                return;
            }

            BasicInventoryItem lItem = null;

            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].ID == lSlot.ItemID)
                {
                    lItem = Items[i];
                    break;
                }
            }

            // We need to disconnect the item, but we may need to destroy it as well
            if (lItem != null && lItem.Instance != null)
            {
                IItemCore lItemCore = lItem.Instance.GetComponent <IItemCore>();
                if (lItemCore != null)
                {
                    lItemCore.OnStored();
                }

                // If we know about a combatant, disconnect the weapon
                ICombatant lCombatant = gameObject.GetComponent <ICombatant>();
                if (lCombatant != null)
                {
                    IWeaponCore lWeaponCore = lItem.Instance.GetComponent <IWeaponCore>();
                    if (lWeaponCore != null)
                    {
                        if (lCombatant.PrimaryWeapon == lWeaponCore)
                        {
                            lCombatant.PrimaryWeapon = null;
                        }
                        if (lCombatant.SecondaryWeapon == lWeaponCore)
                        {
                            lCombatant.SecondaryWeapon = null;
                        }
                    }
                }

#if USE_MOUNT_POINTS
                if (mMountPoints != null)
                {
                    MountPoint lParentMountPoint = mMountPoints.GetMountPoint(lSlot.ID);
                    if (lParentMountPoint != null)
                    {
                        mMountPoints.DisconnectMountPoints(lParentMountPoint, lItem.Instance);
                    }
                }
#endif

                // Without a stored parent, we destroy it
                if (lItem.StoredParent == null)
                {
                    GameObject.Destroy(lItem.Instance);
                    lItem.Instance = null;
                }
                else
                {
                    bool lIsAttached = false;

#if USE_MOUNT_POINTS
                    // See if we can attach it using a mount point
                    if (mMountPoints != null)
                    {
                        MountPoint lParentMountPoint = mMountPoints.GetMountPoint(lItem.StoredParent.name);
                        if (lParentMountPoint == null)
                        {
                            lParentMountPoint = mMountPoints.GetMountPoint(lItem.StoredParent);
                        }
                        if (lParentMountPoint != null)
                        {
                            lIsAttached = mMountPoints.ConnectMountPoints(lParentMountPoint, lItem.Instance, "Handle");
                        }
                    }
#endif

                    if (!lIsAttached)
                    {
                        lItem.Instance.transform.parent        = lItem.StoredParent;
                        lItem.Instance.transform.localPosition = lItem.StoredPosition;
                        lItem.Instance.transform.localRotation = lItem.StoredRotation;
                    }
                }
            }

            lSlot.ItemID = "";
        }