From a001ec447862dfd12904598dde689f350436649b Mon Sep 17 00:00:00 2001 From: liangtongchuan Date: Wed, 2 Dec 2020 00:52:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BB=E5=AE=9D=EF=BC=9A=E4=BA=BA=E6=BB=A1?= =?UTF-8?q?=E4=B8=8D=E5=BC=80=E6=89=93=E9=98=9F=E4=BC=8D=E8=A7=A3=E6=95=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/handler/comBattleHandler.ts | 33 +++++++++++++++---- game-server/app/services/comBattleService.ts | 17 +++++++++- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/game-server/app/servers/battle/handler/comBattleHandler.ts b/game-server/app/servers/battle/handler/comBattleHandler.ts index 15bcbb224..037b18a13 100644 --- a/game-server/app/servers/battle/handler/comBattleHandler.ts +++ b/game-server/app/servers/battle/handler/comBattleHandler.ts @@ -2,10 +2,10 @@ * @Author: 梁桐川 * @Date: 2020-11-30 15:05:48 * @Last Modified by: 梁桐川 - * @Last Modified time: 2020-12-02 00:13:35 + * @Last Modified time: 2020-12-02 00:51:27 */ import { COM_BATTLE_ASSIST_TIME, COM_BATTLE_ROBOT_ROUND_LMT, COM_BATTLE_ROBOT_HURT_RATIO, COM_BATTLE_ROBOT_HURT_CH_RATIO, COM_TEAM_STATUS } from './../../../consts/consts'; -import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_BATTLE_CAP_TIME, COM_BATTLE_TIME_LMT } from './../../../consts/consts'; +import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_BATTLE_CAP_TIME, COM_BATTLE_TIME_LMT, COM_BATTLE_CAP_START_TIME } from './../../../consts/consts'; import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality, getBlueprtComposeByQuality, getBluePrtByQuality } from '../../../pubUtils/gamedata'; import { COM_TEAM_ENABLE_LV } from '../../../consts/consts'; import { ComBattleTeamModel } from '../../../db/ComBattleTeam'; @@ -18,7 +18,7 @@ import { ItemModel } from '../../../db/Item'; import { handleReward } from '../../../services/rewardService'; import { checkRoleInQueue, getTeamSearchByQuality, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService'; import { transBossHpArr } from '../../../services/battleService'; -import { getRandBlueprtId, getRandComBtlRobots, checkComBattleResult } from '../../../services/comBattleService'; +import { getRandBlueprtId, getRandComBtlRobots, checkComBattleResult, clearComBtlTimer } from '../../../services/comBattleService'; export default function(app: Application) { return new ComBattleHandler(app); @@ -72,6 +72,7 @@ export class ComBattleHandler { constructor(private app: Application) { } private teamMap: Map = new Map(); + private teamDisTimer: Map = new Map(); /** * @description 队长创建队伍 @@ -164,8 +165,20 @@ export class ComBattleHandler { } channel.pushMessage('onTeamJoin', {teamInfo: team}); } + // TODO: 代码抽象 + if (team.roleIds && team.roleIds.length === 3) { + let timer = setTimeout(async () => { + thiz.dismiss({teamCode}, session); + }, COM_BATTLE_CAP_START_TIME); + thiz.teamDisTimer.set(teamCode, timer); + } }, COM_BATTLE_CAP_TIME); - + if (team.roleIds && team.roleIds.length === 3) { + let timer = setTimeout(async () => { + thiz.dismiss({teamCode}, session); + }, COM_BATTLE_CAP_START_TIME); + thiz.teamDisTimer.set(teamCode, timer); + } return resResult(STATUS.SUCCESS, { teamCode, roleStatus }); } @@ -288,6 +301,13 @@ export class ComBattleHandler { channel.add(roleId, sid); } + if (teamStatus.roleIds && teamStatus.roleIds.length === 3) { + let thiz = this; + let timer = setTimeout(async () => { + thiz.dismiss({teamCode}, session); + }, COM_BATTLE_CAP_START_TIME); + thiz.teamDisTimer.set(teamCode, timer); + } return resResult(STATUS.SUCCESS, { teamInfo: teamStatus}); } @@ -418,6 +438,7 @@ export class ComBattleHandler { channel.removeMember(roleIdToRm); } channel.pushMessage('onLeaveTeam', {teamCode, roleId: roleIdToRm}); + clearComBtlTimer(teamCode, this.teamDisTimer); // 移除队员停止解散计时 return resResult(STATUS.SUCCESS); } @@ -445,7 +466,7 @@ export class ComBattleHandler { let channel = channelService.getChannel(teamCode, false); channel.pushMessage('onTeamDismiss', {teamCode}); channel.destroy(); - + clearComBtlTimer(teamCode, this.teamDisTimer); // 队伍解散停止解散计时 return resResult(STATUS.SUCCESS); } @@ -469,6 +490,7 @@ export class ComBattleHandler { let team = await ComBattleTeamModel.updateStatus(teamCode, COM_TEAM_STATUS.FIGHTING); if (!team) return resResult(STATUS.COM_BATTLE_START_ERR); + clearComBtlTimer(teamCode, this.teamDisTimer); // 战斗开始停止解散计时 let channelService = this.app.get('channelService'); let channel = channelService.getChannel(teamCode, false); channel.pushMessage('onComBtlStart', {teamCode, roleStatus: teamStatus.roleStatus}); @@ -595,7 +617,6 @@ export class ComBattleHandler { if (isSuccess && teamStatus.bossCurHp <= 0) { let team = await ComBattleTeamModel.updateResult(teamCode, roleId, isSuccess); if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR); - // TODO: 根据策划结论考虑是否在推送中添加掉落 channel.pushMessage('onTeamComplete', {teamCode, result: isSuccess}); } else if (!isSuccess) { let team = await ComBattleTeamModel.updateResult(teamCode, roleId, isSuccess); diff --git a/game-server/app/services/comBattleService.ts b/game-server/app/services/comBattleService.ts index fd2719c8d..57cb6f3c0 100644 --- a/game-server/app/services/comBattleService.ts +++ b/game-server/app/services/comBattleService.ts @@ -94,4 +94,19 @@ export async function checkComBattleDrop(roleId: string, battleCode: string) { } await ComBattleTeamModel.updateRewardSt(roleId, battleCode, true); return {status: 0, fixReward}; -} \ No newline at end of file +} + +export function clearComBtlTimer(teamCode: string, timerMap: Map) { + let timer = timerMap.get(teamCode); + if (timer) { + clearTimeout(timer); + } +} + +export function setComBtlTimer(teamCode: string, timer: NodeJS.Timer, timerMap: Map) { + let preTimer = timerMap.get(teamCode); + if (preTimer) { + clearTimeout(preTimer); + } + timerMap.set(teamCode, timer); +}