import { ActivityModelType } from '../../db/Activity'; import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHuntShop'; import { ActivityTreasureHuntTaskModelType } from '../../db/ActivityTreasureHuntTask'; import { ActivityTreasureHuntTreasureShopModelType } from '../../db/ActivityTreasureHuntTreasureShop'; import { ActivityBase } from './activityField'; /************************************************************/ //购买价格 export class ConsumeData { count: number; // 第几次购买,1开始 consume: string; //消耗资源 "2&31002&400" constructor(data: any) { this.count = data.count; this.consume = data.consume; } } // 商品的数据 export class TreasureHuntShopItem { cellIndex: number; // 第几个,从1开始 name: string; //名称 price: number; // 价格RMB 每次购买价格不变 productID: string; // 商品id reward: string; //奖励 countMax: number; //最大购买次数 imageName: string; consume: ConsumeData[]; //每次购买价格不同 buyCount: number = 0; //购买过的次数 constructor(data: any) { this.cellIndex = data.cellIndex; this.name = data.name; this.price = data.price; this.productID = data.productID; this.reward = data.reward; this.countMax = data.countMax; this.imageName = data.imageName; this.consume = []; for (let obj of data.data) { this.consume.push(new ConsumeData(obj)) } this.buyCount = 0; } public getConsume() { let index = this.consume.findIndex(obj => { return obj && obj.count === this.buyCount + 1 }); return (index != -1) ? this.consume[index].consume : ''; } } // 商店数据 export class TreasureHuntShopData { index: number = 0;//下标 name: string = '';//页签名字 list: Array = [];//商品 public getItem(cellIndex: number): TreasureHuntShopItem { let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex }) return (index != -1) ? this.list[index] : null; } public setPlayerShopRecords(record: ActivityTreasureHuntShopModelType) { if (!record) { return; } for (let item of this.list) { let buyRecords = record.records.filter(obj => { return obj.id === item.cellIndex }); item.buyCount = buyRecords.length; } } public initData(data: any) { this.index = data.index; this.name = data.name; let arr = data.data; for (let obj of arr) { this.list.push(new TreasureHuntShopItem(obj)) } } constructor(data: any) { this.initData(data) } } /************************************************************/ // 寻宝备战的数据 export class TreasureHuntTaskItem { cellIndex: number; // 第几个,从1开始 name: string; //名称 taskType: number; // 任务类型 taskParam: string; // 任务参数 condition: number; //任务条件数据 reward: string; //奖励 fragment: number; //碎片 totalCount: number = 0; //任务统计 isReceive: boolean = false; //是否领取奖励 constructor(data: any) { this.cellIndex = data.cellIndex; this.name = data.name; this.taskType = data.taskType; this.taskParam = data.taskParam; this.condition = data.condition; this.reward = data.reward; this.fragment = data.fragment; this.totalCount = 0; this.isReceive = false; } } // 寻宝备战数据 export class TreasureHuntTaskData { name: string = '';//页签名字 index: number = 0;//下标 reward: string = '';//奖励 fragment: number = 0;//碎片需求量 list: Array = [];//任务 public getItem(cellIndex: number): TreasureHuntTaskItem { let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex }); return (index != -1) ? this.list[index] : null } public setPlayerTaskRecords(record: ActivityTreasureHuntTaskModelType[]) { for (let item of this.list) { let index = record.findIndex(obj => { return obj.cellIndex === item.cellIndex && obj.type === item.taskType }); if (index != -1) { item.totalCount = record[index].totalCount; item.isReceive = record[index].receiveRewardCount ? true : false; } } } public initData(data: any) { this.name = data.name; this.index = data.index; this.reward = data.reward; this.fragment = data.fragment; let arr = data.data; for (let obj of arr) { this.list.push(new TreasureHuntTaskItem(obj)) } } constructor(data: any) { this.initData(data) } } /************************************************************/ // 寻宝大冒险的数据 export class TreasureHuntChallengeData { name: string = '';//页签名字 index: number = 0;//下标 consume: string = '';//消耗 count: number = 0;//碎片需求量 fixReward: string = '';//消耗 jackpotReward: string = '';//消耗 public initData(data: any) { this.name = data.name; this.index = data.index; this.consume = data.consume; this.count = data.count; this.fixReward = data.fixReward; this.jackpotReward = data.jackpotReward; } constructor(data: any) { this.initData(data) } } /************************************************************/ //天子宝库 // 商品的数据 export class TreasureHuntTreasureShopItem { cellIndex: number; // 第几个,从1开始 name: string; //名称 reward: string; //奖励 countMax: number; //最大购买次数 imageName: string; consume: ""; //购买价格 buyCount: number = 0; //购买过的次数 constructor(data: any) { this.cellIndex = data.cellIndex; this.name = data.name; this.reward = data.reward; this.countMax = data.countMax; this.imageName = data.imageName; this.consume = data.consume; this.buyCount = 0; } } // 天子宝库商店数据 export class TreasureHuntTreasureShopData { index: number = 0;//下标 name: string = '';//页签名字 list: Array = [];//商品 public getItem(cellIndex: number): TreasureHuntTreasureShopItem { let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex }) return (index != -1) ? this.list[index] : null; } public setPlayerTreasureShopRecords(record: ActivityTreasureHuntTreasureShopModelType) { if (!record) { return; } for (let item of this.list) { let buyRecords = record.records.filter(obj => { return obj.id === item.cellIndex }); item.buyCount = buyRecords.length; } } public initData(data: any) { this.index = data.index; this.name = data.name; let arr = data.data; for (let obj of arr) { this.list.push(new TreasureHuntTreasureShopItem(obj)) } } constructor(data: any) { this.initData(data) } } /************************************************************/ // 寻宝骑兵活动数据 export class TreasureHuntData extends ActivityBase { name: string = '';//活动名字 day: string = '';//活动持续时间 roundIndex = 0;//周期数 shop: TreasureHuntShopData = null; //每日物资 tasks: TreasureHuntTaskData = null; //寻宝备战 challenge: TreasureHuntChallengeData = null;//寻宝大冒险 treasureShop: TreasureHuntTreasureShopData = null; //天子宝库(商店) public initData(data: any) { let dataObj = JSON.parse(data); this.name = dataObj.name; this.day = dataObj.day; let arr = dataObj.data; this.shop = new TreasureHuntShopData(arr[0]); this.tasks = new TreasureHuntTaskData(arr[1]); this.challenge = new TreasureHuntChallengeData(arr[2]); this.treasureShop = new TreasureHuntTreasureShopData(arr[3]); } constructor(activityData: ActivityModelType) { super(activityData) this.initData(activityData.data) } }