public int AnswerResultCompare(AnswerResult_S x, AnswerResult_S y) { int value = y.score.CompareTo(x.score); return(value); }
private void Game_QA_Thread(object obj) { while (true) { if (!m_QAStop) { //check time if (IsTaskTime()) { answerResult.Clear(); while (m_QACount < m_MaxQuesNum) { if (m_QACount == 0) { SendWorldWords("三国知识竞答即将开始!请各位玩家做好答题准备,找个安静的地图或者关闭不需要的频道"); Thread.Sleep(10 * 1000); SendWorldWords("最先给出正确答案者获得积分,答题需在军团或者军团互通中,发送且仅发送正确选项,否则答题将会被认为无效而过滤。"); Thread.Sleep(20 * 1000); SendWorldWords("答题开始!"); Thread.Sleep(2 * 1000); } SingleAQHandle(1, m_PlayerDat); } //遍历参与者列表排名 answerResult.Sort(new Comparison <AnswerResult_S>(AnswerResultCompare)); if (answerResult.Count <= 0) { string msg = "很遗憾,本次答题无人优胜!"; LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd") + @"答题日志.txt", msg); SendWorldWords(msg); } else { int num = 0; List <AnswerResult_S> ff = new List <AnswerResult_S>(); AnswerResult_S tmp = new AnswerResult_S(); tmp.score = 0; for (int i = 0; i < answerResult.Count; i++) { if (tmp.score == answerResult[i].score) { tmp.name += "," + answerResult[i].name; ff[num - 1] = tmp; } else { tmp = answerResult[i]; ff.Add(tmp); num++; } } int best = ff.Count > 3 ? 3 : ff.Count; for (int i = 0; i < best; i++) { string msg = "第" + (i + 1) + "名 总得分:" + ff[i].score + " 玩家 " + ff[i].name + "。"; LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd") + @"答题日志.txt", msg); //公告 SendWorldWords(msg); } for (int i = 0; i < best; i++) { //发放虚宝 CPlayerCtrl.PlayersAttrListClear(); CPlayerCtrl.LoadPlayerInfos(m_PlayerDat, true); var players = ff[i].name.Split(','); foreach (var player in players) { if (!string.IsNullOrEmpty(player)) { string account = CPlayerCtrl.GetAccByName(player); if (m_TaskRewardString.Count > 0) { int vtid1 = 0; int vtid2 = 0; int vtid3 = 0; int vtid4 = 0; int vtid5 = 0; int vtcount1 = 0; int vtcount2 = 0; int vtcount3 = 0; int vtcount4 = 0; int vtcount5 = 0; string[] rewards = m_TaskRewardString[i].Split(';'); //1,木剑,1 for (int ii = 0; ii <= rewards.Length; ii++) { var detials = rewards[ii].Split(','); if (ii == 0) { vtid1 = int.Parse(detials[0]); vtcount1 = int.Parse(detials[2]); } else if (ii == 1) { vtid2 = int.Parse(detials[0]); vtcount2 = int.Parse(detials[2]); } else if (ii == 2) { vtid3 = int.Parse(detials[0]); vtcount3 = int.Parse(detials[2]); } else if (ii == 3) { vtid4 = int.Parse(detials[0]); vtcount4 = int.Parse(detials[2]); } else if (ii == 4) { vtid5 = int.Parse(detials[0]); vtcount5 = int.Parse(detials[2]); } } if (vtid1 != 0 || vtid2 != 0 || vtid3 != 0 || vtid4 != 0 || vtid5 != 0) { bool vtret = CSGHelper.InsertSanvtItem(account , (uint)vtid1, (uint)vtcount1, (uint)vtid2, (uint)vtcount2, (uint)vtid3, (uint)vtcount3, (uint)vtid4, (uint)vtcount4, (uint)vtid5, (uint)vtcount5); if (vtret) { string answerEx = "角色:" + player + " 答题奖励已经发放,请注意查收(虚宝)!"; //日志 LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd") + "答题日志.txt", answerEx); } } } else { //发放虚宝 bool vtret = CSGHelper.InsertSanvtItem(account, (uint)m_AnswerVtId, 1, 0, 0, 0, 0, 0, 0, 0, 0); if (vtret) { string answerEx = "角色:" + player + " 答题奖励已经发放,请注意查收(虚宝)!"; //日志 LogHelper.WriteLog(DateTime.Now.ToString("yyyy-MM-dd") + "答题日志.txt", answerEx); } } } } } //公告 SendWorldWords("排名奖励已经发放,请注意查收(虚宝)!"); answerResult.Clear(); } } else { if (m_SleepCount >= m_AskNormalInterval)//60 * { m_SleepCount = 0; SingleAQHandle(0, m_PlayerDat); } Thread.Sleep(1000); m_SleepCount++; } } else { m_QAARE.WaitOne(); } } }