Пример #1
0
        /// <summary>
        /// 任务重置
        /// </summary>
        /// <param name="note"></param>
        public static object TaskReset(Notification note)
        {
            string connectionString = ConfigLoader.Config.DbPlayer;
            var db = MongoDatabase.Create(connectionString);
            //取得角色列表
            var mc = db.GetCollection("Player");

            IList nowtask = note.GetValue<IList>(0);
            if (nowtask == null || nowtask.Count == 0)
                return null;
            string nowactid = note.GetString(1);//新触发的任务
            var v = mc.FindAll();
            Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
            List<string> tt = new List<string>()
            {
                "G_s120101","G_s120401","G_s120102","G_s120402","G_s120103","G_s120403"
            };
            dic.Add("1", tt);
            tt = new List<string>()
            {
                "G_s110101","G_s110401","G_s110102","G_s110402","G_s110103","G_s110403"
            };
            dic.Add("2", tt);
            tt = new List<string>()
            {
                "G_s130101","G_s130401","G_s130102","G_s130402","G_s130103","G_s130403"
            };
            dic.Add("3", tt);

            foreach (var item in v)
            {
                BsonValue o;
                if (item.TryGetValue("_id", out o))
                {
                    //将角色ID转换为十六进制
                    try
                    {
                        PlayerBusiness pb = PlayersProxy.FindPlayerByID(Convert.ToInt32(o));

                        if (pb == null)
                            continue;

                        int level = pb.Level;

                        List<Task> list = TaskAccess.Instance.GetTaskList(pb.ID);

                        bool isact = false;//是否需要触发新任务
                        string t = "";
                        foreach (Task task in list)
                        {
                            Variant tv = task.Value;
                            string taskid = tv.GetStringOrDefault("TaskID");
                            int tasktype = tv.GetIntOrDefault("TaskType");
                            if (tasktype != 0)
                                continue;
                            if (tv.GetIntOrDefault("Status") >= 3)
                                continue;
                            if (taskid == nowactid)
                                continue;
                            //表示存在这个新任务,则将这个移除
                            if (nowtask.Contains(taskid))
                            {
                                tv["Status"] = 3;
                                task.Save();
                                t = taskid;
                                isact = true;
                            }
                        }

                        if (isact)
                        {
                            GameConfig gc = GameConfigAccess.Instance.FindOneById(nowactid);
                            if (gc == null)
                                return null;
                            TaskManage.TaskBack(pb, gc);
                            LogWrapper.Warn(pb.UserID + "," + pb.Name + "," + t + "," + level);

                            List<Variant> goodsList = new List<Variant>();
                            List<string> g = dic[pb.RoleID];
                            for (int i = 0; i < g.Count; i++)
                            {
                                Variant gs = new Variant();
                                gs.Add("G", g[i]);
                                gs.Add("A", 1);
                                gs.Add("E", g[i]);
                                gs.Add("H", 1);
                                goodsList.Add(gs);
                            }

                            EmailAccess.Instance.SendEmail
                                (
                                "新手补偿",
                                TipManager.GetMessage(PetsReturn.StealPet12),
                                pb.ID,
                                pb.Name,
                                "因新手任务修改,可能会导致您的任务出错,请凉解!因此重置了您的任务,并且将您没有做的任务的道具通过邮件发送给您,因邮件存在过期时间,请尽快领取;特此申明!",
                                string.Empty,
                                goodsList, 15
                                );
                        }

                        if (pb.Level < 11)
                        {
                            pb.AddExperience(8200, FinanceType.GM, "2");
                        }
                        //移除任务内存
                        TaskAccess.Instance.Remove(pb.ID);
                    }
                    catch
                    {

                    }
                }
            }
            return "重置成功";
        }