Exemple #1
0
    //处理技能产生的效果
    public Damage DoSkillAffect(Skill skill)
    {
        Damage damage = new Damage();

        damage.from     = skill.GetRole();
        damage.target   = this;
        damage.painTime = skill.SkillTpl.Paintime;
        Role     skillRole     = skill.GetRole();
        RoleInfo skillRoleInfo = skillRole.GetRoleInfo();

        if (skill.SkillTpl.Type == Skill.TYPE_BUFF_ONLY)
        {
            TryAddBuff(skill);
        }
        else
        {
            int affValue = 0;
            if (skill.SkillTpl.Targettype == Skill.TARGET_TYPE_SELF || skill.SkillTpl.Targettype == Skill.TARGET_TYPE_SELF_TEAM)
            {
                if (skill.SkillTpl.Type == Skill.TYPE_CURE_VALUE)
                {
                    damage.type  = Damage.TYPE_HEAL;
                    affValue     = (int)skill.SkillTpl.Affectvalue;
                    damage.value = skillRoleInfo.CaluJoinHealValue(affValue);
                    TakeDamage(damage);
                }
                else if (skill.SkillTpl.Type == Skill.TYPE_CURE_PERCENT)
                {
                    damage.type = Damage.TYPE_HEAL;
                    float percent = skill.SkillTpl.Affectvalue * 0.01f;
                    if (skill.SkillTpl.Subtype == Skill.SUB_TYPE_CURE_ON_INT)
                    {
                        float addPercent = _roleInfo.INT / 200f;
                        //if (addPercent > 1)
                        //{
                        //    addPercent = 1;
                        //}
                        percent = (1.0f + addPercent) * percent;
                    }
                    affValue     = Mathf.FloorToInt(this.GetRoleInfo().HpTotal *percent);
                    damage.value = skillRoleInfo.CaluJoinHealValue(affValue);
                    TakeDamage(damage);
                }
            }
            else if (skill.SkillTpl.Targettype == Skill.TARGET_TYPE_ENEMY)
            {
                damage.type   = Damage.TYPE_HURT;
                _harmfulEnemy = skill.GetRole();
                SetBeAttacking(true);
                if (skill.SkillTpl.Type == Skill.TYPE_PHYSICS || skill.SkillTpl.Type == Skill.TYPE_PHYSICS_FAR)
                {
                    //TODO 公式需要重新思考
                    bool miss = false;
                    if (!skill.IgnoreDodge)
                    {
                        if (skillRoleInfo.HitRate - _roleInfo.DodgeRate > 30f)
                        {
                            miss = false;
                        }
                        else
                        {
                            miss = UnityEngine.Random.Range(0f, 100f + skillRoleInfo.HitRate) < _roleInfo.DodgeRate;
                        }
                    }

                    if (miss)
                    {
                        damage.isMiss = true;
                        damage.value  = 0;
                    }
                    else
                    {
                        bool isCrit = false;
                        if (isLife)
                        {
                            isCrit        = Random.Range(0f, 100f) < skillRoleInfo.CritRate;
                            damage.isCrit = isCrit;
                        }

                        int dmg = 1;
                        if (isLife)
                        {
                            dmg = (int)(skillRoleInfo.Attack * skill.SkillTpl.Physicsscale);
                        }
                        else
                        {
                            dmg = (int)(skillRoleInfo.Attack * skillRoleInfo.Tpl.Walldmgscale * skill.SkillTpl.Physicsscale);
                        }
                        if (isCrit)
                        {
                            dmg *= 2;
                        }
                        int sourceDmg = dmg;
                        dmg = dmg - _roleInfo.Defense;
                        if (dmg < 0)
                        {
                            dmg = 0;
                        }

                        bool isDeadly = false;
                        if (isLife)
                        {
                            isDeadly = Random.Range(0f, 100f) < skillRoleInfo.DeadlyRate;
                        }

                        if (isDeadly)
                        {
                            damage.isDeadly = true;
                            dmg             = Mathf.CeilToInt(_roleInfo.Hp * (0.68f - _roleInfo.AntiDeadlyRate));
                            if (dmg < 10)
                            {
                                dmg = 10;
                            }
                        }
                        else
                        {
                            float PhysicsAbsorbRate = _roleInfo.PhysicsAbsorbRate * 0.01f;
                            if (PhysicsAbsorbRate < 0.0f)
                            {
                                PhysicsAbsorbRate = 0f;
                            }
                            dmg = (int)(dmg * (1f - _roleInfo.PhysicsAbsorbRate * 0.01f));
                        }
                        if (dmg < 1)
                        {
                            dmg = 1;
                        }

                        damage.isPain     = FellPain(skill);
                        damage.painMotion = skill.SkillTpl.Paintype;

                        affValue = dmg;

                        if (skill.SkillTpl.Type == Skill.TYPE_PHYSICS)
                        {
                            bool isAntiShock = Random.Range(0f, 100f) < _roleInfo.AntiShockRate;
                            if (isAntiShock)
                            {
                                skill.GetRole().DoAntiShock(sourceDmg, damage.isPain);
                            }
                        }
                    }
                }
                else if (skill.SkillTpl.Type == Skill.TYPE_MAGIC)
                {
                    bool isCrit = false;//Random.Range(0f, 100f) < skill.GetRole().GetRoleInfo().CritRate;
                    //damage.isCrit = isCrit;
                    int dmg = skillRoleInfo.MagicAttack;
                    if (isCrit)
                    {
                        dmg *= 2;
                    }
                    dmg = dmg - _roleInfo.MagicDefense;

                    damage.isPain     = FellPain(skill);
                    damage.painMotion = skill.SkillTpl.Paintype;

                    affValue = dmg;
                }
                if (affValue < 1)
                {
                    affValue = 1;
                }
                else
                {
                    affValue = (int)((Random.Range(-0.02f, 0.02f) + 1.0f) * affValue);
                    if (affValue < 1)
                    {
                        affValue = 1;
                    }
                }
                damage.value = -affValue;

                TakeDamage(damage);
            }
        }

        TryAddBuff(skill, damage);
        return(damage);
    }