Example #1
0
        public static bool GetNpcTaskData(GameClient client, int extensionID, NPCData npcData)
        {
            //再查询属于指定NPC的是否有可以接的任务(要判断前置任务和后置任务等条件,以及级别等条件)

            //查询NPC上挂载的任务
            List <int> tasksList = null;

            if (!GameManager.NPCTasksMgr.SourceNPCTasksDict.TryGetValue(extensionID, out tasksList))
            {
                return(false);   //npc上没任务
            }
            if (0 == tasksList.Count)
            {
                return(false);   //npc上没任务
            }
            Dictionary <int, NpcCircleTaskData> all_circleTask = null;

            //遍历npc上挂载的所有任务,将跑环任务暂存起来稍后处理,非跑环任务直接处理
            for (int i = 0; i < tasksList.Count; i++)
            {
                int           taskID     = tasksList[i];
                SystemXmlItem systemTask = null;
                if (!GameManager.SystemTasksMgr.SystemXmlItemDict.TryGetValue(taskID, out systemTask))
                {
                    continue;   //配置错误,没这个任务
                }

                int taskClass = systemTask.GetIntValue("TaskClass");

                if (taskClass >= (int)TaskClasses.CircleTaskStart && taskClass <= (int)TaskClasses.CircleTaskEnd) //如果是跑环任务
                {
                    // 是否能接这种跑环任务
                    if (!Global.CanTaskPaoHuanTask(client, taskClass))
                    {
                        continue;
                    }
                    //判断是否是能接的新任务
                    if (!Global.CanTakeNewTask(client, taskID, systemTask))
                    {
                        continue;
                    }

                    //本次请求内是否处理过这种跑环任务
                    NpcCircleTaskData circletask = null;
                    if (null == all_circleTask || !all_circleTask.TryGetValue(taskClass, out circletask))
                    {
                        circletask           = new NpcCircleTaskData();
                        circletask.taskclass = taskClass;

                        //之前随机的任务ID
                        circletask.oldTaskID = PaoHuanTasksMgr.FindPaoHuanHistTaskID(client.ClientData.RoleID, taskClass);
                        if (circletask.oldTaskID >= 0)
                        {
                            //验证还是否能继续接
                            //判断是否是能接的新任务
                            if (!Global.CanTakeNewTask(client, circletask.oldTaskID))
                            {
                                circletask.oldTaskID = -1;
                            }
                        }

                        if (null == all_circleTask)
                        {
                            all_circleTask = new Dictionary <int, NpcCircleTaskData>();
                        }

                        all_circleTask[taskClass] = circletask;
                    }
                    //添加到列表
                    if (null != circletask)
                    {
                        circletask.NpcAttachedTaskID.Add(taskID);
                    }
                }
                else //非跑环任务,比如主线任务
                {
                    //判断是否是能接的新任务
                    if (!Global.CanTakeNewTask(client, taskID, systemTask))
                    {
                        continue;
                    }

                    //记录这个任务
                    if (null == npcData.NewTaskIDs)
                    {
                        npcData.NewTaskIDs = new List <int>();
                    }

                    npcData.NewTaskIDs.Add(taskID);

                    if ((int)TaskClasses.SpecialTask == taskClass) //如果是循环任务,要计算已经做过的次数
                    {
                        OldTaskData oldTaskData = Global.FindOldTaskByTaskID(client, tasksList[i]);
                        int         doneCount   = (null == oldTaskData) ? 0 : oldTaskData.DoCount;

                        if (null == npcData.NewTaskIDsDoneCount)
                        {
                            npcData.NewTaskIDsDoneCount = new List <int>();
                        }
                        npcData.NewTaskIDsDoneCount.Add(doneCount);
                    }
                    else
                    {
                        if (null == npcData.NewTaskIDsDoneCount)
                        {
                            npcData.NewTaskIDsDoneCount = new List <int>();
                        }
                        npcData.NewTaskIDsDoneCount.Add(0);
                    }
                }
            }

            //处理刚才暂存的跑环任务

            if (null == all_circleTask)
            {
                return(true);
            }

            foreach (var circletask in all_circleTask)
            {
                bool needRandom = false;
                if (-1 != circletask.Value.oldTaskID)
                {   //之前随机过任务ID
                    if (0 == circletask.Value.NpcAttachedTaskID.Count)
                    {
                        continue;   //npc上没这种跑环任务
                    }
                    //验证之前随机到的任务是否是存在的
                    if (-1 != circletask.Value.NpcAttachedTaskID.IndexOf(circletask.Value.oldTaskID))
                    {
                        //记录这个任务
                        if (null == npcData.NewTaskIDs)
                        {
                            npcData.NewTaskIDs = new List <int>();
                        }
                        npcData.NewTaskIDs.Add(circletask.Value.oldTaskID);
                        if (null == npcData.NewTaskIDsDoneCount)
                        {
                            npcData.NewTaskIDsDoneCount = new List <int>();
                        }
                        npcData.NewTaskIDsDoneCount.Add(0);
                    }
                    else
                    {
                        needRandom = true;
                    }
                }
                else
                {
                    needRandom = true;
                }

                if (needRandom)
                {
                    int randTaskId = circletask.Value.DoRandomTaskID(client);
                    if (-1 != randTaskId)
                    {
                        //记录这个任务
                        if (null == npcData.NewTaskIDs)
                        {
                            npcData.NewTaskIDs = new List <int>();
                        }
                        npcData.NewTaskIDs.Add(randTaskId);
                        if (null == npcData.NewTaskIDsDoneCount)
                        {
                            npcData.NewTaskIDsDoneCount = new List <int>();
                        }
                        npcData.NewTaskIDsDoneCount.Add(0);
                        PaoHuanTasksMgr.SetPaoHuanHistTaskID(client.ClientData.RoleID, circletask.Value.taskclass, randTaskId);
                    }
                }
            }

            return(true);
        }
