Files
ZYZ/shared/domain/activityField/newHeroGKField.ts
2023-06-06 16:35:51 +08:00

62 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { ActivityModelType } from '../../db/Activity';
import { ActivityNewHeroGKModelType } from '../../db/ActivityNewHeroGK';
import { getTimeFunM } from '../../pubUtils/timeUtil';
import { ActivityBase } from './activityField';
/******* 存在数据库里的数据 *******/
interface NewHeroGkWarInDb {
warId: number; // 关卡id
startDay: number; // 活动第几天开启
}
interface NewHeroGkDataInDb {
wars: NewHeroGkWarInDb[]; // 关卡
}
// 每日关卡活动数据
export class NewHeroGachaWar {
warId: number; // 关卡id
startTime: number; // 活动第几天开启13位时间戳
isSuccess: boolean = false; // 是否成功
constructor(data: NewHeroGkWarInDb, beginTime: number) {
this.warId = data.warId;
this.startTime = <number>getTimeFunM(beginTime).getAfterDayWithHour(data.startDay - 1);
}
setPlayerRecord(isSuccess: boolean) {
this.isSuccess = isSuccess;
}
}
export class NewHeroGKData extends ActivityBase {
wars: NewHeroGachaWar[] = []; // 关卡
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
super(activityData, createTime, serverTime)
this.initData(activityData.data)
}
public initData(data: string) {
let dataObj: NewHeroGkDataInDb = JSON.parse(data);
let arr = dataObj.wars||[];
for (let obj of arr) {
this.wars.push(new NewHeroGachaWar(obj, this.beginWithoutHideTime||this.beginTime))
}
}
public findItemByGK(warId: number) {
return this.wars.find(cur => cur.warId == warId);
}
//解析玩家记录
public setPlayerRecords(data: ActivityNewHeroGKModelType) {
if (!data) return;
let records = data.records||[];
for (let data of records) {
let item = this.findItemByGK(data.warId);
if(item) item.setPlayerRecord(true);
}
}
}