秘境本挑战次数

This commit is contained in:
luying
2020-11-13 18:06:53 +08:00
parent 9574bada4f
commit ada3cfe849
18 changed files with 439 additions and 82 deletions
@@ -72,5 +72,5 @@ export async function getDailyNum(dailyRecord: DailyRecord, timesPerDay?: number
if(vLv > 0) {
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
}
return {count: timesPerDay - count + buyCount, buyCount: timesCanBuy - buyCount}
return {battleCount: timesPerDay - count + buyCount, buyCount: timesCanBuy - buyCount}
}
@@ -0,0 +1,55 @@
/**
* 每日本相关
*/
import { resResult, shouldRefresh } from '../pubUtils/util';
import { STATUS } from '../consts/statusCode';
import { RoleModel } from '../db/Role';
import { DUNGEON_CONST } from '../consts/consts';
// 检查秘境本次数checkBattle使用
export async function checkDungeonNum(roleId: string, inc: number) {
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
let needRefresh = shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME);
if(needRefresh) {
dungeonCnt = 0; dungeonBuyCnt = 0;
}
if(dungeonCnt + inc > DUNGEON_CONST.MAX_CNT + dungeonBuyCnt) {
return {status: -1, resResult: resResult(STATUS.DUNGEON_TIMES_LACK)}
}
await RoleModel.increaseDungeonCnt(roleId, needRefresh, 0, curTime);
return { status: 0, data: {
battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt,
buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt
}};
}
/**
* 检查秘境本次数并添加,warEnd和warSweep使用
* @param roleId
* @param inc 增加的次数
* @param isRef 在计算之前是否检查每日的刷新
*/
export async function checkDungeonAndIncrease(roleId: string, inc: number, isRef: boolean) {
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
let needRefresh = isRef && shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME);
if(needRefresh) {
dungeonCnt = 0; dungeonBuyCnt = 0;
}
if(dungeonCnt + inc > DUNGEON_CONST.MAX_CNT + dungeonBuyCnt ) {
return { status: -1, resResult: resResult(STATUS.DUNGEON_TIMES_LACK) }
}
console.log('needRefresh', needRefresh);
await RoleModel.increaseDungeonCnt(roleId, needRefresh, inc, curTime);
return {status: 1, data: {
battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt - inc,
buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt
}};
}
+15 -9
View File
@@ -41,29 +41,35 @@ export class WarReward {
}
public setFixReward(reward: string) {
let last = this.fixReward.substr(this.fixReward.length - 1, 1);
if(this.fixReward.length && last == '&') {
let str = this.fixReward;
let last = str.substr(str.length-1, 1);
if(last == '&') str = str.substr(0, str.length - 1);
if(str.length) {
this.fixReward += reward;
} else {
this.fixReward += '&' + reward;
this.fixReward += '|' + reward;
}
}
public setConditionReward(reward: string) {
let last = this.conditionReward.substr(this.fixReward.length - 1, 1);
if(last == '&') {
let str = this.conditionReward;
let last = str.substr(str.length-1, 1);
if(last == '&') str = str.substr(0, str.length - 1);
if(str.length) {
this.conditionReward += reward;
} else {
this.conditionReward += '&' + reward;
this.conditionReward += '|' + reward;
}
}
public setRandomReward(reward: string) {
let last = this.randomReward.substr(this.fixReward.length - 1, 1);
if(last == '&') {
let str = this.randomReward;
let last = str.substr(str.length-1, 1);
if(last == '&') str = str.substr(0, str.length - 1);
if(str.length) {
this.randomReward += reward;
} else {
this.randomReward += '&' + reward;
this.randomReward += '|' + reward;
}
}