From 6d9961905069b11e8d0d290ad86d376298a38550 Mon Sep 17 00:00:00 2001 From: luying Date: Wed, 2 Jun 2021 20:41:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E7=82=B9=EF=BC=9A=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=88=98=E6=96=97=E7=BB=93=E7=AE=97=E5=A2=9E=E5=8A=A0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/handler/normalBattleHandler.ts | 6 +- .../app/services/dailyBattleService.ts | 57 +++++++++++-------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/game-server/app/servers/battle/handler/normalBattleHandler.ts b/game-server/app/servers/battle/handler/normalBattleHandler.ts index bb3e1080a..f39c95a7a 100644 --- a/game-server/app/servers/battle/handler/normalBattleHandler.ts +++ b/game-server/app/servers/battle/handler/normalBattleHandler.ts @@ -153,6 +153,7 @@ export class NormalBattleHandler { return resResult(STATUS.BATTLE_ACTION_POINT_LACK); } + let { warStar } = await RoleModel.findByRoleId(roleId); let warReward = new WarReward(roleId, roleName, sid, battleId, isSuccess); let dailyNum = {}; @@ -160,7 +161,7 @@ export class NormalBattleHandler { let dungeonNum = {}; if (warInfo.warType == WAR_TYPE.DAILY) { - let checkResult = await checkDailyAndIncrease(roleId, battleId, 1, false); + let checkResult = await checkDailyAndIncrease(roleId, [{id: battleId, star, warType: warInfo.warType}, ...warStar], battleId, 1, false); if (checkResult.status == -1) { return checkResult.resResult; } @@ -208,7 +209,6 @@ export class NormalBattleHandler { if (isSuccess) { // 挑战胜利 // 是否首通 - let { warStar } = await RoleModel.findByRoleId(roleId); let condition1 = warStar.find(cur => cur.id == battleId); if (!condition1) { await switchOnFunc(roleId, FUNC_OPT_TYPE.BATTLE_END, battleId, session); @@ -274,7 +274,7 @@ export class NormalBattleHandler { let dailyNum = {}; let dungeonNum = {}; if (warInfo.warType == WAR_TYPE.DAILY) { - let checkResult = await checkDailyAndIncrease(roleId, battleId, count, true); + let checkResult = await checkDailyAndIncrease(roleId, warStar, battleId, count, true); if (checkResult.status == -1) { return checkResult.resResult } diff --git a/game-server/app/services/dailyBattleService.ts b/game-server/app/services/dailyBattleService.ts index 97eee565a..7657fec8a 100644 --- a/game-server/app/services/dailyBattleService.ts +++ b/game-server/app/services/dailyBattleService.ts @@ -7,6 +7,8 @@ import { resResult } from '../pubUtils/util'; import { STATUS } from '../consts/statusCode'; import { RoleModel, RoleType } from '../db/Role'; import { gameData } from '../pubUtils/data'; +import { DicWar } from '../pubUtils/dictionary/DicWar'; +import { WarStar } from '../domain/dbGeneral'; /** * 获取全部每日关卡列表 @@ -21,27 +23,9 @@ export async function getDailyBattleList(role: RoleType) { let refreshResult = await DailyRecordModel.refreshRecord(roleId, type); let wars: {battleId: number, cost: number, star: number, status: number, name: string}[] = new Array(); let dicDailyWar = gameData.dailyWarByType.get(type); - for(let {war_id, cost, gk_name, previousGk } of dicDailyWar) { - let status = 0, star = 0; - let curBattle = warStar.find(cur => cur.id == war_id); - if(curBattle) { - status = 2; - star = curBattle.star; - } else { - if (previousGk) { - let preBattleRecord = warStar.find(cur => cur.id == previousGk); - if(preBattleRecord) { - status = 1; - } else { - status = 0; - } - } else { - status = 1; - } - } - wars.push({ - battleId: war_id, cost, star, status, name: gk_name - }); + for(let dic of dicDailyWar) { + let war = getDailyWarStatus(dic, warStar); + wars.push(war); } let checkDailyResult = await getDailyNum(refreshResult, timesPerDay, timesCanBuy); result.push({ @@ -52,6 +36,30 @@ export async function getDailyBattleList(role: RoleType) { return result; } +function getDailyWarStatus(dicDailyWar: DicWar, warStar: WarStar[]) { + let {war_id, cost, gk_name, previousGk } = dicDailyWar; + let status = 0, star = 0; + let curBattle = warStar.find(cur => cur.id == war_id); + if(curBattle) { + status = 2; + star = curBattle.star; + } else { + if (previousGk) { + let preBattleRecord = warStar.find(cur => cur.id == previousGk); + if(preBattleRecord) { + status = 1; + } else { + status = 0; + } + } else { + status = 1; + } + } + return { + battleId: war_id, cost, star, status, name: gk_name + } +} + // 检查每日本次数checkBattle使用 export async function checkDaily(roleId: string, battleId: number, inc: number) { let dailyWar = gameData.war.get(battleId); @@ -66,7 +74,7 @@ export async function checkDaily(roleId: string, battleId: number, inc: number) return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) } } let checkDailyResult = await getDailyNum(dailyRecord, curDaily.timesPerDay, curDaily.timesCanBuy); - return {status: 1, data: {type, ...checkDailyResult}}; + return {status: 1, data: {type, ...checkDailyResult }}; } /** @@ -77,10 +85,11 @@ export async function checkDaily(roleId: string, battleId: number, inc: number) * @param isRef 在计算之前是否检查每日的刷新 */ -export async function checkDailyAndIncrease(roleId: string, battleId: number, inc: number, isRef: boolean) { +export async function checkDailyAndIncrease(roleId: string, warStar: WarStar[], battleId: number, inc: number, isRef: boolean) { let dailyWar = gameData.war.get(battleId); if(!dailyWar) return { status: -1, resResult: resResult(STATUS.DAILY_WAR_NOT_FOUND) }; let type = dailyWar.dailyType; + let war = getDailyWarStatus(dailyWar, warStar); let curDaily = gameData.daily.find(cur => cur.dailyType == type); if(!curDaily) return { status: -1, resResult: resResult(STATUS.DAILY_TYPE_NOT_FOUND) }; @@ -97,7 +106,7 @@ export async function checkDailyAndIncrease(roleId: string, battleId: number, in } let result = await DailyRecordModel.increseDailyCount(roleId, type, inc); let checkDailyResult = await getDailyNum(result, curDaily.timesPerDay, curDaily.timesCanBuy); - return {status: 1, data: {type, ...checkDailyResult}}; + return {status: 1, data: {type, ...checkDailyResult, war}}; } export async function getDailyNum(dailyRecord: DailyRecord, timesPerDay?: number, timesCanBuy?: number) {