Exemplo n.º 1
0
    public void TakeDamage(int amount, DamageType damageType)
    {
        float resistance           = resistances[damageType];
        float resistanceMultiplier = resistance / 100f;
        int   modifiedAmount       = (int)((float)amount * resistanceMultiplier);

        curretHeath         -= modifiedAmount;
        healthBar.fillAmount = curretHeath / maxHealth;
        if (curretHeath <= 0)
        {
            Destroy(gameObject);
        }

        damageText.ShowDamage(modifiedAmount, damageType);
    }
Exemplo n.º 2
0
        /// <summary>
        /// Reduce monster's HP
        /// </summary>
        /// <param name="amount"> Amount of HP to lose, not negative </param>
        /// <param name="animationClipName"> Name of clip to play when monster is attacked </param>
        /// <returns> Starts coroutine of monster being attacked, before yielding control </returns>
        public IEnumerator LoseHP(int amount, string animationClipName)
        {
            CHP -= amount;
            if (CHP < 0)
            {
                CHP = 0;
            }

            SetEffectsAnimatorClip(animationClipName);
            yield return(StartCoroutine(PlayAnimation(effectsAnimator, "attacked")));

            dt.ShowDamage(amount);
            HPBar.SetCurrent(CHP);
            yield return(StartCoroutine(PlayTwoAnimations(monsterAnimator, dt.textAnimator, "damaged", "showDamage")));

            dt.HideDamage();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Displays a change in HP
        /// </summary>
        /// <param name="amount"> Positive int amount changed </param>
        /// <param name="isLoss"> True if health is lost, positive if gained </param>
        /// <param name="animationClipName"> Name of animation to play overtop of monster </param>
        /// <param name="setDescription"> True to set description text on healing, false otherwise </param>
        /// <returns> IEnumerator for animations </returns>
        public IEnumerator DisplayHPChange(int amount, bool isLoss, bool setDescription, string animationClipName)
        {
            isAnimating = true;
            SetEffectsAnimatorClip(animationClipName);
            if (isLoss)
            {
                yield return(StartCoroutine(PlayAnimation(effectsAnimator, "attacked")));

                dt.ShowDamage(amount);
                HPBar.SetCurrent(displayedMonster.CHP);
                if (isCrit == true)
                {
                    yield return(StartCoroutine(PlayTwoAnimations(monsterAnimator, dt.textAnimator, "damagedCrit", "showCritDamage")));

                    isCrit = false;
                }
                else
                {
                    yield return(StartCoroutine(PlayTwoAnimations(monsterAnimator, dt.textAnimator, "damaged", "showDamage")));
                }
                dt.HideDamage();
            }
            else
            {
                if (setDescription == true)
                {
                    if (isCrit == true)
                    {
                        eventDescription.SetMHealCritText(displayedMonster, amount);
                        isCrit = false;
                    }
                    else
                    {
                        eventDescription.SetMHealText(displayedMonster, amount);
                    }
                }
                HPBar.SetCurrent(displayedMonster.CHP);

                yield return(new WaitForSeconds(1f / GameManager.instance.gsDataCurrent.animationSpeed));
            }
            isAnimating = false;
        }