Ejemplo n.º 1
0
        public override void Awake()
        {
            SetSubClass(this);
            base.Awake();

            if (unitT.targetMode == _TargetMode.Air)
            {
                maskTarget = 1 << LayerManager.LayerCreepF();
            }
            else if (unitT.targetMode == _TargetMode.Ground)
            {
                maskTarget = 1 << LayerManager.LayerCreep();
            }
            else
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }

            if (stats.Count == 0)
            {
                stats.Add(new UnitStat());
            }
        }
Ejemplo n.º 2
0
        public IEnumerator ScanForTargetRoutine()
        {
            yield return(null);

            if (subClass == _UnitSubClass.Tower)
            {
                if (unitT.targetMode == _TargetMode.Hybrid)
                {
                    LayerMask mask1 = 1 << LayerManager.LayerCreep();
                    LayerMask mask2 = 1 << LayerManager.LayerCreepF();

                    maskTarget = mask1 | mask2;
                }
                else if (unitT.targetMode == _TargetMode.Air)
                {
                    maskTarget = 1 << LayerManager.LayerCreepF();
                }
                else if (unitT.targetMode == _TargetMode.Ground)
                {
                    maskTarget = 1 << LayerManager.LayerCreep();
                }
            }

            while (true)
            {
                ScanForTarget();
                yield return(new WaitForSeconds(0.1f));
            }
        }
Ejemplo n.º 3
0
        IEnumerator AOETowerRoutine()
        {
            if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                maskTarget = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                maskTarget = 1 << LayerManager.LayerCreep();
            }

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

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

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

                Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                if (cols.Length > 0)
                {
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 //Call by inherited class UnitCreep, caching inherited UnitCreep instance to this instance
 public void SetSubClass(UnitCreep unit)
 {
     unitC    = unit;
     subClass = _UnitSubClass.Creep;
     if (!unitC.flying)
     {
         gameObject.layer = LayerManager.LayerCreep();
     }
     else
     {
         gameObject.layer = LayerManager.LayerCreepF();
     }
 }
Ejemplo n.º 5
0
        public IEnumerator ScanForTargetRoutine()
        {
            if (subClass == _UnitSubClass.Tower)
            {
                if (unitT.targetMode == _TargetMode.Hybrid)
                {
                    LayerMask mask1 = 1 << LayerManager.LayerCreep();
                    LayerMask mask2 = 1 << LayerManager.LayerCreepF();

                    maskTarget = mask1 | mask2;
                }
                else if (unitT.targetMode == _TargetMode.Air)
                {
                    maskTarget = 1 << LayerManager.LayerCreepF();
                }
                else if (unitT.targetMode == _TargetMode.Ground)
                {
                    maskTarget = 1 << LayerManager.LayerCreep();
                }
            }
            else if (subClass == _UnitSubClass.Creep)
            {
                maskTarget = 1 << LayerManager.LayerTower();
            }

            //initiate scan direction
            //if(directionalTargeting){
            //	if(IsCreep()) dirScanRot=thisT.rotation;
            //	else dirScanRot=thisT.rotation*Quaternion.Euler(0f, dirScanAngle, 0f);
            //}

            while (true)
            {
                ScanForTarget();
                yield return(new WaitForSeconds(0.1f));

                if (GameControl.ResetTargetAfterShoot())
                {
                    while (turretOnCooldown)
                    {
                        yield return(null);
                    }
                }
            }

            //yield return null;
        }
Ejemplo n.º 6
0
        void FPSHit(Unit hitUnit, Vector3 hitPoint)
        {
            if (attInstance.srcWeapon.GetAOERange() > 0)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                LayerMask mask  = mask1 | mask2;

                Collider[] cols = Physics.OverlapSphere(hitPoint, attInstance.srcWeapon.GetAOERange(), mask);
                if (cols.Length > 0)
                {
                    List <Unit> tgtList = new List <Unit>();
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].gameObject.GetComponent <Unit>();
                        if (!unit.dead)
                        {
                            tgtList.Add(unit);
                        }
                    }
                    if (tgtList.Count > 0)
                    {
                        for (int i = 0; i < tgtList.Count; i++)
                        {
                            AttackInstance attInst = new AttackInstance();
                            attInst.srcWeapon = attInstance.srcWeapon;
                            attInst.tgtUnit   = tgtList[i];
                            tgtList[i].ApplyEffect(attInst);
                        }
                    }
                }
            }
            else
            {
                if (hitUnit != null && hitUnit.IsCreep())
                {
                    attInstance.tgtUnit = hitUnit;
                    hitUnit.ApplyEffect(attInstance);
                }
            }
        }
