Exemple #1
0
    private void attemptAbilityFire(int index)
    {
        Ability ability = main_unit.GetComponent <unit_control_script>().GetAbility(index);

        if (ability.GetLevel() < 1)
        {
            return;
        }
        if (main_unit.GetMana() < ability.GetCost() || ability.OnCooldown())
        {
            return;
        }
        //if the ability is a point target spell see if there is a target under neath the player and that the enemy is in range
        if (ability.ActivationType == AbilityActivationType.Cast)
        {
            if (ability._TargetType == TargetType.PointTarget)
            {
                //see if there is an enemy under the player cursor
                RaycastHit hit;
                if (Physics.Raycast(GameObject.FindObjectOfType <Camera>().ScreenPointToRay(Input.mousePosition), out hit))
                {
                    enemy_controller enemy = hit.transform.gameObject.GetComponent <enemy_controller>();
                    if (hit.transform.CompareTag("Enemy") && UtilityHelper.InRange(main_unit.GetPosition(), enemy.GetPosition(), (ability.GetCastRange() + main_unit.GetCastRange()) / 100.0f))
                    {
                        ability.ActivateAbility(hit.transform.gameObject);
                        //reduce the players mana
                        main_unit.AddMana(-ability.GetCost());
                    }
                }
            }

            if (ability._TargetType == TargetType.Self)
            {
                //check to see if ability is on cooldown
                if (!ability.OnCooldown())
                {
                    ability.ActivateAbility();
                }
            }
        }
    }