活动:修改成长基金的数据结构

This commit is contained in:
qiaoxin
2021-05-27 17:56:09 +08:00
parent 8520adc7f5
commit 265bace67a
5 changed files with 83 additions and 74 deletions

View File

@@ -2,74 +2,63 @@ import { ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityBuyRecordsModelType } from '../../db/ActivityBuyRecords';
import { ActivityGrowthFundModelType } from '../../db/ActivityGrowthFund';
import { RewardInter } from '../../pubUtils/interface';
import { parseGoodStrWithType, parseHeroStrWithType, splitString } from '../../pubUtils/util';
import { CreateHeroParam } from '../roleField/hero';
import { ActivityBase } from './activityField';
// 成长基金每个奖励的数据
export class GrowthFundItem {
pageIndex: number; // 第几页,从1开始
cellIndex: number; // 第几个从1开始
id: number; // 编号
name: string; //名称
cellIndex: number; // 第几个从1开始
taskType: number; // 任务类型 dic_zyz_taskType.json
taskParam: string; //任务数据 dic_zyz_taskType.json
taskParamArray: Array<number>; //任务数据 dic_zyz_taskType.json
condition: number; //0
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
isComplete: boolean //是否完成任务
isComplete: boolean = false; //是否完成任务
isReceive: boolean = false; //是否领取过奖励
// isReceive: boolean = false; //是否领取过奖励
constructor(data: any) {
this.pageIndex = data.pageIndex;
this.id = data.id;
this.cellIndex = data.cellIndex;
this.name = data.name;
this.taskType = data.taskType;
this.taskParam = data.taskParam;
this.reward = data.reward;
this.condition = data.condition;
this.condition = data.conditon;
this.isComplete = false;
this.isReceive = false;
this.taskParamArray = splitString(data.taskParam, '&')
}
public heroReward(): CreateHeroParam[] {
let rewardArray = [];
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
for (let objStr of rewardData) {
let reward = parseHeroStrWithType(objStr);
rewardArray.push(reward);
}
return rewardArray.filter(obj => { return obj && obj.type == ACTIVITY_RESOURCES_TYPE.HERO })
}
public goodReward(): RewardInter[] {
let rewardArray = [];
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
for (let objStr of rewardData) {
let reward = parseGoodStrWithType(objStr);
rewardArray.push(reward);
}
return rewardArray.filter(obj => { return obj && obj.type == ACTIVITY_RESOURCES_TYPE.GOODS })
}
public canReceive(): boolean {
return !this.isReceive;
// this.isReceive = false;
}
}
// 成长基金每页奖励的数据
export class GrowthFundPage {
pageIndex: number = 0;//页
price: number = 0;//高阶价格
productID: string = '';//商品id
items: GrowthFundItem[] = [];//所有任务
constructor(data: any) {
this.pageIndex = data.pageIndex;
this.price = data.price;
this.productID = data.productID;
for (let itemData of data.data) {
this.items.push(new GrowthFundItem(itemData))
}
}
public findItem(cellIndex: number) {
let index = this.items.findIndex(obj => { return obj.cellIndex === cellIndex });
return (index != -1) ? this.items[index] : null;
}
}
// 成长基金活动数据
export class GrowthFundData extends ActivityBase {
list: Array<GrowthFundItem> = [];
price: number = 0;//高阶价格
productID: string = '';//商品id
list: Array<GrowthFundPage> = [];
buyRecords: Array<number> = [];//高阶购买记录
receiveRecords: Array<ActivityGrowthFundModelType> = [];//领取记录
//是否是高阶,需要购买
public isVipActivity() {
@@ -84,30 +73,34 @@ export class GrowthFundData extends ActivityBase {
return index != -1;
}
//是否领取过
public isReceive(pageIndex: number, cellIndex: number) {
let index = this.receiveRecords.findIndex(obj => { obj && obj.pageIndex == pageIndex && cellIndex == obj.cellIndex })
return (index !== -1);
}
//全部领取完成
public isComplete() {
for (let i = 0; i < this.list.length; i++) {
let item = this.list[i];
if (!item.isReceive) {
return false
let page = this.list[i];
for (let item of page.items) {
let index = this.receiveRecords.findIndex(obj => { obj && obj.pageIndex == page.pageIndex && item.cellIndex == obj.cellIndex })
if (index == -1) {
return false
}
}
}
return true;
}
public findGrowthFundItem(pageIndex: number, cellIndex: number) {
let index = this.list.findIndex(obj => { return obj && obj.pageIndex == pageIndex && obj.cellIndex == cellIndex })
return (index != -1) ? this.list[index] : null;
let index = this.list.findIndex(obj => { return obj && obj.pageIndex == pageIndex })
return this.list[index].findItem(cellIndex);
}
//解析玩家领取记录
public setPlayerRecords(data: ActivityGrowthFundModelType[]) {
for (let obj of this.list) {
let index = data.findIndex(record => { return obj.pageIndex == record.pageIndex && obj.cellIndex == record.cellIndex })
if (index != -1) {
obj.isReceive = data[index].isReceive;
}
}
this.receiveRecords = data;
}
//高阶版购买记录
@@ -119,11 +112,9 @@ export class GrowthFundData extends ActivityBase {
public initData(data: string) {
let dataObj = JSON.parse(data);
this.price = dataObj.price;
this.productID = dataObj.productID;
let arr = dataObj.data;
let arr = dataObj;
for (let obj of arr) {
this.list.push(new GrowthFundItem(obj))
this.list.push(new GrowthFundPage(obj))
}
}

View File

@@ -12,6 +12,7 @@ export class ShopItem {
price: number; //价格
productID: string; //商品id
imageName: string;
discount: number; //折扣
buyCount: number = 0; //购买过的次数
@@ -23,6 +24,7 @@ export class ShopItem {
this.price = data.price;
this.productID = data.productID;
this.imageName = data.imageName;
this.discount = data.discount ? data.discount : 0;
this.buyCount = 0;
}
}