活动:每日免费午饭、晚饭活动

This commit is contained in:
qiaoxin
2021-06-10 17:09:31 +08:00
parent c0efcaa07d
commit 1b16ffc6ab
8 changed files with 293 additions and 5 deletions
@@ -0,0 +1,73 @@
import moment = require('moment');
import { REFRESH_TIME, TASK_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityDailyMealModelType } from '../../db/ActivityDailyMeal';
import { ActivityBase } from './activityField';
// 每日配置数据
export class DailyMealItem {
name: string; // 名称
beginTime: number; // 开始时间
endTime: number; // 结束时间
type: number; // 午饭晚饭类型,DAILY_MEAL_TYPE 1.午饭 2晚饭
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
consume: string; //补签消耗资源
isReceive: boolean = false; //是否领取过
constructor(data: any) {
this.beginTime = moment(new Date()).startOf('d').add(data.beginHour, 'h').valueOf();
this.endTime = moment(new Date()).startOf('d').add(data.endHour, 'h').valueOf();
this.type = data.type;
this.reward = data.reward;
this.consume = data.consume;
this.name = data.name;
this.isReceive = false;
}
}
// 每日免费午餐、晚餐活动数据
export class DailyMealData extends ActivityBase {
list: Array<DailyMealItem> = [];
name: string = ''//名字
public findItem(type: number) {
let index = this.list.findIndex(obj => { return obj.type === type })
return (index != -1) ? this.list[index] : null
}
//解析玩家领取记录
public setPlayerRecords(data: ActivityDailyMealModelType[]) {
for (let obj of this.list) {
let index = data.findIndex(record => { return obj.type == record.type })
if (index != -1) {
obj.isReceive = true;
}
}
}
public initData(data: string) {
let dataObj = JSON.parse(data);
this.name = dataObj.name;
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new DailyMealItem(obj))
}
let curDate = moment(new Date());
if (curDate.hour() < REFRESH_TIME) {
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
} else {
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}
@@ -172,9 +172,9 @@ export class TreasureHuntTaskData {
public setPlayerTaskRecords(record: ActivityTreasureHuntTaskModelType[]) {
for (let item of this.list) {
let index = record.findIndex(obj => { return obj.cellIndex === item.cellIndex && obj.type === item.taskType });
let index = record.findIndex(obj => { return obj.cellIndex === item.cellIndex });
if (index != -1) {
item.totalCount = record[index].totalCount;
item.totalCount = record[index].totalCount ? record[index].totalCount : 0;
item.isReceive = record[index].receiveRewardCount ? true : false;
}
}