将两种任务初步合起来

This commit is contained in:
陆莹
2022-03-17 20:24:20 +08:00
parent fdecaf2d74
commit 37d2e6cfa7
51 changed files with 653 additions and 150 deletions

View File

@@ -1,5 +1,6 @@
import ActivityGrowth from './ActivityGrowth';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { UpdateTaskParam } from '../domain/roleField/task';
/**
* 活动系统 - 寻宝骑兵-备战任务
@@ -27,6 +28,48 @@ export default class Activity_Treasure_Hunt_Task extends ActivityGrowth {
return result;
}
// 更新任务
public static async checkAndUpdateTask(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, param: UpdateTaskParam) {
let canSet = true;
if(param.record || param.max || param.min) {
let rec = await this.findDataByCellIndex(serverId, activityId, roleId, roundIndex, cellIndex);
if(rec) {
if(param.record && rec.records.indexOf(param.record) != -1) {
canSet = false;
} else if (param.max && rec.totalCount >= param.max) {
canSet = false;
} else if (param.min && rec.totalCount <= param.min) {
canSet = false;
}
}
}
if(canSet) {
return await this.setOrIncTask(serverId, activityId, roleId, roundIndex, cellIndex, param);
}
}
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, param: UpdateTaskParam) {
if(param.set) {
return await this.setTaskCount(serverId, activityId, roleId, roundIndex, cellIndex, param.set, param.record);
} else if (param.inc) {
return await this.addTaskCount(serverId, activityId, roleId, roundIndex, cellIndex, param.inc, param.record);
}
}
//根据活动统计完成任务次数
public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, count: number, record?: string) {
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
{ $set: { totalCount: count }, $addToSet: { records: record||'' } }, { upsert: true, new: true }).lean();
return result;
}
//根据活动统计完成任务次数
public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, count: number, record?: string) {
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
{ $inc: { totalCount: count }, $addToSet: { records: record||'' } }, { upsert: true, new: true }).lean();
return result;
}
//查询活动数据
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number) {
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOne({ serverId, roleId, activityId, roundIndex, cellIndex }).lean(true);