160 lines
4.8 KiB
TypeScript
160 lines
4.8 KiB
TypeScript
import { ActivityModelType } from '../../db/Activity';
|
||
import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHuntShop';
|
||
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 {
|
||
name: string = '';//页签名字
|
||
list: Array<TreasureHuntShopItem> = [];//商品
|
||
|
||
public getItem(cellIndex: number): TreasureHuntShopItem {
|
||
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex })
|
||
return (index != -1) ? this.list[index] : null;
|
||
}
|
||
|
||
public setPlayerRecords(record: ActivityTreasureHuntShopModelType) {
|
||
if (!record) {
|
||
return;
|
||
}
|
||
for (let item of this.list) {
|
||
let buyRecords = record.records.filter(obj => { obj.id === item.cellIndex });
|
||
item.buyCount = buyRecords.length;
|
||
}
|
||
}
|
||
|
||
public initData(data: any) {
|
||
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 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.imageName) {
|
||
// this.consume.push(new ConsumeData(obj))
|
||
// }
|
||
// this.buyCount = 0;
|
||
// }
|
||
// }
|
||
|
||
// // 寻宝备战数据
|
||
// export class TreasureHuntShopData {
|
||
// name: string = '';//页签名字
|
||
// index: number = 0;//下标
|
||
// list: Array<TreasureHuntShopItem> = [];//商品
|
||
|
||
// public initData(data: any) {
|
||
// this.name = data.name;
|
||
// this.index = data.index;
|
||
// let arr = data.data;
|
||
// for (let obj of arr) {
|
||
// this.list.push(new TreasureHuntShopItem(obj))
|
||
// }
|
||
// }
|
||
|
||
// constructor(data: any) {
|
||
// this.initData(data)
|
||
// }
|
||
// }
|
||
|
||
/************************************************************/
|
||
|
||
// 商店数据
|
||
export class TreasureHuntData extends ActivityBase {
|
||
name: string = '';//活动名字
|
||
day: string = '';//活动持续时间
|
||
roundIndex = 0;//周期数
|
||
shop: TreasureHuntShopData = 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]);
|
||
|
||
}
|
||
|
||
constructor(activityData: ActivityModelType) {
|
||
super(activityData)
|
||
this.initData(activityData.data)
|
||
}
|
||
} |