/// <summary> /// Take damage from an attacker /// </summary> /// <param name="attacker">Stats controller of the attacking entity</param> /// <param name="damageValue">Approximate damage value to apply to enemy health</param> /// <param name="timeDelta">Time since last damage calculation</param> public override void TakeDamage(EntityStatsController attacker, float damageValue, float timeDelta = 1f) { // Ignore attacks if already dead or invincible if (isDead || invincible) { return; } float colourDamagePercentage = characterColour == CharacterColour.All || attacker.characterColour == characterColour ? 1 : colourResistanceModifier; // Calculate any changes based on stats and modifiers here first float hitValue = Mathf.Max(colourDamagePercentage * (damageValue - ComputeDefenseModifier()), 0) * timeDelta; health.Subtract(hitValue); ShowDamage(hitValue); Anim.SetTrigger("TakeDamage"); // Pass damage information to brain Brain.OnDamageTaken(attacker.gameObject, hitValue); if (Mathf.Approximately(health.CurrentValue, 0f)) { Die(); } }
/// <summary> /// Take damage from an attacker /// </summary> /// <param name="attacker">Stats controller of the attacking entity</param> /// <param name="damageValue">Approximate damage value to apply to enemy health</param> /// <param name="timeDelta">Time since last damage calculation</param> public override void TakeDamage(EntityStatsController attacker, float damageValue, float timeDelta = 1f) { // Ignore attacks if already dead if (isDead) { return; } if (characterColour != CharacterColour.All && attacker.characterColour != characterColour) { return; } // Calculate any changes based on stats and modifiers here first float hitValue = Mathf.Max(damageValue - ComputeDefenseModifier(), 0) * timeDelta; health.Subtract(hitValue); ShowDamage(hitValue); Anim.SetTrigger("TakeDamage"); // Pass damage information to brain _brain.OnDamageTaken(attacker.gameObject, hitValue); if (Mathf.Approximately(health.CurrentValue, 0f)) { Die(); } }