Ejemplo n.º 1
0
        IEnumerator MineRoutine()
        {
            LayerMask maskTarget = 1 << LayerManager.LayerCreep();

            while (true)
            {
                if (!dead && !IsInConstruction())
                {
                    Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        Collider[] colls = Physics.OverlapSphere(thisT.position, GetAOERadius(), maskTarget);
                        for (int i = 0; i < colls.Length; i++)
                        {
                            Unit unit = colls[i].transform.GetComponent <Unit>();
                            if (unit == null && !unit.dead)
                            {
                                continue;
                            }

                            AttackInstance attInstance = new AttackInstance();
                            attInstance.srcUnit = this;
                            attInstance.tgtUnit = unit;
                            attInstance.Process();

                            unit.ApplyEffect(attInstance);
                        }

                        Transform soPrefab = GetShootObjectT();
                        if (soPrefab != null)
                        {
                            ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation);
                        }

                        Dead();
                    }
                }
                yield return(new WaitForSeconds(0.1f));
            }
        }
Ejemplo n.º 2
0
        private void AttackTargets(Collider[] targets)
        {
            if (targets.Length > 0)
            {
                List <Unit> tgtList = new List <Unit>();
                for (int i = 0; i < targets.Length; i++)
                {
                    Unit unit = targets[i].gameObject.GetComponent <Unit>();
                    if (unit && !unit.dead)
                    {
                        tgtList.Add(unit);
                    }
                }
                if (tgtList.Count > 0)
                {
                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        if (tgtList[i] == target)
                        {
                            target.ApplyEffect(attInstance);
                            print(attInstance.srcUnit.unitName + " attacks " + target.unitName + " with " + attInstance.damage + " damage");
                        }
                        else
                        {
                            AttackInstance attInst = attInstance.Clone();
                            attInst.srcUnit = attInstance.srcUnit;
                            attInst.tgtUnit = tgtList[i];
                            attInst.Process();
                            tgtList[i].ApplyEffect(attInst);

                            print(attInst.srcUnit.unitName + " attacks " + attInst.tgtUnit.unitName + " with " + attInst.damage + " damage");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        IEnumerator AOETowerRoutine()
        {
            if (CurrentStat.customMask > -1)
            {
                TargetMask = CurrentStat.customMask;
            }
            else if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                TargetMask = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                TargetMask = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                TargetMask = 1 << LayerManager.LayerCreep();
            }

            while (true)
            {
                yield return(new WaitForSeconds(GetCooldown()));

                while (stunned || IsInConstruction())
                {
                    yield return(null);
                }



                Collider[] cols = Physics.OverlapSphere(thisT.position, GetAttackRange(), TargetMask);
                if (cols.Length > 0)
                {
                    Transform soPrefab = GetShootObjectT();
                    if (soPrefab != null)
                    {
                        ObjectPoolManager.Spawn(soPrefab, thisT.position, thisT.rotation);
                    }

                    //SendMessage("OnAttackTargetStarted", SendMessageOptions.DontRequireReceiver);
                    //print("AOE attack");

                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].transform.GetComponent <Unit>(); //damage all units in its range
                        if (unit == null && !unit.dead)
                        {
                            continue;
                        }

                        AttackInstance attInstance = new AttackInstance();
                        attInstance.srcUnit = this;
                        attInstance.tgtUnit = unit;
                        attInstance.Process();

                        unit.ApplyEffect(attInstance);
                    }
                }
                else
                {
                    //SendMessage("OnAttackTargetStopped", SendMessageOptions.DontRequireReceiver);
                    //print("AOE stopped");
                }
            }
        }