活动:添加新的任务统计
This commit is contained in:
@@ -23,6 +23,8 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
@@ -45,6 +47,14 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
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);
|
||||
@@ -58,8 +68,8 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
}
|
||||
|
||||
//查询第几天某个的活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.find({ serverId, roleId, activityId, dayIndex, cellIndex }).lean(lean);
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { TASK_TYPE } from '../consts';
|
||||
|
||||
/**
|
||||
* 活动系统 - 成长任务活动
|
||||
@@ -23,8 +24,8 @@ export default class Activity_Growth extends BaseModel {
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true, default: false })
|
||||
getPointReward: boolean; // 是否兑换领取奖章奖励
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number,) {
|
||||
@@ -33,13 +34,6 @@ export default class Activity_Growth extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//当日奖章领取记录
|
||||
public static async addDayRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $set: { getPointReward: true } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
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 },
|
||||
@@ -54,6 +48,14 @@ export default class Activity_Growth extends BaseModel {
|
||||
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);
|
||||
|
||||
@@ -23,6 +23,8 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
isReceive: boolean; // 是否领取过奖励
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
|
||||
//添加领取记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, lean = true) {
|
||||
@@ -38,6 +40,13 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, data: string,) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, type },
|
||||
|
||||
@@ -2,10 +2,9 @@ import { TASK_TYPE, ACTIVITY_RESOURCES_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||
import { ActivityGrowthPointModelType } from '../../db/ActivityGrowthPoint';
|
||||
import { HeroType } from '../../db/Hero';
|
||||
import { RoleModel } from '../../db/Role';
|
||||
import { RewardInter } from '../../pubUtils/interface';
|
||||
import { parseGoodStrWithType, parseHeroStrWithType } from '../../pubUtils/util';
|
||||
import { CreateHeroParam } from '../roleField/hero';
|
||||
import { splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
@@ -40,6 +39,7 @@ export class GrowthItem {
|
||||
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
|
||||
point: number; // 任务达成获得的奖章数量,只在当前活动中有用,虚拟
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
taskParamArray: number[];
|
||||
|
||||
totalCount: number = 0; //完成任务累计次数
|
||||
receiveRewardCount: number = 0; //领取奖励次数
|
||||
@@ -55,26 +55,8 @@ export class GrowthItem {
|
||||
this.reward = data.reward;
|
||||
this.totalCount = 0;
|
||||
this.receiveRewardCount = 0;
|
||||
}
|
||||
this.taskParamArray = splitString(data.taskParam, '&')
|
||||
|
||||
public heroReward(): CreateHeroParam[] {
|
||||
let rewardArray = [];
|
||||
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||
for (let objStr of rewardData) {
|
||||
let reward = parseHeroStrWithType(objStr);
|
||||
rewardArray.push(reward);
|
||||
}
|
||||
return rewardArray.filter(obj => { return obj && obj.type == ACTIVITY_RESOURCES_TYPE.HERO })
|
||||
}
|
||||
|
||||
public goodReward(): RewardInter[] {
|
||||
let rewardArray = [];
|
||||
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||
for (let objStr of rewardData) {
|
||||
let reward = parseGoodStrWithType(objStr);
|
||||
rewardArray.push(reward);
|
||||
}
|
||||
return rewardArray.filter(obj => { return obj && obj.type == ACTIVITY_RESOURCES_TYPE.GOODS })
|
||||
}
|
||||
|
||||
public canReceive(): boolean {
|
||||
@@ -146,7 +128,6 @@ export class GrowthData extends ActivityBase {
|
||||
|
||||
//第几天的奖章兑换
|
||||
public findPointItem(id: number) {
|
||||
console.log('ddddddddddd', JSON.stringify(this.pointRewardList), id)
|
||||
let index = this.pointRewardList.findIndex(obj => { return obj && obj.id === id })
|
||||
return (index != -1) ? this.pointRewardList[index] : null;
|
||||
}
|
||||
@@ -162,7 +143,7 @@ export class GrowthData extends ActivityBase {
|
||||
})
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
//解析玩家积分兑换记录
|
||||
public setPlayerPointRecord(data: ActivityGrowthPointModelType) {
|
||||
if (!data) {
|
||||
return;
|
||||
@@ -176,17 +157,21 @@ export class GrowthData extends ActivityBase {
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public async setPlayerRecords(data: ActivityGrowthModelType[], roleId: string) {
|
||||
public async setPlayerRecords(data: ActivityGrowthModelType[], roleId: string, userHeroes: HeroType[]) {
|
||||
let { heroNum } = await RoleModel.findByRoleId(roleId);
|
||||
for (let obj of this.list) {
|
||||
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
|
||||
if (index != -1) {
|
||||
obj.totalCount = data[index].totalCount ? data[index].totalCount : 0;
|
||||
|
||||
obj.receiveRewardCount = data[index].receiveRewardCount ? data[index].receiveRewardCount : 0;
|
||||
}
|
||||
if (obj.taskType === TASK_TYPE.HERO_NUM) {
|
||||
obj.totalCount = heroNum;
|
||||
} else if (obj.taskType === TASK_TYPE.HERO_LV) {
|
||||
obj.taskParam
|
||||
let lv = obj.taskParamArray[1];
|
||||
let heroes = userHeroes.filter(hero => { return hero.lv >= lv })
|
||||
obj.totalCount = heroes.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityBuyRecordsModelType } from '../../db/ActivityBuyRecords';
|
||||
import { ActivityGrowthFundModelType } from '../../db/ActivityGrowthFund';
|
||||
import { splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
@@ -15,7 +16,7 @@ export class GrowthFundItem {
|
||||
condition: number; //0
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
isComplete: boolean //是否完成任务
|
||||
|
||||
taskParamArray: number[]//
|
||||
// isReceive: boolean = false; //是否领取过奖励
|
||||
|
||||
constructor(data: any) {
|
||||
@@ -28,6 +29,8 @@ export class GrowthFundItem {
|
||||
this.condition = data.conditon;
|
||||
this.isComplete = false;
|
||||
// this.isReceive = false;
|
||||
this.taskParamArray = splitString(data.taskParam, '&')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,14 +73,14 @@ export class GrowthFundData extends ActivityBase {
|
||||
switch (this.type) {
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_MAIN:
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_MAIN_VIP: {
|
||||
if (!this.isReceive(page.pageIndex, item.cellIndex) && item.condition == condition) {
|
||||
if (!this.isReceive(page.pageIndex, item.cellIndex) && item.taskParamArray[1] == condition) {
|
||||
item.isComplete = true;
|
||||
items.push(Object.assign(item, { pageIndex: page.pageIndex, activityId: this.activityId }))
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_MAIN:
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_MAIN_VIP:
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_TOWER:
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_TOWER_VIP:
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_MAIN_ELITE:
|
||||
case ACTIVITY_TYPE.GROWTH_FUND_MAIN_ELITE_VIP: {
|
||||
if (!this.isReceive(page.pageIndex, item.cellIndex) && item.condition <= condition) {
|
||||
|
||||
@@ -269,6 +269,7 @@ export async function createHeroes(roleId: string, roleName: string, serverId: n
|
||||
let taskPushMessage = m1.concat(m2, m3, m4);
|
||||
//成长任务
|
||||
await accomplishTask(serverId, roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||
await accomplishTask(serverId, roleId, TASK_TYPE.HERO_QUALITY, heroNum, { heroes })
|
||||
return { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage }
|
||||
}
|
||||
|
||||
|
||||
@@ -494,7 +494,9 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
let growthActivity = new GrowthData(activity);
|
||||
let taskArray = growthActivity.findTaskByType(taskType);
|
||||
for (let task of taskArray) {
|
||||
let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma);
|
||||
let taskRecord = await ActivityDailyChallengesModel.findDataByCellIndex(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType)
|
||||
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null;
|
||||
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||
if (addCount) {
|
||||
if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE) {
|
||||
await ActivityGrowthModel.setTaskCount(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||
@@ -502,6 +504,9 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
await ActivityGrowthModel.addTaskCount(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||
}
|
||||
}
|
||||
if (record) {
|
||||
await ActivityGrowthModel.addTaskRecord(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, JSON.stringify(record));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +516,9 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
let growthActivity = new DailyChallengesData(activity);
|
||||
let taskArray = growthActivity.findTaskByType(taskType, growthActivity.today());
|
||||
for (let task of taskArray) {
|
||||
let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma);
|
||||
let taskRecord = await ActivityDailyChallengesModel.findDataByCellIndex(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType)
|
||||
let recordData = taskRecord && taskRecord.data ? taskRecord.data : {}
|
||||
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||
if (addCount) {
|
||||
if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE) {
|
||||
await ActivityDailyChallengesModel.setTaskCount(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||
@@ -519,6 +526,9 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
await ActivityDailyChallengesModel.addTaskCount(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||
}
|
||||
}
|
||||
if (record) {
|
||||
await ActivityGrowthModel.addTaskRecord(serverId, growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, JSON.stringify(record));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,10 +553,15 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
thirtyDaysActivity.setPlayerRecords(playerRecords);
|
||||
let taskArray = thirtyDaysActivity.findUncompleteTaskByType(taskType);
|
||||
for (let task of taskArray) {
|
||||
let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma);
|
||||
let taskRecord = await ActivityDailyChallengesModel.findDataByCellIndex(serverId, thirtyDaysActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType)
|
||||
let recordData = taskRecord && taskRecord.data ? taskRecord.data : {}
|
||||
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||
if (addCount) {
|
||||
await ActivityThirtyDaysModel.addTaskCount(serverId, thirtyDaysActivity.activityId, roleId, task.pageIndex, task.cellIndex, task.taskType, addCount);
|
||||
}
|
||||
if (record) {
|
||||
await ActivityGrowthModel.addTaskRecord(serverId, thirtyDaysActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, JSON.stringify(record));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -614,10 +629,11 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
*
|
||||
*/
|
||||
|
||||
export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: string, count: number, paramObj?: any): number {
|
||||
export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: string, count: number, paramObj?: any, recordData?: any): any {
|
||||
console.log('达成任务标准', roleId, taskType, taskParam, count, paramObj)
|
||||
let param = splitString(taskParam, '&');
|
||||
let addCount: number = 0; // 条件是否满足
|
||||
let record: any = null;
|
||||
switch (taskType) {
|
||||
case TASK_TYPE.ROLE_LV://重置数据
|
||||
addCount = count;
|
||||
@@ -693,18 +709,79 @@ export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: strin
|
||||
case TASK_TYPE.GUILD_ACTIVITY:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.HERO_TRAIN_SUM:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.EQUIP_SUM:
|
||||
addCount = count;
|
||||
break;
|
||||
case TASK_TYPE.HERO_LV://{ hid, lv}
|
||||
{
|
||||
let hid = paramObj.hid;
|
||||
let lv = paramObj.lv;
|
||||
if (lv < param[1]) {
|
||||
break;
|
||||
}
|
||||
if (recordData) {
|
||||
if (recordData.indexOf(hid) != -1) {
|
||||
break;
|
||||
}
|
||||
record = recordData;
|
||||
} else {
|
||||
record = [];
|
||||
}
|
||||
|
||||
addCount = count;
|
||||
record.push(hid)
|
||||
break;
|
||||
}
|
||||
case TASK_TYPE.HERO_TRAIN_SUM://训练X次是所有武将的训练次数的总和达到要求就好了
|
||||
{
|
||||
addCount = count;
|
||||
break;
|
||||
}
|
||||
case TASK_TYPE.HERO_TRAIN://X名武将训练Y次,要求单名武将训练Y次,这样的武将要有X名
|
||||
{
|
||||
let hid = paramObj.hid;
|
||||
if (recordData) {
|
||||
record = recordData;
|
||||
if (record['hid']) {
|
||||
if (record['hid'] < param[1] && (record['hid'] + count >= param[1])) {
|
||||
addCount = count;
|
||||
record['hid'] += count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
record['hid'] = count;
|
||||
break;
|
||||
}
|
||||
case TASK_TYPE.BATTLE_EXPEDITION:
|
||||
{
|
||||
addCount = count;
|
||||
break;
|
||||
}
|
||||
case TASK_TYPE.BATTLE_EXPEDITION_BOX:
|
||||
{
|
||||
addCount = count;
|
||||
break;
|
||||
}
|
||||
case TASK_TYPE.HERO_QUALITY:
|
||||
{
|
||||
let quality = param[1]
|
||||
let heroes = paramObj.heroes.filter(hero => { return hero.quality == quality })
|
||||
addCount = heroes.length;
|
||||
break;
|
||||
}
|
||||
case TASK_TYPE.PVP_WIN_SERIES:
|
||||
{
|
||||
addCount = count;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
addCount = 0;
|
||||
break;
|
||||
|
||||
}
|
||||
return addCount;
|
||||
return { addCount, record };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user