Пример #1
0
    public static int Result(AttackInfo ai, DefenseInfo di, out bool isCriticalHit, ActionController attacker, ActionController target)
    {
        float ret = 0;

        isCriticalHit = false;

        float physicalDamageReduction = 0;

        if (GameManager.Instance.IsPVPMode)
        {
            ret = Mathf.Max(ai._attackPoints[0] - di._defensePoints[0], ((float)ai._attackPoints[0]) * 0.3f);             //pvp damage reduction
            if (attacker.SelfCountAgent != null)
            {
                attacker.SelfCountAgent.OnTryToHit((int)ai._attackPoints[0]);
            }
        }
        else
        {
            ret = Mathf.Max(ai._attackPoints[0] - di._defensePoints[0], ((float)ai._attackPoints[0]) * 0.1f);             //pve damage reduction
        }

        //ret = ret * (1 - di._defensePercents[0]);


        //if (ret < 1)
        //{
        //    ret = 1;
        //}

        for (int i = 1; i < ai._attackPoints.Length; i++)
        {
            float ret1 = ((float)(ai._attackPoints[i] - di._defensePoints[i])) * (1 - di._defensePercents[i]);
            if (ret1 < 0.5)
            {
                ret1 = 0;
            }
            ret += ret1;
        }

        /*if(attacker.IsPlayer)
         * {
         *      float r1 = Mathf.Pow((ai._criticalChance*10/(75* Mathf.Exp((attacker.Data._level-1)*(0.065f-attacker.Data._level*0.0002f)))),1.7f);
         *      chance = (int)(Mathf.Sqrt(r1)*0.7f +0.5f);
         *      //chance = (int)(Mathf.Log(ai._criticalChance*0.25f)*1.25f);
         *      //Debug.Log(chance);
         * }*/

        int chance = Mathf.RoundToInt(ai._criticalChance * 100);

        chance = Mathf.Clamp(chance, 1, 50);

        if (chance >= Random.Range(1, 100))
        {
            ret           = (1 + ai._criticalDamage - di._criticalDamageResist) * ret;
            isCriticalHit = true;
        }

        float addScale = 0;

        if (attacker.ACGetCurrentAttack() != null &&
            attacker.AIUse.AddDamageScale > 0)
        {
            addScale = attacker.AIUse.AddDamageScale;
        }

        ret = ret * (ai._damageScale + addScale);

        if (ai._skillAttackDamage > 0)
        {
            chance = Mathf.RoundToInt(ai._skillTriggerChance * 100);
            chance = Mathf.Clamp(chance, 1, 50);

            if (chance >= Random.Range(1, 100))
            {
                ret = (1 + ai._skillAttackDamage) * ret;
            }
        }

        if (CheatManager.showAttackInfo)
        {
            if (isCriticalHit)
            {
                attacklog = attacklog + "This is a critical \n";
            }

            attacklog = attacklog + "Final damage = " + ret + "\n";
        }

        if (ret < 1 && ret >= 0)
        {
            ret = 1;
        }

        if (attacker.IsPlayerSelf && isCriticalHit)
        {
            if (isCriticalHit)
            {
                if (attacker.ACGetCurrentAttack() != null)
                {
                    attacker.ACHitTargetIsCrit(target);
                }

                if (attacker.SkillGodDown)
                {
                    int deltaHp = Mathf.RoundToInt(ret * attacker.Data.PassiveSkillGodDownCriticalToHp);
                    attacker.ACIncreaseHP(deltaHp);
                }
            }
        }

        if (CheatManager.showAttackInfo)
        {
            attacklog = "------------------------------------------------------\n";
            attacklog = attacklog + "Attacker is " + attacker.Data.id + "\n";
            attacklog = attacklog + "Target is " + target.Data.id + "\t Level " + target.Data.Level + "\tArmor = " + target.Data.TotalDefense + "\n";
            attacklog = attacklog + target.Data.id + " hitpoint before hurt = " + target.HitPoint + "\n";
            attacklog = attacklog + "Normal Attack point = " + ai._attackPoints[0] + "\n";
            attacklog = attacklog + "Normal Defense point = " + di._defensePoints[0] + "\n";
            attacklog = attacklog + "Damage reduction percent = " + physicalDamageReduction + "\n";
            attacklog = attacklog + "Damage = " + ret + "\n";
        }

        return((int)ret);
    }