活动:招财进宝改为领取箱子
This commit is contained in:
@@ -1,19 +1,33 @@
|
||||
import { random } from 'underscore';
|
||||
import { pick, random } from 'underscore';
|
||||
import { DAILY_COIN_BOX_STATUS } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityDailyCoinModelType } from '../../db/ActivityDailyCoin';
|
||||
import { splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
export class CoinRewardFormulaItem {
|
||||
levelMin: number;
|
||||
levelMax: number;
|
||||
rewardFormula: string;
|
||||
interface ConsumeExchangeFormulaInDb {
|
||||
key: number;
|
||||
countMin: number; // 兑换次数下限
|
||||
countMax: number; // 兑换次数上限
|
||||
consumeFormula: string;
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.levelMin = data.levelMin;
|
||||
this.levelMax = data.levelMax;
|
||||
this.rewardFormula = data.rewardFormula;
|
||||
}
|
||||
interface CoinRewardFormulaInDb {
|
||||
key: number;
|
||||
levelMin: number; // 玩家等级下限
|
||||
levelMax: number; // 玩家等级上限
|
||||
rewardFormula: string;
|
||||
}
|
||||
|
||||
interface DailyCoinDataInDb {
|
||||
countMax: number; // 每日上限
|
||||
freeCount: number; // 每日免费次数
|
||||
extraRewardCount: string; // 可额外获得道具奖励的第X次
|
||||
extraReward: string; // 额外获得的道具奖励
|
||||
double: number; // 2倍暴击触发的概率
|
||||
fiveTimes: number; // 5倍暴击触发的概率
|
||||
consumeExchangeFormula: ConsumeExchangeFormulaInDb[]; // 消耗的元宝
|
||||
coinRewardFormula: CoinRewardFormulaInDb[]; // 获得的硬币
|
||||
}
|
||||
|
||||
// 每次配置数据
|
||||
@@ -22,7 +36,7 @@ export class ConsumeExchangeFormulaItem {
|
||||
countMax: number;
|
||||
consumeFormula: string;
|
||||
|
||||
constructor(data: any) {
|
||||
constructor(data: ConsumeExchangeFormulaInDb) {
|
||||
this.countMin = data.countMin;
|
||||
this.countMax = data.countMax;
|
||||
this.consumeFormula = data.consumeFormula;
|
||||
@@ -30,20 +44,50 @@ export class ConsumeExchangeFormulaItem {
|
||||
}
|
||||
|
||||
|
||||
export class CoinRewardFormulaItem {
|
||||
levelMin: number;
|
||||
levelMax: number;
|
||||
rewardFormula: string;
|
||||
|
||||
constructor(data: CoinRewardFormulaInDb) {
|
||||
this.levelMin = data.levelMin;
|
||||
this.levelMax = data.levelMax;
|
||||
this.rewardFormula = data.rewardFormula;
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtraRewardItem {
|
||||
cellIndex: number;
|
||||
exchangeCount: number;
|
||||
reward: string;
|
||||
status: number = DAILY_COIN_BOX_STATUS.CAN_NOT_OPEN;
|
||||
|
||||
constructor(cellIndex: number, exchangeCount: string, reward: string) {
|
||||
this.cellIndex = cellIndex;
|
||||
this.exchangeCount = parseInt(exchangeCount);
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
setRecord(count: number, receivedBox: number[]) {
|
||||
this.status = DAILY_COIN_BOX_STATUS.CAN_NOT_OPEN;
|
||||
if(count >= this.exchangeCount) this.status = DAILY_COIN_BOX_STATUS.CAN_OPEN;
|
||||
if(receivedBox.indexOf(this.cellIndex) != -1) this.status = DAILY_COIN_BOX_STATUS.RECEIVED;
|
||||
}
|
||||
}
|
||||
|
||||
// 每日兑换铜币活动数据
|
||||
export class DailyCoinData extends ActivityBase {
|
||||
countMax: number = 0;//每日上限
|
||||
freeCount: number = 0;//每日免费次数
|
||||
extraRewardCount: string = '';//可额外获得道具奖励的第X次
|
||||
extraReward: string = '';//额外获得的道具奖励
|
||||
double: number = 0;//2倍暴击触发的概率
|
||||
fiveTimes: number = 0;//5倍暴击触发的概率
|
||||
countMax: number = 0; // 每日上限
|
||||
freeCount: number = 0; // 每日免费次数
|
||||
double: number = 0; // 2倍暴击触发的概率
|
||||
fiveTimes: number = 0; // 5倍暴击触发的概率
|
||||
consumeExchangeFormulaItem: ConsumeExchangeFormulaItem[] = [];
|
||||
coinRewardFormulaItem: CoinRewardFormulaItem[] = [];
|
||||
extraReward: ExtraRewardItem[] = [];
|
||||
|
||||
exchangeCount: number = 0;//已经兑换次数
|
||||
coinCount: number = 0;//已经兑换获得铜币数量
|
||||
recordMsg: string[] = [];//历史记录
|
||||
exchangeCount: number = 0; // 已经兑换次数
|
||||
coinCount: number = 0; // 已经兑换获得铜币数量
|
||||
recordMsg: string[] = []; // 历史记录
|
||||
|
||||
public getRate() {
|
||||
let ran = (random(99) + 1) * 0.01;//[1,100]
|
||||
@@ -58,10 +102,9 @@ export class DailyCoinData extends ActivityBase {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public isExtra(index: number) {
|
||||
let arr = splitString(this.extraRewardCount, '&');
|
||||
return arr.indexOf(index);
|
||||
}
|
||||
// public isExtra(index: number) {
|
||||
// return arr.indexOf(index);
|
||||
// }
|
||||
|
||||
public findConsumeExchangeFormulaItem(index: number) {
|
||||
let itemIndex = this.consumeExchangeFormulaItem.findIndex(obj => { return obj.countMin <= index && obj.countMax >= index });
|
||||
@@ -75,20 +118,38 @@ export class DailyCoinData extends ActivityBase {
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityDailyCoinModelType) {
|
||||
this.exchangeCount = data && data.exchangeCount ? data.exchangeCount : 0;
|
||||
this.coinCount = data && data.coinCount ? data.coinCount : 0;
|
||||
this.recordMsg = data && data.recordMsg ? data.recordMsg : [];
|
||||
if(!data) return;
|
||||
this.exchangeCount = data.exchangeCount||0;
|
||||
this.coinCount = data.coinCount || 0;
|
||||
this.recordMsg = data.recordMsg || [];
|
||||
this.setAllBoxStatus(data);
|
||||
}
|
||||
|
||||
public findBoxByCellIndex(cellIndex: number) {
|
||||
return this.extraReward.find(cur => cur.cellIndex == cellIndex);
|
||||
}
|
||||
|
||||
public setAllBoxStatus(data: ActivityDailyCoinModelType) {
|
||||
for(let box of this.extraReward) {
|
||||
box.setRecord(this.exchangeCount, data.receivedBox||[]);
|
||||
}
|
||||
return this.extraReward;
|
||||
}
|
||||
|
||||
public setBoxStatus(cellIndex: number, data: ActivityDailyCoinModelType) {
|
||||
let item = this.extraReward.find(cur => cur.cellIndex == cellIndex);
|
||||
if(!item) return null;
|
||||
item.setRecord(data.exchangeCount, data.receivedBox||[]);
|
||||
return item
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
this.exchangeCount = 0;
|
||||
this.coinCount = 0;
|
||||
|
||||
let dataObj = JSON.parse(data);
|
||||
let dataObj: DailyCoinDataInDb = JSON.parse(data);
|
||||
this.countMax = dataObj.countMax;
|
||||
this.freeCount = dataObj.freeCount;
|
||||
this.extraRewardCount = dataObj.extraRewardCount;
|
||||
this.extraReward = dataObj.extraReward;
|
||||
this.double = dataObj.double;
|
||||
this.fiveTimes = dataObj.fiveTimes;
|
||||
|
||||
@@ -98,16 +159,11 @@ export class DailyCoinData extends ActivityBase {
|
||||
for (let obj of dataObj.coinRewardFormula) {
|
||||
this.coinRewardFormulaItem.push(new CoinRewardFormulaItem(obj))
|
||||
}
|
||||
// let curDate = moment(new Date());
|
||||
// if (curDate.hour() < REFRESH_TIME) {
|
||||
// this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
|
||||
// this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
|
||||
// } else {
|
||||
// this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
// this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
|
||||
// }
|
||||
// console.log('ddddddddddddbbbbbbb')
|
||||
|
||||
let counts = splitString(dataObj.extraRewardCount, '&');
|
||||
let extraReward = dataObj.extraReward.split('|');
|
||||
for(let i = 0; i < counts.length; i++) {
|
||||
this.extraReward.push(new ExtraRewardItem(i + 1, counts[i], extraReward[i]||''));
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
|
||||
Reference in New Issue
Block a user