55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { prop } from '@typegoose/typegoose';
|
|
import { ActivityModelType } from '../../db/Activity';
|
|
import { ActivitySevenDaysModelType } from '../../db/ActivitySevenDays';
|
|
import { ActivityBase } from './activityField';
|
|
|
|
|
|
// 每日配置数据
|
|
export class SevenDayItem {
|
|
@prop({ required: true })
|
|
dayIndex: number = 0;
|
|
@prop({ required: true })
|
|
cellIndex: number = 0;
|
|
@prop({ required: true })
|
|
count: number = 0;
|
|
@prop({ required: true })
|
|
total: number = 0;
|
|
@prop({ required: true })
|
|
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 {
|
|
@prop({ required: true })
|
|
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)
|
|
}
|
|
} |