活动:新手限定礼包

This commit is contained in:
qiaoxin
2021-05-11 17:03:59 +08:00
parent b268c85fa2
commit df13e8181e
26 changed files with 412 additions and 154 deletions

View File

@@ -0,0 +1,75 @@
import { ACTIVITY_RESOURCES_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityShopModelType } from '../../db/ActivityShop';
import { ActivityBase } from './activityField';
// 每个商品的内容
export class ShopItem {
id: number; // 商品id
reward: string; //任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
countMax: number = 0; //可购买的最大次数0表示不限制
name: string; //名字
buyCount: number = 0; //购买过的次数
constructor(data: any) {
this.id = data.id;
this.reward = data.reward;
this.countMax = data.countMax;
this.name = data.name;
}
}
// 商店数据
export class LimitShopData extends ActivityBase {
name: string = '';//活动名称
interval: number = 0;//周期间隔(秒)
list: Array<ShopItem> = [];//商品列表
refreshTime: Date;//下次刷新时间
roundIndex: number = 1;//周期数从1开始
public findItem(id: number) {
let index = this.list.findIndex(obj => { return obj && obj.id === id });
return (index != -1) ? this.list[index] : null
}
//全部领取完成
public isComplete() {
for (let item of this.list) {
if (item.countMax == 0 ||
(item.countMax > 0 && item.buyCount < item.countMax)) {
return false
}
}
return true;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivityShopModelType) {
if (!data) {
return;
}
let records = data.records ? data.records : [];
for (let item of this.list) {
let buyRecords = records.filter(obj => { return obj && obj.id === item.id });
item.buyCount = buyRecords.length;
}
}
public initData(data: string) {
let dataObj = JSON.parse(data);
this.name = dataObj.name;
this.interval = dataObj.interval;
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new ShopItem(obj))
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}