84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import moment = require('moment');
|
|
import { random } from 'underscore';
|
|
import { REFRESH_TIME } from '../../consts';
|
|
import { ActivityModelType } from '../../db/Activity';
|
|
import { ActivityDailyCoinModelType } from '../../db/ActivityDailyCoin';
|
|
import { ActivityBase } from './activityField';
|
|
|
|
|
|
// 每次配置数据
|
|
export class DailyCoinItem {
|
|
index: number; // 第几次从1开始
|
|
baseReward: string; //基础奖励
|
|
extraReward: string; //额外奖励
|
|
exchangeRate: number; // 兑换比例 1元宝兑换多少铜币
|
|
double: number; // 双倍概率 0.25
|
|
fiveTimes: number; // 5倍概率 0.05
|
|
consume: string; //补签消耗资源
|
|
|
|
public getRate() {
|
|
let ran = (random(99) + 1) * 0.01;//[1,100]
|
|
ran -= this.double;
|
|
if (ran <= 0) {
|
|
return 2;
|
|
}
|
|
ran -= this.fiveTimes;
|
|
if (ran <= 0) {
|
|
return 5;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
constructor(data: any) {
|
|
this.index = data.index;
|
|
this.baseReward = data.baseReward;
|
|
this.extraReward = data.extraReward;
|
|
this.exchangeRate = data.exchangeRate;
|
|
this.double = data.double;
|
|
this.fiveTimes = data.fiveTimes;
|
|
this.consume = data.consume;
|
|
}
|
|
}
|
|
|
|
|
|
// 每日兑换铜币活动数据
|
|
export class DailyCoinData extends ActivityBase {
|
|
list: Array<DailyCoinItem> = [];
|
|
name: string = '';//名字
|
|
exchangeCount: number = 0;//已经兑换次数
|
|
coinCount: number = 0;//已经兑换获得铜币数量
|
|
|
|
public findItem(index: number) {
|
|
let itemIndex = this.list.findIndex(obj => { return obj.index === index });
|
|
return (itemIndex != -1) ? this.list[itemIndex] : null;
|
|
}
|
|
|
|
//解析玩家领取记录
|
|
public setPlayerRecords(data: ActivityDailyCoinModelType) {
|
|
this.exchangeCount = data && data.exchangeCount ? data.exchangeCount : 0;
|
|
this.coinCount = data && data.coinCount ? data.coinCount : 0;
|
|
}
|
|
|
|
public initData(data: string) {
|
|
this.exchangeCount = 0;
|
|
this.coinCount = 0;
|
|
let dataObj = JSON.parse(data);
|
|
let arr = dataObj;
|
|
for (let obj of arr) {
|
|
this.list.push(new DailyCoinItem(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()
|
|
}
|
|
}
|
|
|
|
constructor(activityData: ActivityModelType) {
|
|
super(activityData)
|
|
this.initData(activityData.data)
|
|
}
|
|
} |