yyl
3 天以前 cec8b67d82c2c2c1662d55c818c4a46bcc0487db
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
 
using System.Collections.Generic;
using UnityEngine;
 
public class CustomHB426CombinePack : GameNetPackBasic
{
 
    public HB426_tagSCTurnFightTag startTag;
 
    public HB426_tagSCTurnFightTag endTag;
 
    public int fromIndex;
 
    public int toIndex;
 
    public string guid;
 
    public List<GameNetPackBasic> packList = new List<GameNetPackBasic>();
 
    public override void ReadFromBytes(byte[] vBytes)
    {
        base.ReadFromBytes(vBytes);
    }
 
    public void SetHB426End(int _toIndex, HB426_tagSCTurnFightTag _endTag)
    {
        if (_endTag.Sign != 1)
        {
            Debug.LogError("HB426_tagSCTurnFightTag Sign must be 1 for end tag, but got: " + _endTag.Sign);
            return;
        }
        endTag = _endTag;
        toIndex = _toIndex;
 
        packList = CombineToSkillPackFromList(guid, packList);
    }
 
 
    public void SetHB426Start(int _fromIndex, HB426_tagSCTurnFightTag tag)
    {
        if (tag.Sign != 0)
        {
            Debug.LogError("HB426_tagSCTurnFightTag Sign must be 0 for start tag, but got: " + tag.Sign);
            return;
        }
        fromIndex = _fromIndex;
        startTag = tag;
    }
 
    public void AddPack(GameNetPackBasic pack)
    {
        if (startTag == null)
        {
            Debug.LogError("startTag is null, please set it first.");
            return;
        }
 
        packList.Add(pack);
    }
 
    public bool IsEndPack(HB426_tagSCTurnFightTag tag)
    {
        if (tag == null)
        {
            return false;
        }
 
        if (startTag == null)
        {
            Debug.LogError("startTag is null, please set it first.");
            return false;
        }
 
        return startTag.Tag == tag.Tag && tag.Sign == 1;
    }
 
 
    public static List<GameNetPackBasic> CombineToSkillPackFromList(string _guid, List<GameNetPackBasic> b421SeriesPackList)
    {
        CustomHB426CombinePack combinePack = null;
        for (int i = 0; i < b421SeriesPackList.Count; i++)
        {
            var pack = b421SeriesPackList[i];
            if (pack is HB426_tagSCTurnFightTag)
            {
                var tag = pack as HB426_tagSCTurnFightTag;
                if (null == combinePack)
                {
                    combinePack = new CustomHB426CombinePack();
                    combinePack.guid = _guid;
                    combinePack.SetHB426Start(i, tag);
                    continue;
                }
                else
                {
                    if (combinePack.IsEndPack(tag))
                    {
                        combinePack.SetHB426End(i, tag);
                        break;
                    }
                }
            }
 
            if (null != combinePack)
            {
                combinePack.AddPack(pack);
            }
        }
 
        List<GameNetPackBasic> newPackList = new List<GameNetPackBasic>();
 
        if (null != combinePack)
        {
            //  技能包前面的包(不包括b426的开始标签)
            for (int i = 0; i < combinePack.fromIndex; i++)
            {
                newPackList.Add(b421SeriesPackList[i]);
            }
 
            //  把合并的技能包加进来
            newPackList.Add(combinePack);
 
            //  技能包后面的包(不包括b426的结束标签)
            for (int i = combinePack.toIndex + 1; i < b421SeriesPackList.Count; i++)
            {
                newPackList.Add(b421SeriesPackList[i]);
            }
 
            return CombineToSkillPackFromList(_guid, newPackList);
 
        }
        else
        {
            return b421SeriesPackList;
        }
 
    }
 
    public void Distribute()
    {
        BattleField battleField = BattleManager.Instance.GetBattleField(guid);
 
        if (null == battleField)
        {
            Debug.LogError("BattleField not found for guid: " + guid);
            return;
        }
 
        var skillAction = CreateSkillAction();
        if (null != skillAction)
        {
            battleField.PlayRecord(skillAction);
        }
    }
 
    public SkillRecordAction CreateSkillAction()
    {
        BattleField battleField = BattleManager.Instance.GetBattleField(guid);
 
        if (null == battleField)
        {
            Debug.LogError("BattleField not found for guid: " + guid);
            return null;
        }
 
        if (startTag.Tag.StartsWith("Skill_"))
        {
            HB427_tagSCUseSkill skill = packList[0] as HB427_tagSCUseSkill;
            packList.Remove(skill);
            BattleObject _caster = battleField.battleObjMgr.GetBattleObject((int)skill.ObjID);
            SkillRecordAction skillAction = new SkillRecordAction(battleField, _caster, skill, packList);
            return skillAction;
        }
 
        return null;
    }
 
#if UNITY_EDITOR
    public static CustomHB426CombinePack CreateCustomPack(string _guid, HB427_tagSCUseSkill skill)
    {
        CustomHB426CombinePack pack = new CustomHB426CombinePack();
        pack.guid = string.Empty;
 
        pack.startTag = new HB426_tagSCTurnFightTag
        {
            Tag = "Skill_Start",
            Sign = 0
        };
 
        pack.packList.Add(skill);
 
        return pack;
    }
#endif
}