Example #1
0
    // heals the target
    public void TakeHealing(int heal, Unit healer = null)
    {
        int healing = (int)(heal * healingRecievedMod);
        hp += healing;

        if (hp > maxHP) {
            hp = maxHP;
        }

        CheckTriggers (TriggerType.Healed);
        ShowCombatText(healing.ToString(), healingCombatText);

        //tell the attacker that it dealt damage
        if (healer) {
            healer.CheckTriggers(TriggerType.Heal);
        }

        UpdateHealthBar ();
    }
Example #2
0
    // unit takes parameter damage and shows in combat text, returns if the dmg was dodged(-1), blocked(0) or hit(1)
    public int TakeDamage(int dmg, AudioClip sound = null, bool canBeEvaded = true, Unit attacker = null)
    {
        // 1 if hit, 0 if blocked, -1 is dodged
        int outcome = 1;

        //calculate the actual damage after reductions
        int damage = (int)((dmg * damageRecievedMod) * (1 - armourDamageReduction));

        //if the damage can actually be avaded
        if (canBeEvaded && !IsStunned()) {

            //see if the unit dodges the attack
            int dodge = Random.Range (1, 100);
            if (dodge <= dodgeChance) {
                ShowCombatText ("Dodged", statusCombatText);
                CheckTriggers (TriggerType.Dodge, attacker);
                GetComponent<AudioSource> ().PlayOneShot (uManager.GetComponent<PrefabLibrary> ().getSoundEffect ("Dodge"));
                return -1;
            }

            //see if the unit Blocks the attack
            int block = Random.Range (1, 100);
            if (block <= blockChance) {
                //dmg was blocked, reduce damage and display block
                ShowCombatText ("Blocked", statusCombatText);
                damage = (int)(damage * 0.25f);
                CheckTriggers (TriggerType.Block, attacker);
                GetComponent<AudioSource> ().PlayOneShot (uManager.GetComponent<PrefabLibrary> ().getSoundEffect ("Block"));

                outcome = 0; // show the dmg was blocked
            } else if (sound != null) {
                //play the normal sound instead of the block sound
                GetComponent<AudioSource> ().PlayOneShot (sound);
            }
        } else if (sound != null) {
            //play the normal sound instead of the block or dodge sound
            GetComponent<AudioSource> ().PlayOneShot (sound);
        }

        int currentDamage = damage;

        if (shield != 0) {
            currentDamage = DamageShield(currentDamage);
        }

        hp -= currentDamage;
        CheckTriggers (TriggerType.Hit, attacker);
        ShowCombatText(damage.ToString(), damageCombatText);

        if (hp < 0) {
            hp = 0;
        }

        UpdateHealthBar ();

        //tell the attacker that it dealt damage
        if (attacker) {
            attacker.CheckTriggers(TriggerType.DealDamage);
        }

        return outcome;
    }