Example #1
0
 public void SetPiercingDamageText(Unit unit)
 {
     piercing_damage_text.text = "Piercing Damage: " + unit.GetPiercingDamage();
     piercing_damage_bar.value = unit.GetPiercingDamage() / 200.0f;
 }
Example #2
0
    // Returns how much damage the attacker would do to this unit
    public float CalculateDamage(Unit attacker, Hex from)
    {
        // Have the damage be the percentage of the health remaining of this unit. Weak units don't do as much damage
        float raw_normal_damage = attacker.GetDamage() * (attacker.GetHealth() / attacker.GetMaxHealth());
        float raw_piercing_damage = attacker.GetPiercingDamage() * (attacker.GetHealth() / attacker.GetMaxHealth());

        // Get the right type of defence to use. Ranged defence from ranged units
        float defence = 0;
        if (attacker.is_ranged_unit)
        {
            defence = this.GetRangedDefence();
        }
        else
            defence = this.GetDefence();

        // Modify the damage by the defence percentage. 10% defence means 90% of the damage is inflicted.
        float modified_normal_damage = raw_normal_damage - (raw_normal_damage * defence);

        // Piercing damage is not affected by the enemy's defense.
        float damage = modified_normal_damage + raw_piercing_damage;

        // Apply bonuses to damage that's been modified by the enemies' defence
        // Apply bonus against specific type of unit
        if (this.unit_type == Unit_Types.Melee)
            damage += damage * attacker.GetMeleeBonus();
        else if (this.unit_type == Unit_Types.Cavalry)
            damage += damage * attacker.GetMeleeBonus();
        else if (this.unit_type == Unit_Types.Ranged)
            damage += damage * attacker.GetMeleeBonus();

        // If the attacker is flanking, apply a flanking bonus
        if (!IsFacing(from))
        {
            damage += damage * attacker.GetFlankingBonus();
        }

        return damage;
    }