活动:修改每日兑换铜币的数据结构
This commit is contained in:
@@ -19,11 +19,15 @@ export default class Activity_Daily_Coin extends BaseModel {
|
||||
exchangeCount: number; // 兑换次数
|
||||
@prop({ required: true })
|
||||
coinCount: number; // 兑换获得铜币数量
|
||||
@prop({ required: true })
|
||||
recordMsg: string[]; // 兑换记录 exchangeCount&cointCount
|
||||
|
||||
|
||||
|
||||
//兑换记录
|
||||
public static async addExchangeRecord(serverId: number, activityId: number, roleId: string, beginTime: number, count: number, coinCount: number) {
|
||||
let result = await ActivityDailyCoinModel.findOneAndUpdate({ serverId, activityId, roleId, beginTime }, { $inc: { exchangeCount: count, coinCount: coinCount } }, { upsert: true, new: true }).lean(true)
|
||||
public static async addExchangeRecord(serverId: number, activityId: number, roleId: string, beginTime: number, count: number, coinCount: number, msg: string) {
|
||||
let result = await ActivityDailyCoinModel.findOneAndUpdate({ serverId, activityId, roleId, beginTime },
|
||||
{ $inc: { exchangeCount: count, coinCount: coinCount }, $push: { recordMsg: msg } }, { upsert: true, new: true }).lean(true)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,18 +3,53 @@ import { random } from 'underscore';
|
||||
import { REFRESH_TIME } 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;
|
||||
rewardBaseRatio: number;
|
||||
|
||||
constructor(data: any) {
|
||||
this.levelMin = data.levelMin;
|
||||
this.levelMax = data.levelMax;
|
||||
this.rewardFormula = data.rewardFormula;
|
||||
this.rewardBaseRatio = data.rewardBaseRatio;
|
||||
}
|
||||
}
|
||||
|
||||
// 每次配置数据
|
||||
export class DailyCoinItem {
|
||||
index: number; // 第几次从1开始
|
||||
baseReward: string; //基础奖励
|
||||
extraReward: string; //额外奖励
|
||||
exchangeRate: number; // 兑换比例 1元宝兑换多少铜币
|
||||
double: number; // 双倍概率 0.25
|
||||
fiveTimes: number; // 5倍概率 0.05
|
||||
consume: string; //补签消耗资源
|
||||
export class ConsumeExchangeFormulaItem {
|
||||
countMin: number;
|
||||
countMax: number;
|
||||
consumeFormula: string;
|
||||
exchangeRate: number;
|
||||
|
||||
constructor(data: any) {
|
||||
this.countMin = data.countMin;
|
||||
this.countMax = data.countMax;
|
||||
this.consumeFormula = data.consumeFormula;
|
||||
this.exchangeRate = data.exchangeRate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 每日兑换铜币活动数据
|
||||
export class DailyCoinData extends ActivityBase {
|
||||
countMax: number = 0;//每日上限
|
||||
freeCount: number = 0;//每日免费次数
|
||||
extraRewardCount: string = '';//可额外获得道具奖励的第X次
|
||||
extraReward: string = '';//额外获得的道具奖励
|
||||
double: number = 0;//2倍暴击触发的概率
|
||||
fiveTimes: number = 0;//5倍暴击触发的概率
|
||||
consumeExchangeFormulaItem: ConsumeExchangeFormulaItem[] = [];
|
||||
coinRewardFormulaItem: CoinRewardFormulaItem[] = [];
|
||||
|
||||
exchangeCount: number = 0;//已经兑换次数
|
||||
coinCount: number = 0;//已经兑换获得铜币数量
|
||||
recordMsg: string[] = [];//历史记录
|
||||
|
||||
public getRate() {
|
||||
let ran = (random(99) + 1) * 0.01;//[1,100]
|
||||
@@ -29,43 +64,45 @@ export class DailyCoinItem {
|
||||
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;
|
||||
public isExtra(index: number) {
|
||||
let arr = splitString(this.extraRewardCount, '&');
|
||||
return arr.indexOf(index) != -1;
|
||||
}
|
||||
}
|
||||
|
||||
public findConsumeExchangeFormulaItem(index: number) {
|
||||
let itemIndex = this.consumeExchangeFormulaItem.findIndex(obj => { return obj.countMin <= index && obj.countMax >= index });
|
||||
return (itemIndex != -1) ? this.consumeExchangeFormulaItem[itemIndex] : null;
|
||||
}
|
||||
|
||||
// 每日兑换铜币活动数据
|
||||
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 findCoinRewardFormulaItem(level: number) {
|
||||
let itemIndex = this.coinRewardFormulaItem.findIndex(obj => { return obj.levelMin <= level && obj.levelMax >= level });
|
||||
return (itemIndex != -1) ? this.coinRewardFormulaItem[itemIndex] : null;
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
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 : [];
|
||||
}
|
||||
|
||||
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))
|
||||
this.countMax = dataObj.countMax;
|
||||
this.freeCount = dataObj.freeCount;
|
||||
this.extraRewardCount = dataObj.extraRewardCount;
|
||||
this.extraReward = dataObj.extraReward;
|
||||
this.double = dataObj.double;
|
||||
this.fiveTimes = dataObj.fiveTimes;
|
||||
|
||||
for (let obj of dataObj.consumeExchangeFormula) {
|
||||
this.consumeExchangeFormulaItem.push(new ConsumeExchangeFormulaItem(obj))
|
||||
}
|
||||
for (let obj of dataObj.coinRewardFormula) {
|
||||
this.coinRewardFormulaItem.push(new CoinRewardFormulaItem(obj))
|
||||
}
|
||||
let curDate = moment(new Date());
|
||||
if (curDate.hour() < REFRESH_TIME) {
|
||||
|
||||
Reference in New Issue
Block a user