寻宝:提取添加机器人的逻辑;部分其它bug修复和优化
This commit is contained in:
@@ -8,7 +8,7 @@ import { EquipPrintDropType, EquipPrintDropModel } from './../db/EquipPrintDrop'
|
||||
import { FriendPointModel } from './../db/FriendPoint';
|
||||
import { STATUS } from './../consts/statusCode';
|
||||
import { COM_TEAM_STATUS, CURRENCY_BY_TYPE, CURRENCY_TYPE, FRIEND_DROP_TYPE, COM_BTL_CONST, FRIEND_DROP_MAX } from './../consts';
|
||||
import { RoleStatus, ComBattleTeamModel } from './../db/ComBattleTeam';
|
||||
import { RoleStatus, ComBattleTeamModel, ComBattleTeamType } from './../db/ComBattleTeam';
|
||||
import { getBluePrtByQuality, getComBtlSetByQuality, getRewardByBlueprtId, getWarById, getWarIdByBlueprtId, comBtlRangeInfo, getGoodById, comBtlRangeByLv, getBossHpByBlueprtId } from "../pubUtils/gamedata";
|
||||
import { getRandEelm, getRandValue, resResult, ratioReward, getRandValueByMinMax, getRandomWithWeight, decodeStr, getRobotInfo, reduceCe } from "../pubUtils/util";
|
||||
import { getRandRobot, transBossHpArr } from "./battleService";
|
||||
@@ -346,7 +346,7 @@ export function comBtlLvInvalid(lv: number, lvRange: number) {
|
||||
return lv < minLv;
|
||||
}
|
||||
|
||||
export async function dismissTeam(teamStatus, teamMap: Map<string, any>, roleId: string, teamDisTimer: Map<string, NodeJS.Timer>, app) {
|
||||
export async function dismissTeam(teamStatus, teamMap: Map<string, any>, roleId: string, teamDisTimer: Map<string, NodeJS.Timer>, channel) {
|
||||
const { teamCode } = teamStatus;
|
||||
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||
if (teamStatus.status !== COM_TEAM_STATUS.DEFAULT) return resResult(STATUS.COM_BATTLE_DISSMISS_ERR);
|
||||
@@ -358,19 +358,17 @@ export async function dismissTeam(teamStatus, teamMap: Map<string, any>, roleId:
|
||||
let rmSt = teamMap.delete(teamCode);
|
||||
if (!rmSt) return resResult(STATUS.COM_BATTLE_DISSMISS_ERR);
|
||||
|
||||
let channelService = app.get('channelService');
|
||||
let channel = channelService.getChannel(teamCode, false);
|
||||
channel.pushMessage('onTeamDismiss', resResult(STATUS.SUCCESS, {teamCode}));
|
||||
channel.destroy();
|
||||
clearComBtlTimer(teamCode, teamDisTimer); // 队伍解散停止解散计时
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
export function setDismissTimer(teamStatus, teamMap: Map<string, any>, roleId: string, teamDisTimer: Map<string, NodeJS.Timer>, app) {
|
||||
if (teamStatus && teamStatus.roleIds && teamStatus.roleIds.length === 3 && teamStatus.status === COM_TEAM_STATUS.DEFAULT) {
|
||||
export function setDismissTimer(teamStatus, teamMap: Map<string, any>, roleId: string, teamDisTimer: Map<string, NodeJS.Timer>, channel) {
|
||||
if (teamIsFullToStart(teamStatus)) {
|
||||
clearComBtlTimer(teamStatus.teamCode, teamDisTimer);
|
||||
let timer = setTimeout(async () => {
|
||||
await dismissTeam(teamStatus, teamMap, roleId, teamDisTimer, app);
|
||||
await dismissTeam(teamStatus, teamMap, roleId, teamDisTimer, channel);
|
||||
}, COM_BTL_CONST.CAP_START_TIME);
|
||||
teamDisTimer.set(teamStatus.teamCode, timer);
|
||||
}
|
||||
@@ -575,7 +573,7 @@ export async function hasEnoughBlueprt(roleId: string, blueprtId: number) {
|
||||
* @param {boolean} isCap
|
||||
* @param {boolean} isFrd
|
||||
*/
|
||||
export async function addRoleToTeam(comTeam: MemComBtlTeam, roleInfo: RoleType, isCap: boolean, isFrd: boolean) {
|
||||
export function addRoleToTeam(comTeam: MemComBtlTeam, roleInfo: RoleType, isCap: boolean, isFrd: boolean) {
|
||||
const { roleId, roleName, headHid = 19, sHid = 19, lv } = roleInfo;
|
||||
let { topFiveCe = 1000 } = roleInfo;
|
||||
topFiveCe = reduceCe(topFiveCe);
|
||||
@@ -617,4 +615,94 @@ export async function addValidSearchingRoles(comTeam: MemComBtlTeam, channelServ
|
||||
}
|
||||
channelService.pushMessageByUids('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: comTeam}), teammates.map(t => {return {uid: t.roleId, sid: t.sid}}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 判断队伍是否处于可加入状态
|
||||
* @export
|
||||
* @param {MemComBtlTeam} comTeam
|
||||
* @param {string} [roleId=''] 要加入的玩家 id
|
||||
* @returns
|
||||
*/
|
||||
export function validToJoin(comTeam: MemComBtlTeam, roleId = '') {
|
||||
return comTeam && comTeam.roleIds && comTeam.status === COM_TEAM_STATUS.DEFAULT && comTeam.roleIds.length < 3 && comTeam.roleIds.indexOf(roleId) === -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 判断队伍是否处于可满员状态
|
||||
* @export
|
||||
* @param {MemComBtlTeam} comTeam
|
||||
* @returns
|
||||
*/
|
||||
export function teamIsFullToStart(comTeam: MemComBtlTeam) {
|
||||
return comTeam && comTeam.roleIds && comTeam.status === COM_TEAM_STATUS.DEFAULT && comTeam.roleIds.length === 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 添加指定数量的机器人到队伍
|
||||
* @export
|
||||
* @param {MemComBtlTeam} comTeam
|
||||
* @param {number} roleCe 真实玩家战力,用来做机器人战力基准
|
||||
* @param {number} roleLv 真实玩家等级,用来做机器人等级基准
|
||||
* @param {number} [count=1]
|
||||
*/
|
||||
export async function addRobotsToTeam(comTeam: MemComBtlTeam, roleId: string, roleCe: number, roleLv: number, teamMap: Map<string, any>, teamDisTimer: Map<string, NodeJS.Timer>, channel: Channel, count = 1) {
|
||||
const { teamCode } = comTeam;
|
||||
const { robotStArr, robotIdArr } = getRandComBtlRobots(roleCe, comTeam.ceLimit, roleLv, count);
|
||||
comTeam.roleIds = comTeam.roleIds.concat(robotIdArr);
|
||||
comTeam.roleStatus = comTeam.roleStatus.concat(robotStArr);
|
||||
for (let st of robotStArr) {
|
||||
addRoleStToTeam(comTeam, st);
|
||||
await ComBattleTeamModel.addRole(teamCode, st);
|
||||
}
|
||||
channel.pushMessage('onTeamJoin', resResult(STATUS.SUCCESS, {teamInfo: comTeam}));
|
||||
setDismissTimer(comTeam, teamMap, roleId, teamDisTimer, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 在不同的时间加入机器人
|
||||
* @export
|
||||
* @param {MemComBtlTeam} comTeam
|
||||
* @param {RoleType} roleInfo
|
||||
* @param {Map<string, any>} teamMap
|
||||
* @param {Map<string, NodeJS.Timer>} teamDisTimer
|
||||
* @param {Channel} channel
|
||||
*/
|
||||
export async function addRobotsLater(comTeam: MemComBtlTeam, roleInfo: RoleType, teamMap: Map<string, any>, teamDisTimer: Map<string, NodeJS.Timer>, channel: Channel) {
|
||||
const teamStatus = comTeam;
|
||||
const { teamCode } = teamStatus;
|
||||
const { roleId, lv } = roleInfo;
|
||||
let { topFiveCe = 1000 } = roleInfo;
|
||||
topFiveCe = reduceCe(topFiveCe);
|
||||
|
||||
if (validToJoin(teamStatus)) {
|
||||
const robotCnt = 3 - teamStatus.roleIds.length;
|
||||
for(let robotIdx = 0; robotIdx < robotCnt; robotIdx++) {
|
||||
const joinTime = getRandValueByMinMax(COM_BTL_CONST.MIN_CAP_TIME, COM_BTL_CONST.MAX_CAP_TIME, 0);
|
||||
setTimeout(async () => {
|
||||
const curTeamStatus = teamMap.get(teamCode);
|
||||
if (validToJoin(curTeamStatus)) {
|
||||
await addRobotsToTeam(curTeamStatus, roleId, topFiveCe, lv, teamMap, teamDisTimer, channel, 1);
|
||||
}
|
||||
}, joinTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 从数组里找出第一个不在黑名单的队伍
|
||||
* @export
|
||||
* @param {Array<ComBattleTeamType>} teams 队伍数组
|
||||
* @param {string} roleId 要加入的玩家 id
|
||||
* @returns
|
||||
*/
|
||||
export async function oneTeamNotInBlack(teams: Array<ComBattleTeamType>, roleId: string) {
|
||||
for(let team of teams) {
|
||||
let { roleIds } = team;
|
||||
const inBlackList = await teammateInBlackList(roleId, roleIds);
|
||||
if(!inBlackList) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user