コード例 #1
0
        //fixed update for resource, aoe and mine, check '#region support tower' for support
        void TowerFunction()
        {
            if (!GameControl.HasGameStarted())
            {
                return;
            }
            if (InConstruction() || IsStunned() || IsDestroyed())
            {
                return;
            }

            //if(GameControl.HasGameStarted() && !GameControl.IsGamePaused()) cooldown-=Time.fixedDeltaTime;
            if (cooldown > 0)
            {
                return;
            }

            if (IsResource())            // && cooldownRsc<0){
            {
                RscManager.GainRsc(GetRscGain(), RscManager._GainType.RscTower);
                cooldown = GetCooldown();              //cooldownRsc=GetCooldown();
            }

            if (IsAOE())            // && cooldownAOE<0){
            {
                List <Unit> tgtList = SpawnManager.GetUnitsWithinRange(this, GetAttackRange(), GetTargetGroup());
                if (tgtList.Count > 0)
                {
                    cooldown = GetCooldown();                  //cooldownAOE=GetCooldown();
                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        tgtList[i].ApplyAttack(new AttackInfo(this, tgtList[i]));
                    }
                }
                else
                {
                    cooldown = 0.1f;               //cooldownAOE=0.1f;
                }
            }

            if (IsMine())            // && cooldownAttack<0){
            {
                List <Unit> tgtList = SpawnManager.GetUnitsWithinRange(this, TowerManager.GetGridSize() * .25f, GetTargetGroup());
                if (tgtList.Count > 0)
                {
                    tgtList[0].ApplyAttack(new AttackInfo(this, tgtList[0]));
                    Destroyed();
                }
                cooldown = 0.1f;              //cooldownAttack=0.1f;
            }
        }
コード例 #2
0
        //fixed update for resource, aoe and mine, check '#region support tower' for support
        void CreepFunction()
        {
            if (!GameControl.HasGameStarted())
            {
                return;
            }
            if (IsStunned())
            {
                return;
            }

            if (cooldown > 0)
            {
                return;
            }

            if (IsAOE())
            {
                List <Unit> tgtList = TowerManager.GetUnitsWithinRange(this, GetAttackRange());
                if (tgtList.Count > 0)
                {
                    cooldown = GetCooldown();
                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        tgtList[i].ApplyAttack(new AttackInfo(this, tgtList[i]));
                    }
                }
                else
                {
                    cooldown = 0.1f;
                }
            }

            if (IsSupport())
            {
                float range = GetAttackRange();
                for (int i = 0; i < supportTgtList.Count; i++)
                {
                    if (Vector3.Distance(GetPos(), supportTgtList[i].GetPos()) <= range)
                    {
                        continue;
                    }
                    ClearBuffOnTarget(supportTgtList[i]);
                    supportTgtList.RemoveAt(i); i -= 1;
                }

                List <Unit> tgtList = SpawnManager.GetUnitsWithinRange(this, range);
                for (int i = 0; i < tgtList.Count; i++)
                {
                    if (tgtList[i] == GetUnit() || tgtList[i].IsSupport())
                    {
                        continue;
                    }
                    if (supportTgtList.Contains(tgtList[i].GetCreep()))
                    {
                        continue;
                    }

                    Effect effect = GetEffectOnHit();                  //.Clone();
                    effect.duration = Mathf.Infinity;
                    tgtList[i].ApplyEffect(effect);

                    tgtList[i].GetCreep().supportSrcList.Add(this);
                    supportTgtList.Add(tgtList[i].GetCreep());
                }

                cooldown = 0.1f;
            }

            if (IsSpawner() && spawnerCount > 0 && spawnerPrefab != null)
            {
                float      oHP  = spawnerOverride.GetHP(this);
                float      oSH  = spawnerOverride.GetSH(this);
                float      oSpd = spawnerOverride.GetSpd(this);
                int        oExp = spawnerOverride.GetExp(this);
                List <int> oRsc = spawnerOverride.GetRsc(this, rscGainOnDestroyed);

                for (int i = 0; i < spawnerCount; i++)
                {
                    SpawnSubCreep(spawnerPrefab, oHP, oSH, oSpd, oExp, oRsc);
                }

                cooldown = GetCooldown();
            }
        }
