活动:每日兑换铜币活动

This commit is contained in:
qiaoxin
2021-06-10 20:01:20 +08:00
parent 1b16ffc6ab
commit d5242ee9dd
12 changed files with 355 additions and 45 deletions

View File

@@ -0,0 +1,81 @@
import moment = require('moment');
import { random } from 'underscore';
import { REFRESH_TIME, TASK_TYPE } 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;//已经兑换次数
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;
}
public initData(data: string) {
this.exchangeCount = 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)
}
}

View File

@@ -31,6 +31,11 @@ export class SelfServiceShopItem {
buyCount: number = 0; //已经购买次数
public findCellIndex(cellIndex: number) {
let index = this.data.findIndex(obj => { return obj && obj.cellIndex === cellIndex });
return (index != -1) ? this.data[index] : null;
}
constructor(cellData: any) {
this.index = cellData.index;
this.name = cellData.name;