import { ActivityModelType } from '../../db/Activity'; import { UserGachaType } from '../../db/UserGacha'; import { DicGacha } from '../../pubUtils/dictionary/DicGacha'; import { RewardInter } from '../../pubUtils/interface'; 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; isFree: boolean = false; // 免费次数 cost: RewardInter[] = []; // 消耗 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, dic: DicGacha) { if(dic) this.cost = dic.cost; if (data) { this.pickHero = data.pickHero; this.count = data.count; this.isFree = data.freeCount < dic?.free.count; } } public isPickHero(hid: number) { return this.heroes.findIndex(cur => cur.hid == hid) != -1; } }