public void Damage(IDamageInfo damageInfo) { if (IsDead) { Debug.LogWarningFormat("Attempting to damage dead unit {0}", this); return; } float actualDamage = Mathf.Min(current, damageInfo.Amount); float endHealth = current - actualDamage; DamageEvent damageEvent = new DamageEvent(this, damageInfo); if (Equals(actualDamage, 0f)) { return; } damageEvent.HealthChange = -actualDamage; damageEvent.EndHealth = endHealth; ApplyHealthChange(damageEvent); if (IsDead) { OnDeath(); } }
public DamageEvent(IHealth target, IDamageInfo damageInfo) { Target = target; Source = damageInfo.Source; Amount = damageInfo.Amount; DamageType = damageInfo.DamageType; StartHealth = target.Current; EndHealth = target.Current; HealthChange = 0; StartMaxHealth = target.Max; EndMaxHealth = target.Max; }
public void Damage(IDamageInfo damageInfo) { float actualDamage = Mathf.Min(current, damageInfo.Amount); float endHealth = current - actualDamage; if (Equals(actualDamage, 0f)) { return; } if (endHealth <= 0f) { OnDeath(); } }
public void Damage(IDamageInfo damageInfo) { if (IsDead) { return; } float modDamage = damageInfo.Amount; if (damageInfo.DamageType == DamageType.Normal) { modDamage = damageInfo.Amount * (1 - normDamageReduction); } else if (damageInfo.DamageType == DamageType.Lava) { modDamage = damageInfo.Amount * (1 - lavaDamageReduction); } float actualDamage = Mathf.Min(current, modDamage); float endHealth = current - actualDamage; DamageEvent damageEvent = new DamageEvent(this, damageInfo); if (Equals(actualDamage, 0f)) { return; } damageEvent.HealthChange = -actualDamage; damageEvent.EndHealth = endHealth; ApplyHealthChange(damageEvent); if (IsDead && OnDeath != null) { OnDeath.Invoke(); } }
public float Damage(IDamageInfo damageInfo) { if (IsDead) { return(0f); } DamageEvent damageEvent = new DamageEvent(this, damageInfo); DamageEvent adjustedDamageEvent = damageEvent; // run damage through damage modification pipeline foreach (IModifier <DamageEvent> modifier in damageModifiers) { adjustedDamageEvent = modifier.Modify(adjustedDamageEvent, this); } float actualDamage = Mathf.Min(current, adjustedDamageEvent.Amount); float endHealth = current - actualDamage; if (Equals(actualDamage, 0f)) { return(0f); } damageEvent.HealthChange = -actualDamage; damageEvent.EndHealth = endHealth; ApplyHealthChange(damageEvent); if (IsDead && OnDeath != null) { OnDeath.Invoke(); } return(actualDamage); }
private void Health_OnHealthChanged(object sender, IDamageInfo e) { text.text = health.CurrentHealth + "+"; }
private void Health_OnDeath(object sender, IDamageInfo e) { this.enabled = false; }