Пример #1
0
    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;
            }
        }
    }
Пример #2
0
    void Start()
    {
        animator   = GetComponent <Animator>();
        heroStats  = GetComponent <HeroStats>();
        range      = heroStats.getRange();
        meleeBlock = GetComponent <MeleeBlock>();

        nextAttackTime = 0.0f;
    }
Пример #3
0
    void Start()
    {
        heroStats   = GetComponent <HeroStats>();
        animator    = GetComponent <Animator>();
        attack      = heroStats.getAttack();
        attackSpeed = Utils.calculateAttackRate(heroStats.getUnitType(), heroStats.getAgility());
        range       = heroStats.getRange();

        nextAttackTime = 0.0f;
    }
Пример #4
0
    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();
        }
    }
Пример #5
0
 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);
     }
 }
Пример #6
0
 public void executeBehavior()
 {
     sterilizeEngagedEnemies();
     if (currentlyBlocking < heroStats.getBlock())
     {
         List <GameObject> enemiesInRange = Utils.getEnemiesInRange(transform.position, heroStats.getRange());
         if (enemiesInRange.Any())
         {
             tryToBlockEnemy(enemiesInRange);
         }
     }
 }