Пример #1
0
    IEnumerator DoDamage(CharacterStats stats, float delay)
    {
        yield return(new WaitForSeconds(delay));

        opponentStats.TakeDamage(myStats.damage, myStats);

        if (myStats.role == CharacterRole.Predator)
        {
            manaRegen.Regeneration();
        }
    }
Пример #2
0
    public void TakeDamage(float _damage, CharacterStats enemyStats)
    {
        if (_damage <= 0)
        {
            return;
        }

        // Damage multiplier based on armor value.
        float _multiplier = 100f / (100f + armor);
        float _dmgFloat   = _damage;

        // Multiply the damage with the multiplier and round to an even integer.
        _damage = Mathf.RoundToInt(_dmgFloat * _multiplier);

        //Make sure damage doesn't go below 1.
        _damage = Mathf.Clamp(_damage, 1, int.MaxValue);

        // Subtract damage from health
        currentHealth -= _damage;

        // Visual stuff.
        Debug.Log(transform.name + " takes " + _damage + " damage.");
        healthUI.OnHealthChanged(maxHealth, currentHealth, _damage, false);
        healthUI.SpawnDamageNumber(_damage);


        // Mana regeneration for being attacked.
        if (role == CharacterRole.Predator)
        {
            manaRegenFunction.Regeneration();
        }

        // If the unit hits 0hp, it dies.
        if (currentHealth <= 0)
        {
            // Give Mana regen to the unit that killed you if they are of the Scavenger character role.
            if (enemyStats.role == CharacterRole.Scavenger)
            {
                enemyStats.manaRegenFunction.Regeneration();
            }

            Die();
        }
    }