Example #1
0
        //传闻电视广播
        private void Fun_10_7(INetData data)
        {
            ChatRumorMsg_10_7 chatRumorMsg = new ChatRumorMsg_10_7();

            chatRumorMsg.read(data.GetMemoryStream());

            string content = GetRumorText(chatRumorMsg);

            Singleton <ChatMode> .Instance.Rumor = content;
            SendNoticeMsg(content);
        }
Example #2
0
        private string GetRumorText(ChatRumorMsg_10_7 rumorMsg)
        {
            string result     = string.Empty;
            string roleTag    = "$role$";
            string goodsTag   = "$goods$";
            string monsterTag = "$mon$";
            string intTag     = "$int$";
            string stringTag  = "$string$";

            SysRumor rumorVo = BaseDataMgr.instance.GetSysRumor(rumorMsg.typeId);

            if (null == rumorVo)
            {
                return(result);
            }

            PRumor rumerContent = new PRumor();

            if (rumorMsg.content.Count > 0)
            {
                rumerContent = rumorMsg.content[0];
            }

            string formatStr       = rumorVo.format;
            int    i               = 0;
            int    roleTagIndex    = 0;
            int    goodsTagIndex   = 0;
            int    monsterTagIndex = 0;
            int    intTagIndex     = 0;
            int    stringTagIndex  = 0;

            while (i < formatStr.Length)
            {
                if ('$' != formatStr[i])
                {
                    result += formatStr[i];
                    i++;
                }
                else
                {
                    //角色
                    if (roleTag == formatStr.Substring(i, roleTag.Length))
                    {
                        result += "[00ff00]" + rumerContent.role[roleTagIndex].name + "[-]";
                        roleTagIndex++;
                        i += roleTag.Length;
                    }
                    //物品
                    else if (goodsTag == formatStr.Substring(i, goodsTag.Length))
                    {
                        uint      goodsId = rumerContent.goods[goodsTagIndex].goodsId;
                        SysItemVo vo      = BaseDataMgr.instance.GetDataById <SysItemVo>(goodsId);
                        result += "[0000ff]" + vo.name + "[-]";
                        goodsTagIndex++;
                        i += goodsTag.Length;
                    }
                    //怪物
                    else if (monsterTag == formatStr.Substring(i, monsterTag.Length))
                    {
                        uint         monsterId = rumerContent.mon[monsterTagIndex].monId;
                        SysMonsterVo vo        = BaseDataMgr.instance.GetDataById <SysMonsterVo>(monsterId);
                        result += "[ff0000]" + vo.name + "[-]";
                        monsterTagIndex++;
                        i += monsterTag.Length;
                    }
                    //数值
                    else if (intTag == formatStr.Substring(i, intTag.Length))
                    {
                        result += "[ffff00]" + rumerContent.iData[intTagIndex] + "[-]";
                        intTagIndex++;
                        i += intTag.Length;
                    }
                    //字符串
                    else if (stringTag == formatStr.Substring(i, stringTag.Length))
                    {
                        result += "[00ffff]" + rumerContent.sData[stringTagIndex] + "[-]";
                        stringTagIndex++;
                        i += stringTag.Length;
                    }
                    //普通字符
                    else
                    {
                        result += formatStr[i];
                        i++;
                    }
                }
            }

            return(result);
        }