Files
ZYZ/shared/domain/activityField/sevenDaysField.ts
2021-04-21 17:20:08 +08:00

49 lines
1.5 KiB
TypeScript

import { prop } from '@typegoose/typegoose';
import { ActivityModelType } from '../../db/Activity';
import { ActivitySevenDaysModelType } from '../../db/ActivitySevenDays';
import { ActivityBase } from './activityField';
// 每日配置数据
export class SevenDayItem {
dayIndex: number = 0;
cellIndex: number = 0;
count: number = 0;
total: number = 0;
isReceive: boolean = false;
constructor(dayIndex: number, cellIndex: number, count: number, total: number, isReceive: boolean) {
this.dayIndex = dayIndex;//第几天奖励
this.cellIndex = cellIndex;//某天第几个奖励
this.count = count;//已经领取奖励的次数
this.total = total;//总共可领取奖励次数
this.isReceive = isReceive;//是否领取
}
}
// 七天乐活动数据
export class SevenDaysData extends ActivityBase {
items: Array<SevenDayItem> = [];
//解析玩家领取记录
public setPlayerRecords(data: ActivitySevenDaysModelType[]) {
for (let obj of this.items) {
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
if (index != -1) {
obj.count = data[index].count;
}
}
}
public initData(data: string) {
let arr = JSON.parse(data);
for (let obj of arr) {
this.items.push(new SevenDayItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
}
}