lcy
2 天以前 ca577b96e0022e0ddaa8e106e147e53d8166df1c
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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 BattleHurtParam battleHurtParam { get; private set; }
    public List<long> damageList { get { return battleHurtParam.damageList; } }
    public BattleObject hurtObj { get { return battleHurtParam.hurtObj; } }
 
    public BattleObject casterObj { get { return battleHurtParam.casterObj; } }
 
    public HB427_tagSCUseSkill.tagSCUseSkillHurt hurt { get { return battleHurtParam.hurt; } }
 
    public SkillConfig skillConfig { get { return battleHurtParam.skillConfig; } }
 
    //  是否被格挡了
    public bool isBlocked = false;
 
    public bool isLastHit = false;
 
    public List<BattleDmg> targetDamageList = new List<BattleDmg>();
 
    public List<BattleDmg> casterDamageList = new List<BattleDmg>();
 
    public BattleDmgInfo(string battleFieldGuid, BattleHurtParam battleHurtParam)
    {
        this.battleFieldGuid = battleFieldGuid;
        this.battleHurtParam = battleHurtParam;
        this.isLastHit = battleHurtParam.hitIndex >= battleHurtParam.skillConfig.DamageDivide.Length - 1;
        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 = GeneralDefine.blockRatio; // 格挡减伤率
 
        // 处理每一段伤害及其对应的反伤和吸血
        for (int i = 0; i < damageList.Count; i++)
        {
            long actualDamage = damageList[i];
 
            // ============ 1. 先处理当前段对应的反伤 ============
            if (battleHurtParam.reflectHpList != null && i < battleHurtParam.reflectHpList.Count)
            {
                long reflectHp = battleHurtParam.reflectHpList[i];
                if (reflectHp > 0)
                {
                    casterDamageList.Add(new BattleDmg 
                    { 
                        damage = reflectHp, 
                        attackType = (int)DamageType.Reflect 
                    });
                }
            }
 
            // ============ 2. 然后处理当前段对应的吸血 ============
            if (battleHurtParam.suckHpList != null && i < battleHurtParam.suckHpList.Count)
            {
                long suckHp = battleHurtParam.suckHpList[i];
                if (suckHp > 0)
                {
                    casterDamageList.Add(new BattleDmg 
                    { 
                        damage = suckHp, 
                        attackType = (int)DamageType.SuckHP 
                    });
                }
            }
 
            // ============ 3. 最后处理主要伤害 ============
            // 格挡处理
            if (isBlocked)
            {
                // 去掉格挡类型
                int attackType = rawAttackType & (~(int)DamageType.Block);
 
                // 计算格挡伤害
                long totalDamage = (long)(actualDamage / (1 - blockRatio));
                long blockDmg = totalDamage - actualDamage;
                targetDamageList.Add(new BattleDmg { damage = blockDmg, attackType = (int)DamageType.Block });
 
                // 真实伤害特殊处理
                if (IsRealdamage())
                {
                    int showAttackType = (int)DamageType.Realdamage + (IsCrit() ? (int)DamageType.Crit : 0);
                    targetDamageList.Add(new BattleDmg { damage = actualDamage, attackType = showAttackType });
                }
                else
                {
                    // 普通伤害/治疗处理
                    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}");
                    }
                    targetDamageList.Add(new BattleDmg { damage = actualDamage, attackType = attackType });
                }
            }
            else
            {
                int attackType = rawAttackType;
 
                // 真实伤害特殊处理
                if (IsRealdamage())
                {
                    int showAttackType = (int)DamageType.Realdamage + (IsCrit() ? (int)DamageType.Crit : 0);
                    targetDamageList.Add(new BattleDmg { damage = actualDamage, attackType = showAttackType });
                }
                else
                {
                    // 普通伤害/治疗处理
                    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}");
                    }
                    targetDamageList.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;
    }
 
}
 
public class BattleHurtParam
{
    public BattleObject casterObj;
    public BattleObject hurtObj;
    public List<long> damageList;
    public List<long> suckHpList;
    public List<long> reflectHpList;
 
    public long fromHp;
 
    public long toHp;
 
    public BattleDrops battleDrops;
 
    public HB427_tagSCUseSkill.tagSCUseSkillHurt hurt;
 
    public int hitIndex;
 
    public HB422_tagMCTurnFightObjDead deadPack;
 
    public SkillConfig skillConfig;
}