Files
ZYZ/shared/domain/activityField/selfServiceShopField.ts
2021-05-08 19:09:58 +08:00

79 lines
2.7 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 { SELF_SERVICE_SHOP_CELL_TYPE, ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivitySelfServiceShopModelType } from '../../db/ActivitySelfServiceShop';
import { deltaDays } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 自助商店数据坑位数据
export class SelfServiceShopItemInfo {
cellIndex: number; // 第几个坑位从1开始
cellType: number; //坑位类型 SELF_SERVICE_SHOP_CELL_TYPE 1.特殊 2.普通
gift: number; //礼包内容
constructor(data: any) {
this.cellIndex = data.cellIndex;
this.cellType = data.cellType;
this.gift = data.gift;
}
}
// 自助商店数据
export class SelfServiceShopItem {
index: number; // 第几个货架从1开始
name: string; //名称
countMax: number = 0; // 最大可购买次数 0表示无限
price: number; //价格
priceType: number; //价格类型 ACTIVITY_RESOURCES_TYPE 2.物品表 3.RMB
data: Array<SelfServiceShopItemInfo> = [];
buyCount: number = 0; //已经购买次数
constructor(cellData: any) {
this.index = cellData.index;
this.name = cellData.name;
this.countMax = cellData.countMax;
this.price = cellData.price;
this.priceType = cellData.priceType;
this.data = [];
for (let obj of cellData.data) {
this.data.push(new SelfServiceShopItemInfo(obj))
}
}
}
// 自选商店
export class SelfServiceShopData extends ActivityBase {
list: Array<SelfServiceShopItem> = [];//货架
days: number = 20;//刷新周期天数
roundIndex: number = 0; //第几周期 从1开始
public getItem(index: number) {
let listIndex = this.list.findIndex(obj => { return obj.index == index });
return (listIndex != -1) ? this.list[listIndex] : null;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivitySelfServiceShopModelType[]) {
for (let item of this.list) {
let buyData = data.filter(obj => { return obj.index === item.index })
item.buyCount = buyData.length
}
}
public initData(data: string) {
console.log('ddddddd', data)
let dataObj = JSON.parse(data);
this.days = dataObj.days;
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new SelfServiceShopItem(obj))
}
this.roundIndex = Math.ceil(this.todayIndex / this.days);
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}