Beispiel #1
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));
                }
            }
        }
		//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));
				}
			}
			
		}