任务:修改taskType

This commit is contained in:
陆莹
2022-03-18 20:50:11 +08:00
parent 37d2e6cfa7
commit 1c3d1c209c
24 changed files with 821 additions and 2102 deletions

View File

@@ -47,51 +47,23 @@ export default class UserTaskRec extends BaseModel {
}
}
public static async setTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, record?: string) {
public static async setTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, records?: string[]) {
let condition = this.getRefreshCondition(type);
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $set: { count }, $addToSet: { records: record||'' } }, { new: true, upsert: true }).lean();
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $set: { count, records: records||[] } }, { new: true, upsert: true }).lean();
return rec;
}
public static async incTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, record?: string) {
public static async incTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, records?: string[]) {
let condition = this.getRefreshCondition(type);
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $inc: { count }, $addToSet: { records: record||'' } }, { new: true, upsert: true }).lean();
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $inc: { count }, $set: { records: records||[] } }, { new: true, upsert: true }).lean();
return rec;
}
/**
* 检查是否可以更新任务并更新
* @param roleId 玩家id
* @param type 任务大类型,日常、成就、每日
* @param taskType 任务类型
* @param group 活动组
* @param param 更新参数
* @returns
*/
public static async checkAndUpdateTask(roleId: string, type: TASK_FUN_TYPE, taskType: number, group: string, param: UpdateTaskParam) {
let canSet = true;
if(param.record || param.max || param.min) {
let rec = await this.findByRoleAndGroup(roleId, type, taskType, group);
if(rec) {
if(param.record && rec.records.indexOf(param.record) != -1) {
canSet = false;
} else if (param.max && rec.count >= param.max) {
canSet = false;
} else if (param.min && rec.count <= param.min) {
canSet = false;
}
}
}
if(canSet) {
return await this.setOrIncTask(roleId, type, taskType, group, param);
}
}
public static async setOrIncTask(roleId: string, type: number, taskType: number, group: string, param: UpdateTaskParam) {
if(param.set) {
return await this.setTaskRec(roleId, type, taskType, group, param.set, param.record);
return await this.setTaskRec(roleId, type, taskType, group, param.set, param.records);
} else if (param.inc) {
return await this.incTaskRec(roleId, type, taskType, group, param.inc, param.record);
return await this.incTaskRec(roleId, type, taskType, group, param.inc, param.records);
}
}