void Debuff(Transform target) { if (targetEnemy) { Enemy e = target.GetComponent <Enemy>(); if (e != null) { e.TakeDamage(damage); foreach (Debuff debuff in debuffs) { BuffHelper.AddDebuff(e, debuff); } } } else if (!targetEnemy) { Turret t = target.GetComponent <Turret>(); if (t != null) { foreach (Debuff buff in buffs) { BuffHelper.AddDebuff(t, buff); } } } }
void Damage(Transform enemy) { Enemy e = enemy.GetComponent <Enemy>(); if (e != null) { foreach (Debuff debuff in debuffs) { BuffHelper.AddDebuff(e, debuff); } e.TakeDamage(damage, reducedByArmor); } }
public void AltShoot() { shootEffect2.Play(); Collider[] colliders = Physics.OverlapSphere(transform.position, range / 3); foreach (Collider collider in colliders) { if (collider.tag == "Turret") { Turret target = collider.transform.GetComponent <Turret>(); if (target != null) { BuffHelper.AddDebuff(target, DebuffType.AtkSpeed, 5f, 1f, altShootBuffEffect); } } } }
void Laser() { targetEnemy.TakeDamage(damageOverTime * Time.deltaTime * (float)fireRate); //for multitarget bool debuffApplied = false; //if a debuff is applied, apply it to any other targets needed bool resetTargets = false; //if the mulitargets are still valid dont update the array (targets[]) if (buildUpTime != 0) { if (currentBuildUp >= buildUpTime) { BuffHelper.AddDebuff(targetEnemy, type, debuffDuration, debuffAmount, debuffEffect); currentBuildUp = 0.001f; debuffApplied = true; } else { currentBuildUp += Time.deltaTime * (float)fireRate; } } else if (debuffAmount != 0) { BuffHelper.AddDebuff(targetEnemy, type, 0.01f, debuffAmount, null); //if buildUpTime is 0 just apply it for the minimum time } if (!lineRenderer.enabled) { lineRenderer.enabled = true; impactEffect.Play(); impactLight.enabled = true; } lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, target.position); #region multi-target if (extraTargetNumber != 0) { if (target == null) { return; } if (targets[0] == null) { resetTargets = true; } else { for (int i = 1; i < targets.Length; ++i) { if (targets[i] == null) { resetTargets = true; break; } if (Vector3.Distance(targets[i].position, targets[i - 1].position) > extraTargetFindRange) { resetTargets = true; break; } } } if (resetTargets) { for (int i = 0; i < targets.Length; ++i) { targets[i] = null; //reset targets so that the current targets aren't ignored } for (int i = 0; i < targetEnemies.Length; ++i) { targetEnemies[i] = null; } int currentTargets = 0; targets[0] = target.transform; //excluding 0 (initial target) find extra targets in range for (int i = 1; i < targets.Length; ++i) { targets[i] = newTarget(targets[i - 1], extraTargetFindRange, targets); //find a new target within range, excluding things already targeted if (targets[i] == null) { break; } currentTargets++; } //linerender update lineRenderer.positionCount = currentTargets + 2; //position 0 and 1 are already used on the starting position and the initial enemy } for (int i = 1; i < lineRenderer.positionCount - 1; ++i) //position count is no. of extra targets + initial two points (at turret and first enemy { //position count - 1 means points from first enemy to the last enemy if (targets[i] == null) { break; } lineRenderer.SetPosition(i + 1, targets[i].position); } //lineRenderer.positionCount = //number of targets //make enemies take damage (not initial target (already took damage)) for (int i = 1; i < targets.Length; ++i) { if (targets[i] == null) { break; } targetEnemies[i] = targets[i].GetComponent <Enemy>(); targetEnemies[i].TakeDamage(damageOverTime * Time.deltaTime * (float)fireRate); if (debuffApplied && debuffDuration != 0) //don't keep track of build up on all enemies just apply it to all when one is affected { BuffHelper.AddDebuff(targetEnemies[i], type, debuffDuration, debuffAmount, debuffEffect); } else if (debuffDuration == 0) { if (debuffAmount != 0) { BuffHelper.AddDebuff(targetEnemy, type, 0.01f, debuffAmount, null); } } } } else { lineRenderer.positionCount = 2; } #endregion Vector3 dir = firePoint.position - target.position; //TODO: add effect to all extra tagets impactEffect.transform.position = target.position + dir.normalized; impactEffect.transform.rotation = Quaternion.LookRotation(dir); }