Exemplo n.º 1
0
    public virtual long TakeDamage(Creature offender, DamageDesc damageDesc)
    {
        if (m_behaviourType == BehaviourType.Death)
            return 0;

        if (m_buffEffects[(int)DamageDesc.BuffType.Macho].m_run == true)
        {
            DamageText(RefData.Instance.RefTexts(MultiLang.ID.Blocked), Vector3.one, Color.white, DamageNumberSprite.MovementType.ParabolaAlpha);
            return 0;
        }

        if (m_buffEffects[(int)DamageDesc.BuffType.Dash].m_run == true)
        {
            DamageText(RefData.Instance.RefTexts(MultiLang.ID.Blocked), Vector3.one, Color.white, DamageNumberSprite.MovementType.ParabolaAlpha);
            return 0;
        }

        bool critical = false;
        float criticalDamage = 1f;
        if (offender != null)
        {
            if (Random.Range(0, 1f) < offender.m_creatureProperty.CriticalChance)
            {
                critical = true;
                criticalDamage = 1f+offender.m_creatureProperty.CriticalDamage;
            }
        }

        long dmg = (long)(damageDesc.Damage*criticalDamage);
        dmg -= (long)(dmg*m_creatureProperty.DamageReduction);

        if (dmg <= 0)
        {
            dmg = Random.Range(0, 2);
        }

        if (dmg > 0)
        {
            if (Random.Range(0f, 1f) < m_creatureProperty.Dodge)
            {
                DamageText(RefData.Instance.RefTexts(MultiLang.ID.Dodged), Vector3.one, Color.white, DamageNumberSprite.MovementType.ParabolaAlpha);
                return 0;
            }

            if (m_creatureProperty.Shield > 0)
            {
                --m_creatureProperty.Shield;
                DamageText(RefData.Instance.RefTexts(MultiLang.ID.Shielded), Vector3.one, Color.white, DamageNumberSprite.MovementType.ParabolaAlpha);
                return 0;
            }
        }

        string strDamage = dmg.ToString();
        if (dmg == 0)
        {
            strDamage = RefData.Instance.RefTexts(MultiLang.ID.Blocked);
            DamageText(strDamage, Vector3.one, Color.white, DamageNumberSprite.MovementType.ParabolaAlpha);
            return 0;
        }

        if (m_ingTakenDamageEffect < Const.MaxShowDamageNumber)
        {
            Vector3 damageTextScale = Vector3.one;
            ++m_ingTakenDamageEffect;
            Color color = Color.white;
            if (critical == true)
            {
                strDamage = dmg.ToString();
                color = Color.red;
                damageTextScale *= 1.1f;
            }
            else if (damageDesc.DamageBuffType == DamageDesc.BuffType.Poison)
            {
                color = Color.magenta;
            }
            else
            {
                if (offender != null && offender.RefMob.mobAI == MobAIType.Follow)
                {
                    damageTextScale *= 0.8f;
                    switch(offender.RefMob.id)
                    {
                    case 30001:
                        color = Color.clear;
                        break;
                    case 30002:
                        color = Color.red;
                        break;
                    case 30003:
                        color = Color.blue;
                        break;
                    case 30004:
                        color = Color.cyan;
                        break;
                    case 30005:
                        color = Color.yellow;
                        break;
                    case 30006:
                        color = Color.magenta;
                        break;
                    case 30007:
                        color = Color.grey;
                        break;
                    }
                }
            }

            DamageText(strDamage, damageTextScale, color, DamageNumberSprite.MovementType.ParabolaAlpha);

            StartCoroutine(BodyRedColoredOnTakenDamage());

            ApplyDamageEffect(damageDesc.DamageType, damageDesc.PrefEffect);
        }

        if (true == m_creatureProperty.BackwardOnDamage && damageDesc.PushbackOnDamage && m_pushbackSpeedOnDamage <= 0f)
        {
            if (Random.Range(0, 10) == 0)
            {
                m_pushbackSpeedOnDamage = 10f / rigidbody.mass;
                rigidbody.AddForce(transform.right*-2f, ForceMode.Impulse);
                rigidbody.AddTorque(transform.forward*2f, ForceMode.Impulse);
                rigidbody.maxAngularVelocity = 2f;

                EnableNavmeshUpdatePos(false);
            }
        }

        ApplyBuff(offender, damageDesc.DamageBuffType, 2f, damageDesc);

        if (offender != null && damageDesc.LifeSteal == true)
        {
            long lifeSteal = (long)(offender.m_creatureProperty.LifeSteal);
            if (lifeSteal > 0)
            {
                offender.DamageText(lifeSteal.ToString() + "L", Vector3.one, Color.green, DamageNumberSprite.MovementType.ParabolaAlpha);
                offender.Heal(lifeSteal);
            }
        }

        m_creatureProperty.HP-=dmg;
        if (m_creatureProperty.HP == 0)
        {
            Const.GetSpawn().SharePotinsChamps(offender, ItemData.Type.XPPotion, m_creatureProperty.RewardExp, false);
            Death();
        }

        if (offender != null && (offender.CreatureType & Type.Champ) > 0)
        {
            Warehouse.Instance.NewGameStats.DealDamages += dmg;
        }
        else if (CreatureType == Type.Champ)
        {
            Warehouse.Instance.NewGameStats.TakenDamages += dmg;
        }

        return dmg;
    }