Files
ZYZ/shared/domain/activityField/newHeroGiftField.ts
2021-06-22 16:28:36 +08:00

70 lines
2.2 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 { ActivityModelType } from '../../db/Activity';
import { ActivityNewHeroGiftModelType } from '../../db/ActivityNewHeroGift';
import { ActivityBase } from './activityField';
// 礼包的内容
export class NewHeroGiftItem {
index: number; // 下标
reward: string; //任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
countMax: number = 0; //可购买的最大次数0表示不限制
name: string; //名字
consumePoint: number; //消耗点数
buyCount: number = 0; //兑换过的次数
constructor(data: any) {
this.index = data.index;
this.reward = data.reward;
this.countMax = data.countMax;
this.name = data.name;
this.consumePoint = data.consumePoint;
this.buyCount = 0;
}
}
// 新将礼包数据
export class NewHeroGiftData extends ActivityBase {
name: string = '';//活动名称
list: Array<NewHeroGiftItem> = [];//礼包列表
totalPoint: number = 0;//获得总点数
consumeTotalPoint: number = 0;//消耗总点数
public findItem(index: number) {
let itemIndex = this.list.findIndex(obj => { return obj && obj.index === index });
return (itemIndex != -1) ? this.list[itemIndex] : null;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivityNewHeroGiftModelType) {
if (!data) {
return;
}
this.totalPoint = data.totalPoint ? data.totalPoint : 0;
let records = data.records ? data.records : [];
for (let item of this.list) {
let buyRecords = records.filter(obj => { return obj && obj.index === item.index });
item.buyCount = buyRecords.length;
}
for (let obj of records) {
this.consumeTotalPoint += obj.point;
}
}
public initData(data: string) {
let dataObj = JSON.parse(data);
this.name = dataObj.name;
this.totalPoint = 0;
this.consumeTotalPoint = 0;
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new NewHeroGiftItem(obj))
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}