Files
ZYZ/shared/domain/activityField/newHeroGachaField.ts
T
2022-08-01 20:06:37 +08:00

59 lines
1.8 KiB
TypeScript

import { ActivityModelType } from '../../db/Activity';
import { UserGachaType } from '../../db/UserGacha';
import { ActivityBase } from './activityField';
interface NewHeroGachaItemInDb {
hid: number;
position: string; // x&y
}
interface NewHeroGachaDataInDb {
gachaId: number; // dic_zyz_gacha表的id,卡池的概率,消耗都通过这个表读取
icon: string; // 大地图的icon图片文件名
heroes: NewHeroGachaItemInDb[]; // 本期活动pick的武将
bg: string; // 首页背景图片
uiType: number; // 布局格式,具体什么代表什么含义由策划和客户端定
}
// 每日关卡活动数据
export class NewHeroGachaData extends ActivityBase {
gachaId: number;
icon: string;
heroes: NewHeroGachaItemInDb[];
bg: string;
uiType: number;
pickHero: number = 0;
count: number = 0;
freeCount: number = 0;
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
super(activityData, createTime, serverTime)
this.initData(activityData.data)
}
public initData(data: string) {
let dataObj: NewHeroGachaDataInDb = JSON.parse(data);
this.gachaId = dataObj.gachaId;
this.icon = dataObj.icon;
this.heroes = dataObj.heroes;
this.bg = dataObj.bg;
this.uiType = dataObj.uiType;
}
public findItem(hid: number) {
return this.heroes.find(obj => { return obj && obj.hid == hid })
}
//解析玩家记录
public setPlayerRecords(data: UserGachaType) {
if (!data) return;
this.pickHero = data.pickHero;
this.count = data.count;
this.freeCount = data.freeCount;
}
public isPickHero(hid: number) {
return this.heroes.findIndex(cur => cur.hid == hid) != -1;
}
}