public bool TakeDamage(float damageToTake, bool triggerInvin)
    {
        if (!isInvincible)
        {
            health -= damageToTake;
            TookDamage.Invoke();

            if (health <= 0)
            {
                Destroy(this.gameObject);
                return(true);
            }

            if (triggerInvin)
            {
                isInvincible = true;
            }

            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #2
0
 public void TakeDamage(int damageAmount)
 {
     _healthCurrent -= damageAmount;
     Debug.Log(gameObject.name + " took " + damageAmount + " damage!");
     TookDamage?.Invoke();
     CheckDeath();
 }
Exemple #3
0
    /// <summary>
    /// Try to have the player take damage, returning true or false depending on whether it
    /// was successful.
    /// </summary>
    public virtual bool TakeDamage(float damageToTake, bool triggerInvin = true)
    {
        if (isInvincible)
        {
            return(false);
        }

        hp -= damageToTake;
        animator.SetTrigger("Hurt");

        TookDamage.Invoke();

        // If invincibility is to be applied, trigger the timer for it
        if (triggerInvin)
        {
            isInvincible = true;
            invinTimer   = invinTime;
        }

        if (hp <= 0)
        {
            Died.Invoke();
            Respawn();
        }

        return(true);
    }
Exemple #4
0
    public void ApplyDamage(int dmg, Attack.DamageTypes damageType)
    {
        this.hitsTaken++;

        int damageAfterModifiers = dmg;

        for (int i = 0; i < this.modifiers.Count; i++)
        {
            damageAfterModifiers = this.modifiers[i].Apply(damageAfterModifiers, damageType);
        }

        this.HP = Mathf.Max(this.HP - damageAfterModifiers, 0);

        // Fire events
        if (this.HP <= 0)
        {
            if (Destroyed != null)
            {
                Destroyed.Invoke(this);
            }
        }
        else
        {
            if (TookDamage != null)
            {
                TookDamage.Invoke(this, damageAfterModifiers, this.HP);
            }
        }
    }
    public virtual bool TakeDamage(float amount, DamageType type = DamageType.none)
    {
        if (!isDead && !isInvincible)
        {
            float amountToTake = amount;

            if (resistances.Contains(type))
            {
                amountToTake *= 0.5f;
            }
            else if (weaknesses.Contains(type))
            {
                amountToTake *= 2f;
            }

            //Debug.Log("Took " + amount + " damage this frame.");
            health          -= amount;
            effectiveHealth -= amount;

            isInvincible = true;

            TookDamage.Invoke();

            return(true);
        }

        return(false);
    }
Exemple #6
0
        public static void ApplyDamage(float damage)
        {
            Health -= damage;

            TookDamage?.Invoke(Current, EventArgs.Empty);

            if (Health.CompareTo(0.0F) < 0)
            {
                Died?.Invoke(Current, EventArgs.Empty);
            }
        }
 void CheckDeath()
 {
     if (_currentHealth <= 0)
     {
         Kill();
     }
     else
     {
         TookDamage?.Invoke();
     }
 }
 public void Damage(int _damageTaken)
 {
     if (_isDamageable)
     {
         _currentHealth       -= _damageTaken;
         _isDamageable         = false;
         _damageInvulnTimeLeft = _damageInvulnTime;
         TookDamage?.Invoke();
         DamageEffects();
         CheckDeath();
     }
 }
    public void ApplyDamage(int damage)
    {
        TookDamage?.Invoke();

        _health -= damage;

        if (_health <= 0)
        {
            _animator.SetBool("Dead", true);
            _deadSound.Play();
        }
    }
Exemple #10
0
 public void TakeDamage(int amount, Card source)
 {
     if ((source is Card) && (source as Card).HasInfect)
     {
         AddCounters(amount, CounterType.Poison);
     }
     else
     {
         TookDamage?.Invoke(this, source, amount);
         LoseLife(amount, source);
     }
 }
Exemple #11
0
 public void DoDamage(ulong dmg)
 {
     if (dmg >= Health)
     {
         // Monster is dead
         Health = 0;
         OnDeath?.Invoke(this, Reward);
     }
     else
     {
         // Do damage to monster
         Health -= dmg;
         TookDamage?.Invoke(this, dmg);
     }
 }
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.gameObject.tag == "attacker")
     {
         TookDamage?.Invoke();
         GetComponent <SpriteRenderer>().sprite = FacesAfterHit[noOfTimesHit];
         if (noOfTimesHit + 1 < FacesAfterHit.Length)
         {
             noOfTimesHit++;
         }
     }
     if (collider.gameObject.tag == "heartAttacker")
     {
         LifeLost?.Invoke();
     }
 }
    public void Damage(int damageTaken)
    {
        CurrentHealth -= damageTaken;


        if (CurrentHealth > 0)
        {
            TookDamage?.Invoke(damageTaken);
        }
        else
        {
            CurrentHealth = 0;
            Kill();
        }
        HealthSet?.Invoke(CurrentHealth);
    }
        public void TakeDamage(int amount, Card source)
        {
            TookDamage?.Invoke(this, source, amount);

            if (IsAPlaneswalker && !IsACreature)
            {
                RemoveCounters(source, amount, CounterType.Loyalty);
            }
            else
            {
                if (source.HasInfect)
                {
                    AddCounters(source, amount, CounterType.Minus1Minus1);
                }
                else
                {
                    DamageAccumulated.Add(new DamageInfo(source, amount));
                }
            }
        }
Exemple #15
0
    public void Damage(float damageVal, Debuffs debuff = Debuffs.none)
    {
        if (!invulnerable)
        {
            TookDamage?.Invoke(debuff);

            Instantiate(hurtParticle, transform.position, transform.rotation);

            currentHealth -= damageVal;

            if (healthbar != null)
            {
                healthbar.value = currentHealth;
            }

            if (currentHealth <= 0)
            {
                Die();
            }
        }
    }
Exemple #16
0
    public virtual bool TakeDamage(float damageToTake, bool triggerInvin = false)
    {
        if (triggerInvin)
        {
            isInvincible = true;
        }

        if (isInvincible)
        {
            return(false);
        }

        hp.value -= damageToTake;
        TookDamage.Invoke();

        if (dead)
        {
            Died.Invoke();
        }

        return(true);
    }
Exemple #17
0
    public bool TakeDamage(float damage, bool triggerInvin = false)
    {
        if (health.value > 0 && !isInvincible)
        {
            health.value -= damage;
            TookDamage.Invoke();

            if (health.value <= 0)
            {
                Died.Invoke();
            }

            if (triggerInvin)
            {
                // Grant invincibility, let the countdown begin.
                invinTimer   = invinTime;
                isInvincible = true;
            }

            return(true);
        }

        return(false);
    }