Пример #1
0
        /// <summary>
        /// Apply damage to the Health.
        /// </summary>
        /// <param name="dmg">The damage to apply.</param>
        /// <returns>The actual damage amount dealt.</returns>
        public virtual float Damage(Damage dmg)
        {
            if (enabled && dmg.amount > 0 && hitInvulnTimer.Use())
            {
                DamageModifier?.Invoke(ref dmg);

                float prevHealth = health;
                health    -= dmg.amount;
                health     = Mathf.Max(health, 0);
                dmg.amount = prevHealth - health;

                healthRegenTimer.Set();
                SendMessage("OnDamage", dmg, SendMessageOptions.DontRequireReceiver);
                Damaged?.Invoke(dmg);
                if (damageSound)
                {
                    damageSound.Play();
                }

                if (health == 0 && !dead)
                {
                    dead = true;
                    SendMessage("OnZeroHealth", SendMessageOptions.DontRequireReceiver);
                    ZeroHealth?.Invoke();
                }
            }
            else
            {
                dmg.amount = 0;
            }

            return(dmg.amount);
        }
Пример #2
0
 private void Start()
 {
     FullHealth.SetActive(false);
     ThreeFourths.SetActive(false);
     HalfHealth.SetActive(false);
     OneFourth.SetActive(false);
     ZeroHealth.SetActive(false);
 }
Пример #3
0
        public void ChangeHealth(IDamageDealer changer, double damage)
        {
            if (!IsVulnerable)
            {
                return;
            }

            if (owner is EnemySystem enemy)
            {
                enemy.LastDamageDealer = changer;

                if (enemy.Data.Get(Enums.Enemy.Health).AppliedValue > 0)
                {
                    enemy.Data.Get(Enums.Enemy.Health).AppliedValue -= damage;
                }
                else
                {
                    enemy.Data.Get(Enums.Enemy.Health).Value -= damage;
                }

                var remainingHealth =
                    enemy.Data.Get(Enums.Enemy.Health).AppliedValue > 0 ?
                    enemy.Data.Get(Enums.Enemy.Health).AppliedValue :
                    enemy.Data.Get(Enums.Enemy.Health).Value;

                if (remainingHealth <= 0)
                {
                    GiveResources();
                    IsVulnerable = false;

                    ZeroHealth?.Invoke(owner);
                }
            }

            #region  Helper functions

            void GiveResources()
            {
                if (enemy.LastDamageDealer is SpiritSystem spirit)
                {
                    spirit.AddExp((int)enemy.Data.Get(Numeral.Exp).Sum);
                }
            }

            #endregion
        }
Пример #4
0
 void Update()
 {
     // Check for players current health
     // Players current health is 100%
     if (PlayerHealth.Value <= 1.0f && PlayerHealth.Value >= 0.76f)
     {
         FullHealth.SetActive(true);
         ThreeFourths.SetActive(false);
         HalfHealth.SetActive(false);
         OneFourth.SetActive(false);
         ZeroHealth.SetActive(false);
     }
     // Players health is below 76%, check to see where it falls
     if (PlayerHealth.Value <= 0.75f)
     {
         FullHealth.SetActive(false);
         HalfHealth.SetActive(false);
         OneFourth.SetActive(false);
         ZeroHealth.SetActive(false);
         ThreeFourths.SetActive(true);
         if (PlayerHealth.Value <= 0.5f)             //Less than 51% health
         {
             FullHealth.SetActive(false);
             ThreeFourths.SetActive(false);
             OneFourth.SetActive(false);
             ZeroHealth.SetActive(false);
             HalfHealth.SetActive(true);
             if (PlayerHealth.Value <= 0.25f)                 //Less than 26% health
             {
                 FullHealth.SetActive(false);
                 ThreeFourths.SetActive(false);
                 HalfHealth.SetActive(false);
                 ZeroHealth.SetActive(false);
                 OneFourth.SetActive(true);
                 if (PlayerHealth.Value <= 0.0f)                     //Less than 1% health
                 {
                     FullHealth.SetActive(false);
                     ThreeFourths.SetActive(false);
                     HalfHealth.SetActive(false);
                     OneFourth.SetActive(false);
                     ZeroHealth.SetActive(true);
                 }
             }
         }
     }
 }