活动:寻宝骑兵活动添加推送任务

This commit is contained in:
qiaoxin
2021-06-08 21:29:09 +08:00
parent 63845d09c7
commit f64bd7bdd2
4 changed files with 102 additions and 0 deletions

View File

@@ -45,6 +45,33 @@ export async function treasureHuntActivity(serverId: number, roleId: string) {
return playerData;
}
/**
* 获取活动数据
*
* @param {number} serverId 区Id
* @param {number} type 活动类型 ACTIVITY_TYPE
* @param {string} roleId 角色Id
*
*/
export async function treasureHuntTaskActivity(serverId: number, roleId: string) {
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
if (!activityData) {
return null;
}
let playerData = new TreasureHuntData(activityData);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
playerData.roundIndex = huntRoundIndex;
let playerTaskRecord: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityData.activityId, roleId, huntRoundIndex);
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
return playerData;
}
/**
* 玩家活动数据
*

View File

@@ -10,6 +10,8 @@ export default class Activity_Treasure_Hunt_Task extends ActivityGrowth {
@prop({ required: true })
roundIndex: number; // 周期
@prop({ required: true })
isPush: boolean; // 是否推送过
//任务领取记录
@@ -25,6 +27,34 @@ export default class Activity_Treasure_Hunt_Task extends ActivityGrowth {
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);
return result;
}
//根据活动统计完成任务次数
public static async addTreasureHuntTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, addCount: number) {
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(true);
return result;
}
//根据活动记录统计数据
public static async addTreasureHuntTaskRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, data: string,) {
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
return result;
}
//推送标记
public static async pushMessage(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number,) {
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
{ $set: { isPush: true, } }, { upsert: true, new: true }).lean(true);
return result;
}
//删除活动领取记录
public static async deleteActivity(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number) {
await ActivityTreasureHuntTaskModel.deleteMany({ serverId, roleId, activityId, roundIndex, cellIndex });

View File

@@ -180,6 +180,10 @@ export class TreasureHuntTaskData {
}
}
public findItemByTaskType(type: number) {
return this.list.filter(obj => { return obj && obj.taskType === type });
}
public initData(data: any) {
this.name = data.name;
this.index = data.index;

View File

@@ -22,6 +22,9 @@ import { ActivityGrowthFundModel, ActivityGrowthFundModelType } from '../db/Acti
import { ActivityBuyRecordsModel } from '../db/ActivityBuyRecords';
import { PopUpShopData } from '../domain/activityField/popUpShopField';
import { ActivityPopUpShopModel } from '../db/ActivityPopUpShop';
import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp';
import { TreasureHuntData } from '../domain/activityField/treasureHuntField';
import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask';
import { ActivityPopUpShopRecordModel, ActivityPopUpShopRecordModelType } from '../db/ActivityPopUpShopRecord';
import { SevenDaysData } from '../domain/activityField/sevenDaysField';
import moment = require("moment");
@@ -642,6 +645,44 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
}
}
//寻宝骑兵活动任务
let tempData: ServerTempModelType = await ServerTempModel.findData(serverId);
if (tempData) {
let huntActivityId = tempData.huntActivityId;
let huntBeginTime = tempData.huntBeginTime;
let huntEndTime = tempData.huntEndTime;
let huntRoundIndex = tempData.huntRoundIndex;
let activity = await ActivityModel.findActivity(tempData.huntActivityId);
let playerData = new TreasureHuntData(activity);
playerData.beginTime = moment(huntBeginTime).valueOf();
playerData.endTime = moment(huntEndTime).valueOf();
playerData.roundIndex = huntRoundIndex;
let taskArray = playerData.tasks.findItemByTaskType(taskType);
for (let task of taskArray) {
let taskRecord: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findDataByCellIndex(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex);
if (!taskRecord || !taskRecord.isPush) {
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
if (addCount) {
let playerRecord = await ActivityTreasureHuntTaskModel.addTreasureHuntTaskCount(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex, addCount);
//推送
if (task.condition <= playerRecord.totalCount) {//已经完成
playerRecord = await ActivityTreasureHuntTaskModel.pushMessage(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex);
task.totalCount = playerRecord.totalCount;
pushMessage = pushMessage.concat(Object.assign(task, { activityId: activity.activityId }));
} else {//没有完成
task.totalCount = playerRecord.totalCount;
pushMessage = pushMessage.concat(Object.assign(task, { activityId: activity.activityId }));
}
}
if (record) {
await ActivityTreasureHuntTaskModel.addTreasureHuntTaskRecord(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex, JSON.stringify(record));
}
}
}
}
//30天任务统计
if (taskType === TASK_TYPE.HERO_QUALITY_STAR_UP ||
taskType === TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT ||