/// <summary>
        /// Create a BasicInventoryItem and add it to the BasicInventory
        /// </summary>
        /// <param name="rInventory"></param>
        /// <param name="rItemID"></param>
        /// <param name="rMotionForm"></param>
        /// <param name="rResourcePath"></param>
        /// <param name="rUseMotions"></param>
        /// <param name="rAnimatorLayer"></param>
        public static BasicInventoryItem CreateBasicInventoryitem(this BasicInventory rInventory, string rItemID, int rMotionForm,
                                                                  string rResourcePath, bool rUseMotions = true, int rAnimatorLayer = 0)
        {
            if (string.IsNullOrEmpty(rItemID))
            {
                return(null);
            }

            // First remove the item if it already exists
            BasicInventoryItem lItem = rInventory.GetInventoryItem(rItemID);

            if (lItem != null)
            {
                rInventory.Items.Remove(lItem);
            }

            lItem = new BasicInventoryItem()
            {
                ID           = rItemID,
                EquipMotion  = rUseMotions ? "BasicItemEquip" + (rAnimatorLayer > 0 ? rAnimatorLayer.ToString() : "") : string.Empty,
                StoreMotion  = rUseMotions ? "BasicItemStore" + (rAnimatorLayer > 0 ? rAnimatorLayer.ToString() : "") : string.Empty,
                EquipStyle   = rMotionForm,
                StoreStyle   = rMotionForm,
                ResourcePath = rResourcePath
            };

            rInventory.Items.Add(lItem);
            return(lItem);
        }
Esempio n. 2
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;
                        }
                    }
                }
            }
        }
Esempio n. 3
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;
        }
Esempio n. 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 = "";
            }
        }
Esempio n. 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);
        }
Esempio n. 6
0
        /// <summary>
        /// Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.
        /// </summary>
        protected virtual void Start()
        {
            if (WeaponSets.Count == 0)
            {
                _ActiveWeaponSet = -1;
            }
            if (_ActiveWeaponSet >= WeaponSets.Count)
            {
                _ActiveWeaponSet = 0;
            }

            // Cycle through all the items with GameObjects attached and store the
            // parent information.
            for (int i = 0; i < Items.Count; i++)
            {
                BasicInventoryItem lItem = Items[i];
                if (lItem.Instance != null)
                {
                    lItem.StoredParent   = lItem.Instance.transform.parent;
                    lItem.StoredPosition = lItem.Instance.transform.localPosition;
                    lItem.StoredRotation = lItem.Instance.transform.localRotation;
                }
            }
        }
Esempio n. 7
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 = "";
        }