Files
ZYZ/shared/domain/activityField/growthField.ts
2021-04-21 19:20:14 +08:00

49 lines
1.5 KiB
TypeScript

import { prop } from '@typegoose/typegoose';
import { ActivityModelType } from '../../db/Activity';
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
import { ActivityBase } from './activityField';
// 每日配置数据
export class GrowthItem {
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 GrowthData extends ActivityBase {
list: Array<GrowthItem> = [];
//解析玩家领取记录
public setPlayerRecords(data: ActivityGrowthModelType[]) {
for (let obj of this.list) {
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.list.push(new GrowthItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
}
}