/// <summary>
        /// 处理客户端请求
        /// </summary>
        /// <param name="tcpMgr"></param>
        /// <param name="socket"></param>
        /// <param name="tcpClientPool"></param>
        /// <param name="pool"></param>
        /// <param name="nID"></param>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <param name="tcpOutPacket"></param>
        /// <returns></returns>
        public static TCPProcessCmdResults ProcessQueryTodayCandoInfo(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData = null;

            string[] fields = null;
            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                fields = cmdData.Split(':');

                if (fields.Length != 2)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int roleID = Convert.ToInt32(fields[0]);

                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != roleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), roleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                int typeid = Global.SafeConvertToInt32(fields[1]);
                List <TodayCandoData> datalist = TodayCandoManager.GetRoleCandoData(typeid, client);
                tcpOutPacket = DataHelper.ObjectToTCPOutPacket <List <TodayCandoData> >(datalist, pool, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "QueryTodayCandoInfo", false);
            }
            return(TCPProcessCmdResults.RESULT_FAILED);
        }
        /// <summary>
        /// 获得数据
        /// </summary>
        /// <param name="typeId"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        private static List <TodayCandoData> GetRoleCandoData(int typeId, GameClient client)
        {
            List <TodayCandoData> candolist = new List <TodayCandoData>();

            if (xmlData == null)
            {
                return(null);
            }
            IEnumerable <XElement> xmlItems = xmlData.Elements();
            int iMaxlevel      = -1;
            int iMaxchangelife = -1;
            int ifirst         = 0;
            int lastSectype    = -1;
            Dictionary <int, List <TodayCandoData> > temp = new Dictionary <int, List <TodayCandoData> >();

            foreach (var item in xmlItems)
            {
                if (null != item)
                {
                    int      type             = (int)Global.GetSafeAttributeLong(item, "Type");
                    string[] minilevel        = Global.GetSafeAttributeStr(item, "MinLevel").Split(',');
                    string[] maxlevel         = Global.GetSafeAttributeStr(item, "MaxLevel").Split(',');
                    int      curmaxchangelife = Global.SafeConvertToInt32(minilevel[0]);
                    int      curmaxlevel      = Global.SafeConvertToInt32(minilevel[1]);
                    string   NeedRenWu        = Global.GetSafeAttributeStr(item, "NeedRenWu");
                    bool     condition1       = false;

                    //判断等级
                    if (Global.SafeConvertToInt32(minilevel[0]) < client.ClientData.ChangeLifeCount && client.ClientData.ChangeLifeCount < Global.SafeConvertToInt32(maxlevel[0]))
                    {
                        condition1 = true;
                    }
                    if (Global.SafeConvertToInt32(minilevel[0]) == client.ClientData.ChangeLifeCount)
                    {
                        if (Global.SafeConvertToInt32(minilevel[1]) <= client.ClientData.Level)
                        {
                            condition1 = true;
                        }
                    }
                    if (Global.SafeConvertToInt32(maxlevel[0]) == client.ClientData.ChangeLifeCount)
                    {
                        if (Global.SafeConvertToInt32(maxlevel[1]) >= client.ClientData.Level)
                        {
                            condition1 = true;
                        }
                    }

                    //判断前置任务
                    bool condition2 = false;
                    if (string.IsNullOrEmpty(NeedRenWu))
                    {
                        condition2 = true;
                    }
                    else
                    {
                        int taskid = Global.SafeConvertToInt32(NeedRenWu);
                        condition2 = TaskHasDone(client, taskid);
                        //OldTaskData taskData = null;
                        //if (type == typeId)
                        //{
                        //    taskData = Global.FindOldTaskByTaskID(client, taskid);
                        //}

                        //if (null != taskData) //如果任务存在
                        //{
                        //    if (taskData.DoCount > 0)
                        //        condition2 = true;

                        //}
                    }


                    if (type == typeId && condition1 && condition2)
                    {
                        TodayCandoData data = new TodayCandoData();
                        data.ID = (int)Global.GetSafeAttributeLong(item, "ID");
                        int secondtype = (int)Global.GetSafeAttributeLong(item, "SecondType");
                        if (ifirst == 0)
                        {
                            lastSectype = secondtype;
                        }
                        else if (ifirst != 0 && lastSectype != secondtype)
                        {
                            iMaxchangelife = curmaxchangelife;
                            iMaxlevel      = curmaxlevel;
                        }

                        ifirst += 1;
                        if (iMaxchangelife < curmaxchangelife && lastSectype == secondtype)
                        {
                            if (temp.ContainsKey(secondtype))
                            {
                                foreach (var tempitem in temp[secondtype])
                                {
                                    candolist.Remove(tempitem);
                                }
                                temp[secondtype] = new List <TodayCandoData>();
                            }

                            iMaxchangelife = curmaxchangelife;
                            iMaxlevel      = curmaxlevel;
                            //lastSectype =
                        }
                        if (iMaxchangelife == curmaxchangelife && iMaxlevel < curmaxlevel && lastSectype == secondtype)
                        {
                            if (temp.ContainsKey(secondtype))
                            {
                                foreach (var tempitem in temp[secondtype])
                                {
                                    candolist.Remove(tempitem);
                                }
                                temp[secondtype] = new List <TodayCandoData>();
                            }
                            iMaxchangelife = curmaxchangelife;
                            iMaxlevel      = curmaxlevel;
                        }

                        int copyId    = (int)Global.GetSafeAttributeLong(item, "CodeID");
                        int leftcount = TodayCandoManager.GetLeftCountByType(client, secondtype, copyId);
                        if (leftcount <= 0)
                        {
                            continue;
                        }

                        data.LeftCount = leftcount;

                        candolist.Add(data);
                        if (temp.ContainsKey(secondtype))
                        {
                            temp[secondtype].Add(data);
                        }
                        else
                        {
                            temp[secondtype] = new List <TodayCandoData>();
                            temp[secondtype].Add(data);
                        }

                        lastSectype = secondtype;
                    }
                }
            }

            return(candolist);
        }
