将两种任务初步合起来
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 活动系统 - 今日挑战活动
|
||||
@@ -25,6 +26,8 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
@@ -33,28 +36,48 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 更新任务
|
||||
public static async checkAndUpdateTask(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, param: UpdateTaskParam) {
|
||||
let canSet = true;
|
||||
if(param.record || param.max || param.min) {
|
||||
let rec = await this.findDataByCellIndex(serverId, activityId, roleId, dayIndex, 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, dayIndex, cellIndex, param);
|
||||
}
|
||||
}
|
||||
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, param.set, param.record);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, param.inc, param.record);
|
||||
}
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, record?: string) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $set: { totalCount: count }, $addToSet: { records: record||''} }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, addCount: number, record?: string) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $inc: { totalCount: addCount }, $addToSet: { records: record||''} }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, data: string,) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.find({ serverId, roleId, activityId }).lean(lean);
|
||||
@@ -68,8 +91,8 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
}
|
||||
|
||||
//查询第几天某个的活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex, type }).lean(true);
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 活动系统 - 成长任务活动
|
||||
@@ -25,6 +26,8 @@ export default class Activity_Growth extends BaseModel {
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number,) {
|
||||
@@ -33,28 +36,48 @@ export default class Activity_Growth extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 更新任务
|
||||
public static async checkAndUpdateTask(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, param: UpdateTaskParam) {
|
||||
let canSet = true;
|
||||
if(param.record || param.max || param.min) {
|
||||
let rec = await this.findDataByCellIndex(serverId, activityId, roleId, dayIndex, 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, dayIndex, cellIndex, param);
|
||||
}
|
||||
}
|
||||
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, param.set, param.record);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, param.inc, param.record);
|
||||
}
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, record?: string) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $set: { totalCount: count }, $addToSet: { records: record||'' } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, addCount: number, record?: string) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $inc: { totalCount: addCount }, $addToSet: { records: record||'' } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, data: string,) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string, lean = true) {
|
||||
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ serverId, roleId, activityId }).lean(lean);
|
||||
@@ -68,8 +91,8 @@ export default class Activity_Growth extends BaseModel {
|
||||
}
|
||||
|
||||
//查询第几天某个的活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number,) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex, type }).lean(true);
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 活动系统 - 通用的刷新任务(分页,可刷新,限制领取次数)
|
||||
@@ -27,6 +28,8 @@ export default class Activity_Refresh_Task extends BaseModel {
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addReceiveRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number, count: number) {
|
||||
@@ -35,17 +38,47 @@ export default class Activity_Refresh_Task extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 更新任务
|
||||
public static async checkAndUpdateTask(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, param: UpdateTaskParam) {
|
||||
let canSet = true;
|
||||
if(param.record || param.max || param.min) {
|
||||
let rec = await this.findDataById(serverId, activityId, roleId, roundIndex, pageIndex, id);
|
||||
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, pageIndex, id, param);
|
||||
}
|
||||
}
|
||||
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, roundIndex, pageIndex, id, param.set, param.record);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, roundIndex, pageIndex, id, param.inc, param.record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, count: number, record?: string) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id },
|
||||
{ $set: { totalCount: count }, $setOnInsert: { records: record||'' } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, count: number, record?: string) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id },
|
||||
{ $inc: { totalCount: count }, $setOnInsert: { records: record||'' } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -64,8 +97,8 @@ export default class Activity_Refresh_Task extends BaseModel {
|
||||
}
|
||||
|
||||
//查询活动数据
|
||||
public static async findDataById(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOne({ serverId, roleId, activityId, roundIndex, pageIndex, id, type }).lean(true);
|
||||
public static async findDataById(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOne({ serverId, roleId, activityId, roundIndex, pageIndex, id }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 30天目标活动
|
||||
@@ -27,10 +28,8 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
isReceive: boolean; // 是否领取过奖励
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true })
|
||||
isPush: boolean; // 推送过消息
|
||||
|
||||
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//添加领取记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number) {
|
||||
@@ -39,13 +38,6 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, data: string,) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
@@ -53,13 +45,6 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//推送标记
|
||||
public static async pushMessage(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
@@ -79,15 +64,55 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 更新任务
|
||||
public static async checkAndUpdateTask(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, param: UpdateTaskParam) {
|
||||
let canSet = true;
|
||||
if(param.record || param.max || param.min) {
|
||||
let rec = await this.findDataByCellIndex(serverId, activityId, roleId, pageIndex, cellIndex, tab);
|
||||
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, pageIndex, cellIndex, tab, param);
|
||||
}
|
||||
}
|
||||
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, pageIndex, cellIndex, tab, param.set, param.record);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, pageIndex, cellIndex, tab, param.inc, param.record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//查询第*页的某个的活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number,) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOne({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type }).lean(true);
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number,) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOne({ serverId, roleId, activityId, pageIndex, cellIndex, tab }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number) {
|
||||
await ActivityThirtyDaysModel.deleteMany({ serverId, roleId, activityId, pageIndex, cellIndex });
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, count: number, record?: string) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab },
|
||||
{ $inc: { totalCount: count }, $addToSet: { records: record||'' } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, count: number, record?: string) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab },
|
||||
{ $set: { totalCount: count }, $addToSet: { records: record||'' } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -135,7 +135,7 @@ export class ActivityInRemote {
|
||||
}
|
||||
}
|
||||
|
||||
export function transActivityInRemoteToModelType(activity: ActivityInRemote) {
|
||||
export function transActivityInRemoteToModelType(activity: ActivityInRemote): ActivityModelType {
|
||||
if(!activity) return null;
|
||||
return {
|
||||
...activity,
|
||||
|
||||
@@ -164,8 +164,8 @@ export class GrowthFundData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime?: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -128,8 +128,8 @@ export class RefreshTaskData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime?: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||
import { ActivityGrowthPointModelType } from '../../db/ActivityGrowthPoint';
|
||||
import { HeroType } from '../../db/Hero';
|
||||
import { RoleModel } from '../../db/Role';
|
||||
import { splitString } from '../../pubUtils/util';
|
||||
import { parseNumberList, splitString } from '../../pubUtils/util';
|
||||
import { ActivityDailyGiftsModelType } from '../../db/ActivityDailyGifts';
|
||||
import { parseResStr } from '../../pubUtils/util';
|
||||
import { ConsumeResParam } from '../activityField/consumeField';
|
||||
@@ -18,6 +18,7 @@ export class SevenDaysDailyItem {
|
||||
name: string; // 任务名称
|
||||
taskType: number; // 任务类型 dic_zyz_taskType.json
|
||||
taskParam: string; //任务数据 dic_zyz_taskType.json
|
||||
taskParamArray: number[];
|
||||
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
skip: string; // 跳转
|
||||
@@ -35,6 +36,7 @@ export class SevenDaysDailyItem {
|
||||
this.reward = data.reward;
|
||||
this.skip = data.skip;
|
||||
|
||||
this.taskParamArray = parseNumberList(data.taskParam);
|
||||
this.totalCount = 0;
|
||||
this.receiveRewardCount = 0;
|
||||
}
|
||||
@@ -324,8 +326,8 @@ export class SevenDaysData extends ActivityBase {
|
||||
this.dailyChallenge = new SevenDaysDailyChallengesData(objData.dailyChallenge)
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverCreateTime?: number) {
|
||||
super(activityData, createTime, serverCreateTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -118,20 +118,6 @@ export class ThirtyDaysData extends ActivityBase {
|
||||
pointRewardList: Array<ThirtyDaysPointItem> = [];//点数兑换奖励
|
||||
totalPoint: number = 0;//总共点数
|
||||
|
||||
//未完成的任务
|
||||
public findUncompleteTaskByType(type: number): ThirtyDaysItem[] {
|
||||
let task = [];
|
||||
for (let i = 0; i < this.list.length; i++) {
|
||||
let items = this.list[i].item;
|
||||
for (let itemData of items) {
|
||||
if (itemData.taskType == type && !itemData.isComplete) {
|
||||
task.push(itemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
public findTaskByType(type: number) {
|
||||
let task = [];
|
||||
for (let i = 0; i < this.list.length; i++) {
|
||||
@@ -256,8 +242,8 @@ export class ThirtyDaysData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime?: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHunt
|
||||
import { ActivityTreasureHuntTaskModelType } from '../../db/ActivityTreasureHuntTask';
|
||||
import { ActivityTreasureHuntTreasureShopModelType } from '../../db/ActivityTreasureHuntTreasureShop';
|
||||
import { ActivityTreasureHuntFirstPageModelType } from '../../db/ActivityTreasureHuntFirstPage';
|
||||
import { splitString } from '../../pubUtils/util';
|
||||
import { parseNumberList, splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ export class TreasureHuntTaskItem {
|
||||
fragment: number; //碎片
|
||||
skip: string;
|
||||
|
||||
taskParamArray: number[]; // 任务参数
|
||||
totalCount: number = 0; //任务统计
|
||||
isReceive: boolean = false; //是否领取奖励
|
||||
|
||||
@@ -150,6 +151,7 @@ export class TreasureHuntTaskItem {
|
||||
this.name = data.name;
|
||||
this.taskType = data.taskType;
|
||||
this.taskParam = data.taskParam;
|
||||
this.taskParamArray = parseNumberList(data.taskParamArray);
|
||||
this.condition = data.condition;
|
||||
this.reward = data.reward;
|
||||
this.fragment = data.fragment;
|
||||
@@ -339,8 +341,8 @@ export class TreasureHuntData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, sererTime?: number) {
|
||||
super(activityData, createTime, sererTime);
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -38,4 +38,12 @@ export class TaskListReturn {
|
||||
id: number; // 任务id
|
||||
count: number; // 达成次数
|
||||
received: boolean; // 是否领取
|
||||
}
|
||||
|
||||
export interface UpdateTaskParam {
|
||||
inc?: number; // 直接增
|
||||
set?: number; // 直接设
|
||||
record?: string; // 检查是否有这条记录、没有的话增
|
||||
max?: number; // 检查是否是最大的,不是的话更
|
||||
min?: number; // 检查是否是最小的,不是的话更
|
||||
}
|
||||
@@ -630,10 +630,11 @@ function checkRecResult(rec: UserTaskRecType, id: number) {
|
||||
*
|
||||
*/
|
||||
export async function accomplishTask(serverId: number, roleId: string, taskType: TASK_TYPE, count: number, parma?: any, activities?: ActivityInRemote[]) {
|
||||
|
||||
// console.log('accomplishTask', roleId, taskType, count, JSON.stringify(parma))
|
||||
let dicTaskType = gameData.taskDescByType.get(taskType);
|
||||
let pushMessage = [];
|
||||
let serverInfo = await ServerlistModel.findByServerId(serverId);
|
||||
/* let serverInfo = await ServerlistModel.findByServerId(serverId);
|
||||
if (!serverInfo) return [];
|
||||
let { activityGroupId } = serverInfo;
|
||||
let findActivitiesByTypes = async (types: number[]) => {
|
||||
@@ -859,6 +860,7 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// console.log('***** thirtyDay after', Date.now());
|
||||
|
||||
@@ -990,6 +992,7 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
}
|
||||
}
|
||||
// console.log('***** growthFundElite after', Date.now());
|
||||
*/
|
||||
return pushMessage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user