1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System.Collections.Generic;
 
public class BattleDmg
{
    public long damage;
    public int attackType;
 
    public bool IsType(DamageType damageType)
    {
        return (attackType & (int)damageType) == (int)damageType;
    }
}
 
 
public class BattleDmgInfo
{
 
    public string battleFieldGuid { get; private set; }
    public List<long> damageList { get; private set; }
    public BattleObject hurtObj { get; private set; }
 
    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.hurt = hurt;
        this.skillConfig = skillConfig;
        HandleDamageType();
        HandleAttackTypeAndDamage();
    }
 
    private void HandleDamageType()
    {
        int attackTypes = 0;
        foreach (ServerDamageType serverDamageType in System.Enum.GetValues(typeof(ServerDamageType)))
        {
            int nsdt = (int)serverDamageType;
            if ((hurt.AttackTypes & nsdt) == nsdt)
            {
                attackTypes += nsdt;
            }
        }
        hurt.AttackTypes = (uint)attackTypes;
    }
 
    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;
    }
 
}