/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is RoleChatData)) { return; } RoleChatData mData = (RoleChatData)data; if (mData.showData != null) { this.showData = (RoleSimpleShowData)mData.showData.clone(); } else { this.showData = null; nullObjError("showData"); } if (mData.chatData != null) { this.chatData = (ChatData)mData.chatData.clone(); } else { this.chatData = null; nullObjError("chatData"); } this.time = mData.time; this.sendIndex = mData.sendIndex; }
/// <summary> /// 接收聊天内容 /// </summary> public void onReceiveChat(RoleChatData chatData, int channel, long key) { ChatChannelConfig config = ChatChannelConfig.get(channel); ChatChannelData cData = getChatChannelData(channel, key); cData.queue.offer(chatData); if (config.keepNum > 0 && cData.queue.size() > config.keepNum) { cData.queue.poll(); } if (config.offlineReceive) { _chatReceiveIndex = chatData.sendIndex; _chatReceiveIndexModified = true; } NormalEvt evt = me.nEvt; evt.int0 = channel; evt.long0 = key; me.dispatchNormal(GameEventType.ReceiveChat); }
/// <summary> /// 读取字节流(完整版) /// </summary> protected override void toReadBytesFull(BytesReadStream stream) { base.toReadBytesFull(stream); stream.startReadObj(); BaseData chatDataT = stream.readDataFullNotNull(); if (chatDataT != null) { if (chatDataT is RoleChatData) { this.chatData = (RoleChatData)chatDataT; } else { this.chatData = new RoleChatData(); if (!(chatDataT.GetType().IsAssignableFrom(typeof(RoleChatData)))) { stream.throwTypeReadError(typeof(RoleChatData), chatDataT.GetType()); } this.chatData.shadowCopy(chatDataT); } } else { this.chatData = null; } this.channel = stream.readInt(); this.key = stream.readLong(); stream.endReadObj(); }
/// <summary> /// 写入字节流(完整版) /// </summary> protected override void toWriteBytesFull(BytesWriteStream stream) { stream.startWriteObj(); if (this.queue != null) { stream.writeLen(this.queue.size()); if (!this.queue.isEmpty()) { RoleChatData[] queueVValues = this.queue.getValues(); int queueVMark = this.queue.getMark(); int queueVStart = this.queue.getStart(); for (int queueVI = 0, queueVLen = this.queue.length(); queueVI < queueVLen; ++queueVI) { RoleChatData queueV = queueVValues[(queueVI + queueVStart) & queueVMark]; if (queueV != null) { stream.writeDataFullNotNull(queueV); } else { nullObjError("queueV"); } } } } else { nullObjError("queue"); } stream.endWriteObj(); }
/// <summary> /// 回池 /// </summary> protected override void toRelease(DataPool pool) { base.toRelease(pool); this.chatData = null; this.channel = 0; this.key = 0L; }
/// <summary> /// 读取字节流(简版) /// </summary> protected override void toReadBytesSimple(BytesReadStream stream) { base.toReadBytesSimple(stream); this.chatData = (RoleChatData)stream.readDataSimpleNotNull(); this.channel = stream.readInt(); this.key = stream.readLong(); }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { RoleChatData mData = (RoleChatData)data; if (mData.showData != null) { if (this.showData == null) { return(false); } if (!this.showData.dataEquals(mData.showData)) { return(false); } } else { if (this.showData != null) { return(false); } } if (mData.chatData != null) { if (this.chatData == null) { return(false); } if (!this.chatData.dataEquals(mData.chatData)) { return(false); } } else { if (this.chatData != null) { return(false); } } if (this.time != mData.time) { return(false); } if (this.sendIndex != mData.sendIndex) { return(false); } return(true); }
/// <summary> /// 发送聊天 /// </summary> public void chat(ChatData data, int channel, long key) { ChatChannelConfig config = ChatChannelConfig.get(channel); //条件不满足 if (!me.role.checkRoleConditions(config.useConditions, true)) { me.warnLog("聊天条件不满足", channel); return; } ChatChannelData cData = getChatChannelData(channel, key); long now = me.getTimeMillis(); if (config.cd > 0 && (cData.lastChatTime + config.cd > now)) { me.warnLog("聊天cd中", channel); return; } if (config.costID > 0 && !me.bag.hasCost(config.costID)) { me.warnLog("聊天cost不足", channel); return; } //文字 if (data.type == ChatType.Text && BaseGameUtils.hasSensitiveWord(data.text)) { me.warnLog("聊天有屏蔽字内容", data.text); return; } if (config.cd > 0) { cData.lastChatTime = now; } //需要自行添加的 if (channel == ChatChannelType.Whisper) { RoleChatData rData = new RoleChatData(); rData.chatData = data; rData.showData = me.role.createRoleSimpleShowData(); rData.time = me.getTimeMillis(); rData.sendIndex = _chatReceiveIndex; //当前序号 onReceiveChat(rData, channel, key); } me.send(PlayerChatRequest.create(data, channel, key)); }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { ChatChannelData mData = (ChatChannelData)data; if (mData.queue != null) { if (this.queue == null) { return(false); } if (this.queue.size() != mData.queue.size()) { return(false); } SQueue <RoleChatData> queueT = this.queue; SQueue <RoleChatData> queueR = mData.queue; int queueLen = queueT.size(); for (int queueI = 0; queueI < queueLen; ++queueI) { RoleChatData queueU = queueT.get(queueI); RoleChatData queueV = queueR.get(queueI); if (queueV != null) { if (queueU == null) { return(false); } if (!queueU.dataEquals(queueV)) { return(false); } } else { if (queueU != null) { return(false); } } } } else { if (this.queue != null) { return(false); } } return(true); }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is ChatChannelData)) { return; } ChatChannelData mData = (ChatChannelData)data; if (mData.queue != null) { if (this.queue != null) { this.queue.clear(); this.queue.ensureCapacity(mData.queue.size()); } else { this.queue = new SQueue <RoleChatData>(); } SQueue <RoleChatData> queueT = this.queue; if (!mData.queue.isEmpty()) { RoleChatData[] queueVValues = mData.queue.getValues(); int queueVMark = mData.queue.getMark(); int queueVStart = mData.queue.getStart(); for (int queueVI = 0, queueVLen = mData.queue.length(); queueVI < queueVLen; ++queueVI) { RoleChatData queueV = queueVValues[(queueVI + queueVStart) & queueVMark]; RoleChatData queueU; if (queueV != null) { queueU = (RoleChatData)queueV.clone(); } else { queueU = null; nullObjError("queueU"); } queueT.offer(queueU); } } } else { this.queue = null; nullObjError("queue"); } }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is RoleChatData)) { return; } RoleChatData mData = (RoleChatData)data; this.showData = mData.showData; this.chatData = mData.chatData; this.time = mData.time; this.sendIndex = mData.sendIndex; }
/// <summary> /// 读取字节流(完整版) /// </summary> protected override void toReadBytesFull(BytesReadStream stream) { stream.startReadObj(); int queueLen = stream.readLen(); if (this.queue != null) { this.queue.clear(); this.queue.ensureCapacity(queueLen); } else { this.queue = new SQueue <RoleChatData>(); } SQueue <RoleChatData> queueT = this.queue; for (int queueI = queueLen - 1; queueI >= 0; --queueI) { RoleChatData queueV; BaseData queueVT = stream.readDataFullNotNull(); if (queueVT != null) { if (queueVT is RoleChatData) { queueV = (RoleChatData)queueVT; } else { queueV = new RoleChatData(); if (!(queueVT.GetType().IsAssignableFrom(typeof(RoleChatData)))) { stream.throwTypeReadError(typeof(RoleChatData), queueVT.GetType()); } queueV.shadowCopy(queueVT); } } else { queueV = null; } queueT.offer(queueV); } stream.endReadObj(); }
/// <summary> /// 转文本输出 /// </summary> protected override void toWriteDataString(DataWriter writer) { writer.writeTabs(); writer.sb.Append("queue"); writer.sb.Append(':'); writer.sb.Append("Queue<RoleChatData>"); if (this.queue != null) { SQueue <RoleChatData> queueT = this.queue; int queueLen = queueT.size(); writer.sb.Append('('); writer.sb.Append(queueLen); writer.sb.Append(')'); writer.writeEnter(); writer.writeLeftBrace(); for (int queueI = 0; queueI < queueLen; ++queueI) { RoleChatData queueV = queueT.get(queueI); writer.writeTabs(); writer.sb.Append(queueI); writer.sb.Append(':'); if (queueV != null) { queueV.writeDataString(writer); } else { writer.sb.Append("RoleChatData=null"); } writer.writeEnter(); } writer.writeRightBrace(); } else { writer.sb.Append("=null"); } writer.writeEnter(); }