Beispiel #1
0
    // My Mod
    public void TakeDamage(int amount)
    {
        // Set the damaged flag so the screen will flash.
        damaged = true;

        // Reduce the current health by the damage amount.
        currentHealth -= amount;

        // Set the health bar's value to the current health.
        //healthSlider.value = currentHealth;
        if (OnHealthChange != null)
        {
            OnHealthChange(currentHealth);
            OnDamage.Invoke(amount);
        }

        // Play the hurt sound effect.
        playerAudio.Play();

        // If the player has lost all it's health and the death flag hasn't been set yet...
        if (currentHealth <= 0 && !isDead)
        {
            // ... it should die.
            Death();
        }
    }
    public void TakeDamage(DamageInfo damageData)
    {
        if (IsDeath || affectedBy == WeaponType.None)
        {
            return;
        }

        bool canBeAffected = (affectedBy == WeaponType.All) || (damageData.data.weaponType == affectedBy);

        if (!canBeAffected)
        {
            return;
        }

        if (IsInvincible)
        {
            OnNegatedDamageEvent.Invoke();
            return;
        }

        currentHealth -= damageData.data.damage;

        if (currentHealth <= 0)
        {
            OnDeathEvent.Invoke(damageData);
            IsDeath = true;
        }
        else
        {
            OnDamageEvent.Invoke(currentHealth, maxHealth, damageData);
        }
    }
Beispiel #3
0
 public void OnDamage()
 {
     OnDamageEvent.Invoke();
     animator.SetTrigger("Damaging");
     rb.AddForce(impulse * -50);
     FindObjectOfType <AudioCreater>().PlayPain();
     pain++;
 }
Beispiel #4
0
        public void OnDamage(int damage)
        {
            OnDamageEvent?.Invoke();
            CurrentHealth -= damage;

            if (CurrentHealth < 0)
            {
                OnDeath();
            }
        }
    public void Damage(float ammount)
    {
        CurrentHealth -= ammount;
        CurrentHealth  = Mathf.Clamp(CurrentHealth, 0, MaxHealth);

        if (OnDamage != null)
        {
            OnDamage.Invoke(ammount);
        }
        if (OnHealthChanged != null)
        {
            OnHealthChanged.Invoke(CurrentHealth / MaxHealth);
        }
        if (CurrentHealth == 0)
        {
            if (OnDeath != null)
            {
                OnDeath.Invoke();
                if (unit == null)
                {
                    return;
                }
                if (unit.TeamIndex == 1)
                {
                    foreach (var factory in UnitProducer.FactoryList)
                    {
                        if ((factory.TeamIndex != unit.TeamIndex) && (!factory.convertable))
                        {
                            UnitCombat comb = factory.GetComponent <UnitCombat>();
                            if (comb == null)
                            {
                                continue;
                            }
                            comb.recoverHealth(10.0f);
                        }
                    }
                }
            }
            Destroy(unit.gameObject);
        }
    }
Beispiel #6
0
 public void Damage(float damage)
 {
     hp -= damage;
     if (OnDamageEvent != null)
     {
         OnDamageEvent.Invoke(this);
     }
     if (hp <= 0)
     {
         Destroy(gameObject);
     }
 }
        public void DoDamage(DamageInfo info, DamageablePart damageable)
        {
            //if we are dead just apply the impact force
            if (isDead)
            {
                //ApplyImpactForce( info, damageable );

                if (onDamage != null)
                {
                    onDamage.Invoke(info, damageable);
                }
                return;
            }


            //hp -= info.dmg;

            ModifyHP(-info.dmg);


            if (hp <= 0.0f)
            {
                if (onDie != null)
                {
                    onDie.Invoke();
                }

                isDead = true;

                //ApplyImpactForce( info, damageable );
            }

            if (onDamage != null)
            {
                onDamage.Invoke(info, damageable);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Removes all HP from this object, and calls <see cref="OnDamage"/> in addition to <see cref="OnDeath"/>.
 /// </summary>
 /// <param name="hitInfo"></param>
 public void Kill(AttackData data)
 {
     PreviousHitData = data;
     OnDamage.Invoke();
     Kill();
 }
Beispiel #9
0
        public void Damage(float damage, Vector3 hitPoint, AttributeChangeCause cause = AttributeChangeCause.FORCED, Damageable attacker = null, DamageType type = DamageType.NONE)
        {
            //  Invoke a damage event
            DamageEvent e = new DamageEvent {
                cause = cause, victim = this, attacker = attacker, type = type, damage = damage
            };

            OnDamageEvent?.Invoke(this, e);
            if (e.cancel == true)
            {
                return;
            }                               //  return if the event has been cancelled by any subscriber

            bool hadImmunity   = false;
            bool hadWeakness   = false;
            bool hadResistance = false;

            //  Check for immunity
            for (int i = 0; i < immunities.Length; i++)
            {
                if (e.type == immunities[i])
                {
                    e.damage    = 0;
                    hadImmunity = true;
                    break;
                }
            }

            //  Modify any damage by any weaknesses or resistances
            if (e.damage > 0 && e.type != DamageType.NONE)
            {
                for (int i = 0; i < weaknesses.Length; i++)
                {
                    if (e.type == weaknesses[i])
                    {
                        e.damage   *= 2;
                        hadWeakness = true;
                        break;
                    }
                }

                for (int i = 0; i < resistances.Length; i++)
                {
                    if (e.type == resistances[i])
                    {
                        e.damage     /= 2;
                        hadResistance = true;
                        break;
                    }
                }
            }

            //  If the damage is enough to kill, invoke a death event
            if (GetAttributeValue(Attributes.HEALTH) - e.damage <= 0)
            {
                DeathEvent e2 = new DeathEvent {
                    cause = cause, victim = this, attacker = attacker
                };
                OnDeathEvent?.Invoke(this, e2);
                if (e2.cancel == true)
                {
                    return;
                }                                //  return if the event has been cancelled by any subscriber
            }

            //  Update health
            GetAttribute(Attributes.HEALTH).Modify(-e.damage);

            //  Send indicator
            Color indicatorColor = Color.gray * Color.gray;

            if (hadImmunity)
            {
                indicatorColor = Color.red;
            }
            if (hadWeakness)
            {
                indicatorColor = Color.white;
            }
            if (hadResistance)
            {
                indicatorColor = Color.yellow;
            }

            if (hitPoint == null)
            {
                UIMaster.SendFloatingIndicator(this.transform.position + this.transform.rotation * center, e.damage.ToString("#.0"), indicatorColor);
            }
            else
            {
                UIMaster.SendFloatingIndicator(hitPoint, e.damage.ToString("0.0"), indicatorColor);
            }
        }
Beispiel #10
0
 public void InvokeOnDamageEvent(IAttackHitbox hitbox, IDamageable damageable)
 {
     Debug.Log("OnDamageEvent Invoked");
     onDamageEvent.Invoke(hitbox, damageable);
 }
Beispiel #11
0
 public void Hit(double damage)
 {
     _onHitEvent.Invoke();
     _onDamageEvent.Invoke(damage);
 }
Beispiel #12
0
 public void TakeDamage(int dmg)
 {
     OnDamageEvent.Invoke(dmg);
 }