public AttackEventArgs(IAttackCapable attacker, IAttackCapable defender, int damage) { Attacker = attacker; Defender = defender; Damage = damage; }
/// <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(); } }
public override void MarkAsDefending(IAttackCapable other) { }
/// <summary> /// Gives visual indication that the unit is under attack. /// </summary> /// <param name="other"></param> public abstract void MarkAsDefending(IAttackCapable other);
//Allowing the unit to be damaged and defend itself if possible. public virtual void GetDamaged(IAttackCapable attacker, int damage) { Defend(attacker, damage); }
public override void MarkAsDefending(IAttackCapable other) { StartCoroutine(Glow(new Color(1, 0, 0, 0.5f), 1)); }