三国卡牌客户端基础资源仓库
hch
8 天以前 4a3921769c12e492e762c4f6b65e21bd1694ba95
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using System.IO;
 
public class GMQuickPlayingEditor : EditorWindow
{
    private string searchText = "";
    private string commandText = "";
    private Vector2 scrollPosition;
    private Vector2 reportScrollPosition;
    private Vector2 battleInfoScrollPosition;
    private List<ItemConfig> searchResults = new List<ItemConfig>();
    private int itemCount = 1;
    private bool isBattlePaused = false;
    private bool showBattleInfo = false; // 控制战场信息显示/隐藏
    
    // 战报相关
    private string reportFilePath = "";
    private string[] reportFiles = new string[0];
    private int selectedReportIndex = 0;
    
    [MenuItem("Tools/GM快捷工具 &9")]
    public static void ShowWindow()
    {
        GetWindow<GMQuickPlayingEditor>("GM快捷工具");
    }
    
    private void OnEnable()
    {
        RefreshReportList();
    }
    
    private void Update()
    {
        // 每帧更新战场信息
        Repaint();
    }
    
    private void OnGUI()
    {
        GUILayout.BeginHorizontal();
        
        // ========== 左侧面板 ==========
        float leftWidth = showBattleInfo ? position.width * 0.6f : position.width - 20;
        GUILayout.BeginVertical("box", GUILayout.Width(leftWidth));
        
        // 搜索栏
        GUILayout.Label("物品搜索", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        searchText = EditorGUILayout.TextField("搜索:", searchText);
        if (GUILayout.Button("查询物品", GUILayout.Width(80)))
        {
            OnSearchItem();
        }
        GUILayout.EndHorizontal();
        
        GUILayout.Space(10);
        
        // 搜索结果显示区域
        GUILayout.BeginHorizontal();
        GUILayout.Label($"搜索结果 ({searchResults.Count})", EditorStyles.boldLabel);
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("清空列表", GUILayout.Width(80)))
        {
            searchResults.Clear();
        }
        GUILayout.EndHorizontal();
        
        scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(200));
        GUILayout.BeginVertical("box");
        
        if (searchResults.Count > 0)
        {
            foreach (var item in searchResults)
            {
                GUILayout.BeginHorizontal("box");
                GUILayout.Label($"ID: {item.ID}", GUILayout.Width(80));
                GUILayout.Label($"名称: {item.ItemName}", GUILayout.Width(150));
                GUILayout.Label($"等级: {item.LV}", GUILayout.Width(60));
                if (GUILayout.Button("选择", GUILayout.Width(60)))
                {
                    OnSelectItem(item);
                }
                GUILayout.EndHorizontal();
            }
        }
        else
        {
            GUILayout.Label("搜索结果将在这里显示...");
        }
        
        GUILayout.EndVertical();
        GUILayout.EndScrollView();
        
        GUILayout.Space(10);
        
        // 数量输入
        GUILayout.BeginHorizontal();
        GUILayout.Label("物品数量:", GUILayout.Width(80));
        itemCount = EditorGUILayout.IntField(itemCount, GUILayout.Width(100));
        GUILayout.EndHorizontal();
        
        GUILayout.Space(10);
        
        // GM命令编辑区域
        GUILayout.Label("GM命令", EditorStyles.boldLabel);
        GUILayout.BeginVertical("box");
        commandText = EditorGUILayout.TextArea(commandText, GUILayout.Height(60));
        GUILayout.EndVertical();
        
        GUILayout.Space(5);
        
