yyl
19 小时以前 7f9ec6d10ebb5d741b10e2b4168b11ad0ebb22cd
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using System.Collections.Generic;
using UnityEngine;
 
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>();
 
    #region Initialization
 
    public BattleDmgInfo(string battleFieldGuid, BattleHurtParam battleHurtParam)
    {
        this.battleFieldGuid = battleFieldGuid;
        this.battleHurtParam = battleHurtParam;
        this.isLastHit = battleHurtParam.hitIndex >= battleHurtParam.skillConfig.DamageDivide.Length - 1;
        
        HandleDamageType();
        HandleAttackTypeAndDamage();
    }
 
    #endregion
 
    #region Damage Type Processing
 
    private void HandleDamageType()
    {
        if (hurt == null) return;
        
        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;
    }
 
    #endregion
 
    #region Damage List Generation
 
    private void HandleAttackTypeAndDamage()
    {
        isBlocked = HaveBlockDamage();
        int rawAttackType = hurt == null ? 0 : (int)hurt.AttackTypes;
        
        int maxCount = CalculateMaxDamageSegmentCount();
 
        for (int i = 0; i < maxCount; i++)
        {
            ProcessReflectDamage(i);
            ProcessSuckHpDamage(i);
            ProcessMainDamage(i, rawAttackType);
        }
    }
 
    /// <summary>
    /// 计算最大伤害段数
    /// </summary>
    private int CalculateMaxDamageSegmentCount()
    {
        int maxCount = damageList != null ? damageList.Count : 0;
        maxCount = Mathf.Max(maxCount, battleHurtParam.suckHpList != null ? battleHurtParam.suckHpList.Count : 0);
        maxCount = Mathf.Max(maxCount, battleHurtParam.reflectHpList != null ? battleHurtParam.reflectHpList.Count : 0);
        return maxCount;
    }
 
    /// <summary>
    /// 处理反伤伤害
    /// </summary>
    private void ProcessReflectDamage(int segmentIndex)
    {
        if (battleHurtParam.reflectHpList == null || segmentIndex >= battleHurtParam.reflectHpList.Count)
            return;
 
        long reflectHp = battleHurtParam.reflectHpList[segmentIndex];
        if (reflectHp > 0)
        {
            casterDamageList.Add(new BattleDmg
            {
                damage = reflectHp,
                attackType = (int)DamageType.Reflect
            });
        }
    }
 
    /// <summary>
    /// 处理吸血伤害
    /// </summary>
    private void ProcessSuckHpDamage(int segmentIndex)
    {
        if (battleHurtParam.suckHpList == null || segmentIndex >= battleHurtParam.suckHpList.Count)
            return;
 
        long suckHp = battleHurtParam.suckHpList[segmentIndex];
        if (suckHp > 0)
        {
            casterDamageList.Add(new BattleDmg
            {
                damage = suckHp,
                attackType = (int)DamageType.SuckHP
            });
        }
    }
 
    /// <summary>
    /// 处理主要伤害
    /// </summary>
    private void ProcessMainDamage(int segmentIndex, int rawAttackType)
    {
        if (damageList == null || segmentIndex >= damageList.Count)
            return;
 
        long actualDamage = damageList[segmentIndex];
 
        if (isBlocked)
        {
            ProcessBlockedDamage(actualDamage, rawAttackType);
        }
        else
        {
            ProcessNormalDamage(actualDamage, rawAttackType);
        }
    }
 
    /// <summary>
    /// 处理被格挡的伤害
    /// </summary>
    private void ProcessBlockedDamage(long actualDamage, int rawAttackType)
    {
        float blockRatio = GeneralDefine.blockRatio;
        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())
        {
            AddRealdamageToList(actualDamage);
        }
        else
        {
            AddNormalDamageToList(actualDamage, attackType);
        }
    }
 
    /// <summary>
    /// 处理正常伤害(未被格挡)
    /// </summary>
    private void ProcessNormalDamage(long actualDamage, int rawAttackType)
    {
        if (IsRealdamage())
        {
            AddRealdamageToList(actualDamage);
        }
        else
        {
            AddNormalDamageToList(actualDamage, rawAttackType);
        }
    }
 
    /// <summary>
    /// 添加真实伤害到列表
    /// </summary>
    private void AddRealdamageToList(long damage)
    {
        int showAttackType = (int)DamageType.Realdamage + (IsCrit() ? (int)DamageType.Crit : 0);
        targetDamageList.Add(new BattleDmg { damage = damage, attackType = showAttackType });
    }
 
    /// <summary>
    /// 添加普通伤害/治疗到列表
    /// </summary>
    private void AddNormalDamageToList(long damage, int attackType)
    {
        attackType = ValidateAndFixAttackType(attackType);
        targetDamageList.Add(new BattleDmg { damage = damage, attackType = attackType });
    }
 
    /// <summary>
    /// 验证并修复攻击类型
    /// </summary>
    private int ValidateAndFixAttackType(int attackType)
    {
        if (DamageNumConfig.Get(attackType) != null)
            return attackType;
 
        UnityEngine.Debug.LogError($"服务器给的伤害类型不对,强制转换为普通伤害/治疗, attackType: {attackType}");
 
        if ((attackType & (int)DamageType.Damage) != 0)
            return (int)DamageType.Damage;
 
        if ((attackType & (int)DamageType.Recovery) != 0)
            return (int)DamageType.Recovery;
 
        UnityEngine.Debug.LogError($"强制转换失败,该类型不是治疗也不是伤害 {attackType}");
        return attackType;
    }
 
    #endregion
 
    #region Type Checking
 
    public bool IsType(DamageType damageType)
    {
        return hurt != null && (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 bool IsDamage()
    {
        return IsType(DamageType.Damage) || IsRealdamage() || IsType((DamageType)11) || IsType((DamageType)12);
    }
 
    #endregion
}
 
public class BattleHurtParam
{
    public BattleObject casterObj;
    public BattleObject hurtObj;
    public List<long> damageList;
    public List<long> suckHpList;
    public List<long> reflectHpList;
 
    public long fromShieldValue;
    public long toShieldValue;
    public long fromHp;
    public long toHp;
 
    public BattleDrops battleDrops;
    public HB427_tagSCUseSkill.tagSCUseSkillHurt hurt;
    public int hitIndex;
    public HB422_tagMCTurnFightObjDead deadPack;
    public SkillConfig skillConfig;
    public long maxHp;
 
    #region Shield Value Calculations
 
    public long MaxSheildValue
    {
        get
        {
            return hurtObj == null ? 0 : hurtObj.teamHero.maxHp;
        }
    }
 
    public long phase1FromShieldValue
    {
        get
        {
            if (fromShieldValue > 0)
            {
                return Mathf.Min((int)fromShieldValue, (int)MaxSheildValue);
            }
            else
            {
                return 0;
            }
        }
    }
 
    public long phase1ToShieldValue
    {
        get
        {
            if (toShieldValue > 0)
            {
                return Mathf.Min((int)toShieldValue, (int)MaxSheildValue);
            }
            else
            {
                return 0;
            }
        }
    }
 
    public long phase2FromShieldValue
    {
        get
        {
            if (fromShieldValue > MaxSheildValue)
            {
                return fromShieldValue - MaxSheildValue;
            }
            else
            {
                return 0;
            }
        }
    }
 
    public long phase2ToShieldValue
    {
        get
        {
            if (toShieldValue > MaxSheildValue)
            {
                return toShieldValue - MaxSheildValue;
            }
            else
            {
                return 0;
            }
        }
    }
 
    #endregion
}