//******************************************************************** // 文件名: GameChatHistory.cs // 描述: 聊天历史结构 // 作者: WangZhe // 修改记录: // 2014-5-28 Lijia: 客户端效率优化,把OwnSkillData从class改为struct //******************************************************************** using UnityEngine; using System.Collections.Generic; using System; using Games.GlobeDefine; using GCGame; using GCGame.Table; using Games.LogicObj; using Module.Log; namespace Games.ChatHistory { // 聊天历史条目 public class ChatHistoryItem { public enum LINK_INTDATA_COUNT { ITEM = 6, EQUIP = 9, COPYTEAM = 0, MOVETO = 4, PLAYERINFO = 2, SWORDSMAN = 3, GUILDRECRUIT = 7, } public enum LINK_STRDATA_COUNT { ITEM = 0, EQUIP = 0, COPYTEAM = 0, MOVETO = 0, PLAYERINFO = 0, SWORDSMAN = 0, GUILDRECRUIT = 0, } public void CleanUp() { m_eChannel = GC_CHAT.CHATTYPE.CHAT_TYPE_INVALID; m_SenderGuid = GlobeVar.INVALID_GUID; m_SenderName = ""; m_ServerName = ""; m_ReceiverGuid = GlobeVar.INVALID_GUID; m_ReceiverName = ""; m_ChatInfo = ""; m_Duration = 0; if (null == m_eLinkType) { m_eLinkType = new List(); } if (null == m_IntData) { m_IntData = new List(); } if (null == m_StrData) { m_StrData = new List(); } m_SenderVIPLevel = GlobeVar.INVALID_ID; } public bool IsValid() { return m_SenderGuid != GlobeVar.INVALID_GUID; } public int GetLinkIntDataCountByIndex(int index) { switch (m_eLinkType[index]) { case GC_CHAT.LINKTYPE.LINK_TYPE_ITEM: return (int)LINK_INTDATA_COUNT.ITEM; case GC_CHAT.LINKTYPE.LINK_TYPE_EQUIP: return (int)LINK_INTDATA_COUNT.EQUIP; case GC_CHAT.LINKTYPE.LINK_TYPE_COPYTEAM: return (int)LINK_INTDATA_COUNT.COPYTEAM; case GC_CHAT.LINKTYPE.LINK_TYPE_MOVETO: return (int)LINK_INTDATA_COUNT.MOVETO; case GC_CHAT.LINKTYPE.LINK_TYPE_PLAYERINFO: return (int)LINK_INTDATA_COUNT.PLAYERINFO; case GC_CHAT.LINKTYPE.LINK_TYPE_SWORDSMAN: return (int)LINK_INTDATA_COUNT.SWORDSMAN; case GC_CHAT.LINKTYPE.LINK_TYPE_GUILDCRUITE: return (int)LINK_INTDATA_COUNT.GUILDRECRUIT; default: return 0; } } public int GetLinkStrDataCountByIndex(int index) { switch (m_eLinkType[index]) { case GC_CHAT.LINKTYPE.LINK_TYPE_ITEM: return (int)LINK_STRDATA_COUNT.ITEM; case GC_CHAT.LINKTYPE.LINK_TYPE_EQUIP: return (int)LINK_STRDATA_COUNT.EQUIP; case GC_CHAT.LINKTYPE.LINK_TYPE_COPYTEAM: return (int)LINK_STRDATA_COUNT.COPYTEAM; case GC_CHAT.LINKTYPE.LINK_TYPE_MOVETO: return (int)LINK_STRDATA_COUNT.MOVETO; case GC_CHAT.LINKTYPE.LINK_TYPE_PLAYERINFO: return (int)LINK_STRDATA_COUNT.PLAYERINFO; case GC_CHAT.LINKTYPE.LINK_TYPE_SWORDSMAN: return (int)LINK_STRDATA_COUNT.SWORDSMAN; case GC_CHAT.LINKTYPE.LINK_TYPE_GUILDCRUITE: return (int)LINK_STRDATA_COUNT.GUILDRECRUIT; default: return 0; } } GC_CHAT.CHATTYPE m_eChannel; public GC_CHAT.CHATTYPE EChannel { get { return m_eChannel; } set { m_eChannel = value; } } int m_HeadBGType = -1; public int HeadBGType { get { return m_HeadBGType; } set { m_HeadBGType = value; } } int m_chatPopType = -1; public int ChatPopType { get { return m_chatPopType; } set { m_chatPopType = value; } } //只针对队伍信息是否是系统消息,其它频道不能用来判断是否是系统消息 //181120 可以通过 || 添加别的类型 bool m_isSystem = false; public bool IsSystem { get { return m_isSystem; } set { m_isSystem = value; } } UInt64 m_SenderGuid; public UInt64 SenderGuid { get { return m_SenderGuid; } set { m_SenderGuid = value; } } string m_SenderName; public string SenderName { get { return m_SenderName; } set { m_SenderName = value; } } string m_ServerName = ""; public string ServerName { get { return m_ServerName; } set { m_ServerName = value; } } int m_SenderGuildJob = -1; public int SenderGuildJob { get { return m_SenderGuildJob; } set { m_SenderGuildJob = value; } } int m_SenderLevel; public int SenderLevel { get { return m_SenderLevel; } set { m_SenderLevel = value; } } string m_SenderIcon; public string SenderIcon { get { return m_SenderIcon; } set { m_SenderIcon = value; } } public int SenderPro = 0; UInt64 m_ReceiverGuid; public UInt64 ReceiverGuid { get { return m_ReceiverGuid; } set { m_ReceiverGuid = value; } } string m_ReceiverName; public string ReceiverName { get { return m_ReceiverName; } set { m_ReceiverName = value; } } int m_ReceiverPro; public int ReceiverPro { get { return m_ReceiverPro; } set { m_ReceiverPro = value; } } string m_ChatInfo; public string ChatInfo { get { return m_ChatInfo; } set { m_ChatInfo = value; } } float m_Duration; //冒泡用到的 显示的时间 public float Duration { get { return m_Duration; } set { m_Duration = value; } } List m_eLinkType; public List ELinkType { get { return m_eLinkType; } set { m_eLinkType = value; } } List m_IntData; public List IntData { get { return m_IntData; } set { m_IntData = value; } } List m_StrData; public List StrData { get { return m_StrData; } set { m_StrData = value; } } int m_SenderVIPLevel; public int SenderVIPLevel { get { return m_SenderVIPLevel; } set { m_SenderVIPLevel = value; } } int m_SenderPrivilegeVIP; public int SenderPrivilegeVIP { get { return m_SenderPrivilegeVIP; } set { m_SenderPrivilegeVIP = value; } } public int _RedPacketID = -1; public int _RedPacketType = -1; public bool _ReadTip = false; //msgTime public static string _TimeStart = "[Time="; public static string _TimeEnd = "]"; System.DateTime _MsgTime; public DateTime GetMsgTime() { return _MsgTime; } public void SetRecMsgTime() { if (m_eChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND || m_eChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_TELL) { int startIdx = m_ChatInfo.IndexOf(_TimeStart); if (startIdx < 0) { _MsgTime = System.DateTime.Now; } else { int endIdx = m_ChatInfo.IndexOf(_TimeEnd, startIdx); string valueStr = m_ChatInfo.Substring(startIdx + _TimeStart.Length, endIdx - (startIdx + _TimeStart.Length)); valueStr = valueStr.Replace('*', ' '); m_ChatInfo = m_ChatInfo.Substring(endIdx + _TimeEnd.Length, m_ChatInfo.Length - endIdx - _TimeEnd.Length); if(System.DateTime.TryParse(valueStr,out _MsgTime)) { _MsgTime = System.DateTime.Now; } } } } public void SetSendMsgTime() { if (m_eChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND || m_eChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_TELL) { m_ChatInfo = _TimeStart + System.DateTime.Now.ToString() + _TimeEnd + m_ChatInfo; } } } // 整个聊天历史 保存在playerdata中 public class GameChatHistory { List m_ChatHistoryList = new List(); public List ChatHistoryList { get { return m_ChatHistoryList; } set { m_ChatHistoryList = value; } } List m_ReplyHistoryList = new List(); public List ReplyHistoryList { get { return m_ReplyHistoryList; } set { m_ReplyHistoryList = value; } } public const int ReplyHistoryNum = 6; List[] m_ChannelHistory = new List[(int)GC_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER]; int[] Channel_HistoryCount = { 100, 100, 100, 100, 100, 100, 100, 100, 100,100, 100, 100, 100, 100 }; // 各频道聊天记录上限 顺序和m_ChannelHistory一致 List m_FriendSendList = new List(); public List FriendSendList { get { return m_FriendSendList; } set { m_FriendSendList = value; } } private bool m_HasNewTellChat = false; public bool HasNewTellChat { get { return m_HasNewTellChat; } set { m_HasNewTellChat = value; } } private bool m_HasNewFriendChat = false; public bool HasNewFriendChat { get { return m_HasNewFriendChat; } set { m_HasNewFriendChat = value; } } public GameChatHistory() { ClearData(); } public void OnReceiveChat(GC_CHAT pak) { if (pak != null) { if (pak.Chattype - 1 >= m_ChannelHistory.Length || pak.Chattype - 1 >= Channel_HistoryCount.Length || pak.Chattype - 1 < 0) { return; } if (pak.HasSenderguid) { if (pak.Chattype != (int)GC_CHAT.CHATTYPE.CHAT_TYPE_SYSTEM) { if (pak.Senderguid != GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid) { if (Utils.IsStrFilter_Abuse(pak.Chatinfo)) { pak.Chatinfo = Utils.StrFilter_Abuse(pak.Chatinfo); } } } } else { if (Utils.IsStrFilter_Abuse(pak.Chatinfo)) { pak.Chatinfo = Utils.StrFilter_Abuse(pak.Chatinfo); } } if (m_ChannelHistory[pak.Chattype - 1].Count >= Channel_HistoryCount[pak.Chattype - 1]) { ChatHistoryItem item = m_ChannelHistory[pak.Chattype - 1][0]; m_ChannelHistory[pak.Chattype - 1].RemoveAt(0); m_ChatHistoryList.Remove(item); } // 记录聊天历史 ChatHistoryItem history = new ChatHistoryItem(); history.CleanUp(); //string ChatInfo = ""; if (pak.HasSenderguid) { history.SenderGuid = pak.Senderguid; } if (pak.HasSendername) { history.SenderName = pak.Sendername; } if(pak.HasSenderSerName) { history.ServerName = pak.SenderSerName; } if (pak.HasReceiverguid) { history.ReceiverGuid = pak.Receiverguid; } if (pak.HasReceivername) { history.ReceiverName = pak.Receivername; } history.ChatPopType = pak.HasPopType ?pak.PopType : -1; history.HeadBGType = pak.HasHeadBGType ? pak.HeadBGType : -1; if (pak.HasProfession) { LogModule.DebugLog("Profession:" + pak.Profession); history.SenderIcon = Utils.GetProfessionSpriteName( pak.Profession); history.SenderPro = pak.Profession; } if((pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_TEAM || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_GUILD || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_LOUDSPEAKER || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_CROSSSERSPEAKER) && pak.IsSystem == 1) { history.IsSystem = true; }else { history.IsSystem = false; } if (pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_SYSTEM || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_BATTLE || (pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_TEAM && pak.IsSystem == 1)) { char firstChar = pak.Chatinfo[0]; if (firstChar != '#') { history.ChatInfo = pak.Chatinfo; } else { history.ChatInfo = StrDictionary.GetServerDictionaryFormatString(pak.Chatinfo); } } //夺宝分享走帮派跟世界频道(即便是#开头也要在解析完之后过滤一遍,防止世界或者帮派频道可以用#开头从而输入屏蔽内容) else if (pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_WORLD || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_GUILD) { if(pak.HasIsSystem && pak.IsSystem == 1) { history.ChatInfo = StrDictionary.GetServerDictionaryFormatString(pak.Chatinfo); } else { if (!pak.Chatinfo.StartsWith(ChatVoiceInputLogic._VoiceChatStart)) { if (pak.Chatinfo.StartsWith("#")) { //history.ChatInfo = StrDictionary.GetServerDictionaryFormatString(pak.Chatinfo); history.ChatInfo = Utils.StrFilter_Chat(pak.Chatinfo); } } } } if(string.IsNullOrEmpty(history.ChatInfo)) { history.ChatInfo = pak.Chatinfo; } history.ChatInfo = history.ChatInfo.Replace(" ", " "); history.EChannel = (GC_CHAT.CHATTYPE)pak.Chattype; for (int i = 0; i < pak.linktypeCount; i++ ) { history.ELinkType.Add((GC_CHAT.LINKTYPE)pak.linktypeList[i]); } for (int i = 0; i < pak.intdataList.Count; ++i ) { history.IntData.Add(pak.intdataList[i]); } for (int i = 0; i < pak.strdataList.Count; ++i) { history.StrData.Add(pak.strdataList[i]); } if (pak.HasSenderVIPLevel) { history.SenderVIPLevel = pak.SenderVIPLevel; } if (pak.HasSenderPrivilegeVip) { history.SenderPrivilegeVIP = pak.SenderPrivilegeVip; } if (pak.HasSenderlevel) { history.SenderLevel = pak.Senderlevel; } if(pak.HasGuildjob) { history.SenderGuildJob = pak.Guildjob; } history.SetRecMsgTime(); if(pak.Chattype != (int)GC_CHAT.CHATTYPE.CHAT_TYPE_LOUDSPEAKER && pak.Chattype != (int)GC_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER && pak.Chattype != (int)GC_CHAT.CHATTYPE.CHAT_TYPE_CROSSSERSPEAKER) m_ChannelHistory[pak.Chattype - 1].Add(history); else m_ChannelHistory[(int)GC_CHAT.CHATTYPE.CHAT_TYPE_WORLD].Add(history); m_ChatHistoryList.Add(history); if (pak.HasSenderguid && (pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_NORMAL || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_TEAM || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_WORLD)) { if (pak.Senderguid == Singleton.Instance.MainPlayer.GUID) { Singleton.Instance.MainPlayer.ShowChatBubble(history); } else { Obj_OtherPlayer player = Singleton.GetInstance().FindOtherPlayerInScene(pak.Senderguid); if (player != null) { player.ShowChatBubble(history); } } } // 好友频道消息 //history.SenderGuid = GlobeVar.SYSFRIEND_GUID; //history.SenderName = "1"; if (pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_TELL || pak.Chattype == (int)CG_CHAT.CHATTYPE.CHAT_TYPE_FRIEND_GUILD) { if (pak.Chattype == (int)CG_CHAT.CHATTYPE.CHAT_TYPE_FRIEND_GUILD) { history.EChannel = GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND; history.SenderGuid = 0; history.SenderName = "2"; } if (FriendAndMailRoot.Instance() == null) { if (pak.Senderguid == 0) { if (string.Equals("1", pak.Sendername)) { GameManager.gameManager.PlayerDataPool.ChatHistory.AddFriendChat(pak.Senderguid, pak.Sendername, Utils.GetSysIconName(Utils.SysIconType.Sys), pak.Senderlevel, pak.Senderguid, pak.SenderVIPLevel, pak.SenderPrivilegeVip, history); } else if (string.Equals("2", pak.Sendername)) { GameManager.gameManager.PlayerDataPool.ChatHistory.AddFriendChat(pak.Senderguid, pak.Sendername, Utils.GetSysIconName(Utils.SysIconType.Guild), pak.Senderlevel, pak.Senderguid, pak.SenderVIPLevel, pak.SenderPrivilegeVip, history); } } // 发送者不是玩家自己 else if (Singleton.Instance.MainPlayer.GUID != pak.Senderguid) { GameManager.gameManager.PlayerDataPool.ChatHistory.AddFriendChat(pak.Senderguid, pak.Sendername, Utils.GetProfessionSpriteName(pak.Profession), pak.Senderlevel, pak.Senderguid, pak.SenderVIPLevel, pak.SenderPrivilegeVip, history); //GameManager.gameManager.PlayerDataPool.ChatHistory.AddFriendChat(GlobeVar.SYSFRIEND_GUID, "1", Utils.GetSysIconName(Utils.SysIconType.Sys), 0, GlobeVar.SYSFRIEND_GUID, history); //history.SenderGuid = GlobeVar.SYSFRIEND_GUID; //history.SenderName = "1"; } else { GameManager.gameManager.PlayerDataPool.ChatHistory.AddFriendChat(pak.Receiverguid, pak.Receivername, "", pak.Senderlevel, pak.Senderguid, -1, -1, history); } } PlayerPreferenceData.SetFriendChatHistory(GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList); } if (pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_TELL) { if (pak.HasSenderguid && pak.Senderguid != Singleton.Instance.MainPlayer.GUID) { // 聊天界面关闭或者打开但不是密聊频道时 if (ChatInfoLogic.Instance() == null || (ChatInfoLogic.Instance() != null && ChatInfoLogic.Instance().CurChannelType != ChatInfoLogic.CHANNEL_TYPE.CHAT_TYPE_TELL)) { // 通知ChatFrame显示提示红点 if (ChatFrameLogic.Instance() != null) { ChatFrameLogic.Instance().SetChatTips(true); m_HasNewTellChat = true; } // 如果打开但不是密聊频道 通知聊天界面显示密聊频道标签上的红点 if (ChatInfoLogic.Instance() != null && ChatInfoLogic.Instance().CurChannelType != ChatInfoLogic.CHANNEL_TYPE.CHAT_TYPE_TELL) { //ChatInfoLogic.Instance().m_TellInformSprite.SetActive(true); } } } } if(pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_LOUDSPEAKER || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_ALLSERSPEAKER || pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_CROSSSERSPEAKER) { char firstChar = pak.Chatinfo[0]; if (firstChar == '#' && pak.Senderguid == GlobeVar.INVALID_GUID) { history.ChatInfo = StrDictionary.GetServerDictionaryFormatString(pak.Chatinfo); } else { history.ChatInfo = pak.Chatinfo; } UIManager.ShowUI(UIInfo.HornPanel, delegate (bool bSucess, object param) { if (bSucess) { HornPanelCtr.Instance.PopHornInfoToList(history/*'[' + history.SenderName + ']' + " : " + history.ChatInfo*/); } }); } } } public void AddHistory(ChatHistoryItem history) { m_ChatHistoryList.Add(history); } public void AddReplyHistory(CG_CHAT pak) { if (pak != null) { // 记录历史回复 // 如果重复发言 把之前的记录提前 不新增 foreach (ChatHistoryItem item in m_ReplyHistoryList) { if (item.ChatInfo == pak.Chatinfo) { m_ReplyHistoryList.Remove(item); break; } } ChatHistoryItem history = new ChatHistoryItem(); history.CleanUp(); history.ChatInfo = pak.Chatinfo; history.ELinkType.Add((GC_CHAT.LINKTYPE)pak.Linktype); for (int i = 0; i < pak.intdataList.Count; ++i) { history.IntData.Add(pak.intdataList[i]); } for (int i = 0; i < pak.strdataList.Count; ++i) { history.StrData.Add(pak.strdataList[i]); } if (m_ReplyHistoryList.Count >= ReplyHistoryNum) { m_ReplyHistoryList.RemoveAt(0); } m_ReplyHistoryList.Add(history); } } public void ClearData() { m_ChatHistoryList.Clear(); m_ReplyHistoryList.Clear(); for (int i = 0; i < m_ChannelHistory.Length; i++) { if (m_ChannelHistory[i] == null) { m_ChannelHistory[i] = new List(); } m_ChannelHistory[i].Clear(); } } #region friend chat public const int MAX_FRIEND_CHAT_LIST_CNT = 50; public const int MAX_FRIEND_CHAT_HISTORY_CNT = 100; public const int MAX_SHOW_TIME_SECOND = 30; private List _FriendChatList = null; public List FriendChatList { get { if (_FriendChatList == null) { _FriendChatList = PlayerPreferenceData.GetFriendChatHistory(); } return _FriendChatList; } } public FriendChat GetFriendChat(ulong guid) { FriendChat friendChat = FriendChatList.Find((chatInfo) => { if (chatInfo.ChatGuid == guid) return true; return false; }); return friendChat; } public bool AddFriendChat(ulong guid, string name, string icon, int level, ulong senderGuid, int vip, int privilegeVip, ChatHistoryItem chat) { FriendChat friendChat = GetFriendChat(guid); if (friendChat != null) { if (!string.IsNullOrEmpty(icon)) friendChat.ChatIcon = icon; if (level > 0) { friendChat.ChatLevel = level; } if (vip >= 0) { friendChat.VIPLevel = vip; } if (privilegeVip >= 0) { friendChat.PrivilegeVIP = privilegeVip; } // 因为存在改名的情况,所以每次交谈查看交谈对象是否改过名,并更新。 if (!string.IsNullOrEmpty(name) && GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid != senderGuid && friendChat.ChatName != name) { // 当发送者的名称为 1 或者 2 会代表系统相关 if(name != "1" && name != "2") { friendChat.ChatName = name; GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList[senderGuid].Name = name; } } // 最新信息靠前,玩家信息优先级低于系统信息。 FriendChatList.Remove(friendChat); if (guid == 0) { FriendChatList.Insert(0, friendChat); } else { FriendChatList.Insert(1, friendChat); } } else { friendChat = new FriendChat(); friendChat.ChatGuid = guid; friendChat.ChatName = name; friendChat.ChatIcon = icon; friendChat.ChatLevel = level; if (vip >= 0) { friendChat.VIPLevel = vip; } if (privilegeVip >= 0) { friendChat.PrivilegeVIP = privilegeVip; } friendChat.ChatList = new List(); FriendChatList.Insert(1, friendChat); if (GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList.ContainsKey(guid)) { friendChat.ChatName = GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList[guid].Name; friendChat.ChatIcon = Utils.GetProfessionSpriteName( GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList[guid].Profession); friendChat.ChatLevel = GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList[guid].Level; } else if (GameManager.gameManager.PlayerDataPool.GuildFriendList.RelationDataList.ContainsKey(guid)) { friendChat.ChatName = GameManager.gameManager.PlayerDataPool.GuildFriendList.RelationDataList[guid].Name; friendChat.ChatIcon = Utils.GetProfessionSpriteName(GameManager.gameManager.PlayerDataPool.GuildFriendList.RelationDataList[guid].Profession); friendChat.ChatLevel = GameManager.gameManager.PlayerDataPool.GuildFriendList.RelationDataList[guid].Level; } else if (GameManager.gameManager.PlayerDataPool.HateList.RelationDataList.ContainsKey(guid)) { friendChat.ChatName = GameManager.gameManager.PlayerDataPool.HateList.RelationDataList[guid].Name; friendChat.ChatIcon = Utils.GetProfessionSpriteName(GameManager.gameManager.PlayerDataPool.HateList.RelationDataList[guid].Profession); friendChat.ChatLevel = GameManager.gameManager.PlayerDataPool.HateList.RelationDataList[guid].Level; } else if (GameManager.gameManager.PlayerDataPool.BlackList.RelationDataList.ContainsKey(guid)) { friendChat.ChatName = GameManager.gameManager.PlayerDataPool.BlackList.RelationDataList[guid].Name; friendChat.ChatIcon = Utils.GetProfessionSpriteName(GameManager.gameManager.PlayerDataPool.BlackList.RelationDataList[guid].Profession); friendChat.ChatLevel = GameManager.gameManager.PlayerDataPool.BlackList.RelationDataList[guid].Level; } if (FriendAndMailRoot.Instance() != null) { FriendAndMailRoot.Instance()._FriendRootLogic.UpdateTell(); } } if (chat != null && !string.IsNullOrEmpty(chat.ChatInfo)) { bool isNeedSendTime = false; var timeDelta = (chat.GetMsgTime() - friendChat.LastChatTime).TotalSeconds; if (timeDelta > MAX_SHOW_TIME_SECOND) { FriendChatRecord timeRecord = new FriendChatRecord(); timeRecord.RecordType = FriendChatRecord.RECORD_TYPE.Time; timeRecord.ChatInfo = GCGame.Utils.GetServerDateTime().ToString(); friendChat.ChatList.Add(timeRecord); isNeedSendTime = true; } friendChat.LastChatTime = System.DateTime.Now; FriendChatRecord chatRecord = new FriendChatRecord(); if (senderGuid == 0) { if (name == "1") { chatRecord.RecordType = FriendChatRecord.RECORD_TYPE.SysChat; } else if (name == "2") { chatRecord.RecordType = FriendChatRecord.RECORD_TYPE.GuideChat; } friendChat.SetNewRecordChecked(false); } else { if (senderGuid == guid) { chatRecord.RecordType = FriendChatRecord.RECORD_TYPE.OtherChat; friendChat.SetNewRecordChecked(false); } else { chatRecord.RecordType = FriendChatRecord.RECORD_TYPE.MyChat; friendChat.SetNewRecordChecked(true); } } chatRecord.ChatInfo = chat.ChatInfo; chatRecord._HeadType = chat.HeadBGType; chatRecord._ChatPopType = chat.ChatPopType; friendChat.ChatList.Add(chatRecord); return isNeedSendTime; } return false; } public bool IsNeedInsertTime(ulong guid) { FriendChat friendChat = GetFriendChat(guid); if (friendChat != null) { var timeDelta = (System.DateTime.Now - friendChat.LastChatTime).TotalSeconds; if (timeDelta > MAX_SHOW_TIME_SECOND) { return true; } else { return false; } } else { return true; } } #endregion #region chat checked tips private List _UnCheckedChat = new List(); public void AddUncheckedChat(ulong guid) { if (!_UnCheckedChat.Contains(guid)) _UnCheckedChat.Add(guid); if (ChatFrameLogic.Instance()) ChatFrameLogic.Instance().UpdateRedDotTip(); } public void RemoveUncheckedChat(ulong guid) { if (_UnCheckedChat.Contains(guid)) _UnCheckedChat.Remove(guid); } public bool IsHaveUnCheckChat() { return _UnCheckedChat.Count > 0; } public int GetAllUnCheckedChatCount() { return _UnCheckedChat.Count; } #endregion } public class LastSpeaker { public void CleanUp() { m_Guid = GlobeVar.INVALID_GUID; m_Name = ""; } public bool IsValid() { return m_Guid != GlobeVar.INVALID_GUID; } UInt64 m_Guid; public UInt64 Guid { get { return m_Guid; } set { m_Guid = value; } } string m_Name; public string Name { get { return m_Name; } set { m_Name = value; } } } public class LastSpeakerRecord { List m_LastSpeakerList = new List(); public List LastSpeakerList { get { return m_LastSpeakerList; } set { m_LastSpeakerList = value; } } public LastSpeaker Add(UInt64 guid, string name) { if (m_LastSpeakerList.Count >= GlobeVar.MAX_LAST_SPEAKERS) { m_LastSpeakerList.RemoveAt(0); } LastSpeaker speaker = new LastSpeaker(); speaker.CleanUp(); speaker.Guid = guid; speaker.Name = name; m_LastSpeakerList.Add(speaker); return speaker; } public bool IsExist(UInt64 guid) { for (int i = 0; i < m_LastSpeakerList.Count; i++ ) { if (m_LastSpeakerList[i].Guid == guid) { return true; } } return false; } public void ClearData() { m_LastSpeakerList.Clear(); } } public class FriendChatRecord { public enum RECORD_TYPE { Time = 1, OtherChat, MyChat, SysChat, GuideChat } public RECORD_TYPE RecordType;//1time, 2selfsend,3targetsend public string ChatInfo; public int _ReadTip; public int _HeadType = -1; public int _ChatPopType = -1; public ChatHistoryItem _TempChatHistory; } public class FriendChat { public ulong ChatGuid = GlobeVar.INVALID_GUID; public string ChatName = ""; public string ChatIcon = ""; public int ChatLevel = 0; public int ChatCombat = 0; public int VIPLevel = 0; public int PrivilegeVIP = 0; public int OnlineState = (int)CharacterDefine.RELATION_TYPE.ONLINE; public System.DateTime LastChatTime; private bool _NewRecordChecked = true; // 是否已经检查过新的信息 public bool NewRecordChecked { get { return _NewRecordChecked; } } public void SetNewRecordChecked(bool isChecked) { _NewRecordChecked = isChecked; if (!NewRecordChecked) { GameManager.gameManager.PlayerDataPool.ChatHistory.AddUncheckedChat(ChatGuid); } else { GameManager.gameManager.PlayerDataPool.ChatHistory.RemoveUncheckedChat(ChatGuid); } } public List ChatList; public void ClearChatRecord() { LastChatTime = new DateTime(); ChatList.Clear(); } } }