        // 发送命令按钮
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("发送命令", GUILayout.Width(100), GUILayout.Height(30)))
        {
            OnSendCommand();
        }
        if (GUILayout.Button("清空", GUILayout.Width(60), GUILayout.Height(30)))
        {
            commandText = "";
        }
        GUILayout.EndHorizontal();
        
        GUILayout.Space(10);
        
        // 提示信息
        GUIStyle warningStyle = new GUIStyle(EditorStyles.helpBox);
        warningStyle.normal.textColor = new Color(1f, 0.6f, 0f);
        warningStyle.fontSize = 11;
        EditorGUILayout.LabelField("⚠ 添加物品最好跟服务器确认过物品的存在后再添加", warningStyle);
        
        GUILayout.Space(10);
        
        // 战报浏览区域
        GUILayout.Label("战报浏览", EditorStyles.boldLabel);
        GUILayout.BeginVertical("box");
        
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("刷新战报列表", GUILayout.Width(120)))
        {
            RefreshReportList();
        }
        if (GUILayout.Button("打开战报文件夹", GUILayout.Width(120)))
        {
            OpenReportFolder();
        }
        GUILayout.EndHorizontal();
        
        GUILayout.Space(5);
        
        if (reportFiles.Length > 0)
        {
            reportScrollPosition = GUILayout.BeginScrollView(reportScrollPosition, GUILayout.Height(150));
            
            for (int i = 0; i < reportFiles.Length; i++)
            {
                GUILayout.BeginHorizontal("box");
                string fileName = Path.GetFileName(reportFiles[i]);
                GUILayout.Label(fileName, GUILayout.Width(300));
                
                if (GUILayout.Button("加载", GUILayout.Width(60)))
                {
                    LoadReport(reportFiles[i]);
                }
                
                if (GUILayout.Button("删除", GUILayout.Width(60)))
                {
                    DeleteReport(reportFiles[i]);
                }
                
                GUILayout.EndHorizontal();
            }
            
            GUILayout.EndScrollView();
        }
        else
        {
            GUILayout.Label("未找到战报文件(.bytes)");
        }
        
        GUILayout.EndVertical();
        
        GUILayout.Space(10);
        
        // 战场信息Toggle
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("显示战场信息", GUILayout.Width(100));
        showBattleInfo = EditorGUILayout.Toggle(showBattleInfo, GUILayout.Width(20));
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        
        GUILayout.EndVertical();
        
        // ========== 右侧面板 - 战场信息 ==========
        if (showBattleInfo)
        {
            // 分割线
            GUILayout.Box("", GUILayout.Width(2), GUILayout.ExpandHeight(true));
            
            GUILayout.BeginVertical("box", GUILayout.ExpandWidth(true));
            
            GUILayout.Label("战场信息", EditorStyles.boldLabel);
            
            // 暂停/开始战斗按钮
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            string buttonText = isBattlePaused ? "开始当前战斗" : "暂停当前战斗";
            if (GUILayout.Button(buttonText, GUILayout.Width(120), GUILayout.Height(30)))
            {
                OnPauseBattle();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            
            GUILayout.Space(5);
            
            battleInfoScrollPosition = GUILayout.BeginScrollView(battleInfoScrollPosition);
            
            DrawBattleFieldInfo();
            
            GUILayout.EndScrollView();
            
            GUILayout.EndVertical();
        }
        
        GUILayout.EndHorizontal();
    }
    
    private void DrawBattleFieldInfo()
    {
        BattleField battleField = GetActiveBattleField();
        
        if (battleField == null)
        {
            GUILayout.Label("暂无战场", EditorStyles.centeredGreyMiniLabel);
            return;
        }
        
        // 战场基本信息
        GUILayout.BeginVertical("box");
        GUILayout.Label($"战场类型: {battleField.GetType().Name}", EditorStyles.boldLabel);
        GUILayout.Label($"GUID: {battleField.guid}");
        GUILayout.Label($"地图ID: {battleField.MapID}");
        GUILayout.Label($"暂停状态: {battleField.IsPause}");
        GUILayout.EndVertical();
        
        GUILayout.Space(10);
        
        // 红方队伍信息
        DrawTeamInfo("红方队伍", battleField.battleObjMgr.redCampList, new Color(1f, 0.5f, 0.5f));
        
        GUILayout.Space(10);
        
        // 蓝方队伍信息
        DrawTeamInfo("蓝方队伍", battleField.battleObjMgr.blueCampList, new Color(0.5f, 0.5f, 1f));
    }
    
    private void DrawTeamInfo(string teamName, List<BattleObject> team, Color headerColor)
    {
        GUIStyle headerStyle = new GUIStyle(EditorStyles.boldLabel);
        headerStyle.normal.textColor = headerColor;
        
        GUILayout.Label(teamName, headerStyle);
        
        if (team == null || team.Count == 0)
        {
            GUILayout.Label("  无角色", EditorStyles.miniLabel);
            return;
        }
        
        foreach (var obj in team)
        {
            if (obj == null || obj.teamHero == null)
                continue;
                
            GUILayout.BeginVertical("box");
            
            // 角色名称和ID
            GUILayout.BeginHorizontal();
            GUILayout.Label($"ID: {obj.ObjID}", GUILayout.Width(80));
            GUILayout.Label($"名称: {obj.teamHero.name}", GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();
            
            // 血量信息
            long curHp = obj.teamHero.curHp;
            long maxHp = obj.teamHero.maxHp;
            float hpPercent = maxHp > 0 ? (float)curHp / maxHp : 0f;
            
            GUILayout.BeginHorizontal();
            GUILayout.Label("血量:", GUILayout.Width(50));
            
            // 血条
            Rect hpBarRect = GUILayoutUtility.GetRect(100, 18);
            EditorGUI.DrawRect(hpBarRect, new Color(0.3f, 0.3f, 0.3f));
            
            Rect hpFillRect = new Rect(hpBarRect.x, hpBarRect.y, hpBarRect.width * hpPercent, hpBarRect.height);
            Color hpColor = hpPercent > 0.5f ? Color.green : hpPercent > 0.2f ? Color.yellow : Color.red;
            EditorGUI.DrawRect(hpFillRect, hpColor);
            
            GUILayout.Label($"{curHp}/{maxHp} ({(hpPercent * 100f):F1}%)", GUILayout.Width(150));
            GUILayout.EndHorizontal();
            
            // 怒气信息
            long curMp = obj.teamHero.rage;
            long maxMp = 100;
            float mpPercent = maxMp > 0 ? (float)curMp / maxMp : 0f;
            
            GUILayout.BeginHorizontal();
            GUILayout.Label("怒气:", GUILayout.Width(50));
            
            // 怒气条
            Rect mpBarRect = GUILayoutUtility.GetRect(100, 18);
            EditorGUI.DrawRect(mpBarRect, new Color(0.3f, 0.3f, 0.3f));
            
            Rect mpFillRect = new Rect(mpBarRect.x, mpBarRect.y, mpBarRect.width * mpPercent, mpBarRect.height);
            EditorGUI.DrawRect(mpFillRect, new Color(1f, 0.5f, 0f)); // 橙色
            
            GUILayout.Label($"{curMp}/{maxMp} ({(mpPercent * 100f):F1}%)", GUILayout.Width(150));
            GUILayout.EndHorizontal();
            
            GUILayout.EndVertical();
        }
    }
    
    private BattleField GetActiveBattleField()
    {
        if (!Application.isPlaying)
            return null;
            
        for (int i = 0; i < BattleConst.BattleWindows.Count; i++)
        {
            var win = UIManager.Instance.GetUI(BattleConst.BattleWindows[i].Name);
            if (win != null && win.IsActive())
            {
                // 使用反射获取 battleField 字段
                var battleFieldField = win.GetType().GetField("battleField", 
                    System.Reflection.BindingFlags.NonPublic | 
                    System.Reflection.BindingFlags.Instance);
                
                if (battleFieldField != null)
                {
                    var battleField = battleFieldField.GetValue(win) as BattleField;
                    if (battleField != null)
                    {
                        return battleField;
                    }
                }
            }
        }
        
        return null;
    }
    
    private void RefreshReportList()
    {
        string reportFolder = Application.dataPath + "/../BattleReport/";
        if (Directory.Exists(reportFolder))
        {
            reportFiles = Directory.GetFiles(reportFolder, "*.bytes");
            Debug.Log($"找到 {reportFiles.Length} 个战报文件");
        }
        else
        {
            Directory.CreateDirectory(reportFolder);
            reportFiles = new string[0];
            Debug.Log("创建战报文件夹: " + reportFolder);
        }
    }
    
    private void OpenReportFolder()
    {
        string reportFolder = Application.dataPath + "/../BattleReport/";
        if (!Directory.Exists(reportFolder))
        {
            Directory.CreateDirectory(reportFolder);
        }
        EditorUtility.RevealInFinder(reportFolder);
    }
    
    private void LoadReport(string filePath)
    {
        if (!File.Exists(filePath))
        {
            Debug.LogError("战报文件不存在: " + filePath);
            return;
        }
        
        reportFilePath = filePath;
        Debug.Log("已加载战报: " + Path.GetFileName(filePath));
 
        HB430_tagSCTurnFightReport hB430_TagSCTurnFightReport = new HB430_tagSCTurnFightReport();
        hB430_TagSCTurnFightReport.isRecord = true;
        byte[] vBytes = File.ReadAllBytes(filePath);
        hB430_TagSCTurnFightReport.ReadFromBytes(vBytes);
        PackageRegedit.Distribute(hB430_TagSCTurnFightReport);
    }
    
    private void DeleteReport(string filePath)
    {
        if (!File.Exists(filePath))
        {
            Debug.LogError("战报文件不存在: " + filePath);
            return;
        }
        
        if (EditorUtility.DisplayDialog("确认删除", 
            $"确定要删除战报文件吗?\n{Path.GetFileName(filePath)}", 
            "删除", "取消"))
        {
            try
            {
                File.Delete(filePath);
                Debug.Log("已删除战报: " + Path.GetFileName(filePath));
                RefreshReportList();
            }
            catch (System.Exception e)
            {
                Debug.LogError("删除战报文件失败: " + e.Message);
            }
        }
    }
    
    private string ExtractGuidFromFileName(string fileName)
    {
        // 从文件名中提取 GUID
        // 格式: B430_ReportBytes_{GUID}_{DateTime}
        string[] parts = fileName.Split('_');
        if (parts.Length >= 3)
        {
            return parts[2]; // 返回 GUID 部分
        }
        return "unknown_guid";
    }
    
    private void OnSearchItem()
    {
        searchResults.Clear();
        
        if (string.IsNullOrEmpty(searchText))
        {
            Debug.Log("搜索文本为空");
            return;
        }
        
        // 遍历 ItemConfig.dic 进行模糊搜索
        foreach (var kvp in ItemConfig.dic)
        {
            var item = kvp.Value;
            if (!string.IsNullOrEmpty(item.ItemName) && 
                item.ItemName.Contains(searchText))
            {
                searchResults.Add(item);
            }
        }
        
        // 按 ID 排序
        searchResults = searchResults.OrderBy(x => x.ID).ToList();
        
        Debug.Log($"搜索物品: {searchText}, 找到 {searchResults.Count} 个结果");
    }
    
    private void OnSelectItem(ItemConfig item)
    {
        Debug.Log($"选择物品: {item.ItemName} (ID: {item.ID})");
        commandText = $"MakeItemCount {item.ID} {itemCount}";
    }
    
    private void OnSendCommand()
    {
        if (string.IsNullOrEmpty(commandText))
        {
            Debug.LogWarning("命令为空,无法发送");
            return;
        }
        
        Debug.Log("发送命令: " + commandText);
        GMCmdManager.Instance.OnSendGMQuest(commandText);
        GMCmdManager.Instance.SetRecordCmdlist(commandText);
    }
    
    private void OnPauseBattle()
    {
        for (int i = 0; i < BattleConst.BattleWindows.Count; i++)
        {
            var win = UIManager.Instance.GetUI(BattleConst.BattleWindows[i].Name);
            if (win != null && win.IsActive())
            {
                // 使用反射获取 battleField 字段
                var battleFieldField = win.GetType().GetField("battleField", 
                    System.Reflection.BindingFlags.NonPublic | 
                    System.Reflection.BindingFlags.Instance);
                
                if (battleFieldField != null)
                {
                    var battleField = battleFieldField.GetValue(win) as BattleField;
                    if (battleField != null)
                    {
                        battleField.IsPause = !battleField.IsPause;
                        isBattlePaused = battleField.IsPause;
                        Debug.Log($"战斗暂停状态切换: {battleField.IsPause}");
                        return;
                    }
                }
            }
        }
        
        Debug.LogWarning("未找到激活的战斗窗口或 battleField 为空");
    }
}