示例#1
0
 /// <summary>
 /// Auto equip new item.
 /// </summary>
 /// <param name="item">Item to equip.</param>
 /// <param name="indexArea">Index of the area to equip the item.</param>
 /// <param name="immediate">Force equip immediate.</param>
 public void AutoEquipItem(vItem item, int indexArea, bool immediate = false)
 {
     if (item.type == vItemType.MeleeWeapon)
     {
         var MeleeWeapon = item.originalObject.GetComponent <vMeleeWeapon>();
         if (MeleeWeapon)
         {
             var ActualWeapon = Instantiate(item.originalObject) as GameObject;
             if (MeleeWeapon.meleeType == vMeleeType.OnlyDefense)  // left
             {
                 ActualWeapon.transform.parent           = defaultEquipPointL;
                 ActualWeapon.transform.localPosition    = Vector3.zero;
                 ActualWeapon.transform.localEulerAngles = Vector3.zero;
                 TheMeleeManager.SetLeftWeapon(ActualWeapon);
             }
             else  // right
             {
                 ActualWeapon.transform.parent           = defaultEquipPointR;
                 ActualWeapon.transform.localPosition    = Vector3.zero;
                 ActualWeapon.transform.localEulerAngles = Vector3.zero;
                 TheMeleeManager.SetRightWeapon(ActualWeapon);
             }
         }
     }
 }
示例#2
0
    public virtual void HandleCollectableInput(vCollectableStandalone collectableStandAlone)
    {
        if (!meleeManager)
        {
            return;
        }
        if (collectableStandAlone != null && collectableStandAlone.weapon != null)
        {
            var weapon = collectableStandAlone.weapon.GetComponent <vMeleeWeapon>();
            if (!weapon)
            {
                return;
            }
            if (weapon.meleeType != vMeleeType.OnlyDefense)
            {
                var p = GetEquipPoint(rightHandler, collectableStandAlone.targetEquipPoint);
                if (!p)
                {
                    return;
                }
                collectableStandAlone.weapon.transform.SetParent(p);
                collectableStandAlone.weapon.transform.localPosition    = Vector3.zero;
                collectableStandAlone.weapon.transform.localEulerAngles = Vector3.zero;
                if (rightWeapon && rightWeapon != weapon.gameObject)
                {
                    RemoveRightWeapon();
                }

                meleeManager.SetRightWeapon(weapon);
                collectableStandAlone.OnEquip.Invoke();
                rightWeapon = weapon.gameObject;
                UpdateRightDisplay(collectableStandAlone);
            }
            if (weapon.meleeType != vMeleeType.OnlyAttack && weapon.meleeType != vMeleeType.AttackAndDefense)
            {
                var p = GetEquipPoint(leftHandler, collectableStandAlone.targetEquipPoint);
                if (!p)
                {
                    return;
                }
                collectableStandAlone.weapon.transform.SetParent(p);
                collectableStandAlone.weapon.transform.localPosition    = Vector3.zero;
                collectableStandAlone.weapon.transform.localEulerAngles = Vector3.zero;
                if (leftWeapon && leftWeapon != weapon.gameObject)
                {
                    RemoveLeftWeapon();
                }

                meleeManager.SetLeftWeapon(weapon);
                collectableStandAlone.OnEquip.Invoke();
                leftWeapon = weapon.gameObject;
                UpdateLeftDisplay(collectableStandAlone);
            }
        }
    }
示例#3
0
 private void ActiveSecundaryWeapon()
 {
     if (secundaryWeapon)
     {
         secundaryWeapon.gameObject.SetActive(true);
     }
     else
     {
         secundaryWeapon = Instantiate(secundaryWeaponPrefab);
         secundaryWeapon.transform.parent           = otherSideTransform;
         secundaryWeapon.transform.localPosition    = Vector3.zero;
         secundaryWeapon.transform.localEulerAngles = Vector3.zero;
     }
     if (!manager)
     {
         manager = GetComponentInParent <vMeleeManager>();
     }
     if (manager)
     {
         manager.SetLeftWeapon(secundaryWeapon);
     }
 }
