寻宝:抽象队长匹配队友的逻辑;抽象 channel 中的用户

This commit is contained in:
liangtongchuan
2021-02-19 17:58:00 +08:00
parent ea5d507983
commit 45ce962709
4 changed files with 73 additions and 37 deletions

View File

@@ -16,9 +16,11 @@ import { RoleStatus, ComBattleTeamModel, ComBattleTeamType } from '../../../db/C
import { ItemModel } from '../../../db/Item';
import { handleFixedReward, addItems, handleCost } from '../../../services/rewardService';
import { checkRoleInQueue, getTeamSearchByQuality, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService';
import { getRandBlueprtId, getRandComBtlRobots, clearComBtlTimer, getAssistTimesByQuality, getFrd, updateRobotHurtByTime, comBtlLvInvalid, clearRobotHurtTimer, setDismissTimer, dismissTeam, incEquipPrintDrop, randEquipPrintId, handleComBtlProgress, getComBattleFriendAdd, getValidTeammateRoleSt, teammateInBlackList, blueprtIdValid, createComTeamData, hasEnoughBlueprt, addRoleToTeam, addRoleStToTeam } from '../../../services/comBattleService';
import { getRandBlueprtId, getRandComBtlRobots, clearComBtlTimer, getAssistTimesByQuality, getFrd, updateRobotHurtByTime, comBtlLvInvalid, clearRobotHurtTimer, setDismissTimer, dismissTeam, incEquipPrintDrop, randEquipPrintId, handleComBtlProgress, getComBattleFriendAdd, getValidTeammateRoleSt, teammateInBlackList, blueprtIdValid, createComTeamData, hasEnoughBlueprt, addRoleToTeam, addRoleStToTeam, addValidSearchingRoles } from '../../../services/comBattleService';
import { setAp } from '../../../services/actionPointService';
import { roleLevelup } from '../../../services/normalBattleService';
import { addUserToChannel } from '../../../services/roleService';
import { ChannelUser } from '../../../domain/ChannelUser';
export default function(app: Application) {
return new ComBattleHandler(app);
@@ -45,7 +47,6 @@ export class ComBattleHandler {
console.log('createTeam msg: ', msg);
// 检查藏宝图Id是否合法
let goodData = getGoodById(blueprtId);
if (!blueprtIdValid(blueprtId)) return resResult(STATUS.COM_BATTLE_BLUEPRT_INVALID);
const enoughBlueprt = await hasEnoughBlueprt(roleId, blueprtId);
if (!enoughBlueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
@@ -55,47 +56,24 @@ export class ComBattleHandler {
const topFiveCe = reduceCe(roleInfo.topFiveCe || 100);
if (lv < COM_BTL_CONST.ENABLE_LV) return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, true);
// 创建队伍数据结构
let comTeam: MemComBtlTeam = createComTeamData(teamCode, pub, blueprtId, roleId, ceLimit);
addRoleToTeam(comTeam, roleInfo, true, false);
addUserToChannel(channel, new ChannelUser(roleId, sid));
// 将正在匹配的符合要求的玩家加入队伍,并推送入队消息
await addValidSearchingRoles(comTeam, channelService);
// 检查是否有正在匹配的符合要求的玩家
let teammates = await getTeamSearchByQuality(goodData.quality, comBtlRangeByLv(goodData.lvLimited));
if (teammates && teammates.length) {
for (let teammate of teammates) {
const { roleId: teammateRoleId } = teammate;
const st = await getValidTeammateRoleSt(teammateRoleId, comTeam.roleIds, ceLimit, goodData.quality);
if (!st) continue;
await rmRoleFromQueue(teammateRoleId, sid, COM_BTL_QUALITY, null); // 匹配成功后删除redis中该用户的匹配记录
addRoleStToTeam(comTeam, st);
}
// 队伍数据持久化
const team = await ComBattleTeamModel.createTeam(comTeam);
if (!team) {
channel.destroy();
return resResult(STATUS.COM_BATTLE_CREATE_ERR);
}
this.teamMap.set(teamCode, comTeam);
// TODO: 处理助战回滚
const team = await ComBattleTeamModel.createTeam(comTeam);
if (!team) return resResult(STATUS.COM_BATTLE_CREATE_ERR);
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, true);
let users = channel.getMembers();
if (users.indexOf(roleId) === -1) {
channel.add(roleId, sid);
}
let uids = [];
uids.push({roleId, sid});
if (teammates && teammates.length) {
for (let teammate of teammates) {
let { roleId, sid } = teammate;
uids.push({uid: roleId, sid});
let users = channel.getMembers();
if (users.indexOf(roleId) === -1) {
channel.add(roleId, sid);
}
}
channelService.pushMessageByUids('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: comTeam}), uids);
}
let thiz = this;
// 倒计时一定时间给队长匹配机器人