Exemplo n.º 1
0
    protected virtual void SkillAttack(BaseUnit baseUnit)
    {
        StaticSkillLevelVo nowSkill = skillList[Random.Range(0, skillList.Count)];

        if (nowMp >= nowSkill.cost)
        {
            nowMp -= nowSkill.cost;
        }
        float attackNum = 0;
        float atk       = 0;
        float def       = 0;

        critRate = 1 / (1 + 10000 / critNum);
        duckRate = 1 / (1 + 10000 / duckNum);
        bool ifCrit = Random.Range(0f, 1f) < critRate;

        //对敌人的效果
        if (nowSkill.type == 1)//法术
        {
            atk = magicAttack;
            def = baseUnit.magicDefance;
        }
        else if (nowSkill.type == 2)//物理
        {
            atk = Random.Range(attackSmall, attackBig);
            def = baseUnit.magicDefance;
        }
        else
        {
            attackNum = 0;
        }
        if (Random.Range(0f, 1f) < duckRate)
        {
            attackNum = 0;
        }
        else
        {
            if (nowSkill.targetType == 1)//百分比伤害
            {
                attackNum = atk * Random.Range(nowSkill.targetMin, nowSkill.targetMax) * (ifCrit ? critDamage : 1.0f) * (1 - (def / (baseUnit.defanceRate * baseUnit.level + def)));
            }
            else if (nowSkill.targetType == 2)//数值伤害
            {
                attackNum = (atk + Random.Range(nowSkill.targetMin, nowSkill.targetMax)) * (ifCrit ? critDamage : 1.0f) * (1 - (def / (baseUnit.defanceRate * baseUnit.level + def)));
            }
        }
        baseUnit.Hurt(attackNum);
        //对自己的效果,依据属性(0无效果1伤害2血量3蓝量4攻击小5攻击大6护甲7法攻8法抗9固定数值10暴击11闪避12最大血量)
        switch (nowSkill.selfDepend)
        {
        case 1: Effect(nowSkill.selfType, attackNum * nowSkill.selfValue); break;

        case 2: Effect(nowSkill.selfType, nowHp * nowSkill.selfValue); break;

        case 3: Effect(nowSkill.selfType, nowMp * nowSkill.selfValue); break;

        case 4: Effect(nowSkill.selfType, attackSmall * nowSkill.selfValue); break;

        case 5: Effect(nowSkill.selfType, attackBig * nowSkill.selfValue); break;

        case 6: Effect(nowSkill.selfType, defance * nowSkill.selfValue); break;

        case 7: Effect(nowSkill.selfType, magicAttack * nowSkill.selfValue); break;

        case 8: Effect(nowSkill.selfType, magicDefance * nowSkill.selfValue); break;

        case 9: Effect(nowSkill.selfType, nowSkill.selfValue); break;

        case 10: Effect(nowSkill.selfType, critNum * nowSkill.selfValue); break;

        case 11: Effect(nowSkill.selfType, duckNum * nowSkill.selfValue); break;

        case 12: Effect(nowSkill.selfType, maxHp * nowSkill.selfValue); break;

        default: break;
        }
        if (nowSkill.buffId != 0)
        {
            if (Random.Range(0, 1) < nowSkill.buffRate)
            {
                if (nowSkill.buffTarget == 0)
                {
                    baseUnit.AddBuff(nowSkill.buffId, nowSkill.level, this);
                }
                else if (nowSkill.buffTarget == 1)
                {
                    AddBuff(nowSkill.buffId, nowSkill.level, this);
                }
            }
        }
    }