寻宝:人满不开打队伍解散

This commit is contained in:
liangtongchuan
2020-12-02 00:52:43 +08:00
parent cdd889f1aa
commit a001ec4478
2 changed files with 43 additions and 7 deletions

View File

@@ -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<string, ComTeam> = new Map();
private teamDisTimer: Map<string, NodeJS.Timer> = 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);

View File

@@ -94,4 +94,19 @@ export async function checkComBattleDrop(roleId: string, battleCode: string) {
}
await ComBattleTeamModel.updateRewardSt(roleId, battleCode, true);
return {status: 0, fixReward};
}
}
export function clearComBtlTimer(teamCode: string, timerMap: Map<string, NodeJS.Timer>) {
let timer = timerMap.get(teamCode);
if (timer) {
clearTimeout(timer);
}
}
export function setComBtlTimer(teamCode: string, timer: NodeJS.Timer, timerMap: Map<string, NodeJS.Timer>) {
let preTimer = timerMap.get(teamCode);
if (preTimer) {
clearTimeout(preTimer);
}
timerMap.set(teamCode, timer);
}