将两种任务初步合起来
This commit is contained in:
@@ -3,6 +3,7 @@ import { index, getModelForClass, prop, DocumentType, modelOptions } from '@type
|
||||
import { TASK_FUN_TYPE } from '../consts';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { getZeroPointD } from '../pubUtils/timeUtil';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 玩家任务记录表
|
||||
@@ -46,19 +47,53 @@ export default class UserTaskRec extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public static async setTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
|
||||
public static async setTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, record?: string) {
|
||||
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();
|
||||
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();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async incTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
|
||||
public static async incTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, record?: string) {
|
||||
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();
|
||||
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();
|
||||
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);
|
||||
} else if (param.inc) {
|
||||
return await this.incTaskRec(roleId, type, taskType, group, param.inc, param.record);
|
||||
}
|
||||
}
|
||||
|
||||
public static async checkHistoryAndSetTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
|
||||
let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group);
|
||||
|
||||
Reference in New Issue
Block a user