public bool CanReceiveDamage() { if (m_fsm.IsInState <PlayerState_Dead>()) { return(false); } return(HealthComponent.CanReceiveDamage()); }
public IEnumerator Explode() { gameObject.transform.localScale *= m_explosionRadius; // Find all entities near the bomb within a certain radius foreach (var entity in this.EntitiesWithinRadius(m_explosionRadius)) { // TODO: Shameless copied from SwordAttack - Need to be merged into generic code Enemy enemy = entity as Enemy; if (enemy && (!m_singleHitPerEnemy || !m_hitEntities.ContainsKey(enemy))) { HealthComponent healthComponent = enemy.HealthComponent; if (healthComponent.CanReceiveDamage()) { // simple damage formula for now int damage = GameManager.Instance.MainPlayer.Experience.Level; // check if critical hit ! if (RandomManager.Probability(0.10f)) { damage *= 3; } healthComponent.ReceiveDamage(damage); m_hitEntities.Add(enemy, true); Vector2 relativeDir = enemy.transform.position - this.transform.position; enemy.KnockBack(relativeDir.normalized, 3f, 0.05f); } } } EntityRender tickingRenderer = GetTickingRenderer(); tickingRenderer.enabled = false; EntityRender explodeRenderer = GetExplodeRenderer(); explodeRenderer.SetCurrentGroup("Explode"); AudioManager.PlaySfx(m_explodeSfx); yield return(new WaitForSeconds(m_explodeSfx.length)); }
public void OnTouch(Entity other) { Entity entity = GetComponent <Entity>(); // to prevent another attack while being destroyed // this might need to be moved into the OnTouch collision system ... if (entity && entity.IsDestroying()) { return; } Enemy enemy = other as Enemy; if (enemy && (!m_singleHitPerEnemy || !m_hitEntities.ContainsKey(other))) { HealthComponent healthComponent = enemy.HealthComponent; if (healthComponent.CanReceiveDamage()) { // simple damage formula for now int damage = GameManager.Instance.MainPlayer.Experience.Level; // check if critical hit ! if (RandomManager.Probability(0.10f)) { damage *= 3; } healthComponent.ReceiveDamage(damage); m_hitEntities.Add(other, true); Vector2 relativeDir = other.transform.position - this.transform.position; enemy.KnockBack(relativeDir.normalized, 3f, 0.05f); AudioManager.Instance.PlayHit(); } } }