bool doHandler(int taskId, int count, ref byte[] doneParam, ref string stepRecord, ref int curTimes, ref int status, EnumTaskRequireFunc requireType, int subParam = 0, int thirdParam = 0, string doneKey = "") { try { if (count <= 0)//次数,对应一次分解6张卡这种情况 { count = 1; } var taskCache = CacheFactory.TaskConfigCache.GetTask(taskId); if (taskCache == null) { SystemlogMgr.Error("TaskHandler", "no task config taskid:" + taskId); return(false); } int tempRequireType = (int)requireType; if (!taskCache.RequireFuncDic.ContainsKey(tempRequireType)) { return(false); } TaskDoneRecordEntity doneRecordEntity = null; if (taskCache.UniqueConstraint) { if (doneParam == null || doneParam.Length <= 0) { doneRecordEntity = new TaskDoneRecordEntity(taskCache.RequireList.Count); } else { doneRecordEntity = SerializationHelper.FromByte <TaskDoneRecordEntity>(doneParam); } } var stepArray = BuildStepArray(stepRecord, taskCache.RequireList.Count); bool sync = false; for (int i = 0; i < taskCache.RequireList.Count; i++) { if (doneRecordEntity != null) { if (doneRecordEntity.Records[i].Params.Contains(doneKey)) { continue; } } var taskrequireEntity = taskCache.RequireList[i]; //处理连胜 if (requireType == EnumTaskRequireFunc.LadderFight || requireType == EnumTaskRequireFunc.FriendMatchCount) { if (taskrequireEntity.RequireType == (int)requireType) { if (taskrequireEntity.RequireSub == (int)EnumTaskWinType.WinningStreak) { if (subParam == (int)EnumWinType.Win) { subParam = (int)EnumTaskWinType.WinningStreak; } else { subParam = 0; sync = true; curTimes = 0; } } } } if (CheckTaskRequire(taskrequireEntity, requireType, subParam, thirdParam)) { if (doneRecordEntity != null) { doneRecordEntity.Records[i].Add(doneKey); } stepArray[i] = "1"; sync = true; } } bool isDone = true; foreach (var s in stepArray) { if (s != "1") { isDone = false; break; } } if (isDone) { sync = true; curTimes += count; if (curTimes >= taskCache.Times) { status = (int)EnumTaskStatus.Done; } stepRecord = ""; } else { stepRecord = string.Join(",", stepArray); } if (sync) { if (doneRecordEntity != null) { doneParam = SerializationHelper.ToByte(doneRecordEntity); } } return(sync); } catch (Exception ex) { SystemlogMgr.Error("Task Handler", ex); return(false); } }
//成就任务 private bool doAchievementHandler(Guid managerId, int taskId, int count, ref byte[] doneParam, ref string stepRecord, ref int curTimes, ref int status, EnumTaskRequireFunc requireType, int subParam = 0, int thirdParam = 0, string doneKey = "") { try { var taskCache = CacheFactory.TaskConfigCache.GetTask(taskId); if (taskCache == null) { SystemlogMgr.Error("TaskHandler", "no task config taskid:" + taskId); return(false); } int tempRequireType = (int)requireType; if (!taskCache.RequireFuncDic.ContainsKey(tempRequireType)) { return(false); } TaskDoneRecordEntity doneRecordEntity = null; if (taskCache.UniqueConstraint) { if (doneParam == null || doneParam.Length <= 0) { doneRecordEntity = new TaskDoneRecordEntity(taskCache.RequireList.Count); } else { doneRecordEntity = SerializationHelper.FromByte <TaskDoneRecordEntity>(doneParam); } } var stepArray = BuildStepArray(stepRecord, taskCache.RequireList.Count); bool sync = false; for (int i = 0; i < taskCache.RequireList.Count; i++) { if (doneRecordEntity != null) { if (doneRecordEntity.Records[i].Params.Contains(doneKey)) { continue; } } var require = taskCache.RequireList[i]; if (require.RequireType == (int)EnumTaskRequireFunc.PlayCardCollection) { if (require.RequireSub != 0 && require.RequireSub <= 4) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { switch (require.RequireSub) { case 4: curTimes = achievementManager.PurpleCardCount; break; case 3: curTimes = achievementManager.OrangeCardCount; break; case 2: curTimes = achievementManager.SilverCardCount; break; case 1: curTimes = achievementManager.GoldCardCount; break; } stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.PlayerCardLevel) { if (require.RequireSub != 0 && require.RequireSub <= 30) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { switch (require.RequireSub) { case 5: curTimes = achievementManager.Level5CardCount; break; case 10: curTimes = achievementManager.Level10CardCount; break; case 20: curTimes = achievementManager.Level20CardCount; break; case 30: curTimes = achievementManager.Level30CardCount; break; } stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.LeagueChampionScore) { if (require.RequireSub != 0 && require.RequireSub <= 8) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { switch (require.RequireSub) { case 1: if (achievementManager.LeagueScore1 >= require.RequireThird) { curTimes = 1; } break; case 2: if (achievementManager.LeagueScore2 >= require.RequireThird) { curTimes = 1; } break; case 3: if (achievementManager.LeagueScore3 >= require.RequireThird) { curTimes = 1; } break; case 4: if (achievementManager.LeagueScore4 >= require.RequireThird) { curTimes = 1; } break; case 5: if (achievementManager.LeagueScore5 >= require.RequireThird) { curTimes = 1; } break; case 6: if (achievementManager.LeagueScore6 >= require.RequireThird) { curTimes = 1; } break; case 7: if (achievementManager.LeagueScore7 >= require.RequireThird) { curTimes = 1; } break; case 8: if (achievementManager.LeagueScore8 >= require.RequireThird) { curTimes = 1; } break; } } } } else if (require.RequireType == (int)EnumTaskRequireFunc.DailyCupRank) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { if (achievementManager.MaxDailyCupRank <= require.RequireSub) { curTimes = 1; stepArray[i] = "1"; } } } if (require.RequireType == (int)EnumTaskRequireFunc.PkMatchGoals) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { if (achievementManager.MaxPkMatchGoals >= curTimes) { curTimes = achievementManager.MaxPkMatchGoals; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.PkMatchDayGoals) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { if (achievementManager.DayPkMatchGoals >= curTimes) { curTimes = achievementManager.DayPkMatchGoals; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.LadderWinCountSeason) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { if (achievementManager.MaxLadderWin >= curTimes) { curTimes = achievementManager.MaxLadderWin; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.LadderMatchGoals) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { if (achievementManager.MaxLadderGoals >= curTimes) { curTimes = achievementManager.MaxLadderGoals; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.FriendMatchWin) { var achievementManager = AchievementManagerMgr.GetById(managerId); if (achievementManager != null) { if (achievementManager.MaxFriendWinComb >= curTimes) { curTimes = achievementManager.MaxFriendWinComb; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.PkOrFriendMatchCount) { var matchStat = NbMatchstatMgr.GetByManager(managerId); if (matchStat != null) { var matchCount = 0; foreach (var nbMatchstatEntity in matchStat) { if (nbMatchstatEntity.MatchType == (int)EnumMatchType.PlayerKill || nbMatchstatEntity.MatchType == (int)EnumMatchType.Friend) { matchCount += nbMatchstatEntity.TotalCount; } } if (matchCount >= curTimes) { curTimes = matchCount; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.LadderMatchCount) { var matchStat = NbMatchstatMgr.GetByManagerAndType(managerId, (int)EnumMatchType.Ladder); if (matchStat != null) { if (matchStat.TotalCount >= curTimes) { curTimes = matchStat.TotalCount; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.FriendMatchCount) { var matchStat = NbMatchstatMgr.GetByManagerAndType(managerId, (int)EnumMatchType.Friend); if (matchStat != null) { if (matchStat.TotalCount >= curTimes) { curTimes = matchStat.TotalCount; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.LadderScore) { var ladderInfo = LadderCore.Instance.GetLadderManager(managerId); if (ladderInfo != null) { if (ladderInfo.MaxScore >= require.RequireSub) { curTimes = ladderInfo.MaxScore; stepArray[i] = "1"; } } } else if (require.RequireType == (int)EnumTaskRequireFunc.PlayerCardStrengthCollection) { var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.AchievementUpdate); if (package != null) { var cardCount = package.GetStrengthCardCount(require.RequireSub, require.RequireThird); if (cardCount >= curTimes) { curTimes = cardCount; stepArray[i] = "1"; } } } if (doneRecordEntity != null) { doneRecordEntity.Records[i].Add(doneKey); } } bool isDone = true; foreach (var s in stepArray) { if (s != "1") { isDone = false; break; } } if (isDone) { sync = true; if (curTimes >= taskCache.Times) { status = (int)EnumTaskStatus.Done; } stepRecord = ""; } else { stepRecord = string.Join(",", stepArray); } if (sync) { if (doneRecordEntity != null) { doneParam = SerializationHelper.ToByte(doneRecordEntity); } } return(sync); } catch (Exception ex) { SystemlogMgr.Error("Task Handler", ex); return(false); } }