2023-12-11 18:56:57 +08:00
|
|
|
|
using Framework;
|
|
|
|
|
|
using Gameplay;
|
2023-12-25 16:48:52 +08:00
|
|
|
|
using Gameplay.Common;
|
2023-12-11 18:56:57 +08:00
|
|
|
|
using Gameplay.Net;
|
2024-04-16 14:03:32 +08:00
|
|
|
|
using NLDPB;
|
2023-12-11 18:56:57 +08:00
|
|
|
|
using PhxhSDK;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
public class MailSystem : Singlenton<MailSystem>, IInitable
|
|
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 邮件数据字典
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Dictionary<ulong, MailInfo> DicMail;
|
2024-06-28 17:16:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否有全部邮件
|
|
|
|
|
|
/// </summary>
|
2023-12-11 18:56:57 +08:00
|
|
|
|
public bool isHaveAll;
|
2023-12-12 19:35:47 +08:00
|
|
|
|
|
2024-06-28 17:16:23 +08:00
|
|
|
|
private bool needRefresh = false;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否有新的邮件需要更新
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool NeedRefresh
|
|
|
|
|
|
{
|
|
|
|
|
|
get => needRefresh;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
needRefresh = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-11 18:56:57 +08:00
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
DicMail = new Dictionary<ulong, MailInfo>();
|
2023-12-11 18:56:57 +08:00
|
|
|
|
isHaveAll = false;
|
2024-06-28 17:16:23 +08:00
|
|
|
|
NeedRefresh = false;
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2023-12-25 16:48:52 +08:00
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.HaveNewMail, OnHaveNewMail);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
public void Release()
|
2023-12-25 16:48:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.HaveNewMail, OnHaveNewMail);
|
2023-12-11 18:56:57 +08:00
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
isHaveAll = false;
|
2024-06-28 17:16:23 +08:00
|
|
|
|
NeedRefresh = false;
|
2024-04-16 14:03:32 +08:00
|
|
|
|
DicMail.Clear();
|
2023-12-25 16:48:52 +08:00
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2024-06-28 17:16:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 收到MailInfo的Message,表示有新邮件需要更新
|
|
|
|
|
|
/// </summary>
|
2024-04-16 14:03:32 +08:00
|
|
|
|
private void OnHaveNewMail()
|
2023-12-11 18:56:57 +08:00
|
|
|
|
{
|
2024-06-28 17:16:23 +08:00
|
|
|
|
//NetHelper.RequestMailList(!Instance.isHaveAll);
|
|
|
|
|
|
NeedRefresh = true;
|
2023-12-11 18:56:57 +08:00
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2023-12-11 18:56:57 +08:00
|
|
|
|
public void RemoveMail(ulong id)
|
|
|
|
|
|
{
|
2024-04-15 19:34:15 +08:00
|
|
|
|
if (!DicMail.Remove(id))
|
|
|
|
|
|
DebugUtil.LogError($"移除id为{id}的邮件失败");
|
2023-12-11 18:56:57 +08:00
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加邮件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mail"></param>
|
2023-12-11 18:56:57 +08:00
|
|
|
|
public void AddMail(Mail mail)
|
|
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (DicMail.TryGetValue(mail.Id, out MailInfo mailInfo))
|
|
|
|
|
|
mailInfo.Refresh(mail);
|
2023-12-11 18:56:57 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-04-15 19:34:15 +08:00
|
|
|
|
if (DicMail.Count >= GLConfig.Inst.data.MaxMailCount)
|
2023-12-25 16:48:52 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
MailInfo delectMail = null; // 待删除的邮件信息
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
foreach (MailInfo temp in DicMail.Values)
|
2023-12-25 16:48:52 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (delectMail == temp)
|
|
|
|
|
|
delectMail = temp;
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (temp.EStatus < delectMail.EStatus)
|
2024-04-15 19:34:15 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (temp.EStatus > delectMail.EStatus)
|
2024-04-15 19:34:15 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
delectMail = temp;
|
2024-04-15 19:34:15 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-16 15:03:43 +08:00
|
|
|
|
if (delectMail.SendTime < temp.SendTime)
|
2024-04-15 19:34:15 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2024-04-16 15:03:43 +08:00
|
|
|
|
if (delectMail.SendTime > temp.SendTime)
|
2024-04-15 19:34:15 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
delectMail = temp;
|
2024-04-15 19:34:15 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (temp.Cfg.Id < delectMail.Cfg.Id)
|
2024-04-15 19:34:15 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (temp.Cfg.Id > delectMail.Cfg.Id)
|
2023-12-25 16:48:52 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
delectMail = temp;
|
2024-04-15 19:34:15 +08:00
|
|
|
|
continue;
|
2023-12-25 16:48:52 +08:00
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (delectMail != null)
|
|
|
|
|
|
RemoveMail(delectMail.Id);
|
2023-12-25 16:48:52 +08:00
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
|
|
|
|
|
DicMail[mail.Id] = new(mail);
|
|
|
|
|
|
Instance.isHaveAll = true;
|
2024-06-28 17:16:23 +08:00
|
|
|
|
Instance.NeedRefresh = false;
|
2023-12-11 18:56:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置邮件逻辑状态
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <param name="status"></param>
|
|
|
|
|
|
public void SetStatus(ulong id, MailStatus status)
|
2024-04-15 19:34:15 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (DicMail.TryGetValue(id, out MailInfo singleMail))
|
|
|
|
|
|
singleMail.SetStatus(status);
|
2023-12-11 18:56:57 +08:00
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2023-12-12 19:35:47 +08:00
|
|
|
|
public void HandleIds(ulong id)
|
|
|
|
|
|
{
|
2024-04-15 19:34:15 +08:00
|
|
|
|
if (id == 0) // 全部已领取
|
2023-12-12 19:35:47 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
foreach (MailInfo singleMail in DicMail.Values)
|
2023-12-12 19:35:47 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
singleMail.SetStatus(MailStatus.Cliamed);
|
2023-12-12 19:35:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
else
|
2024-04-16 14:03:32 +08:00
|
|
|
|
SetStatus(id, MailStatus.Cliamed);
|
2023-12-18 19:59:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-16 14:03:32 +08:00
|
|
|
|
public MailInfo GetMail(uint mailID)
|
2023-12-18 19:59:06 +08:00
|
|
|
|
{
|
2024-04-16 14:03:32 +08:00
|
|
|
|
if (DicMail.TryGetValue(mailID, out MailInfo mail))
|
2023-12-18 19:59:06 +08:00
|
|
|
|
return mail;
|
2024-04-15 19:34:15 +08:00
|
|
|
|
else
|
2023-12-18 19:59:06 +08:00
|
|
|
|
{
|
2024-04-15 19:34:15 +08:00
|
|
|
|
DebugUtil.LogError($"你莫得Id为{mailID}的邮件,不要找了");
|
2023-12-18 19:59:06 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2023-12-12 19:35:47 +08:00
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2024-04-16 15:03:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否有可以领取的邮件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2024-04-15 19:34:15 +08:00
|
|
|
|
public bool IsHaveGetMail()
|
2023-12-19 14:19:07 +08:00
|
|
|
|
{
|
2024-04-16 15:03:43 +08:00
|
|
|
|
foreach (MailInfo mailInfo in DicMail.Values)
|
2023-12-19 14:19:07 +08:00
|
|
|
|
{
|
2024-04-16 15:03:43 +08:00
|
|
|
|
if(mailInfo.IsHaveClaim)
|
2023-12-19 14:19:07 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
|
2023-12-19 14:19:07 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2024-04-16 15:03:43 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 清理所有到期邮件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ClearOverTime()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<ulong> listDelId = new();
|
|
|
|
|
|
foreach (MailInfo mailInfo in DicMail.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mailInfo.OverTime <= CommonUtils.GetCurTime(CommonUtils.E_TimeType.Server))
|
|
|
|
|
|
listDelId.Add(mailInfo.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (ulong id in listDelId)
|
|
|
|
|
|
{
|
|
|
|
|
|
Instance.RemoveMail(id);
|
|
|
|
|
|
NetHelper.DeleteMail(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-15 19:34:15 +08:00
|
|
|
|
}
|