任务:group读取方式修改
This commit is contained in:
@@ -25,7 +25,7 @@ export default class UserTaskRec extends BaseModel {
|
|||||||
taskType: number; // 行为类型
|
taskType: number; // 行为类型
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
group: number; // 行为类型下的分组
|
group: string; // 行为类型下的分组
|
||||||
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
count: number; // 达成次数
|
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 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 } }, { new: true, upsert: true }).lean();
|
||||||
return rec;
|
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 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 } }, { new: true, upsert: true }).lean();
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async checkHistoryAndSetTaskRec(roleId: string, type: number, taskType: number, group: number, count: number) {
|
public static async checkHistoryAndSetTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
|
||||||
let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, group, taskType);
|
let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group);
|
||||||
if(rec) {
|
if(rec) {
|
||||||
if(rec.count < count) {
|
if(rec.count < count) {
|
||||||
rec = await UserTaskRecModel.setTaskRec(roleId, type, taskType, group, 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) {
|
public static async findByRoleAndType(roleId: string, type: number) {
|
||||||
let condition = this.getRefreshCondition(type);
|
let condition = this.getRefreshCondition(type);
|
||||||
let rec: UserTaskRecType[] = await UserTaskRecModel.find({ roleId, ...condition }).lean();
|
let rec: UserTaskRecType[] = await UserTaskRecModel.find({ roleId, ...condition }).lean();
|
||||||
let map = new Map<number, Map<number, UserTaskRecType>>(); // taskType => group => userTask
|
let map = new Map<number, Map<string, UserTaskRecType>>(); // taskType => group => userTask
|
||||||
for(let userTaskRec of rec) {
|
for(let userTaskRec of rec) {
|
||||||
let { taskType, group } = userTaskRec;
|
let { taskType, group } = userTaskRec;
|
||||||
if(!map.has(taskType)) {
|
if(!map.has(taskType)) {
|
||||||
map.set(taskType, new Map<number, UserTaskRecType>());
|
map.set(taskType, new Map<string, UserTaskRecType>());
|
||||||
}
|
}
|
||||||
map.get(taskType).set(group, userTaskRec);
|
map.get(taskType).set(group, userTaskRec);
|
||||||
}
|
}
|
||||||
return map;
|
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 condition = this.getRefreshCondition(type);
|
||||||
let rec: UserTaskRecType = await UserTaskRecModel.findOne({ roleId, taskType, group, ...condition }).lean();
|
let rec: UserTaskRecType = await UserTaskRecModel.findOne({ roleId, taskType, group, ...condition }).lean();
|
||||||
return rec;
|
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 condition = this.getRefreshCondition(type);
|
||||||
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, taskType, group, ...condition }, { $push: { received: id } }, { new: true }).lean();
|
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, taskType, group, ...condition }, { $push: { received: id } }, { new: true }).lean();
|
||||||
return rec;
|
return rec;
|
||||||
|
|||||||
@@ -888,12 +888,11 @@ function treatTaskGroup() {
|
|||||||
for(let [taskType, arr] of taskByGroup) {
|
for(let [taskType, arr] of taskByGroup) {
|
||||||
let tasks = gameData.taskType.get(taskType);
|
let tasks = gameData.taskType.get(taskType);
|
||||||
for(let i = 0; i < arr.length; i++) {
|
for(let i = 0; i < arr.length; i++) {
|
||||||
let group = i + 1;
|
let { params, ids } = arr[i];
|
||||||
let { ids } = arr[i];
|
|
||||||
for(let id of ids) {
|
for(let id of ids) {
|
||||||
let task = tasks.find(cur => `${cur.type}_${cur.id}` == id);
|
let task = tasks.find(cur => `${cur.type}_${cur.id}` == id);
|
||||||
task.group = group;
|
task.group = params.join('&');
|
||||||
gameData.tasks.get(task.type).get(task.id).group = group;
|
gameData.tasks.get(task.type).get(task.id).group = params.join('&');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gameData.taskType.set(taskType, tasks);
|
gameData.taskType.set(taskType, tasks);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ interface DicTaskBase {
|
|||||||
// 任务类型
|
// 任务类型
|
||||||
readonly taskType: number;
|
readonly taskType: number;
|
||||||
// 类型下面的分组
|
// 类型下面的分组
|
||||||
group: number;
|
group: string;
|
||||||
// 任务参数
|
// 任务参数
|
||||||
readonly taskParam: number[];
|
readonly taskParam: number[];
|
||||||
// 条件
|
// 条件
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ export async function checkTask(roleId: string, taskType: number, count: number,
|
|||||||
for (let [typeAndGroup, { task0, tasks }] of groups) {
|
for (let [typeAndGroup, { task0, tasks }] of groups) {
|
||||||
let arr = typeAndGroup.split('_');
|
let arr = typeAndGroup.split('_');
|
||||||
let type = parseInt(arr[0]);
|
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);
|
let rec = await checkTaskRec(roleId, type, group, task0, count, isInc, param);
|
||||||
if (rec) {
|
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 { taskParam, taskType } = dicTask;
|
||||||
|
|
||||||
let isMatch = true; // 条件是否满足
|
let isMatch = true; // 条件是否满足
|
||||||
|
|||||||
Reference in New Issue
Block a user