hch
2025-09-01 0218597f66eb99cf1ebf13d57623107ed433b49a
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
using System;
using LitJson;
using UnityEngine;
using System.Collections.Generic;
 
// 【主线战斗流程】
// 发送 B413  (ReqType 为 2 或 3)
//        后端回复  B425标记0开始   (中间N个战斗片段封包)  B425标记1结束
// 前端解析 N个战斗片段封包  ,拆解成前端支持的action指令,然后进行战斗表现
// 表现完毕后继续发送 B413  (ReqType 为 4)
//        后端回复  B425标记0开始   (中间N个战斗片段封包)  B425标记1结束
// 前端解析表现,然后一直循环即可
 
public enum StoryBattleState
{
    Break,
    Battle,
}
 
public class StoryBattleField : BattleField
{
    protected int chapter;//   章节
    protected int wave;//  波数
    protected int level;// 关卡
    protected JsonData extendData;
 
    protected MainChapterConfig chapterConfig;
 
    protected MainLevelConfig levelConfig;
 
    public StoryBattleState battleState;
 
    public StoryBattleField() : base(string.Empty)
    {
 
    }
 
    public override void Init(int MapID, int FuncLineID, JsonData _extendData,
        List<TeamBase> _redTeamList, List<TeamBase> _blueTeamList)
    {
        base.Init(MapID, FuncLineID, extendData, _redTeamList, _blueTeamList);
 
        if (null == _blueTeamList || _blueTeamList.Count == 0)
        {
            battleState = StoryBattleState.Break;
        }
        else
        {
            battleState = StoryBattleState.Battle;
        }
 
        // LoadBattleMode();
 
        chapter = FuncLineID / 10000;
        wave = MapID == 1 ? FuncLineID % 100 : 1;//第几波怪
        level = (FuncLineID % 10000) / 100;
 
        extendData = _extendData;
        chapterConfig = MainChapterConfig.Get(chapter);
        levelConfig = MainLevelConfig.Get(level);
 
        TeamManager.Instance.OnTeamChange += OnTeamChange;
    }
 
    public override void Release()
    {
        base.Release();
        TeamManager.Instance.OnTeamChange -= OnTeamChange;
    }
 
    protected void LoadBattleMode()
    {
        //主线模式:stop休息 无怪;Hand/Auto 有怪 等待指令
        BattleMode mode = BattleMode.Hand;
        if (AutoFightModel.Instance.isAutoAttackSet)
        {
            mode = BattleMode.Auto;
        }
        if (GetBattleMode() == mode)
            return;
 
        SetBattleMode(mode);
    }
 
    public override void AutoSetBattleMode()
    {
        LoadBattleMode();
    }
 
 
    public override void TurnFightState(int TurnNum, int State,
        uint FuncLineID, JsonData extendData)
    {
        base.TurnFightState(TurnNum, State, FuncLineID, extendData);
 
        switch (State)
        {
            //  起始状态标记
            case 0:
                break;
            case 1://准备完毕
                break;
            case 2://战斗中
                break;
            case 3://战斗结束
                break;
            case 4://结算奖励
                break;
            case 5://结束状态标记
                break;
            default:
                BattleDebug.LogError("recieve a unknown State");
                break;
        }
    }
 
    public override void OnTurnFightObjAction(int turnNum, int ObjID)
    {
        base.OnTurnFightObjAction(turnNum, ObjID);
    }
 
    public override void OnTurnFightState(int turnNum, int State, int FuncLineID, JsonData extendData)
    {
        base.OnTurnFightState(turnNum, State, FuncLineID, extendData);
 
    }
 
    protected void OnTeamChange(TeamType teamType)
    {
        if (teamType == TeamType.Story)
        {
            if (battleState == StoryBattleState.Break)
            {
                ReloadTeam();
            }
        }
    }
 
    public override void HaveRest()
    {
        base.HaveRest();
        battleState = StoryBattleState.Break;
    }
 
    protected void ReloadTeam()
    {
        battleObjMgr.ReloadTeam(TeamManager.Instance.GetTeam(TeamType.Story), BattleCamp.Red);
    }
 
    // public override void OnBattleEnd(JsonData turnFightStateData)
    // {
    //     base.OnBattleEnd(turnFightStateData);
 
    //     // HaveRest();
    // }
 
    public override void Run()
    {
        if (operationAgent == null)
        {
            //防范异常
            HaveRest();
            return;
        }
        base.Run();
    }
 
    public override void DistributeNextPackage()
    {
        //  不要调用base的函数
        BattleManager.Instance.DistributeNextPackage();
    }
 
 
    //请求单次战斗
    public void RequestFight()
    {
        if (IsPause)
        {
            //还需考虑其他不可战斗状况,主线的BOSS战斗也是另外一个场景且不能切出来 等跳过或者结束
            //外部统一控制 IsPause
            return;
        }
        if (BattleManager.Instance.isWaitServerStory)
            return;
 
        //    当前没有在播放战斗录像
        if (!recordPlayer.IsPlaying())
        {
            BattleDebug.LogError("HandModeOperationAgent DoNext  1");
            // 没有下一个包可以发了
            if (!BattleManager.Instance.DistributeNextPackage())
            {
 
                BattleDebug.LogError("HandModeOperationAgent DoNext  2");
 
                //再检查一次有没装备未处理
                if (PackManager.Instance.GetSinglePack(PackType.DropItem).GetItems().Count > 0)
                {
                    //构建所有物品
                    List<int> dropList = new List<int>();
                    foreach (var item in PackManager.Instance.GetSinglePack(PackType.DropItem).GetItems())
                    {
                        dropList.Add(item.gridIndex);
                    }
                    EquipModel.Instance.NotifyItemDrop(dropList, null);
                    return;
                }
 
                //    检查一下锤子的消耗
                if (!ItemLogicUtility.CheckCurrencyCount(41, PlayerDatas.Instance.baseData.UseHarmerCount, 2))
                {
                    //多次防范
                    if (GetBattleMode() != BattleMode.Stop)
                        HaveRest();
                    return;
                }
 
                // 请求下一个战斗包 或者检查战斗是否结束
                // ReqType; // 0-停止战斗回城;1-设置消耗倍值;2-挑战关卡小怪;3-挑战关卡boss;4-继续战斗;
                // 战斗中只要一直发4就可以,需要发2的情况:休息转变为战斗
                //    进入休息的逻辑:1.主动点击 2.没有战锤 3.断线重连太久(约定1分钟)仍停留在游戏内 4.回到登录界面(含断线超时)
 
                BattleDebug.LogError("HandModeOperationAgent DoNext  3");
                byte reqType;
 
                if (battleState == StoryBattleState.Break)
                {
                    reqType = 2;
                }
                else if (battleState == StoryBattleState.Battle)
                {
                    reqType = 4; // 继续战斗
                }
                else
                {
                    BattleDebug.LogError("unknown battle state");
                    return;
                }
 
                BattleDebug.LogError("HandModeOperationAgent DoNext  4   reqType is " + reqType);
 
 
                //    如果请求的是2 说明要初始化一下战场
                BattleManager.Instance.MainFightRequest(reqType);
 
                //  初始化战场后本来不会自动打 那么就需要再请求一次4继续战斗 来开始战斗
                if (reqType == 2)
                {
                    BattleManager.Instance.MainFightRequest(4);
                }
            }
        }
        else
        {
            if (!AutoFightModel.Instance.isAutoAttack)
                BattleDebug.LogError("action doesnt finish, wait a moment please");
        }
    }
}