活动:神州探秘活动
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { random } from 'underscore';
|
||||
import { pick, random } from 'underscore';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModelType } from '../../db/ActivityTreasureHuntTask';
|
||||
@@ -7,46 +7,125 @@ import { ActivityTreasureHuntFirstPageModelType } from '../../db/ActivityTreasur
|
||||
import { parseNumberList, splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
import { ActivityTreasureHuntChallengeModelTypeParam } from '../../db/ActivityTreasureHuntChallenge';
|
||||
import { TREASURE_HUNT_DATA_TYPE } from '../../consts';
|
||||
|
||||
// 首页
|
||||
interface TreasureHuntFirstPageInDb {
|
||||
index: TREASURE_HUNT_DATA_TYPE.FIRST_PAGE;
|
||||
name: string; // 页签名
|
||||
reward: string; // 奖励
|
||||
imageName: string; // 图片
|
||||
}
|
||||
|
||||
// 商店
|
||||
interface TreasureHuntShopItemConsumeInDb {
|
||||
count: number, // 第几次
|
||||
consume: string, // 消耗 type&id&count
|
||||
discount: number, // 折扣
|
||||
}
|
||||
|
||||
interface TreasureHuntShopItemInDb {
|
||||
cellIndex: number; // 第几项
|
||||
name: string; // 礼包名
|
||||
productID: string; // 商品id
|
||||
price: number; // 价格
|
||||
countMax: number; // 限购数量
|
||||
discount: number; // 折扣
|
||||
reward: string; // 奖励
|
||||
imageName: string; // 图片
|
||||
data: TreasureHuntShopItemConsumeInDb[]; // 消耗
|
||||
}
|
||||
|
||||
interface TreasureHuntShopInDb {
|
||||
index: TREASURE_HUNT_DATA_TYPE.SHOP; // 2. 每日物资,即商店
|
||||
name: string; // 页签名
|
||||
data: TreasureHuntShopItemInDb[];
|
||||
}
|
||||
|
||||
// 任务
|
||||
interface TreasureHuntTaskItemInDb {
|
||||
cellIndex: number; // 第几项
|
||||
name: string; // 任务名
|
||||
taskType: number; // 任务类型
|
||||
taskParam: string; // 任务参数
|
||||
condition: number; // 条件
|
||||
reward: string; // 奖励 type&id&count
|
||||
fragment: number; // 前端显示 碎片数量
|
||||
skip: string; // 前端用 跳转
|
||||
}
|
||||
|
||||
interface TreasureHuntTaskInDb {
|
||||
index: TREASURE_HUNT_DATA_TYPE.TASK; // 3. 任务
|
||||
name: string; // 页签名
|
||||
reward: string; // 奖励 type&id&count
|
||||
data: TreasureHuntTaskItemInDb[]; // 任务
|
||||
}
|
||||
|
||||
// 关卡
|
||||
interface TreasureHuntChallengeInDb {
|
||||
index: TREASURE_HUNT_DATA_TYPE.CHALLENGE; // 4. 关卡
|
||||
name: string; // 页签名
|
||||
consume: string; // 消耗
|
||||
warid: string; // 关卡
|
||||
fixReward: string; // 奖励 type&id&count
|
||||
jackpotReward: string; // 随机奖励
|
||||
imageName: string; // 图标
|
||||
}
|
||||
|
||||
// 高级商店
|
||||
interface TreasureHuntTreasureShopItemInDb {
|
||||
cellIndex: number; // 第几项
|
||||
name: string; // 礼包名
|
||||
reward: string; // 奖励
|
||||
countMax: number; // 限购数量
|
||||
imageName: string; // 图片
|
||||
consume: string; // 消耗
|
||||
}
|
||||
interface TreasureHuntTreasureShopInDb {
|
||||
index: TREASURE_HUNT_DATA_TYPE.TREASURE_SHOP; // 4. 关卡
|
||||
name: string; // 页签名
|
||||
data: TreasureHuntTreasureShopItemInDb[]; // 消耗
|
||||
}
|
||||
interface TreasureHuntInDb {
|
||||
data: (TreasureHuntFirstPageInDb|TreasureHuntShopInDb|TreasureHuntTaskInDb|TreasureHuntChallengeInDb|TreasureHuntTreasureShopInDb)[];
|
||||
}
|
||||
|
||||
|
||||
/************************************************************/
|
||||
// 操作数据
|
||||
// 进入活动首页的数据
|
||||
export class TreasureHuntFirstPageData {
|
||||
name: string = '';//页签名字
|
||||
index: number = 0;//下标
|
||||
reward: string = '';//奖励
|
||||
imageName: string = '';
|
||||
index: number; //下标
|
||||
name: string; //页签名字
|
||||
reward: string; //奖励
|
||||
imageName: string;
|
||||
|
||||
isReceive: boolean = false;//是否领取
|
||||
|
||||
public setPlayerFirstPageRecord(record: ActivityTreasureHuntFirstPageModelType) {
|
||||
this.isReceive = false;
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
this.isReceive = record.isReceive ? record.isReceive : false;
|
||||
constructor(data: TreasureHuntFirstPageInDb) {
|
||||
this.initData(data)
|
||||
}
|
||||
|
||||
public initData(data: any) {
|
||||
public initData(data: TreasureHuntFirstPageInDb) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.reward = data.reward;
|
||||
this.imageName = data.imageName;
|
||||
this.isReceive = false;
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
public setPlayerFirstPageRecord(record: ActivityTreasureHuntFirstPageModelType) {
|
||||
if (!record) return;
|
||||
this.isReceive = !!record.isReceive;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
//购买价格
|
||||
export class ConsumeData {
|
||||
count: number; // 第几次购买,1开始
|
||||
consume: string; //消耗资源 "2&31002&400"
|
||||
discount: number; // 折扣
|
||||
|
||||
constructor(data: any) {
|
||||
constructor(data: TreasureHuntShopItemConsumeInDb) {
|
||||
this.count = data.count;
|
||||
this.consume = data.consume;
|
||||
this.discount = data.discount;
|
||||
@@ -63,11 +142,11 @@ export class TreasureHuntShopItem {
|
||||
countMax: number; //最大购买次数
|
||||
discount: number; //折扣
|
||||
imageName: string;
|
||||
consume: ConsumeData[]; //每次购买价格不同
|
||||
consume: ConsumeData[] = []; //每次购买价格不同
|
||||
|
||||
buyCount: number = 0; //购买过的次数
|
||||
|
||||
constructor(data: any) {
|
||||
constructor(data: TreasureHuntShopItemInDb) {
|
||||
this.cellIndex = data.cellIndex;
|
||||
this.name = data.name;
|
||||
this.price = data.price;
|
||||
@@ -76,24 +155,41 @@ export class TreasureHuntShopItem {
|
||||
this.countMax = data.countMax;
|
||||
this.discount = data.discount;
|
||||
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 : '';
|
||||
}
|
||||
|
||||
public setBuyCount(record: ActivityTreasureHuntShopModelType) {
|
||||
if (!record) return;
|
||||
let buyRecords = record.records.filter(obj => { return obj.id === this.cellIndex });
|
||||
this.buyCount = buyRecords.length;
|
||||
}
|
||||
}
|
||||
|
||||
// 商店数据
|
||||
export class TreasureHuntShopData {
|
||||
index: number = 0;//下标
|
||||
name: string = '';//页签名字
|
||||
list: Array<TreasureHuntShopItem> = [];//商品
|
||||
index: number; //下标
|
||||
name: string; //页签名字
|
||||
list: TreasureHuntShopItem[] = [];//商品
|
||||
|
||||
constructor(data: TreasureHuntShopInDb) {
|
||||
this.initData(data)
|
||||
}
|
||||
|
||||
public initData(data: TreasureHuntShopInDb) {
|
||||
this.index = data.index;
|
||||
this.name = data.name;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new TreasureHuntShopItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
public findProductID(productID: string): TreasureHuntShopItem {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.productID === productID })
|
||||
@@ -110,24 +206,9 @@ export class TreasureHuntShopData {
|
||||
return;
|
||||
}
|
||||
for (let item of this.list) {
|
||||
let buyRecords = record.records.filter(obj => { return obj.id === item.cellIndex });
|
||||
item.buyCount = buyRecords.length;
|
||||
item.setBuyCount(record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
this.index = data.index;
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
@@ -143,45 +224,63 @@ export class TreasureHuntTaskItem {
|
||||
fragment: number; //碎片
|
||||
skip: string;
|
||||
|
||||
taskParamArray: number[]; // 任务参数
|
||||
taskParamArray: number[] = []; // 任务参数
|
||||
totalCount: number = 0; //任务统计
|
||||
isReceive: boolean = false; //是否领取奖励
|
||||
|
||||
constructor(data: any) {
|
||||
constructor(data: TreasureHuntTaskItemInDb) {
|
||||
this.cellIndex = data.cellIndex;
|
||||
this.name = data.name;
|
||||
this.taskType = data.taskType;
|
||||
this.taskParam = data.taskParam;
|
||||
this.taskParamArray = parseNumberList(data.taskParamArray);
|
||||
this.taskParamArray = parseNumberList(data.taskParam);
|
||||
this.condition = data.condition;
|
||||
this.reward = data.reward;
|
||||
this.fragment = data.fragment;
|
||||
this.skip = data.skip;
|
||||
this.totalCount = 0;
|
||||
this.isReceive = false;
|
||||
}
|
||||
|
||||
setPlayerRecord(record: ActivityTreasureHuntTaskModelType) {
|
||||
if(!record) return;
|
||||
this.totalCount = record.totalCount||0;
|
||||
this.isReceive = record.receiveRewardCount ? true : false;
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
return pick(this, ['cellIndex', 'name', 'taskType', 'condition', 'reward', 'fragment', 'skip', 'totalCount', 'isReceive'])
|
||||
}
|
||||
}
|
||||
|
||||
// 寻宝备战数据
|
||||
export class TreasureHuntTaskData {
|
||||
name: string = '';//页签名字
|
||||
index: number = 0;//下标
|
||||
reward: string = '';//奖励
|
||||
fragment: number = 0;//碎片需求量
|
||||
list: Array<TreasureHuntTaskItem> = [];//任务
|
||||
name: string; //页签名字
|
||||
index: number; //下标
|
||||
reward: string; //奖励
|
||||
list: TreasureHuntTaskItem[] = [];//任务
|
||||
|
||||
constructor(data: TreasureHuntTaskInDb) {
|
||||
this.initData(data)
|
||||
}
|
||||
|
||||
public initData(data: TreasureHuntTaskInDb) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.reward = data.reward;
|
||||
let arr = data.data||[];
|
||||
for (let obj of arr) {
|
||||
this.list.push(new TreasureHuntTaskItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
public getItem(cellIndex: number): TreasureHuntTaskItem {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex });
|
||||
return (index != -1) ? this.list[index] : null
|
||||
}
|
||||
|
||||
public setPlayerTaskRecords(record: ActivityTreasureHuntTaskModelType[]) {
|
||||
for (let item of this.list) {
|
||||
let index = record.findIndex(obj => { return obj.cellIndex === item.cellIndex });
|
||||
if (index != -1) {
|
||||
item.totalCount = record[index].totalCount ? record[index].totalCount : 0;
|
||||
item.isReceive = record[index].receiveRewardCount ? true : false;
|
||||
}
|
||||
public setPlayerTaskRecords(records: ActivityTreasureHuntTaskModelType[]) {
|
||||
for(let record of records) {
|
||||
let item = this.getItem(record.cellIndex);
|
||||
if(item) item.setPlayerRecord(record);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,43 +288,32 @@ export class TreasureHuntTaskData {
|
||||
return this.list.filter(obj => { return obj && obj.taskType === type });
|
||||
}
|
||||
|
||||
public initData(data: any) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.reward = data.reward;
|
||||
this.fragment = data.fragment;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new TreasureHuntTaskItem(obj))
|
||||
public getShowResult() {
|
||||
return {
|
||||
...this, list: this.list.map(item => item.getShowResult())
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
|
||||
// 寻宝大冒险的数据
|
||||
export class TreasureHuntChallengeData {
|
||||
name: string = '';//页签名字
|
||||
index: number = 0;//下标
|
||||
consume: string = '';//消耗
|
||||
warid: string = '';//随机的关卡号
|
||||
fixReward: string = '';//客户端显示奖励
|
||||
jackpotReward: string = '';//客户端显示奖励
|
||||
imageName: string = '';
|
||||
name: string; // 页签名字
|
||||
index: number; // 下标
|
||||
consume: string; // 消耗
|
||||
warid: string; // 随机的关卡号
|
||||
fixReward: string; // 客户端显示奖励
|
||||
jackpotReward: string;// 客户端显示奖励
|
||||
imageName: string;
|
||||
|
||||
resultWarId: number = 0; // 玩家随机出的关卡id
|
||||
|
||||
public randomGK() {
|
||||
let gkArray = splitString(this.warid, '&');
|
||||
let index = random(gkArray.length - 1);
|
||||
return gkArray[index];
|
||||
constructor(data: TreasureHuntChallengeInDb) {
|
||||
this.initData(data)
|
||||
}
|
||||
|
||||
public initData(data: any) {
|
||||
public initData(data: TreasureHuntChallengeInDb) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.consume = data.consume;
|
||||
@@ -235,15 +323,17 @@ export class TreasureHuntChallengeData {
|
||||
this.imageName = data.imageName;
|
||||
}
|
||||
|
||||
public randomGK() {
|
||||
let gkArray = splitString(this.warid, '&');
|
||||
let index = random(gkArray.length - 1);
|
||||
return gkArray[index];
|
||||
}
|
||||
|
||||
public setChallengeRecord(record: ActivityTreasureHuntChallengeModelTypeParam) {
|
||||
if(record) {
|
||||
this.resultWarId = record.warId;
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -252,31 +342,48 @@ export class TreasureHuntChallengeData {
|
||||
//天子宝库
|
||||
// 商品的数据
|
||||
export class TreasureHuntTreasureShopItem {
|
||||
cellIndex: number; // 第几个,从1开始
|
||||
name: string; //名称
|
||||
reward: string; //奖励
|
||||
countMax: number; //最大购买次数
|
||||
cellIndex: number; // 第几个,从1开始
|
||||
name: string; //名称
|
||||
reward: string; //奖励
|
||||
countMax: number; //最大购买次数
|
||||
imageName: string;
|
||||
consume: ""; //购买价格
|
||||
consume: string; //购买价格
|
||||
|
||||
buyCount: number = 0; //购买过的次数
|
||||
|
||||
constructor(data: any) {
|
||||
constructor(data: TreasureHuntTreasureShopItemInDb) {
|
||||
this.cellIndex = data.cellIndex;
|
||||
this.name = data.name;
|
||||
this.reward = data.reward;
|
||||
this.countMax = data.countMax;
|
||||
this.imageName = data.imageName;
|
||||
this.consume = data.consume;
|
||||
this.buyCount = 0;
|
||||
}
|
||||
|
||||
setPlayerRecord(record: ActivityTreasureHuntTreasureShopModelType) {
|
||||
let buyRecords = record.records.filter(obj => { return obj.id === this.cellIndex });
|
||||
this.buyCount = buyRecords.length;
|
||||
}
|
||||
}
|
||||
|
||||
// 天子宝库商店数据
|
||||
export class TreasureHuntTreasureShopData {
|
||||
index: number = 0;//下标
|
||||
name: string = '';//页签名字
|
||||
list: Array<TreasureHuntTreasureShopItem> = [];//商品
|
||||
index: number;//下标
|
||||
name: string;//页签名字
|
||||
list: TreasureHuntTreasureShopItem[] = [];//商品
|
||||
|
||||
constructor(data: TreasureHuntTreasureShopInDb) {
|
||||
this.initData(data)
|
||||
}
|
||||
|
||||
public initData(data: TreasureHuntTreasureShopInDb) {
|
||||
this.index = data.index;
|
||||
this.name = data.name;
|
||||
let arr = data.data||[];
|
||||
for (let obj of arr) {
|
||||
this.list.push(new TreasureHuntTreasureShopItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
public getItem(cellIndex: number): TreasureHuntTreasureShopItem {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex })
|
||||
@@ -288,70 +395,51 @@ export class TreasureHuntTreasureShopData {
|
||||
return;
|
||||
}
|
||||
for (let item of this.list) {
|
||||
let buyRecords = record.records.filter(obj => { return obj.id === item.cellIndex });
|
||||
item.buyCount = buyRecords.length;
|
||||
item.setPlayerRecord(record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
this.index = data.index;
|
||||
this.name = data.name;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new TreasureHuntTreasureShopItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
|
||||
// 寻宝骑兵活动数据
|
||||
export class TreasureHuntData extends ActivityBase {
|
||||
name: string = '';//活动名字
|
||||
day: string = '';//活动持续时间
|
||||
// roundIndex = 0;//周期数
|
||||
firstPage: TreasureHuntFirstPageData = null;//首页奖励
|
||||
shop: TreasureHuntShopData = null; //每日物资
|
||||
tasks: TreasureHuntTaskData = null; //寻宝备战
|
||||
challenge: TreasureHuntChallengeData = null;//寻宝大冒险
|
||||
treasureShop: TreasureHuntTreasureShopData = null; //天子宝库(商店)
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
this.day = dataObj.day;
|
||||
|
||||
let arr = dataObj.data;
|
||||
{
|
||||
let index = arr.findIndex(obj => { return obj.index === 1 });
|
||||
this.firstPage = new TreasureHuntFirstPageData(arr[index]);
|
||||
}
|
||||
{
|
||||
let index = arr.findIndex(obj => { return obj.index === 2 });
|
||||
this.shop = new TreasureHuntShopData(arr[index]);
|
||||
}
|
||||
{
|
||||
let index = arr.findIndex(obj => { return obj.index === 3 });
|
||||
this.tasks = new TreasureHuntTaskData(arr[index]);
|
||||
}
|
||||
{
|
||||
let index = arr.findIndex(obj => { return obj.index === 4 });
|
||||
this.challenge = new TreasureHuntChallengeData(arr[index]);
|
||||
}
|
||||
{
|
||||
let index = arr.findIndex(obj => { return obj.index === 5 });
|
||||
this.treasureShop = new TreasureHuntTreasureShopData(arr[index]);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, sererTime: number) {
|
||||
super(activityData, createTime, sererTime);
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj: TreasureHuntInDb = JSON.parse(data);
|
||||
|
||||
let arr = dataObj.data||[];
|
||||
arr.forEach(data => {
|
||||
switch(data.index) {
|
||||
case 1:
|
||||
this.firstPage = new TreasureHuntFirstPageData(data); break;
|
||||
case 2:
|
||||
this.shop = new TreasureHuntShopData(data); break;
|
||||
case 3:
|
||||
this.tasks = new TreasureHuntTaskData(data); break;
|
||||
case 4:
|
||||
this.challenge = new TreasureHuntChallengeData(data); break;
|
||||
case 5:
|
||||
this.treasureShop = new TreasureHuntTreasureShopData(data); break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
return {
|
||||
...this,
|
||||
tasks: this.tasks.getShowResult()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user