1916 lines
82 KiB
C#
1916 lines
82 KiB
C#
using Thousandto.Code.Center;
|
||
using Thousandto.Plugins.Common;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using Thousandto.Core.RootSystem;
|
||
using Thousandto.Core.Base;
|
||
|
||
using System;
|
||
using Thousandto.Cfg.Data;
|
||
using Thousandto.Code.Global;
|
||
using System.Text;
|
||
using MSG_Chat;
|
||
|
||
namespace Thousandto.Code.Logic
|
||
{
|
||
/// <summary>
|
||
/// UIEntergameForm的逻辑处理类
|
||
/// </summary>
|
||
public partial class ChatSystem
|
||
{
|
||
private ChatInfo _chatInfo = null;
|
||
//离线消息
|
||
private List<MSG_Chat.ChatResInfo> _leaveMsgList = new List<MSG_Chat.ChatResInfo>();
|
||
private Dictionary<int, List<LeaveMsg>> _publicLeaveMsgDic = new Dictionary<int, List<LeaveMsg>>();
|
||
|
||
private List<string> _cacheRobotChatList = new List<string>();
|
||
|
||
private int[] _localLeavelChannels = { (int)ChatChanelType.SYSTEM, (int)ChatChanelType.TEAM, (int)ChatChanelType.JOINTEAM, (int)ChatChanelType.CURRENT };
|
||
private Dictionary<int, List<LeaveMsg>> _localLeavelMsgDic = new Dictionary<int, List<LeaveMsg>>();
|
||
|
||
private const int MAM_ROBOT_CHATCOUNT = 10;
|
||
public bool printSystemMsg = false;
|
||
|
||
//翻译消息缓存
|
||
private List<TranslateInfo> _translateCache = new List<TranslateInfo>(100);
|
||
|
||
public TranslateInfo GetTranslateInfo(string time)
|
||
{
|
||
TranslateInfo info = null;
|
||
if (_translateCache != null)
|
||
{
|
||
for (int i = 0; i < _translateCache.Count; i++)
|
||
{
|
||
if (_translateCache[i].receiveTime == time)
|
||
{
|
||
info = _translateCache[i];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return info;
|
||
}
|
||
/// <summary>
|
||
/// 发送聊天消息
|
||
/// </summary>
|
||
/// <param name="channel">频道</param>
|
||
/// <param name="recvId">接收者</param>
|
||
/// <param name="chatType">发送内容类型,如:文本、语音 (图片算做文本)</param>
|
||
public void SendMessage(ChatInfo info, bool isPrivateChat = false)
|
||
{
|
||
if (CacheSendNodes.Count > 0)
|
||
{
|
||
string content = ChatParse.GetTransferContent(CacheSendNodes, isPrivateChat);
|
||
MSG_Chat.ChatReqCS req = new MSG_Chat.ChatReqCS();
|
||
req.chattype = info.ChatType;
|
||
req.recRoleId = info.Receiver;
|
||
req.condition = content;
|
||
req.chatchannel = info.Channel;
|
||
req.Send();
|
||
}
|
||
for (int i = CacheSendNodes.Count - 1; i >= 0; i--)
|
||
{
|
||
var node = CacheSendNodes[i];
|
||
if (isPrivateChat)
|
||
{
|
||
if (node != null && node.isPrivateChatNode)
|
||
{
|
||
GameCenter.ChatSystem.CacheSendNodes.RemoveAt(i);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GameCenter.ChatSystem.CacheSendNodes.RemoveAt(i);
|
||
}
|
||
}
|
||
}
|
||
|
||
public void SendGuildQuickMsg(string content)
|
||
{
|
||
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
||
if (lp == null)
|
||
{
|
||
return;
|
||
}
|
||
MSG_Chat.ChatReqCS req = new MSG_Chat.ChatReqCS();
|
||
req.chattype = 0;
|
||
req.recRoleId = lp.GuildID;
|
||
req.condition = content;
|
||
req.chatchannel = 1;
|
||
req.Send();
|
||
}
|
||
|
||
#region //数据处理
|
||
public void Send(string content, ulong recevePlayerId, ChatChanelType channelType, ChatType msgType = ChatType.TEXT)
|
||
{
|
||
//UnityEngine.Debug.Log(string.Format("发送消息 id={0} content={1}", recevePlayerId, content));
|
||
MSG_Chat.ChatReqCS msg = new MSG_Chat.ChatReqCS();
|
||
msg.chattype = (int)msgType;
|
||
msg.chatchannel = (int)channelType;
|
||
msg.condition = content;
|
||
msg.recRoleId = recevePlayerId;
|
||
|
||
msg.Send();
|
||
}
|
||
|
||
private void copy(ChatInfo chatInfo, MSG_Chat.ChatResInfo data)
|
||
{
|
||
|
||
chatInfo.ChatType = data.chattype;
|
||
chatInfo.SendId = data.chater;
|
||
chatInfo.SendName = data.chatername;
|
||
chatInfo.SendVipLevel = data.vipLv;
|
||
chatInfo.Receiver = data.receiver;
|
||
chatInfo.ReceiverName = data.receivername;
|
||
chatInfo.RecvVipLevel = data.receiverVipLv;
|
||
chatInfo.Content = data.condition;
|
||
chatInfo.Channel = data.chatchannel;
|
||
chatInfo.SenderOcc = data.occ;
|
||
if(data.head != null)
|
||
{
|
||
chatInfo.HeadId = data.head.fashionHead;
|
||
chatInfo.HeadFrameId = data.head.fashionFrame;
|
||
chatInfo.HeadPicID = data.head.customHeadPath;
|
||
chatInfo.ShowHeadPic = data.head.useCustomHead;
|
||
}
|
||
chatInfo.ChatBgId = data.chatBgId;
|
||
}
|
||
|
||
private void copy(ChatInfo chatInfo, MSG_Chat.PersonalChatNotice data)
|
||
{
|
||
|
||
chatInfo.ChatType = 0;
|
||
chatInfo.SendId = data.chater;
|
||
chatInfo.SendName = data.chatername;
|
||
chatInfo.SendVipLevel = data.vipLv;
|
||
chatInfo.SenderLevel = data.chaterlevel;
|
||
if (data.head != null)
|
||
{
|
||
chatInfo.HeadId = data.head.fashionHead;
|
||
chatInfo.HeadFrameId = data.head.fashionFrame;
|
||
chatInfo.HeadPicID = data.head.customHeadPath;
|
||
chatInfo.ShowHeadPic = data.head.useCustomHead;
|
||
}
|
||
chatInfo.ChatBgId = data.chatBgId;
|
||
|
||
string format = null;
|
||
List<string> paramList = new List<string>();
|
||
try
|
||
{
|
||
//转语言
|
||
format = DeclareMessageString.Get(data.content);
|
||
|
||
for (int i = 0; i < data.value.Count; ++i)
|
||
{
|
||
var paramStr = CommonUtils.ConvertParamStruct(data.value[i].mark, data.value[i].paramsValue);
|
||
if (paramStr != null)
|
||
paramList.Add(paramStr);
|
||
}
|
||
if (paramList.Count > 0)
|
||
chatInfo.Content = string.Format(format, paramList.ToArray());
|
||
else
|
||
chatInfo.Content = format;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
UnityEngine.Debug.LogException(ex);
|
||
UnityEngine.Debug.LogError(format + " -- arg count:" + paramList.Count);
|
||
}
|
||
|
||
|
||
chatInfo.Channel = data.channel;
|
||
chatInfo.SenderOcc = data.occ;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region //消息接收
|
||
public void GS2U_ChatResSC(MSG_Chat.ChatResInfo result,bool isHistory = false, bool isTranslate = false, string receiveTime = "", bool isRobot = false)
|
||
{
|
||
//CacheRecvNodes.Clear();
|
||
if (ChatTool == null)
|
||
{
|
||
return;
|
||
}
|
||
if (!isHistory)
|
||
{
|
||
if (result.condition.Contains("<t=4>"))
|
||
{
|
||
ulong id = GameCenter.GameSceneSystem.GetLocalPlayerID();
|
||
if (id == result.chater)
|
||
{
|
||
GameCenter.MsgPromptSystem.ShowPrompt(Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_ZUOBIAO_SUCC));
|
||
}
|
||
}
|
||
}
|
||
ChatInfo info = new ChatInfo();
|
||
if (result.chater == 0)
|
||
{
|
||
info.IsRobot = true;
|
||
}
|
||
copy(info, result);
|
||
|
||
if (!isTranslate)
|
||
{
|
||
ulong lpId = GameCenter.GameSceneSystem.GetLocalPlayerID();
|
||
//不是翻译数据
|
||
Guid guid = Guid.NewGuid();
|
||
info.ReceiveTime = guid.ToString();//GameCenter.HeartSystem.ServerTime;
|
||
//<t=0>,,烧死策划烧死策划烧死策划烧死策划烧死策划烧死策划烧死策划烧死策划</t>
|
||
if (lpId != result.chater && result.condition.Contains("<t=0>"))
|
||
{
|
||
ChatResInfo translateMsg = new ChatResInfo();
|
||
translateMsg.chattype = result.chattype;
|
||
translateMsg.chatchannel = result.chatchannel;
|
||
translateMsg.chater = result.chater;
|
||
translateMsg.chatername = result.chatername;
|
||
translateMsg.vipLv = result.vipLv;
|
||
translateMsg.receiver = result.receiver;
|
||
translateMsg.receivername = result.receivername;
|
||
translateMsg.receiverVipLv = result.receiverVipLv;
|
||
translateMsg.condition = result.condition;
|
||
translateMsg.occ = result.occ;
|
||
translateMsg.chaterlevel = result.chaterlevel;
|
||
translateMsg.receiverLevel = result.receiverLevel;
|
||
translateMsg.head = new MSG_Common.HeadAttribute();
|
||
if (result.head != null)
|
||
{
|
||
translateMsg.head.fashionHead = result.head.fashionHead;
|
||
translateMsg.head.fashionFrame = result.head.fashionFrame;
|
||
translateMsg.head.customHeadPath = result.head.customHeadPath;
|
||
translateMsg.head.useCustomHead = result.head.useCustomHead;
|
||
}
|
||
translateMsg.chatBgId = result.chatBgId;
|
||
translateMsg.chaterSid = result.chaterSid;
|
||
|
||
//生成翻译缓存
|
||
TranslateInfo translate = new TranslateInfo();
|
||
translate.msg = translateMsg;
|
||
translate.isHistory = isHistory;
|
||
translate.receiveTime = info.ReceiveTime;
|
||
_translateCache.Add(translate);
|
||
if (_translateCache.Count > 99)
|
||
{
|
||
_translateCache.RemoveAt(0);
|
||
}
|
||
}
|
||
if (result.condition.Contains("<t=0>") && !isRobot && result.systemId == 0)
|
||
{
|
||
info.canTranslate = true;
|
||
}
|
||
if (result.systemId != 0)
|
||
{
|
||
info.Content = DeclareMessageString.Get(result.systemId);
|
||
result.condition = info.Content;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
info.ReceiveTime = receiveTime;
|
||
info.IsTranslate = true;
|
||
}
|
||
|
||
//替换vip等级为月卡等级
|
||
//result.vipLv = result.moonandOver;
|
||
info.VipLevel = result.vipLv;
|
||
info.MoonardCard = 0;
|
||
info.SenderLevel = result.chaterlevel;
|
||
info.Sid = result.chaterSid;
|
||
if (isHistory)
|
||
{
|
||
info.IsRead = true;
|
||
}
|
||
|
||
if (result.chatchannel == (int)ChatChanelType.SYSTEM)
|
||
{
|
||
result.condition = ParseSystemMsg(result.condition);
|
||
if (printSystemMsg)
|
||
{
|
||
UnityEngine.Debug.LogError(result.condition);
|
||
printSystemMsg = false;
|
||
}
|
||
}
|
||
|
||
List<ChatNode> nodes = ChatParse.ParseContent(result.condition);
|
||
|
||
//检查可链接的跑马灯内容,拆分node,以便展示
|
||
nodes = CheckUrlMarquee(nodes);
|
||
|
||
//系统频道不去做屏蔽字判断
|
||
if (result.chater > CHATER_SHIELD_ID || isRobot)
|
||
{
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
if (!string.IsNullOrEmpty(nodes[i].Param1) && nodes[i].Type != (int)TNodeType.Position)
|
||
nodes[i].Param1 = WordFilter.ReplaceKeyWords(nodes[i].Param1);
|
||
}
|
||
}
|
||
|
||
if (result.chattype == (int)ChatType.AUDIO)
|
||
{
|
||
string[] keyAndLen = result.condition.Split('|');
|
||
nodes = ChatParse.ParseContent(string.Format("<t={0}>,{1},,</t>", (int)TNodeType.Audio, keyAndLen[1]));
|
||
//设置接收到的语音序列id
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
if (nodes[i].Type == (int)TNodeType.Audio)
|
||
{
|
||
nodes[i].VoiceKey = keyAndLen[0];
|
||
//本人发送的语音,在发送时就保存起来了,不需要在这里保存
|
||
if (result.chater != GameCenter.GameSceneSystem.GetLocalPlayerID())
|
||
{
|
||
nodes[i].Param3 = "" + ++VoiceIndex;
|
||
}
|
||
else
|
||
{
|
||
nodes[i].Param3 = "" + LocalVoiceIndex;
|
||
//自己的语音不显示红点
|
||
nodes[i].EnableRedPoint(false);
|
||
}
|
||
|
||
//保存key和voiceIndex的关系
|
||
if (!_voiceKeyToVoiceData.ContainsKey(nodes[i].VoiceKey))
|
||
{
|
||
_voiceKeyToVoiceData.Add(nodes[i].VoiceKey, nodes[i].Param3);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//先取一个字体风格,用来计算字符长度
|
||
object label = GetLabelSkin(0);
|
||
|
||
bool isSelf = false;
|
||
|
||
//插入私聊数据
|
||
if (result.chatchannel == (int)ChatChanelType.PERSONAL)
|
||
{
|
||
List<ChatNode> data = (List<ChatNode>)ChatTool.calcMutiLine(result.chatchannel, nodes, label, info.IsSystemMsg ? ChatSystem.MAX_MAIN_SYS_CHAT_LINE_WIDTH : ChatSystem.MAX_MAIN_CHAT_LINE_WIDTH);
|
||
info.ChatDatas = data;
|
||
|
||
ChatPrivateInfo pInfo = new ChatPrivateInfo();
|
||
|
||
//如果发送者是本人,则key设置为接收人的id
|
||
if (result.chater == GameCenter.GameSceneSystem.GetLocalPlayerID())
|
||
{
|
||
pInfo.ID = result.receiver;
|
||
pInfo.Name = result.receivername;
|
||
pInfo.Occ = result.occ;
|
||
pInfo.Level = result.receiverLevel;
|
||
isSelf = true;
|
||
}
|
||
else
|
||
{
|
||
pInfo.ID = result.chater;
|
||
pInfo.Name = result.chatername;
|
||
pInfo.Occ = result.occ;
|
||
pInfo.Level = result.receiverLevel;
|
||
}
|
||
|
||
pInfo.SendId = result.chater;
|
||
|
||
pInfo.HasUnReadMsg = true;
|
||
pInfo.ReceiveTime = info.ReceiveTime;
|
||
pInfo.IsTranslate = info.IsTranslate;
|
||
|
||
////私聊
|
||
//if ( GameCenter.FriendSystem.FriendPanelEnable )
|
||
//{
|
||
// //GameCenter.FriendSystem.ReqGetRelationList( FriendType.Recent );
|
||
//}
|
||
//else
|
||
//{
|
||
// GameCenter.MainFunctionSystem.SetAlertFlag( FunctionStartIdCode.Sociality, true );
|
||
//}
|
||
//存储私聊数据
|
||
if (!isTranslate)
|
||
GameCenter.ChatPrivateSystem.CachePrivateData(info, pInfo.ID);
|
||
else
|
||
GameCenter.ChatPrivateSystem.CacheTranslateInfo(info);
|
||
//检测好友红点
|
||
GameCenter.ChatPrivateSystem.CheckRedPointShow();
|
||
//发送刷新私聊界面的事件
|
||
GameCenter.PushFixEvent((int)LogicEventDefine.EID_EVENT_CHAT_PRIVATE_REFRESH, pInfo);
|
||
}
|
||
else
|
||
{
|
||
info.ChatDatas = (List<ChatNode>)ChatTool.calcMutiLine(result.chatchannel, nodes, label, info.IsSystemMsg ? MAX_MAIN_SYS_CHAT_LINE_WIDTH : MAX_MAIN_CHAT_LINE_WIDTH);//CacheRecvNodes;
|
||
|
||
for (int i = 0; i < info.ChatDatas.Count; i++)
|
||
{
|
||
if (info.ChatDatas[i].Type == (int)TNodeType.Position)
|
||
{
|
||
info.ChatDatas[i].Param1 = string.Format("<{0}>", info.ChatDatas[i].Param1);
|
||
}
|
||
}
|
||
|
||
InsertData(info.Channel, info);
|
||
|
||
//冒险频道内容不显示在综合,系统也不显示在综合
|
||
if (result.chatchannel != (int)ChatChanelType.Experience && result.chatchannel != (int)ChatChanelType.SYSTEM)
|
||
InsertData((int)ChatChanelType.ALL, info);
|
||
|
||
//小聊天面板需要构造 [频道]vip名字: 结构
|
||
InsertNodes(nodes, result.chatchannel, result.vipLv, 0, result.chatername, result.chater, isSelf?result.receivername: null, result.chaterSid);
|
||
|
||
var miniPanelData = ((List<ChatNode>)ChatTool.calcMutiLine(result.chatchannel, nodes, label, MAX_MINI_CHAT_LINE_WIDTH));
|
||
for (int i = 0; i < miniPanelData.Count; i++)
|
||
{
|
||
if (miniPanelData[i].Type == (int)TNodeType.Position)
|
||
{
|
||
miniPanelData[i].Param1 = string.Format("<{0}>", miniPanelData[i].Param1);
|
||
}
|
||
}
|
||
//小聊天面板不显示冒险信息
|
||
bool needShowInMiniChatForm = false;
|
||
if (result.chatchannel != (int)ChatChanelType.Experience && result.chatchannel != (int)ChatChanelType.SYSTEM)
|
||
{
|
||
needShowInMiniChatForm = true;
|
||
}
|
||
if (needShowInMiniChatForm && !isTranslate)
|
||
insertData((int)ChatChanelType.MINI, miniPanelData.ToArray(), MAX_MSG_COUNT_MINI);
|
||
|
||
if(result.chatchannel == (int)ChatChanelType.PERSONAL)
|
||
{
|
||
//需要在除主播、系统频道外的频道,显示私聊消息
|
||
InsertData((int)ChatChanelType.GUILD, info);
|
||
InsertData((int)ChatChanelType.TEAM, info);
|
||
InsertData((int)ChatChanelType.WORLD, info);
|
||
InsertData((int)ChatChanelType.CURRENT, info);
|
||
InsertData((int)ChatChanelType.Friend, info);
|
||
}
|
||
info.IsShowMini = needShowInMiniChatForm;
|
||
//发送刷新界面的事件
|
||
GameCenter.PushFixEvent((int)LogicEventDefine.EID_EVENT_CHAT_REFRESH, info);
|
||
|
||
//只有组队频道才有弹幕
|
||
if (result.chatchannel == (int)ChatChanelType.TEAM)
|
||
{
|
||
//GameCenter.PushFixEvent((int)UIEventDefine.UIDanMuForm_OPEN, info);
|
||
}
|
||
|
||
//公会消息,刷新主界面公会聊天按钮红点
|
||
if (result.chatchannel == (int)ChatChanelType.GUILD)
|
||
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_GUILD_CHAT_REDPOINT_REFRESH);
|
||
}
|
||
}
|
||
|
||
//新的带转语言的聊天消息处理
|
||
public void GS2U_PersonalChatNotice(MSG_Chat.PersonalChatNotice result, bool isRobot = false)
|
||
{
|
||
ChatInfo info = new ChatInfo();
|
||
|
||
copy(info, result);
|
||
|
||
if (result.channel == (int)ChatChanelType.SYSTEM || result.channel == (int)ChatChanelType.GUILD)
|
||
{
|
||
info.Content = ParseSystemMsg(info.Content);
|
||
}
|
||
|
||
//替换vip等级为月卡等级
|
||
//result.vipLv = result.moonandOver;
|
||
info.VipLevel = result.vipLv;
|
||
info.MoonardCard = result.moonandOver;
|
||
info.SenderLevel = result.chaterlevel;
|
||
List<ChatNode> nodes = ChatParse.ParseContent(info.Content, info.SendId);
|
||
|
||
//检查可链接的跑马灯内容,拆分node,以便展示
|
||
nodes = CheckUrlMarquee(nodes);
|
||
|
||
//系统频道不去做屏蔽字判断
|
||
if (result.chater > CHATER_SHIELD_ID || isRobot)
|
||
{
|
||
if (result.channel != (int)ChatChanelType.JOINTEAM)
|
||
{
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
if (!string.IsNullOrEmpty(nodes[i].Param1))
|
||
nodes[i].Param1 = WordFilter.ReplaceKeyWords(nodes[i].Param1);
|
||
}
|
||
}
|
||
}
|
||
|
||
//先取一个字体风格,用来计算字符长度
|
||
object label = GetLabelSkin(0);
|
||
|
||
{
|
||
info.ChatDatas = (List<ChatNode>)ChatTool.calcMutiLine(result.channel, nodes, label, info.IsSystemMsg ? MAX_MAIN_SYS_CHAT_LINE_WIDTH : MAX_MAIN_CHAT_LINE_WIDTH);//CacheRecvNodes;
|
||
|
||
InsertData(info.Channel, info);
|
||
|
||
//冒险频道内容不显示在综合,系统也不显示在综合
|
||
if (result.channel != (int)ChatChanelType.Experience && result.channel != (int)ChatChanelType.SYSTEM)
|
||
InsertData((int)ChatChanelType.ALL, info);
|
||
|
||
//小聊天面板需要构造 [频道]vip名字: 结构
|
||
InsertNodes(nodes, result.channel, result.vipLv, result.moonandOver, result.chatername, result.chater, null);
|
||
|
||
var miniPanelData = ((List<ChatNode>)ChatTool.calcMutiLine(result.channel, nodes, label, MAX_MINI_CHAT_LINE_WIDTH));
|
||
//小聊天面板不显示冒险信息
|
||
bool needShowInMiniChatForm = result.channel != (int)ChatChanelType.Experience;
|
||
if (needShowInMiniChatForm)
|
||
insertData((int)ChatChanelType.MINI, miniPanelData.ToArray(), MAX_MSG_COUNT_MINI);
|
||
|
||
if (result.channel == (int)ChatChanelType.PERSONAL)
|
||
{
|
||
//需要在除主播、系统频道外的频道,显示私聊消息
|
||
InsertData((int)ChatChanelType.GUILD, info);
|
||
InsertData((int)ChatChanelType.TEAM, info);
|
||
InsertData((int)ChatChanelType.WORLD, info);
|
||
InsertData((int)ChatChanelType.CURRENT, info);
|
||
InsertData((int)ChatChanelType.Friend, info);
|
||
}
|
||
|
||
if (needShowInMiniChatForm)
|
||
{
|
||
//发送刷新界面的事件
|
||
GameCenter.PushFixEvent((int)LogicEventDefine.EID_EVENT_CHAT_REFRESH, info);
|
||
}
|
||
|
||
//只有组队频道才有弹幕
|
||
if (result.channel == (int)ChatChanelType.TEAM)
|
||
{
|
||
//GameCenter.PushFixEvent((int)UIEventDefine.UIDanMuForm_OPEN, info);
|
||
}
|
||
|
||
//公会消息,刷新主界面公会聊天按钮红点
|
||
if (result.channel == (int)ChatChanelType.GUILD)
|
||
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_GUILD_CHAT_REDPOINT_REFRESH);
|
||
}
|
||
}
|
||
|
||
|
||
private void InsertNodes(List<ChatNode> nodes, int channel, int vipLv, int moonand, string name, ulong chater, string toName = null,int sid = 0 )
|
||
{
|
||
//创建频道节点
|
||
ChatNode channelNode = new ChatNode();
|
||
channelNode.Type = (int)TNodeType.Text;
|
||
if (channel == (int)ChatChanelType.Cross)
|
||
{
|
||
if (GameCenter.LuaSystem.Adaptor.GetCurrServerID() == sid)
|
||
{
|
||
channelNode.Param1 =DeclareMessageString.Get(DeclareMessageString.C_LANG_LOCALSERVER);
|
||
}
|
||
else
|
||
{
|
||
if(GameCenter.LuaSystem.Adaptor.HasServer(sid))
|
||
channelNode.Param1 = string.Format(DeclareMessageString.Get(DeclareMessageString.C_LANG_OTHERSERVER), GameCenter.LuaSystem.Adaptor.GetServerShowID(sid));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
channelNode.Param1 = ChannelToString[channel];
|
||
}
|
||
channelNode.SetLabelType(channel);
|
||
channelNode.IsChannelNode = true;
|
||
|
||
|
||
//创建VIP节点
|
||
ChatNode vipNode = new ChatNode();
|
||
vipNode.Type = (int)TNodeType.Vip;
|
||
vipNode.Param1 = string.Format("{0}_{1}", vipLv, moonand);
|
||
vipNode.SetLabelType(channel);
|
||
|
||
//创建发送者节点
|
||
ChatNode playerNode = new ChatNode();
|
||
playerNode.Type = (int)TNodeType.Player;
|
||
if (string.IsNullOrEmpty(toName))
|
||
{
|
||
playerNode.Param1 = name;
|
||
}
|
||
else
|
||
{
|
||
playerNode.Param1 = string.Format(Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHATSYSTEM_SPEAK_TO), toName);
|
||
}
|
||
playerNode.Param2 = string.Format("{0}", chater);
|
||
playerNode.SetLabelType(channel);
|
||
|
||
|
||
//创建说节点
|
||
ChatNode speakNode = new ChatNode();
|
||
speakNode.Type = (int)TNodeType.Text;
|
||
speakNode.Param1 = ": ";
|
||
speakNode.SetLabelType(channel);
|
||
|
||
nodes.Insert(0, speakNode);
|
||
if (channel != (int)ChatChanelType.SYSTEM)
|
||
{
|
||
//名字不为空才添加
|
||
if (!string.IsNullOrEmpty(playerNode.Param1))
|
||
{
|
||
nodes.Insert(0, playerNode);
|
||
if (vipLv > 0 || moonand > 0)
|
||
{
|
||
nodes.Insert(0, vipNode);
|
||
}
|
||
}
|
||
}
|
||
|
||
nodes.Insert(0, channelNode);
|
||
}
|
||
|
||
|
||
//拷贝数据
|
||
private List<ChatNode> copyNodes(List<ChatNode> nodes)
|
||
{
|
||
List<ChatNode> ret = new List<ChatNode>();
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
ChatNode node = new ChatNode(nodes[i]);
|
||
ret.Add(node);
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
|
||
|
||
public void OnGS2U_PersonalNotice(MSG_Chat.PersonalNotice result)
|
||
{
|
||
string msg = "";
|
||
try
|
||
{
|
||
string format = DeclareMessageString.Get(result.content);
|
||
List<string> paramList = new List<string>();
|
||
for(int i = 0; i < result.value.Count; ++i)
|
||
{
|
||
var lan = CommonUtils.ConvertParamStruct(result.value[i].mark, result.value[i].paramsValue);
|
||
//if (!string.IsNullOrEmpty(lan))
|
||
paramList.Add(lan);
|
||
}
|
||
if (paramList.Count > 0)
|
||
msg = string.Format(format, paramList.ToArray());
|
||
else
|
||
msg = format;
|
||
}
|
||
catch(Exception ex) {
|
||
UnityEngine.Debug.LogException (ex);
|
||
UnityEngine.Debug.LogError(ex.Message + "::::" + result.content + "; paramCount:" + result.value.Count);
|
||
return;
|
||
}
|
||
|
||
switch ((PersonNoticeTypeDefine)result.type)
|
||
{
|
||
case PersonNoticeTypeDefine.ERROR:
|
||
GameCenter.MsgPromptSystem.ShowPrompt(msg, MsgInfoPriority.Highest);
|
||
break;
|
||
case PersonNoticeTypeDefine.NORMAL:
|
||
GameCenter.MsgPromptSystem.ShowPrompt(msg, MsgInfoPriority.Normal);
|
||
break;
|
||
case PersonNoticeTypeDefine.SUCCESS:
|
||
GameCenter.MsgPromptSystem.ShowPrompt(msg, MsgInfoPriority.High);
|
||
break;
|
||
case PersonNoticeTypeDefine.MARQUEE:
|
||
{
|
||
//支持系统发送格式化的装备、物品信息能正常显示出来
|
||
string convertMsg = ParseSystemMsg(msg);
|
||
if (convertMsg.StartsWith("<t="))
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
List<ChatNode> nodes = ChatParse.ParseContent(convertMsg);
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
nodes[i].ChannelID = (int)ChatChanelType.WORLD;
|
||
sb.Append(nodes[i].GetDisplayTextBBCode());
|
||
}
|
||
GameCenter.MsgPromptSystem.ShowMarquee(sb.ToString());
|
||
}
|
||
else
|
||
{
|
||
GameCenter.MsgPromptSystem.ShowMarquee(msg);
|
||
}
|
||
}
|
||
break;
|
||
case PersonNoticeTypeDefine.SHOWBOX:
|
||
GameCenter.MsgPromptSystem.ShowMsgBox(msg, DeclareMessageString.Get(DeclareMessageString.C_MSGBOX_OK));
|
||
break;
|
||
case PersonNoticeTypeDefine.CHAT:
|
||
GameCenter.ChatSystem.AddSystemChat(msg);
|
||
break;
|
||
case PersonNoticeTypeDefine.CHAT_SYS_BULL:
|
||
{
|
||
|
||
//支持系统发送格式化的装备、物品信息能正常显示出来
|
||
string convertMsg1 = ParseSystemMsg(msg);
|
||
if (convertMsg1.StartsWith("<t="))
|
||
{
|
||
List<ChatNode> nodes = ChatParse.ParseContent(convertMsg1);
|
||
|
||
StringBuilder sb = new StringBuilder();
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
nodes[i].ChannelID = (int)ChatChanelType.WORLD;
|
||
|
||
sb.Append(nodes[i].GetDisplayTextBBCode());
|
||
}
|
||
GameCenter.MsgPromptSystem.ShowPrompt(sb.ToString());
|
||
}
|
||
}
|
||
|
||
GameCenter.ChatSystem.AddSystemChat(msg);
|
||
break;
|
||
case PersonNoticeTypeDefine.HIGH_ORDER_NOTICE:
|
||
GameCenter.MsgPromptSystem.ShowHighOrderNotice(msg);
|
||
break;
|
||
case PersonNoticeTypeDefine.CHAT_SYS_MARQUEE:
|
||
{
|
||
CallNormalSysChatAndMarquee(msg);
|
||
}
|
||
break;
|
||
case PersonNoticeTypeDefine.CHAT_SYS_URL_MARQUEE:
|
||
{
|
||
//支持系统发送格式化的装备、物品信息能正常显示出来
|
||
string convertMsg = ParseSystemMsg(msg);
|
||
if (convertMsg.StartsWith("<t="))
|
||
{
|
||
List<ChatNode> nodes = ChatParse.ParseContent(convertMsg);
|
||
|
||
StringBuilder sb = new StringBuilder();
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
nodes[i].ChannelID = (int)ChatChanelType.WORLD;
|
||
|
||
//2018/03/14:需求修改-跑马灯不要链接功能
|
||
if (nodes[i].Type == (int)TNodeType.Function && nodes[i].ParseFuncNode() == FuncNodeType.FunctionStartId)
|
||
{
|
||
continue;
|
||
}
|
||
//---
|
||
|
||
sb.Append(nodes[i].GetDisplayTextBBCode());
|
||
}
|
||
GameCenter.MsgPromptSystem.ShowMarquee(sb.ToString());
|
||
GameCenter.MsgPromptSystem.ShowPrompt(sb.ToString());
|
||
}
|
||
if (result.chatChannelList != null)
|
||
{
|
||
for (int i = 0; i < result.chatChannelList.Count; i++)
|
||
{
|
||
if ((ChatChanelType)result.chatChannelList[i] == ChatChanelType.WORLD)
|
||
{
|
||
GameCenter.ChatSystem.AddWorldPersonChat((ChatChanelType)result.chatChannelList[i], convertMsg);
|
||
}
|
||
else
|
||
{
|
||
GameCenter.ChatSystem.AddChat((ChatChanelType)result.chatChannelList[i], convertMsg);
|
||
}
|
||
}
|
||
}
|
||
//GameCenter.ChatSystem.AddSystemChat(msg);
|
||
}
|
||
break;
|
||
case PersonNoticeTypeDefine.CENTER_BLINK_TIPS:
|
||
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_SHOWSKILLWARNING_EFFECT, new object[] { msg, 0f, 3f});
|
||
break;
|
||
case PersonNoticeTypeDefine.YUNYING_MARQUEE:
|
||
{
|
||
CallYunYingSysChatAndMarquee(msg);
|
||
}
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
private void CallNormalSysChatAndMarquee(string msg)
|
||
{
|
||
GameCenter.ChatSystem.AddSystemChat(msg);
|
||
|
||
//支持系统发送格式化的装备、物品信息能正常显示出来
|
||
string convertMsg = ParseSystemMsg(msg);
|
||
if (convertMsg.StartsWith("<t="))
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
List<ChatNode> nodes = ChatParse.ParseContent(convertMsg);
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
nodes[i].ChannelID = (int)ChatChanelType.WORLD;
|
||
sb.Append(nodes[i].GetDisplayTextBBCode());
|
||
}
|
||
GameCenter.MsgPromptSystem.ShowMarquee(sb.ToString());
|
||
}
|
||
else
|
||
{
|
||
GameCenter.MsgPromptSystem.ShowMarquee(msg);
|
||
}
|
||
}
|
||
|
||
private void CallYunYingSysChatAndMarquee(string msg)
|
||
{
|
||
GameCenter.ChatSystem.AddSystemChat(msg);
|
||
|
||
//支持系统发送格式化的装备、物品信息能正常显示出来
|
||
string convertMsg = ParseSystemMsg(msg);
|
||
if (convertMsg.StartsWith("<t="))
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
List<ChatNode> nodes = ChatParse.ParseContent(convertMsg);
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
nodes[i].ChannelID = (int)ChatChanelType.WORLD;
|
||
sb.Append(nodes[i].GetDisplayTextBBCode());
|
||
}
|
||
GameCenter.MsgPromptSystem.ShowYunYingMarquee(sb.ToString());
|
||
}
|
||
else
|
||
{
|
||
GameCenter.MsgPromptSystem.ShowYunYingMarquee(msg);
|
||
}
|
||
}
|
||
|
||
public void GS2U_ChatResLeaveMessageSC(MSG_Chat.ChatResLeaveMessageSC result)
|
||
{
|
||
//UnityEngine.Debug.Log("离线消息1");
|
||
for (int i = 0; result.msgList != null && i < result.msgList.Count; ++i)
|
||
{
|
||
MSG_Chat.ChatResInfo chatMsg = new MSG_Chat.ChatResInfo();
|
||
chatMsg.chatchannel = (int)ChatChanelType.PERSONAL;
|
||
//chatMsg.chattype = result.msgList[i].
|
||
if (result.msgList[i].systemId != 0)
|
||
{
|
||
chatMsg.condition = DeclareMessageString.Get(result.msgList[i].systemId);
|
||
chatMsg.systemId = 0;
|
||
}
|
||
else
|
||
{
|
||
chatMsg.condition = result.msgList[i].condition;
|
||
}
|
||
chatMsg.chater = result.msgList[i].chater;
|
||
chatMsg.chatername = result.msgList[i].chatername;
|
||
chatMsg.vipLv = result.msgList[i].vipLv;
|
||
chatMsg.occ = result.msgList[i].career;
|
||
chatMsg.chaterlevel = result.msgList[i].level;
|
||
var msgHead = result.msgList[i].head;
|
||
chatMsg.head = new MSG_Common.HeadAttribute();
|
||
if(msgHead != null)
|
||
{
|
||
chatMsg.head.fashionHead = msgHead.fashionHead;
|
||
chatMsg.head.fashionFrame = msgHead.fashionFrame;
|
||
chatMsg.head.customHeadPath = msgHead.customHeadPath;
|
||
chatMsg.head.useCustomHead = msgHead.useCustomHead;
|
||
}
|
||
chatMsg.chatBgId = result.msgList[i].chatBgId;
|
||
chatMsg.receiver = (ulong)result.msgList[i].receiverId;
|
||
//GameCenter.ChatSystem.GS2U_Chatc ResSC(chatMsg);
|
||
//将离线消息保存下来,等UI加载完了再分发
|
||
_leaveMsgList.Add(chatMsg);
|
||
}
|
||
}
|
||
|
||
public void ResWorldHistoryChatInfo(MSG_Chat.ResWorldHistoryChatInfo result)
|
||
{
|
||
List<int> timeList = new List<int>();
|
||
Dictionary<int, MSG_Chat.ChatResInfo> serverChatDic = new Dictionary<int, MSG_Chat.ChatResInfo>();
|
||
for (int i = 0; result.msgList != null && i < result.msgList.Count; ++i)
|
||
{
|
||
LeaveMsg leaveMsg = new LeaveMsg();
|
||
MSG_Chat.ChatResInfo chatMsg = new MSG_Chat.ChatResInfo();
|
||
chatMsg.chatchannel = (int)result.msgList[i].channel;
|
||
//chatMsg.chattype = result.msgList[i].
|
||
chatMsg.condition = result.msgList[i].condition;
|
||
chatMsg.chater = result.msgList[i].chater;
|
||
chatMsg.chatername = result.msgList[i].chatername;
|
||
chatMsg.vipLv = result.msgList[i].vipLv;
|
||
chatMsg.occ = result.msgList[i].career;
|
||
chatMsg.chaterlevel = result.msgList[i].level;
|
||
var msgHead = result.msgList[i].head;
|
||
chatMsg.head = new MSG_Common.HeadAttribute();
|
||
if (msgHead != null)
|
||
{
|
||
chatMsg.head.fashionHead = msgHead.fashionHead;
|
||
chatMsg.head.fashionFrame = msgHead.fashionFrame;
|
||
chatMsg.head.customHeadPath = msgHead.customHeadPath;
|
||
chatMsg.head.useCustomHead = msgHead.useCustomHead;
|
||
}
|
||
chatMsg.chatBgId = result.msgList[i].chatBgId;
|
||
leaveMsg.msg = chatMsg;
|
||
leaveMsg.time = result.msgList[i].time;
|
||
leaveMsg.msg.chaterSid = result.msgList[i].chaterSid;
|
||
leaveMsg.isRobot = false;
|
||
//GameCenter.ChatSystem.GS2U_ChatResSC(chatMsg);
|
||
//将离线消息保存下来,等UI加载完了再分发 -- 这里原来是add,可能会出现报错.
|
||
serverChatDic[result.msgList[i].time] = chatMsg;
|
||
if (chatMsg.chatchannel == (int)ChatChanelType.WORLD)
|
||
{
|
||
timeList.Add(result.msgList[i].time);
|
||
}
|
||
else
|
||
{
|
||
List<LeaveMsg> list = null;
|
||
if (_publicLeaveMsgDic.ContainsKey(chatMsg.chatchannel))
|
||
{
|
||
list = _publicLeaveMsgDic[chatMsg.chatchannel];
|
||
list.Add(leaveMsg);
|
||
}
|
||
else
|
||
{
|
||
list = new List<LeaveMsg>();
|
||
list.Add(leaveMsg);
|
||
_publicLeaveMsgDic.Add(chatMsg.chatchannel, list);
|
||
}
|
||
}
|
||
}
|
||
|
||
//解析机器人缓存消息
|
||
Dictionary<int, MSG_Chat.ChatResInfo> RobotChatDic = new Dictionary<int, MSG_Chat.ChatResInfo>();
|
||
int serverId = GameCenter.LuaSystem.Adaptor.GetCurrServerID();
|
||
string key = string.Format("RobotChatCache|{0}|{1}", serverId, GameCenter.LuaSystem.Adaptor.GetLoginAccount());
|
||
string str = PlayerPrefs.GetString(key);
|
||
if (!string.IsNullOrEmpty(str))
|
||
{
|
||
string[] strs = str.Split(';');
|
||
for (int i = 0; i < strs.Length; i++)
|
||
{
|
||
string[] values = strs[i].Split('|');
|
||
if (values.Length <= 11) continue;
|
||
int time = int.TryParse(values[0], out time) ? time : 0;
|
||
int occ = int.TryParse(values[1], out occ) ? occ : 0;
|
||
string name = values[2];
|
||
int level = int.TryParse(values[3], out level) ? level : 0;
|
||
string context = values[4];
|
||
int channel = int.TryParse(values[5], out channel) ? channel : 0;
|
||
int ppId = int.TryParse(values[6], out ppId) ? ppId : 0;
|
||
int headId = int.TryParse(values[7], out headId) ? headId : 0;
|
||
int frameId = int.TryParse(values[8], out frameId) ? frameId : 0;
|
||
ulong chater = ulong.TryParse(values[9], out chater) ? chater : 0;
|
||
ulong receiver = ulong.TryParse(values[10], out receiver) ? receiver : 0;
|
||
ulong paramId = ulong.TryParse(values[11], out paramId) ? paramId : 0;
|
||
if (paramId != 0)
|
||
{
|
||
if (paramId != GameCenter.GameSceneSystem.GetLocalPlayerID())
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
string headPic = string.Empty;
|
||
bool showHeadPic = false;
|
||
MSG_Chat.ChatResInfo chatMsg = new MSG_Chat.ChatResInfo();
|
||
chatMsg.chatchannel = channel;
|
||
chatMsg.chater = chater;
|
||
chatMsg.chaterlevel = level;
|
||
chatMsg.chatername = name;
|
||
chatMsg.condition = context;
|
||
chatMsg.chatBgId = ppId;
|
||
chatMsg.head = new MSG_Common.HeadAttribute();
|
||
chatMsg.head.fashionHead = headId;
|
||
chatMsg.head.fashionFrame = frameId;
|
||
chatMsg.head.customHeadPath = headPic;
|
||
chatMsg.head.useCustomHead = showHeadPic;
|
||
chatMsg.occ = occ;
|
||
chatMsg.receiver = receiver;
|
||
//-- 这里原来是字典add,可能会出现报错.
|
||
RobotChatDic[time] = chatMsg;
|
||
timeList.Add(time);
|
||
}
|
||
}
|
||
timeList.Sort((x, y) =>
|
||
{
|
||
if (x > y)
|
||
{
|
||
return 1;
|
||
}
|
||
else if (x == y)
|
||
{
|
||
return 0;
|
||
}
|
||
else
|
||
{
|
||
return -1;
|
||
}
|
||
});
|
||
int index = 0;
|
||
if (timeList.Count > 10)
|
||
{
|
||
index = timeList.Count - 10;
|
||
}
|
||
int lenght = timeList.Count < 10 ? timeList.Count : 10;
|
||
List<LeaveMsg> worldChatList = new List<LeaveMsg>();
|
||
for (int i = index; i < timeList.Count; i++)
|
||
{
|
||
LeaveMsg leaveMsg = new LeaveMsg();
|
||
MSG_Chat.ChatResInfo chat = null;
|
||
//_publicLeaveMsgList.Add();
|
||
if (serverChatDic.ContainsKey(timeList[i]))
|
||
{
|
||
chat = serverChatDic[timeList[i]];
|
||
leaveMsg.isRobot = false;
|
||
}
|
||
else
|
||
{
|
||
if (RobotChatDic.ContainsKey(timeList[i]))
|
||
{
|
||
chat = RobotChatDic[timeList[i]];
|
||
leaveMsg.isRobot = true;
|
||
}
|
||
}
|
||
leaveMsg.msg = chat;
|
||
leaveMsg.time = timeList[i];
|
||
if (chat.chatchannel == (int)ChatChanelType.WORLD)
|
||
{
|
||
worldChatList.Add(leaveMsg);
|
||
}
|
||
else
|
||
{
|
||
List<LeaveMsg> list = null;
|
||
if (_publicLeaveMsgDic.ContainsKey(chat.chatchannel))
|
||
{
|
||
list = _publicLeaveMsgDic[chat.chatchannel];
|
||
list.Add(leaveMsg);
|
||
}
|
||
else
|
||
{
|
||
list = new List<LeaveMsg>();
|
||
list.Add(leaveMsg);
|
||
_publicLeaveMsgDic.Add(chat.chatchannel, list);
|
||
}
|
||
}
|
||
}
|
||
_publicLeaveMsgDic[(int)ChatChanelType.WORLD] = worldChatList;
|
||
}
|
||
|
||
public void InitCacheLocalLeaveMsg()
|
||
{
|
||
if (IsInitLocalLeaveMsg)
|
||
return;
|
||
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
||
int length = _localLeavelChannels.Length;
|
||
for (int i = 0; i < length; i++)
|
||
{
|
||
int channel = _localLeavelChannels[i];
|
||
int serverId = GameCenter.LuaSystem.Adaptor.GetCurrServerID();
|
||
//string key = string.Format("LocalMsg_{0}_{1}_{2}_{3}", serverId, GameCenter.LoginSystem.Account, channel, index);
|
||
//string headKey = string.Format("LocalMsgHead|{0}|{1}|{2}", serverId, channel, lp.ID);
|
||
//int count = PlayerPrefs.GetInt(headKey);
|
||
string key = string.Format("LocalMsg|{0}|{1}|{2}", serverId, channel, lp.ID);
|
||
var allMsg = PlayerPrefs.GetString(key);
|
||
if (!string.IsNullOrEmpty(allMsg))
|
||
{
|
||
var msgList = allMsg.Split('#');
|
||
for (int m = 0; m < msgList.Length; m++)
|
||
{
|
||
string msg = msgList[m];
|
||
//string.Format("{0}_{1}_{2}_{3}",msg.occ, msg.chatername, msg.chaterlevel, msg.condition);
|
||
LeaveMsg leaveMsg = new LeaveMsg();
|
||
string[] strs = msg.Split('|');
|
||
if (strs.Length == 9)
|
||
{
|
||
int occ = int.TryParse(strs[0], out occ) ? occ : 0;
|
||
string name = strs[1];
|
||
int level = int.TryParse(strs[2], out level) ? level : 0;
|
||
ulong chater = ulong.TryParse(strs[3], out chater) ? chater : 0;
|
||
string context = strs[4];
|
||
int time = int.TryParse(strs[5], out time) ? time : 0;
|
||
int headFrameId = int.TryParse(strs[6], out headFrameId) ? headFrameId : 0;
|
||
int bgId = int.TryParse(strs[7], out bgId) ? bgId : 0;
|
||
int headId = int.TryParse(strs[8], out headId) ? headId : 0;
|
||
string headPic = string.Empty;
|
||
bool showHeadPic = false;
|
||
|
||
MSG_Chat.ChatResInfo chatMsg = new MSG_Chat.ChatResInfo();
|
||
chatMsg.chatchannel = channel;
|
||
chatMsg.chater = chater;
|
||
chatMsg.chaterlevel = level;
|
||
chatMsg.chatername = name;
|
||
chatMsg.condition = context;
|
||
chatMsg.chatBgId = bgId;
|
||
chatMsg.head = new MSG_Common.HeadAttribute();
|
||
chatMsg.head.fashionFrame = headFrameId;
|
||
chatMsg.head.fashionHead = headId;
|
||
chatMsg.head.customHeadPath = headPic;
|
||
chatMsg.head.useCustomHead = showHeadPic;
|
||
chatMsg.occ = occ;
|
||
leaveMsg.msg = chatMsg;
|
||
leaveMsg.time = time;
|
||
}
|
||
else if (strs.Length == 10)
|
||
{
|
||
int occ = int.TryParse(strs[0], out occ) ? occ : 0;
|
||
string name = strs[1];
|
||
int level = int.TryParse(strs[2], out level) ? level : 0;
|
||
ulong chater = ulong.TryParse(strs[3], out chater) ? chater : 0;
|
||
int content = int.TryParse(strs[4], out content) ? content : 0;
|
||
int time = int.TryParse(strs[5], out time) ? time : 0;
|
||
string paramValue = strs[6];
|
||
int headFrameId = int.TryParse(strs[7], out headFrameId) ? headFrameId : 0;
|
||
int bgId = int.TryParse(strs[8], out bgId) ? bgId : 0;
|
||
int headId = int.TryParse(strs[9], out headId) ? headId : 0;
|
||
string headPic = string.Empty;
|
||
bool showHeadPic = false;
|
||
|
||
MSG_Chat.PersonalChatNotice chatMsg = new MSG_Chat.PersonalChatNotice();
|
||
chatMsg.channel = channel;
|
||
chatMsg.chater = chater;
|
||
chatMsg.chaterlevel = level;
|
||
chatMsg.chatername = name;
|
||
chatMsg.content = content;
|
||
chatMsg.head = new MSG_Common.HeadAttribute();
|
||
chatMsg.head.fashionFrame = headFrameId;
|
||
chatMsg.head.fashionHead = headId;
|
||
chatMsg.head.customHeadPath = headPic;
|
||
chatMsg.head.useCustomHead = showHeadPic;
|
||
chatMsg.chatBgId = bgId;
|
||
chatMsg.occ = occ;
|
||
chatMsg.value.Clear();
|
||
string[] values = paramValue.Split(';');
|
||
for (int k = 0; k < values.Length; k++)
|
||
{
|
||
string[] results = values[k].Split('&');
|
||
int mark = int.TryParse(results[0], out mark) ? mark : 0;
|
||
string value = results[1];
|
||
paramStruct pStuc = new paramStruct();
|
||
pStuc.mark = mark;
|
||
pStuc.paramsValue = value;
|
||
chatMsg.value.Add(pStuc);
|
||
}
|
||
leaveMsg.notice = chatMsg;
|
||
leaveMsg.time = time;
|
||
}
|
||
List<LeaveMsg> chatList = _localLeavelMsgDic.TryGetValue(channel, out chatList) ? chatList : null; ;
|
||
if (chatList != null)
|
||
{
|
||
//判断数量数据数量是否大于最大数量
|
||
if (chatList.Count < MAM_ROBOT_CHATCOUNT)
|
||
{
|
||
chatList.Add(leaveMsg);
|
||
}
|
||
else
|
||
{
|
||
//删除第一条数据
|
||
chatList.RemoveAt(0);
|
||
chatList.Add(leaveMsg);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//一条数据都没有
|
||
chatList = new List<LeaveMsg>();
|
||
chatList.Add(leaveMsg);
|
||
_localLeavelMsgDic.Add(channel, chatList);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
IsInitLocalLeaveMsg = true;
|
||
}
|
||
|
||
public void CacheLocalLeavelMsg(MSG_Chat.ChatResInfo msg1, MSG_Chat.PersonalChatNotice msg2, bool isPerson = false)
|
||
{
|
||
int channelId = 0;
|
||
LeaveMsg leaveMsg = new LeaveMsg();
|
||
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
||
if (!isPerson)
|
||
{
|
||
MSG_Chat.ChatResInfo clone = new MSG_Chat.ChatResInfo();
|
||
clone.chattype = msg1.chattype;
|
||
clone.chater = msg1.chater;
|
||
clone.chatername = msg1.chatername;
|
||
clone.vipLv = msg1.vipLv;
|
||
clone.receiver = msg1.receiver;
|
||
clone.receivername = msg1.receivername;
|
||
clone.receiverVipLv = msg1.receiverVipLv;
|
||
clone.condition = msg1.condition;
|
||
clone.chatchannel = msg1.chatchannel;
|
||
clone.occ = msg1.occ;
|
||
clone.head = new MSG_Common.HeadAttribute();
|
||
if(msg1.head != null)
|
||
{
|
||
clone.head.fashionHead = msg1.head.fashionHead;
|
||
clone.head.fashionFrame = msg1.head.fashionFrame;
|
||
clone.head.customHeadPath = msg1.head.customHeadPath;
|
||
clone.head.useCustomHead = msg1.head.useCustomHead;
|
||
}
|
||
clone.chatBgId = msg1.chatBgId;
|
||
clone.chaterlevel = msg1.chaterlevel;
|
||
leaveMsg.msg = clone;
|
||
channelId = msg1.chatchannel;
|
||
}
|
||
else
|
||
{
|
||
MSG_Chat.PersonalChatNotice notice = new MSG_Chat.PersonalChatNotice();
|
||
notice.channel = msg2.channel;
|
||
notice.chatBgId = msg2.chatBgId;
|
||
notice.chater = msg2.chater;
|
||
notice.chaterlevel = msg2.chaterlevel;
|
||
notice.chatername = msg2.chatername;
|
||
notice.content = msg2.content;
|
||
notice.head = new MSG_Common.HeadAttribute();
|
||
if (msg2.head != null)
|
||
{
|
||
notice.head.fashionHead = msg2.head.fashionHead;
|
||
notice.head.fashionFrame = msg2.head.fashionFrame;
|
||
notice.head.customHeadPath = msg2.head.customHeadPath;
|
||
notice.head.useCustomHead = msg2.head.useCustomHead;
|
||
}
|
||
notice.moonandOver = msg2.moonandOver;
|
||
notice.occ = msg2.occ;
|
||
notice.value.AddRange(msg2.value);
|
||
notice.vipLv = msg2.vipLv;
|
||
leaveMsg.notice = notice;
|
||
channelId = msg2.channel;
|
||
}
|
||
leaveMsg.time = (int)GameCenter.HeartSystem.ServerTime;
|
||
int length = _localLeavelChannels.Length;
|
||
for (int i = 0; i < length; i++)
|
||
{
|
||
var channel = _localLeavelChannels[i];
|
||
if (channelId == channel)
|
||
{
|
||
List<LeaveMsg> chatList = _localLeavelMsgDic.TryGetValue(channel, out chatList) ? chatList : null;
|
||
if (chatList != null)
|
||
{
|
||
//判断数量数据数量是否大于最大数量
|
||
if (chatList.Count < MAM_ROBOT_CHATCOUNT)
|
||
{
|
||
chatList.Add(leaveMsg);
|
||
}
|
||
else
|
||
{
|
||
//删除第一条数据
|
||
chatList.RemoveAt(0);
|
||
chatList.Add(leaveMsg);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//一条数据都没有
|
||
chatList = new List<LeaveMsg>();
|
||
chatList.Add(leaveMsg);
|
||
_localLeavelMsgDic.Add(channel, chatList);
|
||
}
|
||
if (GameCenter.ChatSystem.CacheMsgTick != 0)
|
||
{
|
||
return;
|
||
}
|
||
string chatStr = string.Empty;
|
||
int serverId = GameCenter.LuaSystem.Adaptor.GetCurrServerID();
|
||
var count = 0;
|
||
for (int k = 0; k < chatList.Count; k++)
|
||
{
|
||
int occ = 0;
|
||
int lv = 0;
|
||
int time = chatList[k].time;
|
||
int content = 0;
|
||
int headId = 0;
|
||
int headFrameId = 0;
|
||
int bgId = 0;
|
||
ulong uID = 0;
|
||
string name = string.Empty;
|
||
string condition = string.Empty;
|
||
if (chatList[k].msg != null)
|
||
{
|
||
var chatMsg = chatList[k].msg;
|
||
occ = chatMsg.occ;
|
||
lv = chatMsg.chaterlevel;
|
||
uID = chatMsg.chater;
|
||
name = chatMsg.chatername;
|
||
condition = chatMsg.condition;
|
||
bgId = chatMsg.chatBgId;
|
||
headId = chatMsg.head.fashionHead;
|
||
headFrameId = chatMsg.head.fashionFrame;
|
||
if (string.IsNullOrEmpty(chatStr))
|
||
{
|
||
chatStr = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}", occ, name, lv, uID, condition, time, headFrameId, bgId, headId);
|
||
}
|
||
else
|
||
{
|
||
string msg = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}", occ, name, lv, uID, condition, time, headFrameId, bgId, headId);
|
||
chatStr = "#" + msg;
|
||
}
|
||
count += 1;
|
||
}
|
||
else if(chatList[k].notice != null)
|
||
{
|
||
var chatMsg = chatList[k].notice;
|
||
occ = chatMsg.occ;
|
||
lv = chatMsg.chaterlevel;
|
||
time = chatList[k].time;
|
||
uID = chatMsg.chater;
|
||
name = chatMsg.chatername;
|
||
content = chatMsg.content;
|
||
headId = chatMsg.head.fashionHead;
|
||
headFrameId = chatMsg.head.fashionFrame; ;
|
||
StringBuilder sb = new StringBuilder();
|
||
for (int m = 0; m < chatMsg.value.Count; m++)
|
||
{
|
||
var param = chatMsg.value[m];
|
||
sb.Append(param.mark);
|
||
sb.Append("&");
|
||
sb.Append(param.paramsValue);
|
||
if (m != chatMsg.value.Count - 1)
|
||
{
|
||
sb.Append(";");
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(chatStr))
|
||
{
|
||
chatStr = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}", occ, name, lv, uID, content, time, sb.ToString(), headFrameId, bgId, headId);
|
||
}
|
||
else
|
||
{
|
||
string msg = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}", occ, name, lv, uID, content, time, sb.ToString(), headFrameId, bgId, headId);
|
||
chatStr = "#" + msg;
|
||
}
|
||
count += 1;
|
||
}
|
||
//string value = PlayerPrefs.GetString(key);
|
||
|
||
}
|
||
if (count > 0 && lp != null)
|
||
{
|
||
string key = string.Format("LocalMsg|{0}|{1}|{2}", serverId, channel, lp.ID);
|
||
string key1 = string.Format("LocalMsgHead|{0}|{1}|{2}", serverId, channel, lp.ID);
|
||
PlayerPrefs.SetString(key, chatStr);
|
||
PlayerPrefs.SetInt(key1, count);
|
||
PlayerPrefs.Save();
|
||
}
|
||
GameCenter.ChatSystem.CacheMsgTick = GameCenter.ChatSystem.CacheMsgTime;
|
||
}
|
||
}
|
||
}
|
||
|
||
public void ForceCacheLocalLeavelMsg()
|
||
{
|
||
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
||
int length = _localLeavelChannels.Length;
|
||
for (int i = 0; i < length; i++)
|
||
{
|
||
var channel = _localLeavelChannels[i];
|
||
List<LeaveMsg> chatList = _localLeavelMsgDic.TryGetValue(channel, out chatList) ? chatList : null;
|
||
if (chatList == null)
|
||
continue;
|
||
string chatStr = string.Empty;
|
||
var count = 0;
|
||
for (int k = 0; k < chatList.Count; k++)
|
||
{
|
||
int occ = 0;
|
||
int lv = 0;
|
||
int time = chatList[k].time;
|
||
int content = 0;
|
||
int headId = 0;
|
||
int headFrameId = 0;
|
||
int bgId = 0;
|
||
ulong uID = 0;
|
||
string name = string.Empty;
|
||
string condition = string.Empty;
|
||
if (chatList[k].msg != null)
|
||
{
|
||
var chatMsg = chatList[k].msg;
|
||
occ = chatMsg.occ;
|
||
lv = chatMsg.chaterlevel;
|
||
uID = chatMsg.chater;
|
||
name = chatMsg.chatername;
|
||
condition = chatMsg.condition;
|
||
headId = chatMsg.head.fashionHead;
|
||
headFrameId = chatMsg.head.fashionFrame;
|
||
bgId = chatMsg.chatBgId;
|
||
if (string.IsNullOrEmpty(chatStr))
|
||
{
|
||
chatStr = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}", occ, name, lv, uID, condition, time, headFrameId, bgId, headId);
|
||
}
|
||
else
|
||
{
|
||
string msg = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}", occ, name, lv, uID, condition, time, headFrameId, bgId, headId);
|
||
chatStr = "#" + msg;
|
||
}
|
||
count += 1;
|
||
}
|
||
else if (chatList[k].notice != null)
|
||
{
|
||
var chatMsg = chatList[k].notice;
|
||
occ = chatMsg.occ;
|
||
lv = chatMsg.chaterlevel;
|
||
time = chatList[k].time;
|
||
uID = chatMsg.chater;
|
||
name = chatMsg.chatername;
|
||
content = chatMsg.content;
|
||
headId = chatMsg.head.fashionHead;
|
||
headFrameId = chatMsg.head.fashionFrame;
|
||
bgId = chatMsg.chatBgId;
|
||
StringBuilder sb = new StringBuilder();
|
||
for (int m = 0; m < chatMsg.value.Count; m++)
|
||
{
|
||
var param = chatMsg.value[m];
|
||
sb.Append(param.mark);
|
||
sb.Append("&");
|
||
sb.Append(param.paramsValue);
|
||
if (m != chatMsg.value.Count - 1)
|
||
{
|
||
sb.Append(";");
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(chatStr))
|
||
{
|
||
chatStr = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}", occ, name, lv, uID, content, time, sb.ToString(), headFrameId, bgId, headId);
|
||
}
|
||
else
|
||
{
|
||
string msg = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}", occ, name, lv, uID, content, time, sb.ToString(), headFrameId, bgId, headId);
|
||
chatStr = "#" + msg;
|
||
}
|
||
count += 1;
|
||
}
|
||
|
||
//string value = PlayerPrefs.GetString(key);
|
||
|
||
}
|
||
if (count > 0 && lp !=null)
|
||
{
|
||
int serverId = GameCenter.LuaSystem.Adaptor.GetCurrServerID();
|
||
string key = string.Format("LocalMsg|{0}|{1}|{2}", serverId, channel, lp.ID);
|
||
string key1 = string.Format("LocalMsgHead|{0}|{1}|{2}", serverId, channel, lp.ID);
|
||
PlayerPrefs.SetString(key, chatStr);
|
||
PlayerPrefs.SetInt(key1, chatList.Count);
|
||
PlayerPrefs.Save();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//主界面UI加载完了调用这个方法
|
||
public void CheckLeaveMsg()
|
||
{
|
||
if (IsCheckLeaveMsg)
|
||
{
|
||
return;
|
||
}
|
||
if(_leaveMsgList.Count > 0)
|
||
{
|
||
for(int i = 0; i < _leaveMsgList.Count; ++i)
|
||
{
|
||
GameCenter.ChatSystem.GS2U_ChatResSC(_leaveMsgList[i], true);
|
||
}
|
||
|
||
_leaveMsgList.Clear();
|
||
}
|
||
List<LeaveMsg> leaveList = new List<LeaveMsg>();
|
||
var enumer = _publicLeaveMsgDic.GetEnumerator();
|
||
try
|
||
{
|
||
while (enumer.MoveNext())
|
||
{
|
||
var list = enumer.Current.Value;
|
||
if (list != null)
|
||
{
|
||
for (int i = 0; i < list.Count; i++)
|
||
{
|
||
var leaveMsg = list[i];
|
||
leaveList.Add(leaveMsg);
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
enumer.Dispose();
|
||
}
|
||
var enumer1 = _localLeavelMsgDic.GetEnumerator();
|
||
try
|
||
{
|
||
while (enumer1.MoveNext())
|
||
{
|
||
var list = enumer1.Current.Value;
|
||
if (list != null)
|
||
{
|
||
for (int i = 0; i < list.Count; i++)
|
||
{
|
||
var leaveMsg = list[i];
|
||
leaveList.Add(leaveMsg);
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
enumer.Dispose();
|
||
}
|
||
//排序
|
||
leaveList.Sort((x, y) =>
|
||
{
|
||
if (x.time > y.time)
|
||
{
|
||
return 1;
|
||
}
|
||
else if (x.time == y.time)
|
||
{
|
||
return 0;
|
||
}
|
||
else
|
||
{
|
||
return -1;
|
||
}
|
||
});
|
||
for (int i = 0; i < leaveList.Count; i++)
|
||
{
|
||
if (leaveList[i].msg != null)
|
||
{
|
||
GS2U_ChatResSC(leaveList[i].msg, true, false, "", leaveList[i].isRobot);
|
||
}
|
||
else if (leaveList[i].notice != null)
|
||
{
|
||
GS2U_PersonalChatNotice(leaveList[i].notice, leaveList[i].isRobot);
|
||
}
|
||
}
|
||
_publicLeaveMsgDic.Clear();
|
||
IsCheckLeaveMsg = true;
|
||
}
|
||
|
||
public bool IsEnableDanMu()
|
||
{
|
||
return GetSavedDanMuPrefs() == 1;
|
||
}
|
||
|
||
public void SetEnableDanMu(bool enable)
|
||
{
|
||
if(enable)
|
||
{
|
||
PlayerPrefs.SetInt("danmu", 1);
|
||
}
|
||
else
|
||
{
|
||
PlayerPrefs.SetInt("danmu", 0);
|
||
}
|
||
}
|
||
|
||
public int GetSavedDanMuPrefs()
|
||
{
|
||
return PlayerPrefs.GetInt("danmu", 1);
|
||
}
|
||
|
||
//测试用
|
||
public void TestMarquee(string msg)
|
||
{
|
||
//支持系统发送格式化的装备、物品信息能正常显示出来
|
||
string convertMsg = ParseSystemMsg(msg);
|
||
if (convertMsg.StartsWith("<t="))
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
List<ChatNode> nodes = ChatParse.ParseContent(convertMsg);
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
nodes[i].ChannelID = (int)ChatChanelType.WORLD;
|
||
sb.Append(nodes[i].GetDisplayTextBBCode());
|
||
}
|
||
GameCenter.MsgPromptSystem.ShowMarquee(sb.ToString());
|
||
}
|
||
else
|
||
{
|
||
GameCenter.MsgPromptSystem.ShowMarquee(msg);
|
||
}
|
||
}
|
||
|
||
//解析系统发下来的字符,格式化为chatNode支持的字符串
|
||
public string ParseSystemMsg(string msg)
|
||
{
|
||
// UnityEngine.Debug.Log("System: " + msg);
|
||
// string retStr = "";
|
||
// //string msg = "恭喜xxx从xxx获取<t=0>,,asdasdsd</t><t=3>true,8,@12_1</t><t=2>576837515639801471,50005,神兵进阶丹</t><t=5>0_0,23012200,明光袍</t>";
|
||
// if (msg.Contains("<t="))
|
||
// {
|
||
// int begin = msg.IndexOf("<t=");
|
||
// int end = msg.LastIndexOf("</t>") + 4;
|
||
// string nodeStr = msg.Substring(begin, end - begin);
|
||
// string msgStr = msg.Substring(0, begin);
|
||
// msgStr = string.Format("<t=0>,,{0}</t>", msgStr);
|
||
//
|
||
// retStr = msgStr + nodeStr;
|
||
// }
|
||
// else
|
||
// retStr = msg;
|
||
|
||
return parseContent(msg);
|
||
}
|
||
|
||
private string parseContent(string msg)
|
||
{
|
||
int start = 0;
|
||
int end = 0;
|
||
StringBuilder sb = new StringBuilder();
|
||
end = msg.IndexOf("<t=", start);
|
||
while (end >= 0)
|
||
{
|
||
if (end - start > 0)
|
||
{
|
||
string commonStr = msg.Substring(start, end - start);
|
||
sb.Append(string.Format("<t=0>,,{0}</t>", commonStr));
|
||
}
|
||
|
||
start = msg.IndexOf("</t>", end) + 4;
|
||
sb.Append(msg.Substring(end, start - end));
|
||
end = msg.IndexOf("<t=", start);
|
||
}
|
||
|
||
string endStr = msg.Substring(start);
|
||
if(!string.IsNullOrEmpty(endStr))
|
||
sb.Append(string.Format("<t=0>,,{0}</t>", endStr));
|
||
return sb.ToString();
|
||
}
|
||
|
||
private List<ChatNode> CheckUrlMarquee(List<ChatNode> nodes)
|
||
{
|
||
//if(nodes.Count == 1)
|
||
//{
|
||
// if(nodes[0].Type == (int)TNodeType.Function)
|
||
// {
|
||
// if(nodes[0].Param3 == ((int)(FuncNodeType.FunctionStartId)).ToString())
|
||
// {
|
||
// int cfgId = int.Parse(nodes[0].Param2);
|
||
// string content = DeclareUrlMarquee.Get(cfgId).Content;
|
||
// ChatNode node = new ChatNode();
|
||
// node.ChannelID = nodes[0].ChannelID;
|
||
// node.Type = (int)TNodeType.Text;
|
||
// node.Param1 = content;
|
||
|
||
// ChatNode node2 = new ChatNode();
|
||
// node2.ChannelID = nodes[0].ChannelID;
|
||
// node2.Type = (int)TNodeType.Function;
|
||
// node2.Param3 = nodes[0].Param3;
|
||
// node2.Param2 = nodes[0].Param2;
|
||
// node2.Param1 = nodes[0].Param1;
|
||
|
||
// nodes.Clear();
|
||
// nodes.Add(node);
|
||
// nodes.Add(node2);
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
return nodes;
|
||
}
|
||
|
||
//模拟聊天数据
|
||
public void RobotChat(int occ,string name, int level, string context, int channel = 0, ulong id = 0)
|
||
{
|
||
int ppId = GameCenter.LuaSystem.Adaptor.GetChatDefaultPaoPaoCfgId();
|
||
int headId = GameCenter.LuaSystem.Adaptor.GetChatDefaultHeadCfgId();
|
||
int frameId = GameCenter.LuaSystem.Adaptor.GetChatDefaultHeadFrameCfgId();
|
||
RobotChatEx(id, occ, name, level, headId, frameId, ppId, context, channel);
|
||
}
|
||
|
||
|
||
public void RobotChatEx(ulong id, int occ, string name, int level, int headId, int frameId, int ppId, string context, int channel = 0, ulong receiver = 0)
|
||
{
|
||
if (_cacheRobotChatList.Count >= MAM_ROBOT_CHATCOUNT)
|
||
{
|
||
//删除第一条缓存数据
|
||
_cacheRobotChatList.RemoveAt(0);
|
||
}
|
||
ulong paramId = 0;
|
||
if (receiver != 0 && receiver != GameCenter.GameSceneSystem.GetLocalPlayerID())
|
||
{
|
||
paramId = GameCenter.GameSceneSystem.GetLocalPlayerID();
|
||
}
|
||
//组装缓存数据
|
||
string chatStr = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}", (int)GameCenter.HeartSystem.ServerTime, occ, name, level,
|
||
context, channel, ppId, headId, frameId, id, receiver, paramId);
|
||
_cacheRobotChatList.Add(chatStr);
|
||
string tempStr = string.Empty;
|
||
//组装缓存数据
|
||
for (int i = 0; i < _cacheRobotChatList.Count; i++)
|
||
{
|
||
if (i == 0)
|
||
{
|
||
tempStr = _cacheRobotChatList[i];
|
||
}
|
||
else
|
||
{
|
||
tempStr = string.Format("{0};{1}", tempStr, _cacheRobotChatList[i]);
|
||
}
|
||
}
|
||
int serverId = GameCenter.LuaSystem.Adaptor.GetCurrServerID();
|
||
string key = string.Format("RobotChatCache|{0}|{1}", serverId, GameCenter.LuaSystem.Adaptor.GetLoginAccount());
|
||
PlayerPrefs.SetString(key, tempStr);
|
||
PlayerPrefs.Save();
|
||
var result = new MSG_Chat.ChatResInfo();
|
||
byte[] buffer = Guid.NewGuid().ToByteArray();
|
||
if (id == 0)
|
||
{
|
||
id = BitConverter.ToUInt64(buffer, 0);
|
||
}
|
||
result.chatchannel = channel;
|
||
result.chater = id;
|
||
result.chaterlevel = level;
|
||
result.chatername = name;
|
||
result.condition = context;
|
||
result.chatBgId = ppId;
|
||
result.head = new MSG_Common.HeadAttribute();
|
||
result.head.fashionHead = headId;
|
||
result.head.fashionFrame = frameId;
|
||
result.occ = occ;
|
||
result.receiver = receiver;
|
||
if (ChatTool == null)
|
||
{
|
||
return;
|
||
}
|
||
ChatInfo info = new ChatInfo();
|
||
info.IsRobot = true;
|
||
copy(info, result);
|
||
//替换vip等级为月卡等级
|
||
//result.vipLv = result.moonandOver;
|
||
info.VipLevel = result.vipLv;
|
||
info.MoonardCard = 0;
|
||
info.SenderLevel = result.chaterlevel;
|
||
if (result.chatchannel == (int)ChatChanelType.SYSTEM)
|
||
{
|
||
result.condition = ParseSystemMsg(result.condition);
|
||
}
|
||
|
||
List<ChatNode> nodes = ChatParse.ParseContent(result.condition);
|
||
|
||
//检查可链接的跑马灯内容,拆分node,以便展示
|
||
nodes = CheckUrlMarquee(nodes);
|
||
|
||
//系统频道不去做屏蔽字判断
|
||
if (result.chatchannel != (int)ChatChanelType.SYSTEM
|
||
&& result.chatchannel != (int)ChatChanelType.Experience
|
||
&& result.chater != 0
|
||
)
|
||
{
|
||
//for (int i = 0; i < nodes.Count; ++i)
|
||
//{
|
||
// if (!string.IsNullOrEmpty(nodes[i].Param1))
|
||
// nodes[i].Param1 = WordFilter.ReplaceKeyWords(nodes[i].Param1);
|
||
//}
|
||
}
|
||
|
||
if (result.chattype == (int)ChatType.AUDIO)
|
||
{
|
||
string[] keyAndLen = result.condition.Split('|');
|
||
nodes = ChatParse.ParseContent(string.Format("<t={0}>,{1},,</t>", (int)TNodeType.Audio, keyAndLen[1]));
|
||
//设置接收到的语音序列id
|
||
for (int i = 0; i < nodes.Count; ++i)
|
||
{
|
||
if (nodes[i].Type == (int)TNodeType.Audio)
|
||
{
|
||
nodes[i].VoiceKey = keyAndLen[0];
|
||
//本人发送的语音,在发送时就保存起来了,不需要在这里保存
|
||
if (result.chater != GameCenter.GameSceneSystem.GetLocalPlayerID())
|
||
{
|
||
nodes[i].Param3 = "" + ++VoiceIndex;
|
||
}
|
||
else
|
||
{
|
||
nodes[i].Param3 = "" + LocalVoiceIndex;
|
||
//自己的语音不显示红点
|
||
nodes[i].EnableRedPoint(false);
|
||
}
|
||
|
||
//保存key和voiceIndex的关系
|
||
if (!_voiceKeyToVoiceData.ContainsKey(nodes[i].VoiceKey))
|
||
{
|
||
_voiceKeyToVoiceData.Add(nodes[i].VoiceKey, nodes[i].Param3);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//先取一个字体风格,用来计算字符长度
|
||
object label = GetLabelSkin(0);
|
||
|
||
bool isSelf = false;
|
||
|
||
//插入私聊数据
|
||
if (result.chatchannel == (int)ChatChanelType.PERSONAL)
|
||
{
|
||
List<ChatNode> data = (List<ChatNode>)ChatTool.calcMutiLine(result.chatchannel, nodes, label, MAX_PRIVATE_CHAT_LINE_WIDTH);
|
||
info.ChatDatas = data;
|
||
|
||
ChatPrivateInfo pInfo = new ChatPrivateInfo();
|
||
|
||
//如果发送者是本人,则key设置为接收人的id
|
||
if (result.chater == GameCenter.GameSceneSystem.GetLocalPlayerID())
|
||
{
|
||
pInfo.ID = result.receiver;
|
||
pInfo.Name = result.receivername;
|
||
pInfo.Occ = result.occ;
|
||
pInfo.Level = result.receiverLevel;
|
||
isSelf = true;
|
||
}
|
||
else
|
||
{
|
||
pInfo.ID = result.chater;
|
||
pInfo.SendId = result.chater;
|
||
pInfo.Name = result.chatername;
|
||
pInfo.Occ = result.occ;
|
||
pInfo.Level = result.receiverLevel;
|
||
}
|
||
|
||
pInfo.SendId = result.chater;
|
||
|
||
pInfo.HasUnReadMsg = true;
|
||
|
||
////私聊
|
||
//if ( GameCenter.FriendSystem.FriendPanelEnable )
|
||
//{
|
||
// //GameCenter.FriendSystem.ReqGetRelationList( FriendType.Recent );
|
||
//}
|
||
//else
|
||
//{
|
||
// GameCenter.MainFunctionSystem.SetAlertFlag( FunctionStartIdCode.Sociality, true );
|
||
//}
|
||
//存储私聊数据
|
||
GameCenter.ChatPrivateSystem.CachePrivateData(info, pInfo.ID);
|
||
//检测好友红点
|
||
GameCenter.ChatPrivateSystem.CheckRedPointShow();
|
||
//发送刷新私聊界面的事件
|
||
GameCenter.PushFixEvent((int)LogicEventDefine.EID_EVENT_CHAT_PRIVATE_REFRESH, pInfo);
|
||
}
|
||
else
|
||
{
|
||
info.ChatDatas = (List<ChatNode>)ChatTool.calcMutiLine(result.chatchannel, nodes, label, info.IsSystemMsg ? MAX_MAIN_SYS_CHAT_LINE_WIDTH : MAX_MAIN_CHAT_LINE_WIDTH);//CacheRecvNodes;
|
||
|
||
InsertData(info.Channel, info);
|
||
|
||
//冒险频道内容不显示在综合,系统也不显示在综合
|
||
if (result.chatchannel != (int)ChatChanelType.Experience && result.chatchannel != (int)ChatChanelType.SYSTEM)
|
||
InsertData((int)ChatChanelType.ALL, info);
|
||
|
||
//小聊天面板需要构造 [频道]vip名字: 结构
|
||
InsertNodes(nodes, result.chatchannel, result.vipLv, 0, result.chatername, result.chater, isSelf ? result.receivername : null);
|
||
|
||
var miniPanelData = ((List<ChatNode>)ChatTool.calcMutiLine(result.chatchannel, nodes, label, MAX_MINI_CHAT_LINE_WIDTH));
|
||
//小聊天面板不显示冒险信息
|
||
bool needShowInMiniChatForm = result.chatchannel != (int)ChatChanelType.Experience;
|
||
if (needShowInMiniChatForm)
|
||
insertData((int)ChatChanelType.MINI, miniPanelData.ToArray(), MAX_MSG_COUNT_MINI);
|
||
|
||
if (result.chatchannel == (int)ChatChanelType.PERSONAL)
|
||
{
|
||
//需要在除主播、系统频道外的频道,显示私聊消息
|
||
InsertData((int)ChatChanelType.GUILD, info);
|
||
InsertData((int)ChatChanelType.TEAM, info);
|
||
InsertData((int)ChatChanelType.WORLD, info);
|
||
InsertData((int)ChatChanelType.CURRENT, info);
|
||
InsertData((int)ChatChanelType.Friend, info);
|
||
}
|
||
|
||
if (needShowInMiniChatForm)
|
||
{
|
||
//发送刷新界面的事件
|
||
GameCenter.PushFixEvent((int)LogicEventDefine.EID_EVENT_CHAT_REFRESH, info);
|
||
}
|
||
|
||
//只有组队频道才有弹幕
|
||
if (result.chatchannel == (int)ChatChanelType.TEAM)
|
||
{
|
||
//GameCenter.PushFixEvent((int)UIEventDefine.UIDanMuForm_OPEN, info);
|
||
}
|
||
|
||
//公会消息,刷新主界面公会聊天按钮红点
|
||
if (result.chatchannel == (int)ChatChanelType.GUILD)
|
||
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_GUILD_CHAT_REDPOINT_REFRESH);
|
||
}
|
||
}
|
||
|
||
//发送位置
|
||
public void SendPos(ChatChanelType type, int param = 0)
|
||
{
|
||
string text = string.Empty;
|
||
if (GameCenter.GameSceneSystem.GetActivedScene().Cfg.IsLink == 0)
|
||
{
|
||
GameCenter.MsgPromptSystem.ShowPrompt(Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_CHAT_ZUOBIAO_FAILED));
|
||
return;
|
||
}
|
||
Vector2 position = GameCenter.GameSceneSystem.GetLocalPlayer().Position2d;
|
||
int mapid = GameCenter.GameSceneSystem.ActivedScene.MapId;
|
||
ChatNode node = new ChatNode();
|
||
node.Type = (int)TNodeType.Position;
|
||
node.Param1 = string.Format("{0},{1},{2}", (int)position.x, (int)position.y, param);
|
||
node.Param2 = string.Format("{0}", mapid);
|
||
|
||
GameCenter.ChatSystem.CacheSendNodes.Add(node);
|
||
ChatInfo info = new ChatInfo()
|
||
{
|
||
Channel = (int)type,
|
||
SendId = GameCenter.GameSceneSystem.GetLocalPlayerID(),
|
||
SendName = GameCenter.GameSceneSystem.GetLocalPlayer().Name,
|
||
ChatType = (int)ChatType.TEXT,
|
||
};
|
||
|
||
//GameCenter.ChatInsertSystem.AddChatToHistoryData(GameCenter.ChatSystem.CacheSendNodes);
|
||
SendMessage(info);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region//UI界面按钮的回调函数
|
||
|
||
#endregion
|
||
|
||
public class LeaveMsg
|
||
{
|
||
public int time = 0;
|
||
public bool isRobot = false;
|
||
public MSG_Chat.ChatResInfo msg = null;
|
||
public MSG_Chat.PersonalChatNotice notice = null;
|
||
}
|
||
|
||
public class TranslateInfo
|
||
{
|
||
public ChatResInfo msg = null; //消息数据
|
||
public bool isHistory = false; //是否是历史数据
|
||
public string receiveTime = string.Empty; //消息接收时间
|
||
}
|
||
}
|
||
}
|