hch
2026-01-15 af0d59c2da7eb91de99d568ed17cbf2aa441f5b3
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
using System;
using System.Collections.Generic;
using LitJson;
using UnityEngine;
 
public class EquipRecordManager : GameSystemManager<EquipRecordManager>
{
    private List<EquipRecordData> recordList = new List<EquipRecordData>();
    public Dictionary<int, ItemModel> oldEquipDic = new Dictionary<int, ItemModel>();
 
    /// <summary>
    /// 调试用:遍历输出所有装备记录的详细信息(单条Log)
    /// </summary>
    public void DebugLogAllRecords()
    {
        var sb = new System.Text.StringBuilder();
        sb.AppendLine($"=== 装备记录总数: {recordList.Count} | 旧装备字典条目数: {oldEquipDic.Count} ===");
 
        for (int i = 0; i < recordList.Count; i++)
        {
            var record = recordList[i];
            sb.AppendLine($"--- 记录 {i + 1} ---");
            sb.AppendLine($"记录ID: {record.recordId} | 时间: {TimeUtility.GetTime((uint)record.timestamp)} | 类型: {record.recordType}");
 
            // 新装备详情
            if (record.newEquip != null)
            {
                sb.AppendLine($"[新装备] ID:{record.newEquip.itemId} | 名称:{record.newEquip.itemName} | 强化:{record.newEquip.level} | 评分:{record.newEquip.score} | 部位:{record.newEquip.equipPlace} | 战力:{record.newEquip.fightPower} | GUID:{record.newEquip.guid}");
            }
            else
            {
                sb.AppendLine($"[新装备] 无数据");
            }
 
            // 旧装备详情
            if (record.oldEquip != null)
            {
                sb.AppendLine($"[旧装备] ID:{record.oldEquip.itemId} | 名称:{record.oldEquip.itemName} | 强化:{record.oldEquip.level} | 评分:{record.oldEquip.score} | 部位:{record.oldEquip.equipPlace} | 战力:{record.oldEquip.fightPower} | GUID:{record.oldEquip.guid}");
            }
            else
            {
                sb.AppendLine($"[旧装备] 无数据");
            }
 
            sb.AppendLine(); // 空行分隔
        }
 
        // 旧装备字典
        sb.AppendLine("=== 旧装备字典详情 ===");
        foreach (var kvp in oldEquipDic)
        {
            sb.AppendLine($"Key:{kvp.Key} | Value:ItemModel(itemId={kvp.Value?.itemId}, guid={kvp.Value?.guid})");
        }
 
        UnityEngine.Debug.Log(sb.ToString());
    }
 
 
 
    private int maxCnt;
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitializeEventOnRelogin;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        // 监听装备操作结果
        EquipModel.Instance.OnEquipOPResultAction += OnEquipOPResult;
 
        var config = FuncConfigConfig.Get("AutoGuaji1");
        maxCnt = int.Parse(config.Numerical5);
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitializeEventOnRelogin;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
        EquipModel.Instance.OnEquipOPResultAction -= OnEquipOPResult;
    }
 
 
 
    private void OnBeforePlayerDataInitializeEventOnRelogin()
    {
 
    }
 
    private void OnPlayerLoginOk()
    {
        LoadRecords();
    }
 
    string Key { get { return $"EquipRecordData_{PlayerDatas.Instance.PlayerId}"; } }
    private void SaveRecords()
    {
        // 持久化存储
        var json = JsonMapper.ToJson(recordList);
        LocalSave.SetString(Key, json);
    }
 
    private void LoadRecords()
    {
        var json = LocalSave.GetString(Key);
        if (!string.IsNullOrEmpty(json))
        {
            recordList = JsonMapper.ToObject<List<EquipRecordData>>(json);
        }
    }
 
    /// <summary>
    /// 装备操作结果回调 - 记录装备变化
    /// </summary>
    /// <param name="isDone">是否成功更换</param>
    /// <param name="equipIndex">装备栏索引</param>
    private void OnEquipOPResult(bool isDone, int equipIndex)
    {
        if (equipIndex < 0) return;
 
        // 获取新装备和旧装备信息
        var newEquip = PackManager.Instance.GetItemByIndex(PackType.Equip, equipIndex);
        if (newEquip == null) return;
 
        // 获取被替换的装备(需要从其他地方记录)
        // 这里需要配合 EquipModel 的 OnEquipResult 记录被替换的装备
        // ...
    }
 
    /// <summary>
    /// 获取装备详情
    /// </summary>
    private EquipDetail GetEquipDetail(ItemModel item)
    {
        if (item == null) return null;
 
        var detail = new EquipDetail
        {
            itemId = item.itemId,
            level = item.GetUseDataFirstValue(22),
            equipPlace = item.config.EquipPlace,
            guid = item.guid,
        };
        return detail;
    }
 
 
 
 
 
 
    // 装备记录数据类型
    public class EquipRecordData
    {
        public string recordId;              // 记录唯一ID
        public long timestamp;               // 时间戳
        public RecordType recordType;        // 记录类型
        public EquipDetail newEquip;         // 新装备详情
        public EquipDetail oldEquip;         // 旧装备详情
 
    }
 
    public class EquipDetail
    {
        public int itemId;                   // 物品配置ID
        public string itemName;              // 物品名称
        public int level;                    // 强化等级
        public int score;                    // 装备评分
        public int equipPlace;               // 装备部位
        public long fightPower;              // 战力
        public string guid;                  // 装备唯一ID
    }
 
    public enum RecordType
    {
        Equip = 0,        // 装备
        Decompose = 1     // 分解
    }
}