Example #1
0
        protected virtual void CheckHurtables()
        {
            if (hitHurtables.Count > 0)
            {
                for (int i = 0; i < hitHurtables.Count; i++)
                {
                    IHurtable ih = hitHurtables[i].GetComponent <IHurtable>();
                    if (ignoreList.Contains(ih))
                    {
                        continue;
                    }
                    switch (hitInfo.forceRelation)
                    {
                    case HitboxForceRelation.ATTACKER:
                        ih.Hurt(directionOwner.position, directionOwner.forward, directionOwner.right, hitInfo);
                        break;

                    case HitboxForceRelation.HITBOX:
                        ih.Hurt(transform.position, transform.forward, transform.right, hitInfo);
                        break;

                    case HitboxForceRelation.WORLD:
                        ih.Hurt(transform.position, Vector3.forward, Vector3.right, hitInfo);
                        break;
                    }
                    ignoreList.Add(ih);
                    OnHurt?.Invoke(hitHurtables[i], hitInfo);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Apply a delta health object to this controller
        /// </summary>
        /// <param name="dHealth"></param>
        public void ApplyDeltaHealth(DeltaHealth dHealth)
        {
            float delta = dHealth.GetDelta(this);

            health += delta;

            if (maxHealth >= 0f)
            {
                health = Mathf.Max(maxHealth, health);
            }

            if (health <= 0f)
            {
                OnDeath(this, dHealth);
            }

            if (delta != 0f)
            {
                OnDelta?.Invoke(this, dHealth);
            }
            if (delta > 0f)
            {
                OnHeal?.Invoke(this, dHealth);
            }
            else if (delta < 0f)
            {
                OnHurt?.Invoke(this, dHealth);
            }
        }
Example #3
0
        public override void TakeDamage(float damage, Transform source)
        {
            if (Invincible)
            {
                return;
            }

            // Check if the damage source is a spike (to play different sounds in response)
            var spikes = source.CompareTag(SpikeTag);

            // Perform the rebound
            HurtReboundMove.ThreatPosition = source ? (Vector2)source.position : default(Vector2);
            HurtReboundMove.OnEnd.AddListener(OnHurtReboundEnd);
            HurtReboundMove.Perform();

            // Start our invincibility frames
            HurtInvincibilityTimer = HurtInvinciblilityTime;
            HurtInvincible         = Invincible = true;

            // See if the player had a shield
            var shield = Controller.GetPowerup <Shield>();

            if (shield == null)
            {
                // If not, and we're out of rings, we're dead
                if (RingCounter.Rings <= 0)
                {
                    Kill();
                    return;
                }

                // Otherwise just spill the beans
                RingCounter.Spill(RingsLost);

                if (RingLossSound != null)
                {
                    SoundManager.Instance.PlayClipAtPoint(RingLossSound, transform.position);
                }
            }
            else
            {
                // Special spike sound
                if (spikes)
                {
                    if (SpikeSound != null)
                    {
                        SoundManager.Instance.PlayClipAtPoint(SpikeSound, transform.position);
                    }
                }
                else
                {
                    if (ReboundSound != null)
                    {
                        SoundManager.Instance.PlayClipAtPoint(ReboundSound, transform.position);
                    }
                }
            }

            OnHurt.Invoke(null);
        }
Example #4
0
    public void Hurt(int damage, Vector3 contactPoint, Vector3 normal, GameObject attacker)
    {
        currentHealth -= damage;

        OnHurt?.Invoke(-damage, currentHealth, contactPoint, normal, attacker);

        if (currentHealth <= 0)
        {
            OnDeath?.Invoke(attacker);
        }
    }
Example #5
0
    /// <summary>Deals damage to this player and returns the percentage of damage dealt</summary>
    public float Hurt(Player damageDealer, float damage)
    {
        if (Invincible || ghost) //no damage is done if invincable
        {
            return(0.0f);
        }
        float damageDealt = Mathf.Min(damage, health);

        health -= damageDealt;
        float percent = damageDealt / stats.maxHealth; // Percentage of max health dealt

        lastHurtBy = damageDealer;                     // Remember last player that dealt damage, this is used to attribute kills
        OnHurt.Invoke(damageDealer, this, percent);
        return(percent);
    }
    public void Hurt(float damage)
    {
        HP -= damage;

        if (OnHurt != null)
        {
            OnHurt.Invoke();
        }

        if (HP <= 0)
        {
            HP = 0;
            Die();
        }
    }
 protected virtual void CheckHurtables()
 {
     if (hitHurtables.Count > 0)
     {
         for (int i = 0; i < hitHurtables.Count; i++)
         {
             IHurtable ih = hitHurtables[i].GetComponent <IHurtable>();
             if (ignoreList.Contains(ih))
             {
                 continue;
             }
             HurtHurtable(ih);
             ignoreList.Add(ih);
             OnHurt?.Invoke(hitHurtables[i], hitInfo);
         }
     }
 }
Example #8
0
        public void Hurt(float damage)
        {
            if (cheat)
            {
                damage /= 2;
            }

            HP -= damage;

#if UNITY_ANDROID
            Handheld.Vibrate();
#endif

            if (OnHurt != null)
            {
                OnHurt.Invoke();
            }

            if (HP <= 0)
            {
                HP = 0;
                Die();
            }
        }
Example #9
0
 public void Hurt(float value)
 {
     health -= value;
     OnHurt?.Invoke(gameObject, health + value, health);
 }