From 1b4b01956de5d072e3281176ff5e219bd5e2b511 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期二, 30 九月 2025 15:26:58 +0800
Subject: [PATCH] Merge branch 'master' of http://mobile.secondworld.net.cn:10010/r/Project_SG_scripts

---
 Main/System/Mail/MailManager.cs |   93 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/Main/System/Mail/MailManager.cs b/Main/System/Mail/MailManager.cs
index 39a03f0..85cb78c 100644
--- a/Main/System/Mail/MailManager.cs
+++ b/Main/System/Mail/MailManager.cs
@@ -2,6 +2,8 @@
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
+using LitJson;
+
 
 public class MailManager : GameSystemManager<MailManager>
 {
@@ -17,13 +19,15 @@
     public Redpoint tabRedpoint1;
     public event Action OnUpdateMailListEvent;// 鏇存柊閭欢鍒楄〃鏁版嵁
     public event Action OnUpdateMailStateChangeEvent;// 鏇存柊閭欢鐘舵�佸彉鏇�
-    public readonly string dateFormat = "yyyy-MM-dd";
+    public readonly string dateFormat = "yyyy.MM.dd";
     public string nowUuid = string.Empty;
+    public int personalMailMaxLimitCount;
     public override void Init()
     {
         tabRedpoint0 = new Redpoint(MainRedDot.MailRepoint, GetTabRedpointId(MailCategory.Personal));
         tabRedpoint1 = new Redpoint(MainRedDot.MailRepoint, GetTabRedpointId(MailCategory.Global));
         DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent;
+        personalMailMaxLimitCount = int.Parse(FuncConfigConfig.Get("PersonalMail").Numerical1);
     }
 
     public override void Release()
@@ -103,11 +107,50 @@
         }
     }
 
-    //杩斿洖鏈夋晥鏈熷ぉ鏁�(姝f暟=宸茶繃鏈熷ぉ鏁帮紝璐熸暟=鍓╀綑澶╂暟)
-    public int GetMailExpiryDays(DateTime createDateTime, int limitDays)
+    //杩斿洖鏈夋晥鏈熷ぉ鏁�(姝f暟=鍓╀綑澶╂暟锛岃礋鏁�=宸茶繃鏈熷ぉ鏁�)
+    public float GetMailExpiryDays(DateTime createDateTime, int limitDays)
     {
         DateTime expiryDate = createDateTime.AddDays(limitDays);
-        return (int)(TimeUtility.ServerNow - expiryDate).TotalDays;
+        TimeSpan remainingTime = expiryDate - TimeUtility.ServerNow;
+        return (float)remainingTime.TotalDays;
+    }
+
+    public string FormatMailExpiryDays(DateTime createDateTime, int limitDays)
+    {
+        string result = string.Empty;
+        float days = GetMailExpiryDays(createDateTime, limitDays);
+        // 闃叉姢锛氬鐞嗗洜瀹㈡埛绔笌鏈嶅姟鍣ㄦ椂闂存埑鐨勫井灏忓樊寮傦紝瀵艰嚧鍓╀綑鏃堕棿鐣ュぇ浜庢湁鏁堟湡涓婇檺鐨勬儏鍐点��
+        // 灏嗚绠楀嚭鐨勫墿浣欏ぉ鏁伴檺鍒跺湪閭欢鐨勬湁鏁堟湡澶╂暟涔嬪唴銆�
+        if (days > limitDays)
+        {
+            days = limitDays;
+        }
+
+        if (days > 1.0f)
+        {
+            // 澶т簬1澶╋細鎸夊悜涓婂彇鏁寸殑澶╂暟鏄剧ず銆�
+            // MathF.Ceiling(1.01f) -> 2.0f
+            int daysRounded = (int)MathF.Ceiling(days);
+            result = Language.Get("Mail07", (int)MathF.Ceiling(days));
+        }
+        else if (days > 0.0f)
+        {
+            // 灏忎簬1澶╋紙浣嗘湭杩囨湡锛夛細鎸夌簿纭殑灏忔椂/鍒嗛挓鏄剧ず銆�
+            TimeSpan t = TimeSpan.FromDays(days);
+            result = Language.Get("Mail12",StringUtility.Contact( " ", Language.Get("Mail13", t.Hours, t.Minutes)));
+        }
+        else
+        {
+            // (棰勭暀)宸茶繃鏈燂細鎸夎礋鏁板悜涓嬪彇鏁达紙鍚戞洿灏忕殑璐熸暟鍙栨暣锛屼互鑾峰緱宸茶繃鏈熷ぉ鏁扮殑鏁存暟缁濆鍊硷級
+            // MathF.Floor(-1.01f) -> -2.0f
+            // MathF.Floor(-0.5f)  -> -1.0f
+            // float expiredDaysFloor = MathF.Floor(days);
+            // int expiredDays = (int)expiredDaysFloor;
+
+            //鐩存帴鏄剧ず宸茶繃鏈�
+            result = Language.Get("Mail11"); ;
+        }
+        return result;
     }
 
 
