using Snxxz.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Text.RegularExpressions;
|
using System.Text;
|
|
using UnityEngine;
|
using System.Linq;
|
|
public class MailItemModel
|
{
|
public uint ItemID; //物品ID
|
|
public int Count; //数量
|
|
public byte IsBind; //是否绑定
|
|
public string UserData; //自定义数据
|
}
|
|
public class MailInfo
|
{
|
public string GUID; //补偿标识
|
|
public string CreateTime; //邮件接收时间
|
|
public string Text; //文字内容
|
|
public byte Count; //当前补偿物品数
|
|
public byte IsRead; //已读状态 0 未读取 1已读取
|
|
public uint Gold; //仙玉
|
|
public uint GoldPaper; //绑定仙玉
|
|
public uint Silver; //铜钱
|
|
public bool isChoose = false;
|
|
public DateTime mailGetTime; //邮件接收时间
|
|
public MailItemModel[] Items = null; //补偿物品信息
|
|
}
|
|
public class MailAllModel
|
{
|
public static MailAllModel _instance;
|
public static MailAllModel Instance
|
{
|
get {
|
if (_instance == null)
|
_instance = new MailAllModel();
|
return _instance;
|
}
|
}
|
|
DailyQuestModel m_dailyModel;
|
DailyQuestModel dailyModel
|
{
|
get { return m_dailyModel ?? (m_dailyModel = ModelCenter.Instance.GetModel<DailyQuestModel>()); }
|
}
|
|
AwardExchangeModel exchangeModel { get { return ModelCenter.Instance.GetModel<AwardExchangeModel>(); } }
|
bool isLogin = true;
|
public MailAllModel()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerDataInit;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
|
}
|
|
private void BeforePlayerDataInit()
|
{
|
isLogin = true;
|
funcType = MailFuncType.Mail;
|
mailModelDict.Clear();
|
timeOrderMailInfo.Clear();
|
mailTitleStr = "";
|
mailContentstr = "";
|
mailSendPersonStr = "";
|
}
|
|
|
private void OnPlayerLoginOk()
|
{
|
isLogin = false;
|
}
|
|
public MailFuncType funcType = MailFuncType.Mail;
|
|
public event Action GetNewMailEvent;
|
public event Action<string, int> CallBackReceiveEvent;
|
public event Action DeleteMailEvent;
|
public event Action MailCntChangeEvent;
|
|
private Dictionary<string, MailInfo> mailModelDict = new Dictionary<string,MailInfo>();
|
private List<MailInfo> timeOrderMailInfo = new List<MailInfo>();
|
private Regex smatch = new Regex(@"<MailTemplate>([^>.\n]*)</MailTemplate>([^>.\n]*)", RegexOptions.Singleline);
|
private Regex smatchSystem = new Regex(@"[\\]*\/[\\]*", RegexOptions.Singleline);
|
|
public string mailTitleStr = "";
|
public string mailContentstr = "";
|
public string mailSendPersonStr = "";
|
|
public int addMailCnt { get; private set; }
|
|
public void ReFreshModel(HA9A1_tagGCQueryCompensationResult mailModel)
|
{
|
DebugEx.Log("刷新邮件数据" + mailModel.Count);
|
if(mailModel.Count > 0)
|
{
|
int preMailCnt = mailModelDict.Count;
|
for (int i = 0; i < mailModel.Count; i++)
|
{
|
if(!mailModelDict.ContainsKey(mailModel.PackList[i].GUID))
|
{
|
MailInfo mailInfo = new MailInfo();
|
mailInfo.GUID = mailModel.PackList[i].GUID;
|
mailInfo.CreateTime = mailModel.PackList[i].CreateTime;
|
mailInfo.mailGetTime = Convert.ToDateTime(UIHelper.GetTime(mailInfo.CreateTime));
|
mailInfo.Text = mailModel.PackList[i].Text;
|
mailInfo.Count = mailModel.PackList[i].Count;
|
mailInfo.IsRead = mailModel.PackList[i].IsRead;
|
mailInfo.Gold = mailModel.PackList[i].Gold;
|
mailInfo.GoldPaper = mailModel.PackList[i].GoldPaper;
|
mailInfo.Silver = mailModel.PackList[i].Silver;
|
mailInfo.Items = new MailItemModel[mailInfo.Count];
|
if (mailInfo.Count > 0)
|
{
|
for (int j = 0; j < mailInfo.Count; j++)
|
{
|
mailInfo.Items[j] = new MailItemModel();
|
mailInfo.Items[j].ItemID = mailModel.PackList[i].Items[j].ItemID;
|
mailInfo.Items[j].Count = (int)mailModel.PackList[i].Items[j].Count;
|
mailInfo.Items[j].IsBind = mailModel.PackList[i].Items[j].IsBind;
|
mailInfo.Items[j].UserData = mailModel.PackList[i].Items[j].UserData;
|
}
|
}
|
mailModelDict.Add(mailInfo.GUID, mailInfo);
|
DeleteTodayDailyMail(mailInfo);
|
}
|
else
|
{
|
MailInfo mailInfo = mailModelDict[mailModel.PackList[i].GUID];
|
mailInfo.GUID = mailModel.PackList[i].GUID;
|
mailInfo.CreateTime = mailModel.PackList[i].CreateTime;
|
mailInfo.mailGetTime = Convert.ToDateTime(UIHelper.GetTime(mailInfo.CreateTime));
|
mailInfo.Text = mailModel.PackList[i].Text;
|
mailInfo.Count = mailModel.PackList[i].Count;
|
mailInfo.IsRead = mailModel.PackList[i].IsRead;
|
mailInfo.Gold = mailModel.PackList[i].Gold;
|
mailInfo.GoldPaper = mailModel.PackList[i].GoldPaper;
|
mailInfo.Silver = mailModel.PackList[i].Silver;
|
mailInfo.Items = null;
|
mailInfo.Items = new MailItemModel[mailInfo.Count];
|
if (mailInfo.Count > 0)
|
{
|
for (int j = 0; j < mailInfo.Count; j++)
|
{
|
mailInfo.Items[j] = new MailItemModel();
|
mailInfo.Items[j].ItemID = mailModel.PackList[i].Items[j].ItemID;
|
mailInfo.Items[j].Count = (int)mailModel.PackList[i].Items[j].Count;
|
mailInfo.Items[j].IsBind = mailModel.PackList[i].Items[j].IsBind;
|
mailInfo.Items[j].UserData = mailModel.PackList[i].Items[j].UserData;
|
}
|
}
|
}
|
|
if (mailModelDict.ContainsKey(mailModel.PackList[i].GUID))
|
{
|
MailInfo info = mailModelDict[mailModel.PackList[i].GUID];
|
string mailTitle = GetMailTitle(info);
|
if(mailTitle.Contains("<gcode>"))
|
{
|
exchangeModel.SetAwardExchangeModel(info.Items);
|
}
|
else if(GetMailType(info) == "CodeRewardMail")
|
{
|
exchangeModel.SetAwardExchangeModel(info.Items);
|
}
|
|
if(!isLogin)
|
{
|
if (info.Count > 0 || info.Gold > 0 || info.GoldPaper > 0
|
|| info.Silver > 0)
|
{
|
SoundPlayer.Instance.PlayUIAudio(740);
|
}
|
}
|
|
}
|
}
|
addMailCnt = mailModelDict.Count - preMailCnt;
|
MailRedPointCtrl();
|
OnTimeOrderMailModel();
|
|
if (GetNewMailEvent != null)
|
GetNewMailEvent();
|
|
if(MailCntChangeEvent != null)
|
{
|
MailCntChangeEvent();
|
}
|
|
|
}
|
|
}
|
|
#region 红点逻辑处理
|
private void MailRedPointCtrl()
|
{
|
|
int sum = 0;
|
foreach(var key in mailModelDict.Keys)
|
{
|
if(mailModelDict[key].IsRead == 0)
|
{
|
sum += 1;
|
}
|
}
|
|
if(sum > 0)
|
{
|
MainRedDot.Instance.redpointMailFunc.count = sum;
|
MainRedDot.Instance.redpointMainMail.count = sum;
|
MainRedDot.Instance.redpointMailFunc.state = RedPointState.Quantity;
|
}
|
else
|
{
|
MainRedDot.Instance.redpointMailFunc.state = RedPointState.None;
|
}
|
|
}
|
#endregion
|
|
public void RecieveMail(HA31A_tagMCGiveCompensationResult receiveMail)
|
{
|
|
if (CallBackReceiveEvent != null)
|
CallBackReceiveEvent(receiveMail.GUID,receiveMail.Result);
|
}
|
|
public void DeleteMail(HA9AA_tagGCDelCompensationResult deleteMail)
|
{
|
if(deleteMail.Result == 1)
|
{
|
DeleteMailData(deleteMail.GUID);
|
if (DeleteMailEvent != null)
|
{
|
DeleteMailEvent();
|
}
|
|
if (MailCntChangeEvent != null)
|
{
|
MailCntChangeEvent();
|
}
|
}
|
}
|
|
|
//按时间给邮件数据排序
|
public void OnTimeOrderMailModel()
|
{
|
timeOrderMailInfo.Clear();
|
foreach(MailInfo info in mailModelDict.Values)
|
{
|
timeOrderMailInfo.Add(info);
|
}
|
if(timeOrderMailInfo.Count > 1)
|
{
|
timeOrderMailInfo.Sort(Compare);
|
}
|
|
}
|
|
public int Compare(MailInfo startTime, MailInfo nextTime)
|
{
|
int startRead = startTime.IsRead;
|
int nextRead = nextTime.IsRead;
|
if(startRead.CompareTo(nextRead) != 0) return startRead.CompareTo(nextRead);
|
|
DateTime curtime = startTime.mailGetTime;
|
DateTime nexttime = nextTime.mailGetTime;
|
if (curtime.CompareTo(nexttime) != 0) return -curtime.CompareTo(nexttime);
|
|
return 0;
|
}
|
|
public List<MailInfo> GetTimeOrderMaillist()
|
{
|
if (timeOrderMailInfo != null)
|
return timeOrderMailInfo;
|
else
|
return null;
|
}
|
|
public void DeleteMailData(string id)
|
{
|
if (mailModelDict.ContainsKey(id))
|
mailModelDict.Remove(id);
|
|
for(int i = 0; i < timeOrderMailInfo.Count; i++)
|
{
|
if(timeOrderMailInfo[i].GUID == id)
|
{
|
timeOrderMailInfo.Remove(timeOrderMailInfo[i]);
|
break;
|
}
|
}
|
MailRedPointCtrl();
|
}
|
|
List<MailInfo> todayDailylist = new List<MailInfo>();
|
List<MailInfo> orderTodayDailylist = new List<MailInfo>();
|
|
public void DeleteTodayDailyMail(MailInfo curInfo)
|
{
|
if (!smatch.IsMatch(curInfo.Text)) return;
|
|
Match curMatch = smatch.Match(curInfo.Text);
|
MailConfig curMailModel = MailConfig.Get(curMatch.Groups[1].Value);
|
if (curMailModel == null || curMailModel.MailType != "TodayDailyTask") return;
|
|
todayDailylist.Clear();
|
foreach (MailInfo info in mailModelDict.Values)
|
{
|
if (smatch.IsMatch(info.Text))
|
{
|
Match match = smatch.Match(info.Text);
|
MailConfig _mailModel = MailConfig.Get(match.Groups[1].Value);
|
if (_mailModel != null)
|
{
|
if (_mailModel.MailType == "TodayDailyTask")
|
{
|
todayDailylist.Add(info);
|
}
|
}
|
}
|
}
|
orderTodayDailylist.Clear();
|
orderTodayDailylist.AddRange(todayDailylist);
|
orderTodayDailylist.Sort(CompareByTime);
|
for(int i = 0; i < orderTodayDailylist.Count - 1; i++)
|
{
|
SendMailDelete(orderTodayDailylist[i].GUID);
|
mailModelDict.Remove(orderTodayDailylist[i].GUID);
|
}
|
}
|
|
public int CompareByTime(MailInfo start,MailInfo next)
|
{
|
DateTime startTime = start.mailGetTime;
|
DateTime nextTime = next.mailGetTime;
|
if (startTime.CompareTo(nextTime) != 0) return startTime.CompareTo(nextTime);
|
|
int startIndex = todayDailylist.IndexOf(start);
|
int nextIndex = todayDailylist.IndexOf(next);
|
if (startIndex.CompareTo(nextIndex) != 0) return startIndex.CompareTo(nextIndex);
|
|
return 0;
|
}
|
|
public void GetReciveMailContent(MailInfo info)
|
{
|
Debug.Log(info.Text);
|
info.Text = smatchSystem.Replace(info.Text, "/");
|
if (smatch.IsMatch(info.Text))
|
{
|
Match match = smatch.Match(info.Text);
|
if(match.Groups.Count > 2)
|
{
|
MailConfig _mailModel = MailConfig.Get(match.Groups[1].Value);
|
List<string> _mailParalist = new List<string>();
|
if (_mailModel != null)
|
{
|
mailTitleStr = _mailModel.Title;
|
string strCont = "";
|
if (match.Groups[2].Value != "")
|
{
|
_mailParalist.Clear();
|
string paraStr = "";
|
paraStr = match.Groups[2].Value.Remove(0, 1);
|
paraStr = paraStr.Remove(paraStr.Length - 1, 1);
|
string[] paraArray = paraStr.Split(',');
|
for (int i = 0; i < paraArray.Length; i++)
|
{
|
string para = paraArray[i].Replace("'", "");
|
para = para.Trim();
|
_mailParalist.Add(para);
|
}
|
|
string[] mailCont = _mailModel.Content.Split(new string[] { "{0}" }, StringSplitOptions.None);
|
|
if (mailCont != null && mailCont.Length > 0 && _mailParalist.Count != mailCont.Length)
|
{
|
DebugEx.Log("参数数量不一致" + info.Text);
|
}
|
|
for (int i = 0; i < mailCont.Length; i++)
|
{
|
if (i < mailCont.Length - 1)
|
{
|
switch (_mailModel.MailType)
|
{
|
case "TodayDailyTask":
|
strCont = StringUtility.Contact(strCont, mailCont[i], GetTodayDailyNotify(info.mailGetTime));
|
break;
|
default:
|
strCont = StringUtility.Contact(strCont, mailCont[i], _mailParalist[i]);
|
break;
|
}
|
}
|
else
|
{
|
strCont = StringUtility.Contact(strCont, mailCont[i]);
|
}
|
|
}
|
|
}
|
|
mailContentstr = strCont;
|
string[] mailContentArray = info.Text.Split(new string[] { "<$_$>" }, StringSplitOptions.RemoveEmptyEntries);
|
if (mailContentArray.Length > 0)
|
{
|
FuncConfigConfig funcMailModel = FuncConfigConfig.Get(mailContentArray[0]);
|
if (funcMailModel != null)
|
mailSendPersonStr = funcMailModel.Numerical1;
|
else
|
mailSendPersonStr = mailContentArray[0];
|
|
}
|
}
|
}
|
else
|
{
|
DebugEx.LogError("服务端下发格式不正确");
|
}
|
}
|
else
|
{
|
DebugEx.Log("不需要解析模板邮件");
|
string[] mailContentArray = info.Text.Split(new string[] { "<$_$>" }, StringSplitOptions.RemoveEmptyEntries);
|
if (mailContentArray.Length > 1)
|
{
|
FuncConfigConfig funcMailModel = FuncConfigConfig.Get(mailContentArray[0]);
|
if (funcMailModel != null)
|
mailSendPersonStr = funcMailModel.Numerical1;
|
else
|
mailSendPersonStr = mailContentArray[0];
|
|
mailTitleStr = mailContentArray[1];
|
|
if(mailContentArray.Length > 2)
|
{
|
string mailDes = mailContentArray[2];
|
mailContentstr = mailDes;
|
}
|
}
|
else
|
{
|
DebugEx.LogError("服务端下发格式不正确");
|
}
|
|
}
|
mailTitleStr = mailTitleStr.Replace("<gcode>","");
|
}
|
|
public string GetMailType(MailInfo info)
|
{
|
if (smatch.IsMatch(info.Text))
|
{
|
Match match = smatch.Match(info.Text);
|
MailConfig _mailModel = MailConfig.Get(match.Groups[1].Value);
|
if (_mailModel != null)
|
{
|
return _mailModel.MailType;
|
}
|
}
|
return string.Empty;
|
}
|
|
public string GetMailTitle(MailInfo info)
|
{
|
if (smatch.IsMatch(info.Text))
|
{
|
Match match = smatch.Match(info.Text);
|
MailConfig _mailModel = MailConfig.Get(match.Groups[1].Value);
|
if (_mailModel != null)
|
{
|
return _mailModel.Title;
|
}
|
}
|
else
|
{
|
string[] mailContentArray = info.Text.Split(new string[] { "<$_$>" }, StringSplitOptions.RemoveEmptyEntries);
|
if (mailContentArray.Length > 0)
|
{
|
return mailContentArray[1];
|
}
|
}
|
return string.Empty;
|
}
|
|
StringBuilder todayDailySB = new StringBuilder();
|
List<int> dailyIdlist = new List<int>();
|
public string GetTodayDailyNotify(DateTime getTime)
|
{
|
dailyIdlist.Clear();
|
todayDailySB.Length = 0;
|
var dayOfWeek = (int)getTime.DayOfWeek;
|
var quests = dailyModel.GetQuestByWeekTime(dayOfWeek % 7);
|
List<int> openTimelist = quests.Keys.ToList();
|
openTimelist.Sort();
|
for(int i = 0; i < openTimelist.Count; i++)
|
{
|
int openTime = openTimelist[i];
|
for (int j = 0;j < quests[openTime].Count; j++)
|
{
|
if(dailyIdlist.Contains(quests[openTime][j]))
|
{
|
continue;
|
}
|
dailyIdlist.Add(quests[openTime][j]);
|
DailyQuestOpenTime dailyQuestOpenTime;
|
dailyModel.TryGetOpenTime(quests[openTime][j], out dailyQuestOpenTime);
|
if (dailyQuestOpenTime.IsValidServerOpenTime())
|
{
|
List<HourMinute> hourMinutelist = dailyQuestOpenTime.GetHourMinuteByWeek(dayOfWeek);
|
if (hourMinutelist != null)
|
{
|
for (int k = 0; k < hourMinutelist.Count; k++)
|
{
|
HourMinute hourMinute = hourMinutelist[k];
|
if (!hourMinute.wholeDay)
|
{
|
var config = DailyQuestConfig.Get(quests[openTime][j]);
|
string openTimeStr = StringUtility.Contact(hourMinute.hourBegin > 9 ? hourMinute.hourBegin.ToString() : "0" + hourMinute.hourBegin, ":", hourMinute.minuteBegin > 9 ? hourMinute.minuteBegin.ToString() : "0" + hourMinute.minuteBegin);
|
string endTimeStr = StringUtility.Contact(hourMinute.hourEnd > 9 ? hourMinute.hourEnd.ToString() : "0" + hourMinute.hourEnd, ":", hourMinute.minuteEnd > 9 ? hourMinute.minuteEnd.ToString() : "0" + hourMinute.minuteEnd);
|
todayDailySB.Append(StringUtility.Contact("【", config.Title, "】", openTimeStr, "-", endTimeStr, "\n"));
|
}
|
}
|
}
|
}
|
}
|
}
|
return todayDailySB.ToString();
|
}
|
|
public void SendReadMailQuest(string id)
|
{
|
CA9A6_tagCGReadCompensation readMail = new CA9A6_tagCGReadCompensation();
|
readMail.GUID = id;
|
GameNetSystem.Instance.SendInfo(readMail);
|
MailRedPointCtrl();
|
}
|
|
public void SendMailDelete(string id)
|
{
|
CA9A7_tagCGDelCompensation askDelete = new CA9A7_tagCGDelCompensation();
|
askDelete.GUID = id;
|
GameNetSystem.Instance.SendInfo(askDelete);
|
}
|
public MailInfo GetMailInfo(string guid)
|
{
|
MailInfo mailInfo = null;
|
mailModelDict.TryGetValue(guid,out mailInfo);
|
return mailInfo;
|
}
|
}
|
|
public enum MailFuncType
|
{
|
Mail,
|
}
|