From 69fdc58cb97714f856df268f08451f2ba7e5ecf2 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 21 一月 2026 10:40:56 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_scripts
---
Main/System/Main/EquipRecordManager.cs | 237 ++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 146 insertions(+), 91 deletions(-)
diff --git a/Main/System/Main/EquipRecordManager.cs b/Main/System/Main/EquipRecordManager.cs
index 4451e85..1098e08 100644
--- a/Main/System/Main/EquipRecordManager.cs
+++ b/Main/System/Main/EquipRecordManager.cs
@@ -6,64 +6,11 @@
public class EquipRecordManager : GameSystemManager<EquipRecordManager>
{
private List<EquipRecordData> recordList = new List<EquipRecordData>();
- public Dictionary<int, ItemModel> oldEquipDic = new Dictionary<int, ItemModel>();
-
- /// <summary>
- /// 璋冭瘯鐢細閬嶅巻杈撳嚭鎵�鏈夎澶囪褰曠殑璇︾粏淇℃伅锛堝崟鏉og锛�
- /// </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 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);
@@ -73,14 +20,12 @@
{
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitializeEventOnRelogin;
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
- EquipModel.Instance.OnEquipOPResultAction -= OnEquipOPResult;
}
private void OnBeforePlayerDataInitializeEventOnRelogin()
{
-
}
private void OnPlayerLoginOk()
@@ -99,28 +44,29 @@
private void LoadRecords()
{
var json = LocalSave.GetString(Key);
- if (!string.IsNullOrEmpty(json))
+ if (string.IsNullOrEmpty(json))
+ {
+ recordList = new List<EquipRecordData>();
+ return;
+ }
+
+ try
{
recordList = JsonMapper.ToObject<List<EquipRecordData>>(json);
+ // 鎺掑簭瑙勫垯锛氭椂闂存埑灏忕殑闈犲墠锛屾椂闂存埑鐩稿悓鍒欑储寮曞皬鐨勯潬鍓�
+ recordList.Sort((a, b) =>
+ {
+ int timeCompare = a.timestamp.CompareTo(b.timestamp);
+ if (timeCompare != 0)
+ return timeCompare;
+ return 0;
+ });
}
- }
-
- /// <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 璁板綍琚浛鎹㈢殑瑁呭
- // ...
+ catch (Exception ex)
+ {
+ Debug.LogError($"鍔犺浇瑁呭璁板綍澶辫触: {ex.Message}");
+ recordList = new List<EquipRecordData>();
+ }
}
/// <summary>
@@ -133,43 +79,152 @@
var detail = new EquipDetail
{
itemId = item.itemId,
- level = item.GetUseDataFirstValue(22),
- equipPlace = item.config.EquipPlace,
+ lv = item.GetUseDataFirstValue(22),
guid = item.guid,
};
return detail;
}
+ public List<EquipRecordData> GetRecordList(bool isSort = false)
+ {
+ if (recordList == null)
+ {
+ return null;
+ }
+ if (isSort)
+ {
+ // 鎺掑簭瑙勫垯锛氭椂闂存埑灏忕殑闈犲墠锛屾椂闂存埑鐩稿悓鍒欑储寮曞皬鐨勯潬鍓�
+ recordList.Sort((a, b) =>
+ {
+ int timeCompare = a.timestamp.CompareTo(b.timestamp);
+ if (timeCompare != 0)
+ return timeCompare;
+ return 0;
+ });
+ }
+ return recordList;
+ }
+ public event Action OnUpdateRecordListEvent;
+ public void AddRecord(int recordType, ItemModel newEquip, ItemModel oldEquip)
+ {
+ if (newEquip == null)
+ return;
+ long showFightPower = FightPowerManager.Instance.GetFightPowerChange(newEquip);
+ // 鏂拌澶囨垬鍔涗綆浜庢棫瑁呭鎴樺姏锛屼笉鍏佽娣诲姞
+ if (showFightPower <= 0)
+ return;
+ var newDetail = GetEquipDetail(newEquip);
+ var oldDetail = GetEquipDetail(oldEquip);
+ if (recordList == null)
+ return;
+
+ // 閬嶅巻鐜版湁璁板綍锛屾鏌ユ槸鍚﹀瓨鍦ㄥ尮閰嶇殑璁板綍锛堜笉闄愬埗椤哄簭锛�
+ foreach (var existingRecord in recordList)
+ {
+ if (IsSameRecord(existingRecord, newDetail, oldDetail))
+ {
+ // 鎵惧埌鍖归厤鐨勮褰曪紝涓嶆坊鍔�
+ return;
+ }
+ }
+
+ var record = new EquipRecordData
+ {
+ recordType = (int)recordType,
+ newEquip = GetEquipDetail(newEquip),
+ oldEquip = GetEquipDetail(oldEquip),
+ fightPower = showFightPower,
+ timestamp = TimeUtility.AllSeconds,
+ };
+
+ if (recordList.Count >= maxCnt)
+ {
+ // 绉婚櫎鏈�鏃╁姞鍏ョ殑璁板綍锛堟帓搴忓悗绗竴涓級
+ recordList.RemoveAt(0);
+ }
+
+ recordList.Add(record);
+ SaveRecords();
+ OnUpdateRecordListEvent?.Invoke();
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇涓ゆ潯璁板綍鏄惁涓�鑷达紙涓嶉檺鍒� new/old 椤哄簭锛�
+ /// </summary>
+ private bool IsSameRecord(EquipRecordData existingRecord, EquipDetail newDetail, EquipDetail oldDetail)
+ {
+ // 鍙傛暟鏍¢獙
+ if (newDetail == null && oldDetail == null)
+ return true;
+ if (existingRecord == null)
+ return true;
+
+ // 璁$畻鍚勫瓧娈垫槸鍚︿负 null
+ bool newIsNull = IsNullOrEmptyGuid(newDetail);
+ bool oldIsNull = IsNullOrEmptyGuid(oldDetail);
+ bool recordNewIsNull = IsNullOrEmptyGuid(existingRecord.newEquip);
+ bool recordOldIsNull = IsNullOrEmptyGuid(existingRecord.oldEquip);
+
+ // 濡傛灉涓よ竟閮戒负绌猴紝鍒欒涓虹浉鍚�
+ if (newIsNull && oldIsNull && recordNewIsNull && recordOldIsNull)
+ return true;
+
+ // 濡傛灉鍙湁涓�杈逛负绌猴紝鍒欎笉鍚�
+ if (newIsNull != recordNewIsNull || oldIsNull != recordOldIsNull)
+ return false;
+
+ // 妫�鏌ラ『搴忔槸鍚﹀尮閰�
+ bool orderMatch = IsGuidMatch(existingRecord.newEquip, newDetail) &&
+ IsGuidMatch(existingRecord.oldEquip, oldDetail);
+
+ // 妫�鏌ラ『搴忔槸鍚︾浉鍙�
+ bool reverseMatch = IsGuidMatch(existingRecord.newEquip, oldDetail) &&
+ IsGuidMatch(existingRecord.oldEquip, newDetail);
+
+ return orderMatch || reverseMatch;
+ }
+
+ // 鍒ゆ柇瑁呭璇︽儏鏄惁涓� null 鎴� guid 涓虹┖
+ private bool IsNullOrEmptyGuid(EquipDetail detail)
+ {
+ return detail == null || string.IsNullOrEmpty(detail.guid);
+ }
+
+ // 姣旇緝涓や釜瑁呭璇︽儏鐨� guid 鏄惁鐩哥瓑锛堝畨鍏ㄦ瘮杈冿紝閬垮厤 null 寮傚父锛�
+ private bool IsGuidMatch(EquipDetail a, EquipDetail b)
+ {
+ // 浠讳竴瀵硅薄涓� null 鍒欎笉鍖归厤
+ if (a == null || b == null)
+ return false;
+
+ return a.guid == b.guid;
+ }
// 瑁呭璁板綍鏁版嵁绫诲瀷
public class EquipRecordData
{
- public string recordId; // 璁板綍鍞竴ID
- public long timestamp; // 鏃堕棿鎴�
- public RecordType recordType; // 璁板綍绫诲瀷
+ public int recordType; // 璁板綍绫诲瀷
public EquipDetail newEquip; // 鏂拌澶囪鎯�
public EquipDetail oldEquip; // 鏃ц澶囪鎯�
-
+ public long fightPower; // 鎴樺姏宸�
+ public int timestamp; // 鏃堕棿鎴�
}
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 string guid; // 瑁呭鍞竴ID
+ public int itemId; // 鐗╁搧ID
+ public int lv; // 绛夌骇
}
- public enum RecordType
+
+ public enum EquipOPType
{
- Equip = 0, // 瑁呭
- Decompose = 1 // 鍒嗚В
+ Decompose = 1, // 鍒嗚В
+ Equip = 2, // 瑁呭
}
}
\ No newline at end of file
--
Gitblit v1.8.0