public void OnDamageReceived(DamageReceived message) { var ai = (ArtificialIntelligence)Manager.GetComponent(message.Damagee, ArtificialIntelligence.TypeId); if (ai != null && ai.CurrentBehavior != ArtificialIntelligence.BehaviorType.Attack && // Make sure it makes sense to fire back. For example, it doesn't make sense // to start shooting a radiating body / nebula. Manager.GetComponent(message.Owner, Health.TypeId) != null) { ai.Attack(message.Owner); } }
public void TakeDamage(GameObject from, float damage) { if (_currentHealthPoints > 0) { _currentHealthPoints -= damage; SetEventArgs(from, damage, damage / maxHealthPoints); DamageReceived?.Invoke(this, _eventArgs); } if (_currentHealthPoints <= 0) { Death?.Invoke(this, _eventArgs); Destroy(gameObject); } if (destructionSequence != null) { var remainingHealth = 1 - damage / maxHealthPoints; StartCoroutine(destructionSequence.DestructionSequenceCorutine(this, remainingHealth)); } }
public void ChangeHP(int deltaHP) { int newHP = (int)HP; newHP += deltaHP; if (newHP > HP) { HealReceived?.Invoke(); } else if (newHP < HP) { DamageReceived?.Invoke(); } else if (newHP <= 0) { Death?.Invoke(); } HP = (uint)newHP; HealthChanged?.Invoke(); }
public virtual void ReceiveDamage(int amount) { DamageReceived?.Invoke(amount); }
public void OnDamageReceived(DamageReceived message) { ApplyDamage(message.Owner, message.Attributes, message.Damagee); }