コード例 #3
0
ファイル: Ability.cs プロジェクト: asd540578/TD_Project
        IEnumerator AbilityEffect(Vector3 pos)
        {
            if (effectDelay > 0)
            {
                yield return(new WaitForSeconds(effectDelay));
            }

            List <Unit> tgtList = new List <Unit>();

            if (targetType == _TargetType.Hostile)
            {
                if (!requireTargetSelection)
                {
                    tgtList = SpawnManager.GetActiveUnitList();
                }
                else
                {
                    tgtList = SpawnManager.GetUnitsWithinRange(pos, stats.aoeRange);
                }
            }
            else if (targetType == _TargetType.Friendly)
            {
                if (!requireTargetSelection)
                {
                    tgtList = TowerManager.GetActiveUnitList();
                }
                else
                {
                    tgtList = TowerManager.GetUnitsWithinRange(pos, stats.aoeRange);
                }
            }
            else
            {
                if (!requireTargetSelection)
                {
                    tgtList = SpawnManager.GetActiveUnitList();
                    List <Unit> towerList = TowerManager.GetActiveUnitList();
                    for (int i = 0; i < towerList.Count; i++)
                    {
                        tgtList.Add(towerList[i]);
                    }
                }
                else
                {
                    tgtList = SpawnManager.GetUnitsWithinRange(pos, stats.aoeRange);
                    List <Unit> towerList = TowerManager.GetUnitsWithinRange(pos, stats.aoeRange);
                    for (int i = 0; i < towerList.Count; i++)
                    {
                        tgtList.Add(towerList[i]);
                    }
                }
            }

            for (int i = 0; i < tgtList.Count; i++)
            {
                tgtList[i].ApplyAttack(new AttackInfo(this, tgtList[i], false));
                effectOnTarget.Spawn(tgtList[i].GetTargetPoint(), Quaternion.identity);
            }

            yield return(null);
        }
コード例 #4
0
ファイル: Unit.cs プロジェクト: asd540578/TD_Project
        public void ApplyAttack(AttackInfo aInfo)
        {
            if (aInfo.aoeRange > 0)
            {
                if (aInfo.srcUnit.IsTower())
                {
                    List <Unit> tgtList = SpawnManager.GetUnitsWithinRange(this, aInfo.aoeRange);
                    for (int i = 0; i < tgtList.Count; i++)
                    {
                        if (tgtList[i] == this)
                        {
                            continue;
                        }
                        tgtList[i].ApplyAttack(new AttackInfo(aInfo.srcUnit, tgtList[i], false));
                    }
                }
            }

            if (IsDestroyed())
            {
                return;
            }

            if (aInfo.damage > 0)
            {
                if (aInfo.hit)
                {
                    TDTK.TextOverlay(aInfo.damage.ToString(), GetTargetPoint());

                    AnimPlayHit();

                    //~ if(sh>0){
                    //~ if(aInfo.damage<sh){
                    //~ sh-=aInfo.damage;
                    //~ aInfo.damage=0;
                    //~ }
                    //~ else{
                    //~ aInfo.damage-=sh;
                    //~ sh=0;
                    //~ }
                    //~ }
                    aInfo.damage = ApplyShieldDamage(aInfo.damage);
                    shStagger    = GetSHStagger();

                    hp -= aInfo.damage;
                }
                else
                {
                    TDTK.TextOverlay("missed", GetTargetPoint());
                }

                if (hp <= 0)
                {
                    Destroyed();
                    return;
                }
            }

            if (aInfo.UseEffect())
            {
                ApplyEffect(aInfo.effect);
            }
        }