@@ -123,6 +166,20 @@
         }
         return result;
     }
+
+    public int GetMailCount(MailCategory mailCategory)
+    {
+        var result = new List<string>();
+        foreach (var kvp in mailDataDict)
+        {
+            if (kvp.Value.Category == mailCategory)
+            {
+                result.Add(kvp.Key);
+            }
+        }
+        return result.Count;
+    }
+
 
     public List<string> GetSortMailScrList(MailCategory mailCategory)
     {
@@ -161,6 +218,16 @@
                 IsBind = i.IsBind,
                 UserData = i.UserData
             }).ToList();
+
+            if (!mailData.Items.IsNullOrEmpty())
+            {
+                mailData.Items = mailData.Items
+                    .Where(item => ItemConfig.HasKey((int)item.ItemID)) // 闃叉姢锛岀‘淇濈墿鍝佸瓨鍦�
+                    .OrderByDescending(item => ItemConfig.Get((int)item.ItemID).ItemColor) // 鎸夊搧璐ㄩ檷搴�
+                    .ThenBy(item => item.Count) // 鍝佽川鐩稿悓鎸夋暟閲忓崌搴�
+                    .ToList();
+            }
+
             mailDataDict[mail.GUID] = mailData;
         }
 
@@ -239,7 +306,7 @@
         pack.ReqType = ReqType;
         GameNetSystem.Instance.SendInfo(pack);
     }
-        
+
     //娌℃湁涓�涓彲棰嗗彇鐨勪釜浜洪偖浠�
     public bool IsCanHaveMail()
     {
@@ -273,12 +340,17 @@
     public string GUID;        //閭欢GUID
     public byte Type;        //閭欢绫诲瀷锛屾殏鏃堕粯璁�0
     public string CreateTime;        //鍒涘缓鏃堕棿
-    public DateTime CreateDateTime;
+    public DateTime CreateDateTime;//鍒涘缓鏃堕棿
     public byte LimitDays;        //鏈夋晥澶╂暟
     public string Title;        //鏍囬
     public string Text;        //鍐呭
     public byte MailState;        //閭欢鐘舵�侊細 0-鏈煡锛�1-鏈锛�2-宸茶锛�3-宸查锛�
     public List<MailItemData> Items;        //鐗╁搧淇℃伅
+
+    public bool HasAward()
+    {
+        return Items != null && Items.Count > 0;
+    }
 
     /// <summary>
     /// 鍒ゆ柇鏄惁涓烘ā鏉跨被鍨嬮偖浠�
@@ -320,12 +392,15 @@
 
         try
         {
-            // 鍙傛暟鏍煎紡涓篔SON鏁扮粍锛歔鍙傛暟1, 鍙傛暟2, ...]
-            return JsonUtility.FromJson<List<string>>(Text);
+            List<string> result = JsonMapper.ToObject<List<string>>(Text);
+            // 濡傛灉瑙f瀽缁撴灉涓簄ull锛堜緥濡俆ext鐨勫唴瀹规槸 "null" 瀛楃涓诧級锛屽垯杩斿洖涓�涓┖鍒楄〃浠ラ槻鍚庣画鍑洪敊
+            return result ?? new List<string>();
         }
-        catch
+        catch (Exception ex)
         {
+            Debug.LogError($"浣跨敤 LitJson 瑙f瀽閭欢鍙傛暟澶辫触銆� Text: {Text}, 閿欒: {ex.Message}");
             return new List<string>();
         }
     }
 }
+

--
Gitblit v1.8.0