活动:节日活动添加每日关卡
This commit is contained in:
61
shared/domain/activityField/dailyGKField.ts
Normal file
61
shared/domain/activityField/dailyGKField.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityDailyGKModelType } from '../../db/ActivityDailyGK';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每日配置数据
|
||||
export class DailyGKItem {
|
||||
dayIndex: number; // 第几天,从1开始
|
||||
gk: number; // 关卡
|
||||
name: string; // 名称
|
||||
reward: string; // 奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
isSuccess: boolean; //是否成功
|
||||
|
||||
constructor(data: any) {
|
||||
this.dayIndex = data.dayIndex;
|
||||
this.name = data.name;
|
||||
this.reward = data.reward;
|
||||
this.isSuccess = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 每日关卡活动数据
|
||||
export class DailyGKData extends ActivityBase {
|
||||
list: Array<DailyGKItem> = [];
|
||||
|
||||
public findItemByGK(gk: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.gk == gk })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
public findDailyGKItem(dayIndex: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
//解析玩家记录
|
||||
public setPlayerRecords(data: ActivityDailyGKModelType) {
|
||||
if (!data)
|
||||
return;
|
||||
let records = data.days ? data.days : [];
|
||||
for (let obj of this.list) {
|
||||
let index = records.findIndex(dayIndex => { return obj.dayIndex == dayIndex })
|
||||
if (index != -1) {
|
||||
obj.isSuccess = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let arr = JSON.parse(data);
|
||||
for (let obj of arr) {
|
||||
this.list.push(new DailyGKItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user