寻宝:抽象队长匹配队友的逻辑;抽象 channel 中的用户
This commit is contained in:
@@ -13,11 +13,14 @@ import { getBluePrtByQuality, getComBtlSetByQuality, getRewardByBlueprtId, getWa
|
||||
import { getRandEelm, getRandValue, resResult, ratioReward, getRandValueByMinMax, getRandomWithWeight, decodeStr, getRobotInfo, reduceCe } from "../pubUtils/util";
|
||||
import { getRandRobot, transBossHpArr } from "./battleService";
|
||||
import { difference, omit } from 'underscore';
|
||||
import { Channel } from 'pinus';
|
||||
import { Channel, ChannelService } from 'pinus';
|
||||
import { TREASURE } from '../pubUtils/dicParam';
|
||||
import { decreaseItems } from './rewardService';
|
||||
import { getFriendLvAdd } from './friendService';
|
||||
import { getRoleIds } from '../pubUtils/friendUtil';
|
||||
import { getTeamSearchByQuality, rmRoleFromQueue } from './redisService';
|
||||
import { addUserToChannel } from './roleService';
|
||||
import { ChannelUser } from '../domain/ChannelUser';
|
||||
|
||||
|
||||
/**
|
||||
@@ -590,4 +593,28 @@ export function addRoleStToTeam(comTeam: MemComBtlTeam, roleSt: RoleStatus) {
|
||||
const { roleStatus = [], roleIds = [] } = comTeam;
|
||||
comTeam.roleStatus = [roleSt, ...roleStatus];
|
||||
comTeam.roleIds = [roleSt.roleId, ...roleIds];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 将符合要求的用户匹配到队伍中
|
||||
* @export
|
||||
* @param {MemComBtlTeam} comTeam 队伍数据
|
||||
* @param {string} sid 当前用户 sid
|
||||
* @returns
|
||||
*/
|
||||
export async function addValidSearchingRoles(comTeam: MemComBtlTeam, channelService: ChannelService) {
|
||||
const { quality, lvLimited } = getGoodById(comTeam.blueprtId);
|
||||
let teammates = await getTeamSearchByQuality(quality, comBtlRangeByLv(lvLimited));
|
||||
if (teammates && teammates.length) {
|
||||
for (let teammate of teammates) {
|
||||
const { roleId: teammateRoleId, sid } = teammate;
|
||||
const st = await getValidTeammateRoleSt(teammateRoleId, comTeam.roleIds, comTeam.ceLimit, quality);
|
||||
if (!st) continue;
|
||||
await rmRoleFromQueue(teammateRoleId, sid, COM_BTL_QUALITY, null); // 匹配成功后删除redis中该用户的匹配记录
|
||||
addRoleStToTeam(comTeam, st);
|
||||
const channel = channelService.getChannel(comTeam.teamCode, false);
|
||||
addUserToChannel(channel, new ChannelUser(teammateRoleId, sid));
|
||||
}
|
||||
channelService.pushMessageByUids('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: comTeam}), teammates.map(t => {return {uid: t.roleId, sid: t.sid}}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user