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);
        }
    }
Exemplo n.º 2
0
 void Awake()
 {
     m_Instance = this;
     OnDamaged  = new OnDamageEvent();
     OnAttack   = new OnAttackEvent();
     OnDeath    = new UnityEvent();
     DoAction   = DoActionNormal;
 }
Exemplo n.º 3
0
Arquivo: Boss.cs Projeto: swet-s/Dark
 public void OnDamage()
 {
     OnDamageEvent.Invoke();
     animator.SetTrigger("Damaging");
     rb.AddForce(impulse * -50);
     FindObjectOfType <AudioCreater>().PlayPain();
     pain++;
 }
Exemplo n.º 4
0
        public void OnDamage(int damage)
        {
            OnDamageEvent?.Invoke();
            CurrentHealth -= damage;

            if (CurrentHealth < 0)
            {
                OnDeath();
            }
        }
Exemplo n.º 5
0
 public void Damage(float damage)
 {
     hp -= damage;
     if (OnDamageEvent != null)
     {
         OnDamageEvent.Invoke(this);
     }
     if (hp <= 0)
     {
         Destroy(gameObject);
     }
 }
Exemplo n.º 6
0
 void Initialize()
 {
     onPlayerJoinEvent        = new OnPlayerJoinEvent();
     onPlayerLeaveEvent       = new OnPlayerLeaveEvent();
     onCharacterSelectEvent   = new OnCharacterSelectEvent();
     onCharacterDeSelectEvent = new OnCharacterDeSelectEvent();
     onHitEvent      = new OnHitEvent();
     onGrabEvent     = new OnGrabEvent();
     onDamageEvent   = new OnDamageEvent();
     onHitStunEvent  = new OnHitStunEvent();
     onEdgeGrabEvent = new OnEdgeGrabEvent();
     onDeathEvent    = new OnDeathEvent();
     onGameOverEvent = new OnGameOverEvent();
 }
Exemplo n.º 7
0
    void Awake()
    {
        // Setting up the references.
        anim           = GetComponent <Animator>();
        playerAudio    = GetComponent <AudioSource>();
        playerMovement = GetComponent <PlayerMovement>();
        playerShooting = GetComponentInChildren <PlayerShooting>();

        // Set the initial health of the player.
        currentHealth = startingHealth;

        OnHealthChange += UpdateHealthUI; // My Mod

        // My Mod
        if (OnDamage != null)
        {
            OnDamage = new OnDamageEvent();
        }

        // My Mod
        OnDamage.AddListener(DamageUpdate);
    }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
 public void TakeDamage(int dmg)
 {
     OnDamageEvent.Invoke(dmg);
 }