yyl
2025-09-04 cdf7098c937c5f4a70383ef70897bf9fedbb3d99
Main/System/Battle/Define/BattleDmgInfo.cs
@@ -1,21 +1,125 @@
using System.Collections.Generic;
public class BattleDmg
{
    public long damage;
    public int attackType;
}
public class BattleDmgInfo
{
    public string battleFieldGuid { get; private set; }
    public List<long> damageList { get; private set; }
    public int attackType { get; private set; }
    public BattleObject hurtObj { get; private set; }
    public BattleDmgInfo(string battleFieldGuid, List<long> damageList, BattleObject hurtObj, int attackType)
    public HB427_tagSCUseSkill.tagSCUseSkillHurt hurt { get; private set; }
    public SkillConfig skillConfig { get; private set; }
    //  是否被格挡了
    public bool isBlocked = false;
    public List<BattleDmg> battleDamageList = new List<BattleDmg>();
    public BattleDmgInfo(string battleFieldGuid, List<long> damageList, BattleObject hurtObj, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, SkillConfig skillConfig)
    {
        this.battleFieldGuid = battleFieldGuid;
        this.damageList = damageList;
        this.hurtObj = hurtObj;
        this.attackType = attackType;
        this.hurt = hurt;
        this.skillConfig = skillConfig;
        HandleAttackTypeAndDamage();
    }
    private void HandleAttackTypeAndDamage()
    {
        isBlocked = HaveBlockDamage();
        int rawAttackType = (int)hurt.AttackTypes;
        float blockRatio = float.Parse(GeneralDefine.parryCfg.Numerical3); // 格挡减伤率
        for (int i = 0; i < damageList.Count; i++)
        {
            long actualDamage = damageList[i];
            // 格挡处理
            if (isBlocked)
            {
                // 去掉格挡类型
                int attackType = rawAttackType & (~(int)DamageType.Block);
                // 计算格挡伤害
                long totalDamage = (long)(actualDamage / (1 - blockRatio));
                long blockDmg = totalDamage - actualDamage;
                battleDamageList.Add(new BattleDmg { damage = blockDmg, attackType = (int)DamageType.Block });
                // 真实伤害特殊处理
                if (IsRealdamage())
                {
                    int showAttackType = (int)DamageType.Realdamage + (IsCrit() ? (int)DamageType.Crit : 0);
                    battleDamageList.Add(new BattleDmg { damage = actualDamage, attackType = showAttackType });
                    continue;
                }
                // 普通伤害/治疗处理
                if (DamageNumConfig.Get(attackType) == null)
                {
                    UnityEngine.Debug.LogError($"服务器给的伤害类型不对,强制转换为普通伤害/治疗, attackType: {attackType}");
                    if ((attackType & (int)DamageType.Damage) != 0)
                        attackType = (int)DamageType.Damage;
                    else if ((attackType & (int)DamageType.Recovery) != 0)
                        attackType = (int)DamageType.Recovery;
                    else
                        UnityEngine.Debug.LogError($"强制转换失败,该类型不是治疗也不是伤害 {attackType}");
                }
                battleDamageList.Add(new BattleDmg { damage = actualDamage, attackType = attackType });
            }
            else
            {
                int attackType = rawAttackType;
                // 真实伤害特殊处理
                if (IsRealdamage())
                {
                    int showAttackType = (int)DamageType.Realdamage + (IsCrit() ? (int)DamageType.Crit : 0);
                    battleDamageList.Add(new BattleDmg { damage = actualDamage, attackType = showAttackType });
                    continue;
                }
                // 普通伤害/治疗处理
                if (DamageNumConfig.Get(attackType) == null)
                {
                    UnityEngine.Debug.LogError($"服务器给的伤害类型不对,强制转换为普通伤害/治疗, attackType: {attackType}");
                    if ((attackType & (int)DamageType.Damage) != 0)
                        attackType = (int)DamageType.Damage;
                    else if ((attackType & (int)DamageType.Recovery) != 0)
                        attackType = (int)DamageType.Recovery;
                    else
                        UnityEngine.Debug.LogError($"强制转换失败,该类型不是治疗也不是伤害 {attackType}");
                }
                battleDamageList.Add(new BattleDmg { damage = actualDamage, attackType = attackType });
            }
        }
    }
    public bool IsType(DamageType damageType)
    {
        return (hurt.AttackTypes & (int)damageType) == (int)damageType;
    }
    public bool IsCrit()
    {
        return IsType(DamageType.Crit);
    }
    public bool HaveBlockDamage()
    {
        return IsType(DamageType.Block);
    }
    public bool IsRealdamage()
    {
        return skillConfig.HurtType / 10 == 1;
    }
}