From da8dca2f22aebef3863d305cb0b7d90855c8a639 Mon Sep 17 00:00:00 2001 From: luying Date: Sat, 20 Nov 2021 10:48:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=EF=BC=9Agroup=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/db/UserTaskRec.ts | 18 +++++++++--------- shared/pubUtils/data.ts | 7 +++---- shared/pubUtils/dictionary/DicTask.ts | 2 +- shared/pubUtils/taskUtil.ts | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/shared/db/UserTaskRec.ts b/shared/db/UserTaskRec.ts index 1b055634f..884c887b1 100644 --- a/shared/db/UserTaskRec.ts +++ b/shared/db/UserTaskRec.ts @@ -25,7 +25,7 @@ export default class UserTaskRec extends BaseModel { taskType: number; // 行为类型 @prop({ required: true }) - group: number; // 行为类型下的分组 + group: string; // 行为类型下的分组 @prop({ required: true }) count: number; // 达成次数 @@ -43,20 +43,20 @@ export default class UserTaskRec extends BaseModel { } } - public static async setTaskRec(roleId: string, type: number, taskType: number, group: number, count: number) { + public static async setTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) { let condition = this.getRefreshCondition(type); let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $set: { count } }, { new: true, upsert: true }).lean(); return rec; } - public static async incTaskRec(roleId: string, type: number, taskType: number, group: number, count: number) { + public static async incTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) { let condition = this.getRefreshCondition(type); let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $inc: { count } }, { new: true, upsert: true }).lean(); return rec; } - public static async checkHistoryAndSetTaskRec(roleId: string, type: number, taskType: number, group: number, count: number) { - let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, group, taskType); + public static async checkHistoryAndSetTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) { + let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group); if(rec) { if(rec.count < count) { rec = await UserTaskRecModel.setTaskRec(roleId, type, taskType, group, count); @@ -70,24 +70,24 @@ export default class UserTaskRec extends BaseModel { public static async findByRoleAndType(roleId: string, type: number) { let condition = this.getRefreshCondition(type); let rec: UserTaskRecType[] = await UserTaskRecModel.find({ roleId, ...condition }).lean(); - let map = new Map>(); // taskType => group => userTask + let map = new Map>(); // taskType => group => userTask for(let userTaskRec of rec) { let { taskType, group } = userTaskRec; if(!map.has(taskType)) { - map.set(taskType, new Map()); + map.set(taskType, new Map()); } map.get(taskType).set(group, userTaskRec); } return map; } - public static async findByRoleAndGroup(roleId: string, type: number, taskType: number, group: number) { + public static async findByRoleAndGroup(roleId: string, type: number, taskType: number, group: string) { let condition = this.getRefreshCondition(type); let rec: UserTaskRecType = await UserTaskRecModel.findOne({ roleId, taskType, group, ...condition }).lean(); return rec; } - public static async receiveTask(roleId: string, type: number, taskType: number, group: number, id: number) { + public static async receiveTask(roleId: string, type: number, taskType: number, group: string, id: number) { let condition = this.getRefreshCondition(type); let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, taskType, group, ...condition }, { $push: { received: id } }, { new: true }).lean(); return rec; diff --git a/shared/pubUtils/data.ts b/shared/pubUtils/data.ts index 388af76dc..1e30184c3 100644 --- a/shared/pubUtils/data.ts +++ b/shared/pubUtils/data.ts @@ -888,12 +888,11 @@ function treatTaskGroup() { for(let [taskType, arr] of taskByGroup) { let tasks = gameData.taskType.get(taskType); for(let i = 0; i < arr.length; i++) { - let group = i + 1; - let { ids } = arr[i]; + let { params, ids } = arr[i]; for(let id of ids) { let task = tasks.find(cur => `${cur.type}_${cur.id}` == id); - task.group = group; - gameData.tasks.get(task.type).get(task.id).group = group; + task.group = params.join('&'); + gameData.tasks.get(task.type).get(task.id).group = params.join('&'); } } gameData.taskType.set(taskType, tasks); diff --git a/shared/pubUtils/dictionary/DicTask.ts b/shared/pubUtils/dictionary/DicTask.ts index 227087093..ad2973dab 100644 --- a/shared/pubUtils/dictionary/DicTask.ts +++ b/shared/pubUtils/dictionary/DicTask.ts @@ -12,7 +12,7 @@ interface DicTaskBase { // 任务类型 readonly taskType: number; // 类型下面的分组 - group: number; + group: string; // 任务参数 readonly taskParam: number[]; // 条件 diff --git a/shared/pubUtils/taskUtil.ts b/shared/pubUtils/taskUtil.ts index 8b580f23c..9d61ca4d2 100644 --- a/shared/pubUtils/taskUtil.ts +++ b/shared/pubUtils/taskUtil.ts @@ -319,7 +319,7 @@ export async function checkTask(roleId: string, taskType: number, count: number, for (let [typeAndGroup, { task0, tasks }] of groups) { let arr = typeAndGroup.split('_'); let type = parseInt(arr[0]); - let group = parseInt(arr[1]); + let group = arr[1]; let rec = await checkTaskRec(roleId, type, group, task0, count, isInc, param); if (rec) { @@ -335,7 +335,7 @@ export async function checkTask(roleId: string, taskType: number, count: number, } // 检查各项任务是否达成,达成了就保存到数据库 -export async function checkTaskRec(roleId: string, type: number, group: number, dicTask: DicTask, count: number, isInc: boolean, param: TaskParam) { +export async function checkTaskRec(roleId: string, type: number, group: string, dicTask: DicTask, count: number, isInc: boolean, param: TaskParam) { let { taskParam, taskType } = dicTask; let isMatch = true; // 条件是否满足