public override void Activate() { /* * Transform[] enemyPos = reference.GetEnemyPositions(); * Transform playerPos = reference.GetPlayerPosition(0); // WIP * * int currentCounter = enemyPos.Length / 2; * int min = 0; * int max = enemyPos.Length; * * bool found = false; * * // Find closest target in terms of x-pos (testing). Improve on this later (look up Kd-tree etc) * while((min < max) && (!found)) * { * // Less than * if (playerPos.position.x < enemyPos[currentCounter].position.x) * min = currentCounter + 1; * else if (playerPos.position.x > enemyPos[currentCounter].position.x) // Greater than * max = currentCounter - 1; * else * found = true; * * if (min >= max) // Keep currentCounter * found = true; * else if (!found) * currentCounter = min + max / 2; * }*/ // Very crude GameObject[] enemyPositions = GameObject.FindGameObjectsWithTag("Enemy"); Transform playerPosition = reference.GetPlayerPosition(0); float closestDistance = Mathf.Infinity; int closestEnemy = -1; // Targets whichever in front of the character is facing only. Ignores enemies behind for (int i = 0; i < enemyPositions.Length; i++) { if ((enemyPositions[i].transform.position.x > playerPosition.position.x) && (Mathf.Pow(enemyPositions[i].transform.position.x - playerPosition.position.x, 2) + Mathf.Pow(enemyPositions[i].transform.position.y - playerPosition.position.y, 2) < closestDistance)) { closestDistance = Mathf.Pow(enemyPositions[i].transform.position.x - playerPosition.position.x, 2) + Mathf.Pow(enemyPositions[i].transform.position.y - playerPosition.position.y, 2); closestEnemy = i; } } // Temporary if (closestEnemy != -1) { DamageCalculations.ApplyCalculation(enemyPositions[closestEnemy], parent, power); return; } else { print("No target"); } return; }
public override void Activate() { targets = GameObject.FindGameObjectsWithTag(targetTag); for (int i = 0; i < targets.Length; i++) { if (targets[i].GetComponent <CharacterStats>() != null) { DamageCalculations.ApplyCalculation(targets[i], parent, power * Random.Range(0.01f, 4f)); } } }
//string targetTag = "Enemy"; public override void Activate() { targets = GameObject.FindGameObjectsWithTag("Enemy"); for (int i = 0; i < targets.Length; i++) { if (targets[i].GetComponent <CharacterStats>() != null) { DamageCalculations.ApplyCalculation(targets[i], parent, power); } } // Do the same with "Boss" }
private void OnTriggerEnter2D(Collider2D collision) { for (int i = 0; i < targets.Length; i++) { if (collision.gameObject.tag == targets[i]) { DamageCalculations.ApplyCalculation(collision.gameObject, gameObject, power, actions); if (numHits == 0) { Destroy(gameObject); } numHits--; } } }
private void OnTriggerStay2D(Collider2D collision) { if (hitCooldown <= 0) { for (int i = 0; i < targets.Length; i++) { if (collision.gameObject.tag == targets[i]) { if ((instantKill) && (targets[i] != "Boss")) { collision.gameObject.GetComponent <CharacterStats>().SetCurrentStat(1, 0); } DamageCalculations.ApplyCalculation(collision.gameObject, gameObject, power, actions); } } } }
// LASERS SHOULD HAVE THEIR OWN TAGS AND NOT BE DESTROYED ON BLOCK private void OnTriggerEnter2D(Collider2D collision) { bool triggerCounter = false; for (int i = 0; i < tags.Length; i++) { if (collision.gameObject.tag == tags[i]) { Destroy(collision.gameObject); if (variation == 2) { triggerCounter = true; } else if (variation == 1) { reference.AddMana(Mathf.CeilToInt(reference.GetMaxMana() * 0.03f)); } numHits--; if (numHits <= 0) { enabled = false; } } } if (triggerCounter) { // Enemy...might need to change to incorporate boss or even players later allTargets = GameObject.FindGameObjectsWithTag("Enemy"); for (int i = 0; i < allTargets.Length; i++) { // Take into account stats of the CHARACTER THIS SHIELD IS ATTACHED TO if (Mathf.Pow(gameObject.transform.position.x - allTargets[i].transform.position.x, 2) + Mathf.Pow(gameObject.transform.position.y - allTargets[i].transform.position.y, 2) < 400) { DamageCalculations.ApplyCalculation(allTargets[i], gameObject, gameObject.GetComponent <CharacterStats>().GetCurrentStat(0) * 0.7f); } } } }
public override void Stack(StatusEffect sameEffect) { power += 0.1f; if (stackCount < maxStacks) { stackCount++; } if (variation == 1) { stackCount = 0; power = 1; // Damage calculation occurs without the extra damage if ((parent != null) && (parent.GetComponent <Projectile>() != null)) { DamageCalculations.ApplyCalculation(gameObject, parent, parent.GetComponent <Projectile>().GetPower() * 3); } } }
private void OnDestroy() { if (debuffObject != null) { Destroy(debuffObject); } if (variation == 0) { if (buffTimer >= 0) { GameObject[] allEnemies = GameObject.FindGameObjectsWithTag("Enemy"); // If enemies are in range for (int i = 0; i < allEnemies.Length; i++) { if (Mathf.Pow(gameObject.transform.position.x - allEnemies[i].transform.position.x, 2) + Mathf.Pow(gameObject.transform.position.y - allEnemies[i].transform.position.y, 2) < 400) { DamageCalculations.ApplyCalculation(allEnemies[i], parent, 1.2f * power); } } } } }