示例#4
0
        IEnumerator Start()
        {
            itemCollection = GetComponentInChildren <vItemCollection>(true);
            ai             = GetComponent <v_AIController>();
            manager        = GetComponent <vMeleeManager>();
            yield return(new WaitForEndOfFrame());

            if (itemCollection && ai && manager)
            {
                ai.onSetAgressive.AddListener(OnSetAgressive);
                leftArm  = ai.animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
                rightArm = ai.animator.GetBoneTransform(HumanBodyBones.RightLowerArm);

                for (int i = 0; i < itemCollection.items.Count; i++)
                {
                    if (itemCollection.items[i].amount > 0)
                    {
                        var item = itemCollection.itemListData.items.Find(_item => _item.id == itemCollection.items[i].id && _item.type == vItemType.MeleeWeapon);
                        if (item != null)
                        {
                            AddItem(itemCollection.items[i].id, itemCollection.items[i].amount);
                        }
                    }
                }

                if (useRightWeapon)
                {
                    if (randomRightWeapon)
                    {
                        GetRandomWeapon(ref rightWeaponItem, vMeleeType.OnlyAttack);
                    }
                    else
                    {
                        GetItemWeapon(rightWeaponID, ref rightWeaponItem, vMeleeType.OnlyAttack);
                    }
                }

                if (useLeftWeapon)
                {
                    if (randomLeftWeapon)
                    {
                        GetRandomWeapon(ref leftWeaponItem, vMeleeType.OnlyDefense);
                    }
                    else
                    {
                        GetItemWeapon(leftWeaponID, ref leftWeaponItem, vMeleeType.OnlyDefense);
                    }
                }

                if (rightArm && rightWeaponItem)
                {
                    Transform equipPoint = null;
                    if (customEquipPointR.Count > 0)
                    {
                        equipPoint = customEquipPointR.Find(t => t.name == rightWeaponItem.customHandler);
                    }

                    if (equipPoint == null)
                    {
                        equipPoint = defaultEquipPointR;
                    }

                    if (equipPoint)
                    {
                        rightWeapon = Instantiate(rightWeaponItem.originalObject) as GameObject;
                        rightWeapon.transform.parent           = equipPoint;
                        rightWeapon.transform.localPosition    = Vector3.zero;
                        rightWeapon.transform.localEulerAngles = Vector3.zero;
                        manager.SetRightWeapon(rightWeapon);
                        rightWeapon.SetActive(false);
                        if (ai.agressiveAtFirstSight)
                        {
                            StartCoroutine(EquipItemRoutine(false, rightWeaponItem, rightWeapon));
                        }
                    }
                }

                if (leftArm && leftWeaponItem)
                {
                    Transform equipPoint = null;
                    if (customEquipPointL.Count > 0)
                    {
                        equipPoint = customEquipPointL.Find(t => t.name == leftWeaponItem.customHandler);
                    }

                    if (equipPoint == null)
                    {
                        equipPoint = defaultEquipPointL;
                    }

                    if (equipPoint)
                    {
                        leftWeapon = Instantiate(leftWeaponItem.originalObject) as GameObject;
                        leftWeapon.transform.parent           = equipPoint;
                        leftWeapon.transform.localPosition    = Vector3.zero;
                        leftWeapon.transform.localEulerAngles = Vector3.zero;
                        var scale = leftWeapon.transform.localScale;
                        scale.x *= -1;
                        leftWeapon.transform.localScale = scale;
                        manager.SetLeftWeapon(leftWeapon);
                        leftWeapon.SetActive(false);
                        if (ai.agressiveAtFirstSight)
                        {
                            StartCoroutine(EquipItemRoutine(true, leftWeaponItem, leftWeapon));
                        }
                    }
                }
            }
        }