Esempio n. 1
0
    public AttackEventArgs(IAttackCapable attacker, IAttackCapable defender, int damage)
    {
        Attacker = attacker;
        Defender = defender;

        Damage = damage;
    }
Esempio n. 2
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected virtual void Defend(IAttackCapable other, int damage)
    {
        MarkAsDefending(other);
        HitPoints -= Mathf.Clamp(damage - DefenceFactor, 1, damage);  //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
                                                                      //This behaviour can be overridden in derived classes.
        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }

        if (HitPoints <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
            }
            OnDestroyed();
        }
    }
Esempio n. 3
0
 public override void MarkAsDefending(IAttackCapable other)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Gives visual indication that the unit is under attack.
 /// </summary>
 /// <param name="other"></param>
 public abstract void MarkAsDefending(IAttackCapable other);
Esempio n. 5
0
 //Allowing the unit to be damaged and defend itself if possible.
 public virtual void GetDamaged(IAttackCapable attacker, int damage)
 {
     Defend(attacker, damage);
 }
Esempio n. 6
0
 public override void MarkAsDefending(IAttackCapable other)
 {
     StartCoroutine(Glow(new Color(1, 0, 0, 0.5f), 1));
 }