Example #2
0
        public static bool GetNpcTaskData(GameClient client, int extensionID, NPCData npcData)
        {
            List <int> tasksList = null;
            bool       result;

            if (!GameManager.NPCTasksMgr.SourceNPCTasksDict.TryGetValue(extensionID, out tasksList))
            {
                result = false;
            }
            else if (0 == tasksList.Count)
            {
                result = false;
            }
            else
            {
                Dictionary <int, GlobalNew.NpcCircleTaskData> all_circleTask = null;
                for (int i = 0; i < tasksList.Count; i++)
                {
                    int           taskID     = tasksList[i];
                    SystemXmlItem systemTask = null;
                    if (GameManager.SystemTasksMgr.SystemXmlItemDict.TryGetValue(taskID, out systemTask))
                    {
                        int taskClass = systemTask.GetIntValue("TaskClass", -1);
                        if ((taskClass >= 3 && taskClass <= 9) || (taskClass >= 100 && taskClass <= 150))
                        {
                            if (Global.CanTaskPaoHuanTask(client, taskClass))
                            {
                                if (Global.CanTakeNewTask(client, taskID, systemTask))
                                {
                                    GlobalNew.NpcCircleTaskData circletask = null;
                                    if (all_circleTask == null || !all_circleTask.TryGetValue(taskClass, out circletask))
                                    {
                                        circletask           = new GlobalNew.NpcCircleTaskData();
                                        circletask.taskclass = taskClass;
                                        circletask.oldTaskID = PaoHuanTasksMgr.FindPaoHuanHistTaskID(client.ClientData.RoleID, taskClass);
                                        if (circletask.oldTaskID >= 0)
                                        {
                                            if (!Global.CanTakeNewTask(client, circletask.oldTaskID, null))
                                            {
                                                circletask.oldTaskID = -1;
                                            }
                                        }
                                        if (null == all_circleTask)
                                        {
                                            all_circleTask = new Dictionary <int, GlobalNew.NpcCircleTaskData>();
                                        }
                                        all_circleTask[taskClass] = circletask;
                                    }
                                    if (null != circletask)
                                    {
                                        circletask.NpcAttachedTaskID.Add(taskID);
                                    }
                                }
                            }
                        }
                        else if (Global.CanTakeNewTask(client, taskID, systemTask))
                        {
                            if (null == npcData.NewTaskIDs)
                            {
                                npcData.NewTaskIDs = new List <int>();
                            }
                            npcData.NewTaskIDs.Add(taskID);
                            if (2 == taskClass)
                            {
                                OldTaskData oldTaskData = Global.FindOldTaskByTaskID(client, tasksList[i]);
                                int         doneCount   = (oldTaskData == null) ? 0 : oldTaskData.DoCount;
                                if (null == npcData.NewTaskIDsDoneCount)
                                {
                                    npcData.NewTaskIDsDoneCount = new List <int>();
                                }
                                npcData.NewTaskIDsDoneCount.Add(doneCount);
                            }
                            else
                            {
                                if (null == npcData.NewTaskIDsDoneCount)
                                {
                                    npcData.NewTaskIDsDoneCount = new List <int>();
                                }
                                npcData.NewTaskIDsDoneCount.Add(0);
                            }
                        }
                    }
                }
                if (null == all_circleTask)
                {
                    result = true;
                }
                else
                {
                    foreach (KeyValuePair <int, GlobalNew.NpcCircleTaskData> circletask2 in all_circleTask)
                    {
                        bool needRandom = false;
                        if (-1 != circletask2.Value.oldTaskID)
                        {
                            if (0 == circletask2.Value.NpcAttachedTaskID.Count)
                            {
                                continue;
                            }
                            if (-1 != circletask2.Value.NpcAttachedTaskID.IndexOf(circletask2.Value.oldTaskID))
                            {
                                if (null == npcData.NewTaskIDs)
                                {
                                    npcData.NewTaskIDs = new List <int>();
                                }
                                npcData.NewTaskIDs.Add(circletask2.Value.oldTaskID);
                                if (null == npcData.NewTaskIDsDoneCount)
                                {
                                    npcData.NewTaskIDsDoneCount = new List <int>();
                                }
                                npcData.NewTaskIDsDoneCount.Add(0);
                            }
                            else
                            {
                                needRandom = true;
                            }
                        }
                        else
                        {
                            needRandom = true;
                        }
                        if (needRandom)
                        {
                            int randTaskId = circletask2.Value.DoRandomTaskID(client);
                            if (-1 != randTaskId)
                            {
                                if (null == npcData.NewTaskIDs)
                                {
                                    npcData.NewTaskIDs = new List <int>();
                                }
                                npcData.NewTaskIDs.Add(randTaskId);
                                if (null == npcData.NewTaskIDsDoneCount)
                                {
                                    npcData.NewTaskIDsDoneCount = new List <int>();
                                }
                                npcData.NewTaskIDsDoneCount.Add(0);
                                PaoHuanTasksMgr.SetPaoHuanHistTaskID(client.ClientData.RoleID, circletask2.Value.taskclass, randTaskId);
                            }
                        }
                    }
                    result = true;
                }
            }
            return(result);
        }