Ejemplo n.º 1
0
    public static BattleCalculator.DamageResult CalculateDamage(BattleBaseAttrs caster, BattleBaseAttrs target, bool isCasterPlayer, bool isTargetPlayer, XDict <GameData.AttrType, long> casterTempAttrs, XDict <GameData.AttrType, long> targetTempAttrs)
    {
        FileStream    fileStream    = null;
        StreamWriter  streamWriter  = null;
        StringBuilder stringBuilder = null;

        if (ClientApp.Instance.isShowFightLog)
        {
            string text = Application.get_dataPath() + "/../BattleLog.txt";
            try
            {
                fileStream    = new FileStream(text, 4, 3);
                streamWriter  = new StreamWriter(fileStream, Encoding.get_UTF8());
                stringBuilder = new StringBuilder();
            }
            catch (Exception ex)
            {
                Debug.LogError("Can't Write Log File!\n" + ex.get_Message());
                return(null);
            }
            stringBuilder.Append("Caster: \n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.Atk, caster.Atk) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.Defence, caster.Defence) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PveAtk, caster.PveAtk) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PvpAtk, caster.PvpAtk) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.HitRatio, caster.HitRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.CritRatio, caster.CritRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.CritHurtAddRatio, caster.CritHurtAddRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.DeparryRatio, caster.DeparryRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.SuckBloodScale, caster.SuckBloodScale) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.HurtAddRatio, caster.HurtAddRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PveHurtAddRatio, caster.PveHurtAddRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PvpHurtAddRatio, caster.PvpHurtAddRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.AtkMulAmend, caster.AtkMulAmend) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PveAtkMulAmend, caster.PveAtkMulAmend) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PvpAtkMulAmend, caster.PvpAtkMulAmend) + "\n");
            stringBuilder.Append("Target: \n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.Defence, target.Defence) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.HpLmt, target.HpLmt) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.DodgeRatio, target.DodgeRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.DecritRatio, target.DecritRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.ParryRatio, target.ParryRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.ParryHurtDeRatio, target.ParryHurtDeRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.HurtDeRatio, target.ParryHurtDeRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PveHurtDeRatio, target.PveHurtDeRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.PvpHurtDeRatio, target.PvpHurtDeRatio) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.DefMulAmend, target.DefMulAmend) + "\n");
            stringBuilder.Append(AttrUtility.GetStandardDesc(GameData.AttrType.HpLmtMulAmend, target.HpLmtMulAmend) + "\n");
            stringBuilder.Append("Calculate: \n");
        }
        BattleCalculator.DamageResult damageResult = new BattleCalculator.DamageResult();
        if (BattleCalculator.CheckHit(caster, target, stringBuilder))
        {
            if (ClientApp.Instance.isShowFightLog)
            {
                stringBuilder.Append("IsHit: " + true + "\n");
            }
            bool   flag = BattleCalculator.CheckParry(caster, target, out damageResult.parryRandomIndex, stringBuilder);
            double finalParryAddRatio = BattleCalculator.GetFinalParryAddRatio(target, flag);
            if (ClientApp.Instance.isShowFightLog)
            {
                stringBuilder.Append("IsParry: " + flag + "\n");
            }
            bool   flag2             = BattleCalculator.CheckCrit(caster, target, out damageResult.critRandomIndex, stringBuilder);
            double finalCritAddRatio = BattleCalculator.GetFinalCritAddRatio(caster, flag2);
            if (ClientApp.Instance.isShowFightLog)
            {
                stringBuilder.Append("IsCrit: " + flag2 + "\n");
            }
            double        tempDamage         = BattleCalculator.GetTempDamage(caster, target, isTargetPlayer);
            double        holyDamage         = BattleCalculator.GetHolyDamage(caster, target, casterTempAttrs);
            double        ignoreTargetDamage = BattleCalculator.GetIgnoreTargetDamage(caster, isTargetPlayer, casterTempAttrs);
            double        num  = (double)BattleCalculator.GetCritAddDamage(caster, flag2);
            List <double> list = new List <double>();
            list.Add(tempDamage * (double)caster.TryAddValue(GameData.AttrType.SkillNmlDmgScale, casterTempAttrs) * 0.001 + (double)caster.TryAddValue(GameData.AttrType.SkillNmlDmgAddAmend, casterTempAttrs));
            list.Add(finalCritAddRatio);
            list.Add(finalParryAddRatio);
            list.Add((!isCasterPlayer || !isTargetPlayer) ? Math.Max(0.0, (1000.0 + (double)caster.PveHurtAddRatio - (double)target.PveHurtDeRatio) * 0.001) : Math.Max(0.0, (1000.0 + (double)caster.PvpHurtAddRatio - (double)target.PvpHurtDeRatio) * 0.001));
            list.Add(Math.Max(0.0, (double)(1000 + caster.HurtAddRatio - target.HurtDeRatio) * 0.001));
            double num2 = BattleCalculator.GetMultipleResult(list) + holyDamage + ignoreTargetDamage + num;
            double num3 = Math.Max(1.0, num2 * (double)BattleCalculator.serverRandom.Next(9500, 10500, out damageResult.damageRandomIndex) * 9.9999997473787516E-05);
            double num4 = BattleCalculator.CalculateLifeSteal(caster, (int)num3);
            damageResult.IsMiss    = false;
            damageResult.IsCrit    = flag2;
            damageResult.IsParry   = flag;
            damageResult.Damage    = (long)num3;
            damageResult.Lifesteal = (long)num4;
            if (ClientApp.Instance.isShowFightLog)
            {
                stringBuilder.Append("TempDamage: " + tempDamage + "\n");
                stringBuilder.Append("HolyDamage: " + holyDamage + "\n");
                stringBuilder.Append("SkillNmlDmgScale: " + caster.TryAddValue(GameData.AttrType.SkillNmlDmgScale, casterTempAttrs) + "\n");
                stringBuilder.Append("SkillNmlDmgAddAmend: " + caster.TryAddValue(GameData.AttrType.SkillNmlDmgAddAmend, casterTempAttrs) + "\n");
                stringBuilder.Append("FixFinalDamage: " + num3 + "\n");
                stringBuilder.Append("Lifesteal: " + num4 + "\n");
            }
        }
        else
        {
            damageResult.parryRandomIndex  = 0;
            damageResult.critRandomIndex   = 0;
            damageResult.damageRandomIndex = 0;
            damageResult.IsMiss            = true;
            damageResult.IsParry           = false;
            damageResult.IsCrit            = false;
            damageResult.Damage            = 0L;
            damageResult.Lifesteal         = 0L;
            if (ClientApp.Instance.isShowFightLog)
            {
                stringBuilder.Append("IsHit: " + false + "\n");
            }
        }
        if (ClientApp.Instance.isShowFightLog)
        {
            stringBuilder.Append("================================================================\n\n");
            Debug.LogError(stringBuilder.ToString());
            streamWriter.Write(stringBuilder.ToString());
            streamWriter.Close();
            fileStream.Close();
        }
        return(damageResult);
    }