218 lines
6.0 KiB
C#
218 lines
6.0 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using GCGame;
|
|
using GCGame.Table;
|
|
using Games.GlobeDefine;
|
|
|
|
public class MailData : MonoBehaviour {
|
|
|
|
public enum MailState
|
|
{
|
|
UNREAD,
|
|
READ,
|
|
UNGETITEM,
|
|
GETITEM,
|
|
}
|
|
|
|
public enum MailUpdateType
|
|
{
|
|
UPDATE,
|
|
ADD,
|
|
DEL,
|
|
}
|
|
public class UserMail
|
|
{
|
|
public GC_MAIL_UPDATE.MailSender senderType;
|
|
|
|
public UInt64 key;
|
|
public UInt64 SenderID;
|
|
public string SenderName;
|
|
public string time;
|
|
public string text;
|
|
public int[] itemID = new int[0];
|
|
public int[] itemCount = new int[0];
|
|
public int bReaded = 0;
|
|
public bool bGetItem = false;
|
|
public int[] moneyType = new int[0];
|
|
public int[] moneyCount = new int[0];
|
|
public int sortTime;
|
|
}
|
|
|
|
public const int MailCountMax = 32;
|
|
|
|
public static Dictionary<System.UInt64, UserMail> UserMailMap = new Dictionary<System.UInt64, UserMail>();
|
|
private static ulong m_curPlayGuid = 0;
|
|
|
|
|
|
public delegate void MailDelUpdate(MailUpdateType updateType, UserMail curMail);
|
|
public static MailDelUpdate delMailUpdate;
|
|
|
|
public static void CleanMailData()
|
|
{
|
|
UserMailMap.Clear();
|
|
}
|
|
|
|
public static bool IsHaveUpReadMail()
|
|
{
|
|
foreach (var mailInfo in UserMailMap)
|
|
{
|
|
if (mailInfo.Value.bReaded != 1)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static int GetAllUnLoadMainCount()
|
|
{
|
|
var totalCount = 0;
|
|
foreach (var mailInfo in UserMailMap)
|
|
{
|
|
if (mailInfo.Value.bReaded != 1)
|
|
{
|
|
totalCount++;
|
|
}
|
|
}
|
|
|
|
return totalCount;
|
|
}
|
|
|
|
public static int GetAllMailCount()
|
|
{
|
|
return UserMailMap.Count;
|
|
}
|
|
|
|
public static void UpdateMailData(GC_MAIL_UPDATE data)
|
|
{
|
|
MailUpdateType curUpdateType = MailUpdateType.UPDATE;
|
|
if (m_curPlayGuid != PlayerPreferenceData.LastRoleGUID)
|
|
{
|
|
UserMailMap.Clear();
|
|
}
|
|
|
|
m_curPlayGuid = PlayerPreferenceData.LastRoleGUID;
|
|
|
|
UserMail curMail = null;
|
|
if (UserMailMap.ContainsKey(data.MailGuid))
|
|
{
|
|
curMail = UserMailMap[data.MailGuid];
|
|
curUpdateType = MailUpdateType.UPDATE;
|
|
}
|
|
else
|
|
{
|
|
curMail = new UserMail();
|
|
UserMailMap.Add(data.MailGuid, curMail);
|
|
curUpdateType = MailUpdateType.ADD;
|
|
|
|
if (ChatFrameLogic.Instance())
|
|
{
|
|
ChatFrameLogic.Instance().UpdateRedDotTip();
|
|
}
|
|
if (FriendAndMailRoot.Instance())
|
|
{
|
|
FriendAndMailRoot.Instance().UpdateMailRedTip();
|
|
}
|
|
}
|
|
|
|
if (null == curMail)
|
|
return;
|
|
|
|
curMail.key = data.MailGuid;
|
|
curMail.senderType = (GC_MAIL_UPDATE.MailSender)data.SenderType;
|
|
curMail.SenderID = data.SenderGuid;
|
|
if (curMail.senderType == GC_MAIL_UPDATE.MailSender.MAILSENDER_SYS)
|
|
{
|
|
if (data.HasOrigin && data.Origin == GlobeVar.MAIL_GUILDMAIL_ORIGIN)
|
|
{
|
|
curMail.SenderName = Utils.GetDicByID(4017);
|
|
}
|
|
else
|
|
{
|
|
curMail.SenderName = Utils.GetDicByID(1363);
|
|
}
|
|
if (!string.IsNullOrEmpty(data.TextContent))
|
|
{
|
|
char firstChar = data.TextContent[0];
|
|
if (firstChar != '#')
|
|
{
|
|
curMail.text = data.TextContent;
|
|
}
|
|
else
|
|
{
|
|
curMail.text = StrDictionary.GetServerDictionaryFormatString(data.TextContent);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
curMail.text = "";
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
curMail.SenderName = data.SenderName;
|
|
curMail.text = data.TextContent;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(curMail.text))
|
|
{
|
|
//curMail.text = Utils.StrFilter_Mail(curMail.text);
|
|
//curMail.text = Utils.StrFilter_Abuse(curMail.text);
|
|
}
|
|
|
|
|
|
DateTime startTime = new DateTime(1970, 1, 1);
|
|
DateTime sendDate = new DateTime((long)data.SendTime*10000000L + startTime.Ticks, DateTimeKind.Utc);
|
|
sendDate = sendDate.AddHours(8); //调到北京时间
|
|
//sendDate = sendDate.ToLocalTime();
|
|
curMail.time = sendDate.ToString("yyyy-MM-dd");
|
|
curMail.bReaded = data.ReadTime > 0 ? 1 : 0;
|
|
curMail.itemID = new int[data.ItemIDCount];
|
|
for (int i = 0; i < data.ItemIDCount; ++i)
|
|
{
|
|
curMail.itemID[i] = data.GetItemID(i);
|
|
}
|
|
curMail.itemCount = new int[data.ItemCountCount];
|
|
for (int i = 0; i < data.ItemCountCount; ++i)
|
|
{
|
|
curMail.itemCount[i] = data.GetItemCount(i);
|
|
|
|
Hashtable tab = new Hashtable();
|
|
tab["dataID"] = data.GetItemCount(i);
|
|
tab["type"] = Games.LogicObj.Obj_Fellow.FellowDialogType.GetGameItem;
|
|
Games.Events.EventDispatcher.Instance.SendMessage(Games.Events.EventId.FellowDialogEvent, tab);
|
|
|
|
}
|
|
curMail.moneyType = new int[data.MoneyTypeCount];
|
|
for (int i = 0; i < data.MoneyTypeCount; ++i)
|
|
{
|
|
curMail.moneyType[i] = data.GetMoneyType(i);
|
|
}
|
|
curMail.moneyCount = new int[data.MoneyCountCount];
|
|
for (int i = 0; i < data.MoneyCountCount; ++i)
|
|
{
|
|
curMail.moneyCount[i] = data.GetMoneyCount(i);
|
|
}
|
|
curMail.sortTime = data.SendTime;
|
|
|
|
if (null != delMailUpdate) delMailUpdate(curUpdateType, UserMailMap[data.MailGuid]);
|
|
|
|
if (ChatFrameLogic.Instance()) ChatFrameLogic.Instance().UpdateRedDotTip();
|
|
}
|
|
|
|
public static void DelMail(System.UInt64 mailID)
|
|
{
|
|
if (UserMailMap.ContainsKey(mailID))
|
|
{
|
|
UserMailMap.Remove(mailID);
|
|
}
|
|
|
|
if (null != delMailUpdate) delMailUpdate(MailUpdateType.DEL, null);
|
|
|
|
}
|
|
}
|