private void acquireTarget() { List <GameObject> alliesInRange = Utils.getAlliesInRange(transform.position, heroStats.getRange()); //find targets with a health less than maxhealth + overheal currentTarget = alliesInRange.FirstOrDefault(ally => !ally.GetComponent <HealthBar>().isMaxHealth(overheal)); //this sucks because once "alliesInRange" is populated the first ally in the list will always be prioritized //heal ally with the lowest health //this kinda sucks, revisit this // currentTarget = alliesInRange?.Aggregate((lowestHpAlly, otherAlly) => // lowestHpAlly.GetComponent<HealthBar>().getCurrentHealth() < otherAlly.GetComponent<HealthBar>().getCurrentHealth() ? lowestHpAlly : otherAlly // ); // //clear out current target if they have full health // if(currentTarget.GetComponent<HealthBar>().getMaxHealth(overheal) == currentTarget.GetComponent<HealthBar>().getCurrentHealth() + overheal){ // currentTarget = null; // } //if none, attack nearest enemies if (currentTarget == null) { List <GameObject> enemiesInRange = Utils.getEnemiesInRange(transform.position, heroStats.getRange()); if (enemiesInRange.Count > 0) { currentTarget = enemiesInRange[0]; } else { currentTarget = null; } } }
void Start() { animator = GetComponent <Animator>(); heroStats = GetComponent <HeroStats>(); range = heroStats.getRange(); meleeBlock = GetComponent <MeleeBlock>(); nextAttackTime = 0.0f; }
void Start() { heroStats = GetComponent <HeroStats>(); animator = GetComponent <Animator>(); attack = heroStats.getAttack(); attackSpeed = Utils.calculateAttackRate(heroStats.getUnitType(), heroStats.getAgility()); range = heroStats.getRange(); nextAttackTime = 0.0f; }
void FixedUpdate() { //clean out enemies that have been killed by other units sterilizeEngagedEnemies(); //fetch and block enemies in range List <GameObject> enemiesInRange = Utils.getEnemiesInRange(transform.position, heroStats.getRange()); if (enemiesInRange.Count > 0 && currentlyBlocking < heroStats.getBlock()) { tryToBlockEnemy(enemiesInRange); } //try to attack enemies if (engagedEnemies.Count > 0 && Time.time > nextAttackTime) { nextAttackTime = Time.time + attackSpeed; attackEngagedEnemies(); } }
public bool acquireTarget() { if (currentTarget != null) { return(true); } else if (meleeBlock == null) { currentTarget = Utils.getEnemiesInRange(transform.position, heroStats.getRange()).First(); return(currentTarget != null); } else if (meleeBlock.getEnagedEnemies().Any()) { currentTarget = meleeBlock.getEnagedEnemies().First(); return(currentTarget != null); } else { return(false); } }
public void executeBehavior() { sterilizeEngagedEnemies(); if (currentlyBlocking < heroStats.getBlock()) { List <GameObject> enemiesInRange = Utils.getEnemiesInRange(transform.position, heroStats.getRange()); if (enemiesInRange.Any()) { tryToBlockEnemy(enemiesInRange); } } }