Ejemplo n.º 7
0
        //apply the ability effect, damage, stun, buff and so on
        IEnumerator ApplyAbilityEffect(Ability ab, Vector3 pos, Unit tgtUnit = null)
        {
            yield return(new WaitForSeconds(ab.effectDelay));

            LayerMask mask1 = 1 << LayerManager.LayerTower();
            LayerMask mask2 = 1 << LayerManager.LayerCreep();
            LayerMask mask3 = 1 << LayerManager.LayerCreepF();
            LayerMask mask  = mask1 | mask2 | mask3;

            List <Unit> creepList = new List <Unit>();
            List <Unit> towerList = new List <Unit>();

            if (tgtUnit == null)
            {
                float      radius = ab.requireTargetSelection ? ab.GetAOERadius() : Mathf.Infinity;
                Collider[] cols   = Physics.OverlapSphere(pos, radius, mask);

                if (cols.Length > 0)
                {
                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[i].gameObject.GetComponent <Unit>();
                        if (unit.unitC != null)
                        {
                            creepList.Add(unit.unitC);
                        }
                        if (unit.unitT != null)
                        {
                            towerList.Add(unit.unitT);
                        }
                    }
                }
            }
            else
            {
                creepList.Add(tgtUnit);
                towerList.Add(tgtUnit);
            }

            AbilityEffect eff = ab.GetActiveEffect();

            for (int n = 0; n < creepList.Count; n++)
            {
                if (eff.damageMax > 0)
                {
                    creepList[n].ApplyDamage(Random.Range(eff.damageMin, eff.damageMax));
                }
                else if (eff.stunChance > 0 && eff.duration > 0)
                {
                    if (Random.Range(0f, 1f) < eff.stunChance)
                    {
                        creepList[n].ApplyStun(eff.duration);
                    }
                }
                else if (eff.slow.IsValid())
                {
                    creepList[n].ApplySlow(eff.slow);
                }
                else if (eff.dot.GetTotalDamage() > 0)
                {
                    creepList[n].ApplyDot(eff.dot);
                }
            }
            for (int n = 0; n < towerList.Count; n++)
            {
                if (eff.duration > 0)
                {
                    if (eff.damageBuff > 0)
                    {
                        towerList[n].ABBuffDamage(eff.damageBuff, eff.duration);
                    }
                    else if (eff.rangeBuff > 0)
                    {
                        towerList[n].ABBuffRange(eff.rangeBuff, eff.duration);
                    }
                    else if (eff.cooldownBuff > 0)
                    {
                        towerList[n].ABBuffCooldown(eff.cooldownBuff, eff.duration);
                    }
                }
                else if (eff.HPGainMax > 0)
                {
                    towerList[n].RestoreHP(Random.Range(eff.HPGainMin, eff.HPGainMax));
                }
            }
        }
Ejemplo n.º 8
0
        public IEnumerator SupportRoutine()
        {
            supportRoutineRunning = true;

            LayerMask maskTarget = 0;

            if (subClass == _UnitSubClass.Tower)
            {
                maskTarget = 1 << LayerManager.LayerTower();
            }
            else if (subClass == _UnitSubClass.Creep)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }

            while (true)
            {
                yield return(new WaitForSeconds(0.1f));

                if (!dead)
                {
                    List <Unit> tgtList = new List <Unit>();
                    Collider[]  cols    = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                    if (cols.Length > 0)
                    {
                        for (int i = 0; i < cols.Length; i++)
                        {
                            Unit unit = cols[i].gameObject.GetComponent <Unit>();
                            if (!unit.dead)
                            {
                                tgtList.Add(unit);
                            }
                        }
                    }

                    for (int i = 0; i < buffedUnit.Count; i++)
                    {
                        Unit unit = buffedUnit[i];
                        if (unit == null || unit.dead)
                        {
                            buffedUnit.RemoveAt(i); i -= 1;
                        }
                        else if (!tgtList.Contains(unit))
                        {
                            unit.UnBuff(GetBuff());
                            buffedUnit.RemoveAt(i); i -= 1;
                        }
                    }

                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        Unit unit = tgtList[i];
                        if (!buffedUnit.Contains(unit))
                        {
                            unit.Buff(GetBuff());
                            buffedUnit.Add(unit);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        IEnumerator AOETowerRoutine()
        {
            if (targetMode == _TargetMode.Hybrid)
            {
                LayerMask mask1 = 1 << LayerManager.LayerCreep();
                LayerMask mask2 = 1 << LayerManager.LayerCreepF();
                maskTarget = mask1 | mask2;
            }
            else if (targetMode == _TargetMode.Air)
            {
                maskTarget = 1 << LayerManager.LayerCreepF();
            }
            else if (targetMode == _TargetMode.Ground)
            {
                maskTarget = 1 << LayerManager.LayerCreep();
            }

            UnitTower electricitySource;

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

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

                // disable shooting while there is no electricity
                electricitySource = getElectricitySource(GetElectricityNeedForShoot());

                while (electricitySource == null)
                {
                    // Paint deactivated towers black
                    for (int i = 0; i < myRenderers.Length; i++)
                    {
                        myRenderers[i].material.color = new Color(0.2f, 0.2f, 0.2f);
                    }

                    electricitySource = getElectricitySource(GetElectricityNeedForShoot());
                    yield return(null);
                }

                // Restore original color
                for (int i = 0; i < myRenderers.Length; i++)
                {
                    myRenderers[i].material.color = myRenderersColors[i];
                }

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

                Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget);
                if (electricitySource != null && !electricitySource.dead && cols.Length > 0)
                {
                    // target will shoot so take that energy
                    electricitySource.electricityCurrentlyStored -= GetElectricityNeedForShoot();

                    for (int i = 0; i < cols.Length; i++)
                    {
                        Unit unit = cols[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);
                    }
                }
            }
        }