活动:重写七天乐活动的数据结构

This commit is contained in:
qiaoxin
2021-06-04 11:54:47 +08:00
parent f77de8eb78
commit d6134ce67e
12 changed files with 852 additions and 110 deletions
+3 -5
View File
@@ -5,7 +5,6 @@
*/
export enum ACTIVITY_TYPE {
SEVEN_DAY = 0, // 七天乐活动(虚)
DAILY_DISCOUNT_GIFT = 1, // 七天乐活动,每日特惠礼包
TASK_GROWTH = 2, // 成长任务活动
TASK_DAILY_CHALLENGES = 3, // 今日挑战活动
@@ -32,10 +31,9 @@ export enum ACTIVITY_TYPE {
POP_UP_SHOP = 24, // 弹出商店
NEW_PLAYER_SIGN_IN = 25, // 新手签到活动
VIP_RECHARGE_MONEY = 26, // vip累计充值RMB活动
// FOURTEEN_DAY = 25, // 14天乐活动()
// FOURTEEN_DAILY_DISCOUNT_GIFT = 26, // 14天乐活动,每日特惠礼包
// FOURTEEN_TASK_GROWTH = 27, // 14天乐成长任务活动
// FOURTEEN_TASK_DAILY_CHALLENGES = 28, // 14天乐今日挑战活动
SEVEN_DAY = 27, // 天乐活动(每日特惠礼包,成长任务活动,今日挑战活动)
FOURTEEN_DAY = 28, // 十四天乐活动
COMMON_SEVEN_DAY = 29, // 通用七天乐活动
}
/**
@@ -0,0 +1,328 @@
import { ActivityModelType } from '../../db/Activity';
import { ActivityBase } from './activityField';
import { TASK_TYPE } from '../../consts';
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 { ActivityDailyGiftsModelType } from '../../db/ActivityDailyGifts';
import { parseResStr } from '../../pubUtils/util';
import { ConsumeResParam } from '../activityField/consumeField';
import { ActivityDailyChallengesModelType } from '../../db/ActivityDailyChallenges';
// 今日挑战的每日配置数据
export class SevenDaysDailyItem {
dayIndex: number; // 第几天,从1开始
cellIndex: number; // 当天第几行,从1开始
name: string; // 任务名称
taskType: number; // 任务类型 dic_zyz_taskType.json
taskParam: string; //任务数据 dic_zyz_taskType.json
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
totalCount: number = 0; //完成任务累计次数
receiveRewardCount: number = 0; //领取奖励次数
constructor(data: any) {
this.dayIndex = data.dayIndex;
this.cellIndex = data.cellIndex;
this.name = data.name;
this.taskType = data.taskType;
this.taskParam = data.taskParam;
this.condition = data.condition;
this.reward = data.reward;
this.totalCount = 0;
this.receiveRewardCount = 0;
}
public canReceive(): boolean {
return this.receiveRewardCount == 0;
}
public isComplete(): boolean {
let complete = this.totalCount >= this.condition;
return complete;
}
}
// 今日挑战活动数据
export class SevenDaysDailyChallengesData {
list: Array<SevenDaysDailyItem> = [];
public findDailyChallengesItem(dayIndex: number, cellIndex: number, type: number) {
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == cellIndex && obj.taskType == type })
return (index != -1) ? this.list[index] : null;
}
public findTaskByType(type: TASK_TYPE, dayIndex: number) {
return this.list.filter(obj => {
return obj && obj.taskType == type && obj.dayIndex == dayIndex;
})
}
//解析玩家领取记录
public setPlayerRecords(data: ActivityDailyChallengesModelType[]) {
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;
}
}
}
public initData(data: any) {
for (let obj of data) {
this.list.push(new SevenDaysDailyItem(obj))
}
}
constructor(activityData: any) {
this.initData(activityData)
}
}
/****************************************************************/
// 每日礼包配置数据
export class SevenDaysDailyGiftItem {
dayIndex: number; // 第几天,从1开始
cellIndex: number; // 当天第几行,从1开始
name: string; // 名称
consume: string; // 购买的资源数据; 格式:type:id:count, type:ACTIVITY_RESOURCES_TYPE;RMB时id无效
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
maxCount: number = 1; //最大可购买次数
discount: number = 0;// 商品显示的折扣
buyCount: number = 0; //购买次数
constructor(data: any) {
this.dayIndex = data.dayIndex;
this.cellIndex = data.cellIndex;
this.name = data.name;
this.consume = data.consume;
this.reward = data.reward;
this.maxCount = data.maxCount;
this.discount = data.discount;
this.buyCount = 0;
}
//消耗的资源
public consumeRes(): ConsumeResParam {
let consumeArray = parseResStr(this.consume);
return consumeArray[0];
}
public canBuy(): boolean {
return this.buyCount < this.maxCount;
}
}
// 今日挑战活动数据
export class SevenDaysDailyGiftsData {
list: Array<SevenDaysDailyGiftItem> = [];
public findDailyGiftsItem(dayIndex: number, cellIndex: number) {
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == cellIndex })
return (index != -1) ? this.list[index] : null;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivityDailyGiftsModelType[]) {
for (let obj of this.list) {
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
if (index != -1) {
obj.buyCount = data[index].buyCount ? data[index].buyCount : 0;
} else {
obj.buyCount = 0;
}
}
}
public initData(dataObj: any) {
let arr = dataObj;
for (let obj of arr) {
this.list.push(new SevenDaysDailyGiftItem(obj))
}
}
constructor(activityData: any) {
this.initData(activityData)
}
}
/****************************************************************/
// 积分兑换奖励数据
export class SevenDaysPointRewardItem {
id: number; // 第几天,从1开始
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
progress: number; // 需要的奖章数量
quality: string; //
star: number; //
getPointReward: boolean = false; // 是否兑换领取奖章奖励
constructor(data: any) {
this.id = data.id;
this.reward = data.reward;
this.progress = data.progress;
this.quality = data.quality;
this.star = data.star;
this.getPointReward = false;
}
}
// 每日配置数据
export class SevenDaysGrowthItem {
id: number;
dayIndex: number; // 第几天,从1开始
cellIndex: number; // 当天第几行,从1开始
name: string; // 任务名称
taskType: number; // 任务类型 dic_zyz_taskType.json
taskParam: string; //任务数据 dic_zyz_taskType.jsonT
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
point: number; // 任务达成获得的奖章数量,只在当前活动中有用,虚拟
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
taskParamArray: number[];
totalCount: number = 0; //完成任务累计次数
receiveRewardCount: number = 0; //领取奖励次数
constructor(data: any) {
this.dayIndex = data.dayIndex;
this.cellIndex = data.cellIndex;
this.name = data.name;
this.taskType = data.taskType;
this.taskParam = data.taskParam;
this.condition = data.condition;
this.point = data.point;
this.reward = data.reward;
this.totalCount = 0;
this.receiveRewardCount = 0;
this.taskParamArray = splitString(data.taskParam, '&')
}
public canReceive(): boolean {
return this.receiveRewardCount == 0;
}
public isComplete(): boolean {
let complete = this.totalCount >= this.condition;
return complete;
}
}
// 成长活动数据
export class SevenDaysGrowthData extends ActivityBase {
list: Array<SevenDaysGrowthItem> = [];
pointRewardList: Array<SevenDaysPointRewardItem> = [];
public getTotalPoint() {
let total = 0;
for (let obj of this.list) {
if (obj.receiveRewardCount) {
total += obj.point;
}
}
return total;
}
//第几天的奖章兑换
public findPointItem(id: number) {
let index = this.pointRewardList.findIndex(obj => { return obj && obj.id === id })
return (index != -1) ? this.pointRewardList[index] : null;
}
public findGrowthItem(dayIndex: number, cellIndex: number, type: number) {
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == cellIndex && obj.taskType == type })
return (index != -1) ? this.list[index] : null;
}
public findTaskByType(type: TASK_TYPE) {
return this.list.filter(obj => {
return obj && obj.taskType == type;
})
}
//解析玩家积分兑换记录
public setPlayerPointRecord(data: ActivityGrowthPointModelType) {
if (!data) {
return;
}
for (let obj of this.pointRewardList) {
let index = data.ids.findIndex(id => { return id === obj.id })
if (index != -1) {
obj.getPointReward = true;
}
}
}
//解析玩家领取记录
public async setPlayerRecords(data: ActivityGrowthModelType[], roleId: string, userHeroes: HeroType[]) {
let { heroNum, towerLv } = 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) {
let lv = obj.taskParamArray[1];
let heroes = userHeroes.filter(hero => { return hero.lv >= lv })
obj.totalCount = heroes.length;
} else if (obj.taskType === TASK_TYPE.BATTLE_TOWER_LV) {
obj.totalCount = towerLv;
}
}
}
public initData(data: string) {
let objData = JSON.parse(data);
let arr = objData.data;
for (let obj of arr) {
this.list.push(new SevenDaysGrowthItem(obj))
}
let pointRewardArray = objData.pointReward;
for (let obj of pointRewardArray) {
this.pointRewardList.push(new SevenDaysPointRewardItem(obj))
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}
/****************************************************************/
// 七天乐活动数据
export class SevenDaysData extends ActivityBase {
growth: SevenDaysGrowthData = null;
dailyGift: SevenDaysDailyGiftsData = null;
dailyChallenge: SevenDaysDailyChallengesData = null;
public initData(data: string) {
let objData = JSON.parse(data);
this.growth = new SevenDaysGrowthData(objData.growth)
this.dailyGift = new SevenDaysDailyGiftsData(objData.dailyGift)
this.dailyChallenge = new SevenDaysDailyChallengesData(objData.dailyChallenge)
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}
+2 -2
View File
@@ -64,7 +64,7 @@ export class SignInData extends ActivityBase {
this.endTime = moment(endTime).valueOf();
this.roundIndex = 1;
let date = new Date();
this.todayIndex = Math.ceil((moment(date).valueOf() - this.beginTime) / 24 * 60 * 60 * 1000);
this.todayIndex = Math.ceil((moment(date).valueOf() - this.beginTime) / (24 * 60 * 60 * 1000));
}
public initData(data: string) {
@@ -83,7 +83,7 @@ export class SignInData extends ActivityBase {
if (this.type === ACTIVITY_TYPE.NEW_PLAYER_SIGN_IN) {
this.roundIndex = 1;
}
this.todayIndex = Math.ceil((moment(date).valueOf() - this.beginTime) / 24 * 60 * 60 * 1000);
this.todayIndex = Math.ceil((moment(date).valueOf() - this.beginTime) / (24 * 60 * 60 * 1000));
let arr = dataObj.data
for (let obj of arr) {
+1 -1
View File
@@ -492,7 +492,7 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
console.log('accomplishTask', roleId, taskType, count, JSON.stringify(parma))
let pushMessage = [];
let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
//七天乐-成长活动统计
//成长活动统计
let allActivity: ActivityModelType[] = await ActivityModel.findOpenActivityByType(activityGroupId, ACTIVITY_TYPE.TASK_GROWTH, new Date());
for (let activity of allActivity) {
let growthActivity = new GrowthData(activity);