private bool DamageableIsImmune(DamageableTemplate damageable) { bool dodgeItsOwnAttack = damageable == spawnerOfThisDamager && spawnerIsImmune; bool damageableTypeIsImmune = immuneDamageableTypes.Contains(damageable.GetType()); return(dodgeItsOwnAttack || damageableTypeIsImmune); }
private void OnTriggerEnter2D(Collider2D other) { DamageableTemplate damageable = other.GetComponent <DamageableTemplate>(); if (damageable) { DecideIfIsImmuneThenDealDamage(damageable); } }
private void DecideIfIsImmuneThenDealDamage(DamageableTemplate damageable) { if (DamageableIsImmune(damageable)) { return; } else { ExecuteDamageAlgorightm(damageable); } }
private void ExecuteDamageAlgorightm(DamageableTemplate damageable) { BeforeDoingDamage(damageable); damageable.Damage(this, damageAmount); AfterDoingDamage(); if (destroyItselfAfterHit) { Destroy(gameObject); } }
public void SetSpawner(DamageableTemplate spawner) { this.spawnerOfThisDamager = spawner; }
protected virtual void BeforeDoingDamage(DamageableTemplate damageable) { }