コード例 #5
0
ファイル: Unit.cs プロジェクト: asd540578/TD_Project
        public void ScanForTarget()
        {
            if (attackTarget != null)
            {
                if (attackTarget.IsDestroyed())
                {
                    attackTarget = null;
                }
                else
                {
                    float dist = Vector3.Distance(GetPos(), attackTarget.GetPos());
                    if (dist > GetDetectionRange(attackTarget))
                    {
                        attackTarget = null;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (CreepIsOnAttackCD())
            {
                return;                                 //for creep only
            }
            //if(cooldownAttack>0) return;

            List <Unit> unitList = null;

            if (IsTower())
            {
                unitList = SpawnManager.GetUnitsWithinRange(this, GetAttackRange(), GetTargetGroup());
            }
            else
            {
                unitList = TowerManager.GetUnitsWithinRange(this, GetAttackRange());
            }

            if (targetingFov > 0 && targetingFov < 360)
            {
                Quaternion curDir = thisT.rotation * Quaternion.Euler(0, targetingDir, 0);
                for (int i = 0; i < unitList.Count; i++)
                {
                    Quaternion dirToTarget = Quaternion.LookRotation(unitList[i].GetPos() - GetPos());
                    if (Quaternion.Angle(curDir, dirToTarget) > targetingFov * 0.5f)
                    {
                        unitList.RemoveAt(i);      i -= 1;
                    }
                }
            }

            if (unitList.Count <= 0)
            {
                return;
            }

            if (IsCreep() && targetMode == _TargetMode.NearestToDestination)
            {
                targetMode = _TargetMode.Random;
            }

            int newTargetIdx = -1;

            if (unitList.Count == 1)
            {
                newTargetIdx = 0;
            }
            else if (targetMode == _TargetMode.Random)
            {
                newTargetIdx = Random.Range(0, unitList.Count);
            }
            else if (targetMode == _TargetMode.NearestToSelf)
            {
                float nearest = Mathf.Infinity;
                for (int i = 0; i < unitList.Count; i++)
                {
                    float dist = Vector3.Distance(GetPos(), unitList[i].GetPos());
                    if (dist < nearest)
                    {
                        newTargetIdx = i; nearest = dist;
                    }
                }
            }
            else if (targetMode == _TargetMode.MostHP)
            {
                float mostHP = 0;
                for (int i = 0; i < unitList.Count; i++)
                {
                    if (unitList[i].hp + unitList[i].sh > mostHP)
                    {
                        newTargetIdx = i; mostHP = unitList[i].hp + unitList[i].sh;
                    }
                }
            }
            else if (targetMode == _TargetMode.LeastHP)
            {
                float leastHP = Mathf.Infinity;
                for (int i = 0; i < unitList.Count; i++)
                {
                    if (unitList[i].hp + unitList[i].sh < leastHP)
                    {
                        newTargetIdx = i; leastHP = unitList[i].hp + unitList[i].sh;
                    }
                }
            }
            else if (targetMode == _TargetMode.NearestToDestination)
            {
                float pathDist = Mathf.Infinity; int furthestWP = 0; int furthestSubWP = 0; float distToDest = Mathf.Infinity;
                for (int i = 0; i < unitList.Count; i++)
                {
                    float pDist         = unitList[i].GetPathDist();
                    int   wpIdx         = unitList[i].GetWPIdx();
                    int   subWpIdx      = unitList[i].GetSubWPIdx();
                    float tgtDistToDest = unitList[i].GetDistToTargetPos();

                    if (pDist < pathDist)
                    {
                        newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest;
                    }
                    else if (pDist == pathDist)
                    {
                        if (furthestWP < wpIdx)
                        {
                            newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest;
                        }
                        else if (furthestWP == wpIdx)
                        {
                            if (furthestSubWP < subWpIdx)
                            {
                                newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest;
                            }
                            else if (furthestSubWP == subWpIdx && tgtDistToDest < distToDest)
                            {
                                newTargetIdx = i; pathDist = pDist; furthestWP = wpIdx; furthestSubWP = subWpIdx; distToDest = tgtDistToDest;
                            }
                        }
                    }
                }
            }


            if (newTargetIdx >= 0)
            {
                attackTarget = unitList[newTargetIdx];
                if (snapAiming)
                {
                    Aim();
                }
            }
        }