示例#3
0
        private static List <TodayCandoData> GetRoleCandoData(int typeId, GameClient client)
        {
            List <TodayCandoData> candolist = new List <TodayCandoData>();
            List <TodayCandoData> result;

            if (TodayCandoManager.xmlData == null)
            {
                result = null;
            }
            else
            {
                IEnumerable <XElement> xmlItems = TodayCandoManager.xmlData.Elements();
                int iMaxlevel      = -1;
                int iMaxchangelife = -1;
                int ifirst         = 0;
                int lastSectype    = -1;
                Dictionary <int, List <TodayCandoData> > temp = new Dictionary <int, List <TodayCandoData> >();
                foreach (XElement item in xmlItems)
                {
                    if (null != item)
                    {
                        int      type      = (int)Global.GetSafeAttributeLong(item, "Type");
                        string[] minilevel = Global.GetSafeAttributeStr(item, "MinLevel").Split(new char[]
                        {
                            ','
                        });
                        string[] maxlevel = Global.GetSafeAttributeStr(item, "MaxLevel").Split(new char[]
                        {
                            ','
                        });
                        int    curmaxchangelife = Global.SafeConvertToInt32(minilevel[0]);
                        int    curmaxlevel      = Global.SafeConvertToInt32(minilevel[1]);
                        string NeedRenWu        = Global.GetSafeAttributeStr(item, "NeedRenWu");
                        bool   condition        = false;
                        if (Global.SafeConvertToInt32(minilevel[0]) < client.ClientData.ChangeLifeCount && client.ClientData.ChangeLifeCount < Global.SafeConvertToInt32(maxlevel[0]))
                        {
                            condition = true;
                        }
                        if (Global.SafeConvertToInt32(minilevel[0]) == client.ClientData.ChangeLifeCount)
                        {
                            if (Global.SafeConvertToInt32(minilevel[1]) <= client.ClientData.Level)
                            {
                                condition = true;
                            }
                        }
                        if (Global.SafeConvertToInt32(maxlevel[0]) == client.ClientData.ChangeLifeCount)
                        {
                            if (Global.SafeConvertToInt32(maxlevel[1]) >= client.ClientData.Level)
                            {
                                condition = true;
                            }
                        }
                        bool condition2;
                        if (string.IsNullOrEmpty(NeedRenWu))
                        {
                            condition2 = true;
                        }
                        else
                        {
                            int taskid = Global.SafeConvertToInt32(NeedRenWu);
                            condition2 = TodayCandoManager.TaskHasDone(client, taskid);
                        }
                        if (type == typeId && condition && condition2)
                        {
                            TodayCandoData data = new TodayCandoData();
                            data.ID = (int)Global.GetSafeAttributeLong(item, "ID");
                            int secondtype = (int)Global.GetSafeAttributeLong(item, "SecondType");
                            if (ifirst == 0)
                            {
                                lastSectype = secondtype;
                            }
                            else if (ifirst != 0 && lastSectype != secondtype)
                            {
                                iMaxchangelife = curmaxchangelife;
                                iMaxlevel      = curmaxlevel;
                            }
                            ifirst++;
                            if (iMaxchangelife < curmaxchangelife && lastSectype == secondtype)
                            {
                                if (temp.ContainsKey(secondtype))
                                {
                                    foreach (TodayCandoData tempitem in temp[secondtype])
                                    {
                                        candolist.Remove(tempitem);
                                    }
                                    temp[secondtype] = new List <TodayCandoData>();
                                }
                                iMaxchangelife = curmaxchangelife;
                                iMaxlevel      = curmaxlevel;
                            }
                            if (iMaxchangelife == curmaxchangelife && iMaxlevel < curmaxlevel && lastSectype == secondtype)
                            {
                                if (temp.ContainsKey(secondtype))
                                {
                                    foreach (TodayCandoData tempitem in temp[secondtype])
                                    {
                                        candolist.Remove(tempitem);
                                    }
                                    temp[secondtype] = new List <TodayCandoData>();
                                }
                                iMaxchangelife = curmaxchangelife;
                                iMaxlevel      = curmaxlevel;
                            }
                            int copyId    = (int)Global.GetSafeAttributeLong(item, "CodeID");
                            int leftcount = TodayCandoManager.GetLeftCountByType(client, secondtype, copyId);
                            if (leftcount > 0)
                            {
                                data.LeftCount = leftcount;
                                candolist.Add(data);
                                if (temp.ContainsKey(secondtype))
                                {
                                    temp[secondtype].Add(data);
                                }
                                else
                                {
                                    temp[secondtype] = new List <TodayCandoData>();
                                    temp[secondtype].Add(data);
                                }
                                lastSectype = secondtype;
                            }
                        }
                    }
                }
                result = candolist;
            }
            return(result);
        }