hch
2025-07-23 2336d5e71a6ed9c00f9a86c29d7aa33b9a1e38d5
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
using System.Collections.Generic;
using UnityEngine;
using LitJson;
 
 
public class BattleManager : GameSystemManager<BattleManager>
{
    public StoryBattleField storyBattleField = null;
 
    //  同时只能有一场战斗在进行 guid, battlefield
    protected Dictionary<string, BattleField> battleFields = new Dictionary<string, BattleField>();
 
    protected LogicUpdate logicUpdate = new LogicUpdate();
 
    public override void Init()
    {
        base.Init();
        // StartStoryBattle();
        logicUpdate.Start(Run);
    }
 
    public override void Release()
    {
        base.Release();
        logicUpdate.Destroy();
    }
 
    public void CreateStoryBattle(int MapID, int FuncLineID, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
    {
        if (null == storyBattleField)
        {
            storyBattleField = new StoryBattleField();
        }
 
        storyBattleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList);
    }
 
 
 
    public void OnBattleClose(BattleField _battleField)
    {
 
    }
 
 
#region 截断网络派发包 只收入当前包的后续
    private bool allow = true;
 
    private Queue<GameNetPackBasic> packQueue = new Queue<GameNetPackBasic>();
 
    public bool IsCanDistributePackage(GameNetPackBasic _package)
    {
        if (_package is HB425_tagSCTurnFightReportSign)
        {
            HB425_tagSCTurnFightReportSign pkg = _package as HB425_tagSCTurnFightReportSign;
 
            // 0-战报片段开始;1-战报片段结束;
            if (pkg.Sign == 0)
            {
                allow = false;
            }
            else
            {
                allow = true;
            }
        }
        else
        {
            if (!allow)
            {
                packQueue.Enqueue(_package);
            }
        }
 
        return allow;
    }
 
    public bool DistributeNextPackage()
    {
        if (packQueue.Count > 0)
        {
            GameNetPackBasic pack = packQueue.Dequeue();
            PackageRegedit.Distribute(pack);
            return true;
        }
        else
        {
            return false;
        }
    }
 
    public void OnConnected()
    {
        if (!allow)
        {
            allow = true;
            packQueue.Clear();
 
            //  重新发送要上一组战斗包的请求
            //  TODO YYL
        }
    }
 
#endregion
 
#region 战报部分
 
    protected Dictionary<string, Queue<GameNetPackBasic>> battleReportDict = new Dictionary<string, Queue<GameNetPackBasic>>();
 
    protected Dictionary<string, List<ulong>> battlePackRelationList = new Dictionary<string, List<ulong>>();
 
    public void PushPackage(string guid, GameNetPackBasic vNetPack)
    {
        Queue<GameNetPackBasic> queue = null;
 
        if (!battleReportDict.TryGetValue(guid, out queue))
        {
            queue = new Queue<GameNetPackBasic>();
        }
 
        queue.Enqueue(vNetPack);
 
        List<ulong> uidList = null;
 
        if (!battlePackRelationList.TryGetValue(guid, out uidList))
        {
            uidList = new List<ulong>();
        }
 
        uidList.Add(vNetPack.packUID);
    }
 
    public BattleField GetBattleField(ulong packUID)
    {
        return GetBattleField(GetGUID(packUID));
    }
 
    public BattleField GetBattleField(string guid)
    {
        BattleField battleField = null;
        battleFields.TryGetValue(guid, out battleField);
        if (battleField == null)
        {
            battleField = storyBattleField;
        }
        return battleField;
    }
 
 
 
    public string GetGUID(ulong packUID)
    {
        foreach (var kv in battlePackRelationList)
        {
            if (kv.Value.Contains(packUID))
            {
                return kv.Key;
            }   
        }
        return string.Empty;
    }
 
 
    public void DistributeNextReportPackage(string guid)
    {
        Queue<GameNetPackBasic> queue = null;
 
        if (!battleReportDict.TryGetValue(guid, out queue))
        {
            Debug.LogError("DistributeNextReportPackage could not find queue for guid : " + guid);
            return;
        }
 
        PackageRegedit.Distribute(queue.Dequeue());
 
        if (queue.Count <= 0)
        {
            battleReportDict.Remove(guid);
            battlePackRelationList.Remove(guid);
        }
    }
#endregion
 
    public BattleField CreateBattleField(string guid, int MapID, int FuncLineID, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
    {
        BattleField battleField = null;
 
        if (battleFields.TryGetValue(guid, out battleField))
        {
            Debug.LogError("战场已存在 先进行销毁");
            battleField.Destroy();
        }
 
 
        battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
 
        battleFields.Add(guid, battleField);
 
        if (string.Empty == guid)
        {
            storyBattleField = battleField as StoryBattleField;
        }
 
        return battleField;
    }
 
 
    // public void OnTurnFightObjAction(battleType, vNetData.TurnNum, (int)vNetData.ObjID)
 
 
    public void Run()
    {
        if (null != storyBattleField)
        {
            storyBattleField.Run();
        }
 
        foreach (var battleField in battleFields)
        {
            battleField.Value?.Run();
        }
    }
 
}