秘境本挑战次数
This commit is contained in:
@@ -77,7 +77,7 @@ export class DailyBattleHandler {
|
||||
if(vLv > 0) {
|
||||
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
|
||||
}
|
||||
if(buyCount + 1 > curDaily.timesCanBuy ) {
|
||||
if(buyCount + count > timesCanBuy ) {
|
||||
return resResult(STATUS.DAILY_REFRESH_TIMES_LACK)
|
||||
}
|
||||
let buyCost = 0;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { GOLD_COST_RATIO, DUNGEON_CONST } from '../../../consts/consts';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult, calculateNum, shouldRefresh } from '../../../pubUtils/util';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new DungeonBattleHandler(app);
|
||||
}
|
||||
|
||||
export class DungeonBattleHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
// 获取关卡列表
|
||||
async getData(msg: { }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
|
||||
let curTime = new Date();
|
||||
if(shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME)) {
|
||||
dungeonCnt = 0; dungeonBuyCnt = 0;
|
||||
}
|
||||
|
||||
let nextCostGold = calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num: dungeonBuyCnt + 1 }, 50);
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
nextCostGold,
|
||||
battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt,
|
||||
buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt
|
||||
});
|
||||
}
|
||||
|
||||
// 购买每日次数
|
||||
async buyNum(msg: { count: number }, session: BackendSession) {
|
||||
let { count } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
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;
|
||||
}
|
||||
|
||||
let timesCanBuy = DUNGEON_CONST.MAX_BUY_CNT;
|
||||
let { vLv } = await RoleModel.findByRoleId(roleId);
|
||||
if(vLv > 0) {
|
||||
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
|
||||
}
|
||||
if(dungeonBuyCnt + count > timesCanBuy ) {
|
||||
return resResult(STATUS.DUNGEON_REFRESH_TIMES_LACK)
|
||||
}
|
||||
let buyCost = 0;
|
||||
for(let i = 1; i <= count; i++) {
|
||||
let num = dungeonBuyCnt + i;
|
||||
buyCost += calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num}, 50);
|
||||
}
|
||||
let {gold} = await RoleModel.findByRoleId(roleId);
|
||||
if(buyCost > gold) {
|
||||
return resResult(STATUS.DAILY_REFRESH_GOLD_LACK);
|
||||
}
|
||||
await RoleModel.costGold(roleId, buyCost);
|
||||
await RoleModel.buyCnt(roleId, needRefresh, count, curTime);
|
||||
|
||||
let nextCostGold = calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num: dungeonBuyCnt + count + 1 }, 50);
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
costGold: buyCost,
|
||||
nextCostGold,
|
||||
battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt + count - dungeonCnt,
|
||||
buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt - count
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { HeroModel } from '../../../db/Hero';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { RScriptRecordModel } from '../../../db/RScriptRecord';
|
||||
import { updateWarStar, checkBattleHeroes, roleLevelup } from '../../../services/normalBattleService';
|
||||
import { checkDungeonNum, checkDungeonAndIncrease } from '../../../services/dungeonService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new NormalBattleHandler(app);
|
||||
@@ -46,8 +47,9 @@ export class NormalBattleHandler {
|
||||
// 前置关卡是否挑战过
|
||||
let previousGk = warInfo.previousGk;
|
||||
if(previousGk) {
|
||||
let preBattle = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, previousGk, 1);
|
||||
if(!preBattle) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
let {warStar} = await RoleModel.findByRoleId(roleId);
|
||||
let preBattle = warStar.findIndex(cur => cur.id == previousGk);
|
||||
if(preBattle == -1) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
}
|
||||
|
||||
let checkHeroes = await checkBattleHeroes(roleId, heroes);
|
||||
@@ -56,6 +58,7 @@ export class NormalBattleHandler {
|
||||
const battleCode = genCode(8); // 关卡唯一值
|
||||
let dailyNum = {};
|
||||
let towerData = {};
|
||||
let dungeonNum = {};
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDaily(roleId, battleId, 1);
|
||||
if(checkResult.status == -1) {
|
||||
@@ -75,6 +78,12 @@ export class NormalBattleHandler {
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
} else if (warInfo.warType == WAR_TYPE.MYSTERY || warInfo.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
let checkResult = await checkDungeonNum(roleId, 1);
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dungeonNum = Object.assign(dungeonNum, checkResult.data);
|
||||
}
|
||||
|
||||
const BattleRecord = await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
@@ -91,7 +100,7 @@ export class NormalBattleHandler {
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleId, battleCode, status, apJson, dailyNum, towerData
|
||||
battleId, battleCode, status, apJson, dailyNum, towerData, dungeonNum
|
||||
});
|
||||
}
|
||||
|
||||
@@ -176,10 +185,12 @@ export class NormalBattleHandler {
|
||||
|
||||
let channelService = this.app.get('channelService');
|
||||
|
||||
let warReward = new WarReward(roleId, roleName, battleId, isSuccess);
|
||||
|
||||
let dailyNum = {};
|
||||
let towerRec = null;
|
||||
let towerStatus = null;
|
||||
let towerReward = null;
|
||||
let dungeonNum = {};
|
||||
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, 1, false);
|
||||
if(checkResult.status == -1) {
|
||||
@@ -195,24 +206,27 @@ export class NormalBattleHandler {
|
||||
if(towerEndResult.status == -1) {
|
||||
return towerEndResult.resResult;
|
||||
}
|
||||
towerRec = towerEndResult.data.newRec;
|
||||
towerStatus = towerEndResult.data.towerStatus;
|
||||
towerReward = towerEndResult.data.towerReward;
|
||||
if(towerEndResult.data.towerReward)
|
||||
warReward.setFixReward(towerEndResult.data.towerReward)
|
||||
}
|
||||
} else if (warInfo.warType == WAR_TYPE.MYSTERY || warInfo.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
let checkResult = await checkDungeonAndIncrease(roleId, 1, false);
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult;
|
||||
}
|
||||
dungeonNum = Object.assign(dungeonNum, checkResult.data)
|
||||
}
|
||||
|
||||
let warReward = new WarReward(roleId, roleName, battleId, isSuccess);
|
||||
|
||||
if(isSuccess) { // 挑战胜利
|
||||
// 是否首通
|
||||
let condition1 = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, battleId, 1);
|
||||
let {warStar} = await RoleModel.findByRoleId(roleId);
|
||||
let condition1 = warStar.find(cur => cur.id == battleId);
|
||||
if(!condition1) warReward.setCondition(0, true);
|
||||
// 是否首次3星
|
||||
if(star == 3) {
|
||||
let condition2 = await BattleRecordModel.getBattleRecordByIdAndStar(roleId, battleId, 3);
|
||||
if(!condition2) warReward.setCondition(1, true);
|
||||
if(star == 3 && (!condition1 || condition1.star != 3)) {
|
||||
warReward.setCondition(1, true);
|
||||
}
|
||||
if(towerReward) warReward.setFixReward(towerReward);
|
||||
|
||||
await updateWarStar(roleId, battleId, warInfo.warType, star);
|
||||
}
|
||||
@@ -226,20 +240,13 @@ export class NormalBattleHandler {
|
||||
|
||||
let actordata = await roleLevelup(roleId, isSuccess?warInfo.kingExp:0);// 主公升级经验
|
||||
|
||||
let curHeroes = [];
|
||||
for(let hid of heroes) {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
curHeroes.push(hero);
|
||||
}
|
||||
|
||||
// 返回值:
|
||||
// towerStatus: false-本层未通过, true-本层已通过
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
battleCode, battleId, status, towerStatus,
|
||||
battleCode, battleId, status,
|
||||
...reward,
|
||||
apJson,
|
||||
dailyNum,
|
||||
heroes: curHeroes,
|
||||
towerStatus, dailyNum, dungeonNum,
|
||||
...actordata
|
||||
});
|
||||
}
|
||||
@@ -254,8 +261,9 @@ export class NormalBattleHandler {
|
||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
}
|
||||
// 校验是否三星通关过
|
||||
let condition1 = await BattleRecordModel.getBattleRecordByIdAndStar(roleId, battleId, 3);
|
||||
if(!condition1) {
|
||||
let { warStar } = await RoleModel.findByRoleId(roleId);
|
||||
let curWar = warStar.find(cur => cur.id == battleId);
|
||||
if(!curWar || curWar.star != 3) {
|
||||
return resResult(STATUS.BATTLE_SWEEP_CONDITION_STAR);
|
||||
}
|
||||
|
||||
@@ -271,12 +279,19 @@ export class NormalBattleHandler {
|
||||
|
||||
// 扫荡次数
|
||||
let dailyNum = {};
|
||||
let dungeonNum = {};
|
||||
if(warInfo.warType == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, count, true);
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dailyNum = Object.assign(dailyNum, checkResult.data)
|
||||
} else if(warInfo.warType == WAR_TYPE.MYSTERY|| warInfo.warType == WAR_TYPE.MYSTERY_ELITE) {
|
||||
let checkResult = await checkDungeonAndIncrease(roleId, count, true);
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dungeonNum = Object.assign(dungeonNum, checkResult.data)
|
||||
}
|
||||
|
||||
// 发奖励
|
||||
@@ -299,7 +314,7 @@ export class NormalBattleHandler {
|
||||
battleId, count,
|
||||
...result,
|
||||
apJson,
|
||||
dailyNum,
|
||||
dailyNum, dungeonNum,
|
||||
...actordata
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user