private void PUN_ConvertvItemCollection(GameObject obj)
    {
        if (obj.GetComponent <vItemCollection>())
        {
            vItemCollection org = obj.GetComponent <vItemCollection>();
            if (!obj.GetComponent <PhotonView>())
            {
                obj.AddComponent <PhotonView>();
            }
            if (!obj.GetComponent <PUN_ItemCollect>())
            {
                obj.AddComponent <PUN_ItemCollect>();
                for (int i = 0; i < obj.GetComponent <vItemCollection>().onDoActionWithTarget.GetPersistentEventCount(); i++)
                {
                    if (obj.GetComponent <vItemCollection>().onDoActionWithTarget.GetPersistentMethodName(i) == "NetworkDestroy")
                    {
                        UnityEventTools.RemovePersistentListener(obj.GetComponent <vItemCollection>().onDoActionWithTarget, i);
                    }
                }
                obj.GetComponent <vItemCollection>().OnDoAction.AddListener(obj.GetComponent <PUN_ItemCollect>().NetworkDestory);
                UnityEventTools.AddPersistentListener(obj.GetComponent <vItemCollection>().OnDoAction, obj.GetComponent <PUN_ItemCollect>().NetworkDestory);
            }

            modified.Add(obj);
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Trigger the AI dropping all items.
        /// </summary>
        /// <param name="target">Drop target.</param>
        public void DropAllItens(GameObject target = null)
        {
            if (target != null && target != gameObject)
            {
                return;
            }
            List <ItemReference> itemReferences = new List <ItemReference>();

            for (int i = 0; i < items.Count; i++)
            {
                if (itemReferences.Find(_item => _item.id == items[i].id) == null)
                {
                    var           sameItens     = items.FindAll(_item => _item.id == items[i].id);
                    ItemReference itemReference = new ItemReference(items[i].id);
                    for (int a = 0; a < sameItens.Count; a++)
                    {
                        itemReference.amount += sameItens[a].amount;
                        Destroy(sameItens[a]);
                    }
                    itemReferences.Add(itemReference);
                    if (items[i].dropObject)
                    {
                        var             dropObject = Instantiate(items[i].dropObject, transform.position, transform.rotation) as GameObject;
                        vItemCollection collection = dropObject.GetComponent <vItemCollection>();
                        if (collection != null)
                        {
                            collection.items.Clear();
                            collection.items.Add(itemReference);
                        }
                    }
                }
            }
            items.Clear();
        }
Esempio n. 3
0
        public static void CB_COMP_vItemCollection(GameObject target)
        {
            //BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
            GameObject      go = null;
            vItemCollection ic = null;

            if (target.GetComponent <vItemCollection>())
            {
                go = target;
                ic = target.GetComponent <vItemCollection>();
            }
            else if (target.GetComponentInChildren <vItemCollection>())
            {
                go = target.GetComponentInChildren <vItemCollection>().transform.gameObject;
                ic = target.GetComponentInChildren <vItemCollection>();
            }
            if (go)
            {
                if (!go.GetComponent <SyncItemCollection>())
                {
                    go.AddComponent <SyncItemCollection>();
                }
                go.GetComponent <SyncItemCollection>().OnPressActionInput           = ic.OnPressActionInput;
                go.GetComponent <SyncItemCollection>().onPressActionInputWithTarget = ic.onPressActionInputWithTarget;
                go.GetComponent <SyncItemCollection>().onPressActionDelay           = ic.onPressActionDelay;
                bool sync = !FindObjectOfType <NetworkManager>().syncScenes;
                if (sync == true)
                {
                    go.GetComponent <SyncItemCollection>().OnSceneEnterUpdate = ic.OnPressActionInput;
                    if (ic.transform.parent != null)
                    {
                        go.GetComponent <SyncItemCollection>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), ic.transform.parent);
                    }
                    else
                    {
                        go.GetComponent <SyncItemCollection>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), ic.transform);
                    }
                }
                go.GetComponent <SyncItemCollection>().GetType().GetField("syncCrossScenes", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), sync);
                //bool skipStart = (ic.items.Count > 0);
                go.GetComponent <SyncItemCollection>().GetType().GetField("skipStartCheck", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), false);
                go.GetComponent <SyncItemCollection>().GetType().GetField("syncCreateDestroy", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), true);
                go.GetComponent <SyncItemCollection>().GetType().GetField("resourcesPrefab", E_Helpers.allBindings).SetValue(go.GetComponent <SyncItemCollection>(), ic.transform.root.name);

                ic.OnPressActionInput           = new UnityEvent();
                ic.onPressActionInputWithTarget = new OnDoActionWithTarget();
                ic.onPressActionDelay           = 0;

                UnityEventTools.AddPersistentListener(ic.onPressActionInputWithTarget, go.GetComponent <SyncItemCollection>().Collect);

                E_Helpers.SetObjectIcon(go, E_Core.h_genericIcon);

                CB_COMP_SHOOTER_vItemCollection(ic, go);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Occurs when an vItem has been dropped by the AI.
 /// </summary>
 /// <param name="item">Item that has been dropped.</param>
 /// <param name="amount">Amount that has been dropped.</param>
 public void DropItem(vItem item, int amount)
 {
     item.amount -= amount;
     if (item.dropObject != null)
     {
         var             dropObject = Instantiate(item.dropObject, transform.position, transform.rotation) as GameObject;
         vItemCollection collection = dropObject.GetComponent <vItemCollection>();
         if (collection != null)
         {
             collection.items.Clear();
             var itemReference = new ItemReference(item.id);
             itemReference.amount     = amount;
             itemReference.attributes = new List <vItemAttribute>(item.attributes);
             collection.items.Add(itemReference);
         }
     }
     onDropItem.Invoke(item, amount);
     if (item.amount <= 0 && items.Contains(item))
     {
         items.Remove(item);
         Destroy(item);
     }
 }
Esempio n. 5
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));
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public static void CB_CONTEXT_vItemCollection(MenuCommand command)
        {
            vItemCollection prefab = (vItemCollection)command.context;

            CB_COMP_vItemCollection(prefab.gameObject);
        }
Esempio n. 7
0
 static partial void CB_COMP_SHOOTER_vItemCollection(vItemCollection ic, GameObject go);
Esempio n. 8
0
 protected virtual void Awake()
 {
     ic = (ic == null) ? GetComponent <vItemCollection>() : ic;
 }