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 // 分解
|
}
|
}
|