From ea5d507983205699cf1059d00b4404e11455ae46 Mon Sep 17 00:00:00 2001 From: liangtongchuan Date: Fri, 19 Feb 2021 17:04:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BB=E5=AE=9D=EF=BC=9A=E6=8A=BD=E8=B1=A1?= =?UTF-8?q?=E6=8A=8A=E7=8E=A9=E5=AE=B6=E6=95=B0=E6=8D=AE=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E9=98=9F=E4=BC=8D=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/handler/comBattleHandler.ts | 36 ++++++++----------- game-server/app/services/comBattleService.ts | 36 +++++++++++++++++++ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/game-server/app/servers/battle/handler/comBattleHandler.ts b/game-server/app/servers/battle/handler/comBattleHandler.ts index 99f3486d6..5d2c7ea99 100644 --- a/game-server/app/servers/battle/handler/comBattleHandler.ts +++ b/game-server/app/servers/battle/handler/comBattleHandler.ts @@ -16,7 +16,7 @@ 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 } 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 } from '../../../services/comBattleService'; import { setAp } from '../../../services/actionPointService'; import { roleLevelup } from '../../../services/normalBattleService'; @@ -39,7 +39,6 @@ export class ComBattleHandler { */ async createTeam(msg: {blueprtId: number, pub: boolean, ceLimit: number}, session: BackendSession) { let roleId = session.get('roleId'); - let roleName = session.get('roleName'); let sid = session.get('sid'); let teamCode = session.get('teamCode'); const { blueprtId, pub, ceLimit } = msg; @@ -51,32 +50,26 @@ export class ComBattleHandler { const enoughBlueprt = await hasEnoughBlueprt(roleId, blueprtId); if (!enoughBlueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH); - let { lv, headHid = 19, topFiveCe = 100, sHid = 19 } = await RoleModel.findByRoleId(roleId); + const roleInfo = await RoleModel.findByRoleId(roleId); + const { lv } = roleInfo; + const topFiveCe = reduceCe(roleInfo.topFiveCe || 100); if (lv < COM_BTL_CONST.ENABLE_LV) return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH); - let roleStatus = []; - let roleIds = []; - roleIds.push(roleId); - topFiveCe = reduceCe(topFiveCe); - let capStatus = new RoleStatus(roleId, roleName, true, false, headHid, sHid, topFiveCe, lv); - roleStatus.push(capStatus); + // 创建队伍数据结构 + let comTeam: MemComBtlTeam = createComTeamData(teamCode, pub, blueprtId, roleId, ceLimit); + addRoleToTeam(comTeam, roleInfo, true, false); // 检查是否有正在匹配的符合要求的玩家 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, roleIds, ceLimit, goodData.quality); + const st = await getValidTeammateRoleSt(teammateRoleId, comTeam.roleIds, ceLimit, goodData.quality); if (!st) continue; await rmRoleFromQueue(teammateRoleId, sid, COM_BTL_QUALITY, null); // 匹配成功后删除redis中该用户的匹配记录 - roleStatus.push(st); - roleIds.push(teammateRoleId); + addRoleStToTeam(comTeam, st); } } - // 创建队伍数据结构 - let comTeam: MemComBtlTeam = createComTeamData(teamCode, pub, blueprtId, roleId, ceLimit); - comTeam.roleStatus = roleStatus; - comTeam.roleIds = roleIds; this.teamMap.set(teamCode, comTeam); @@ -127,7 +120,7 @@ export class ComBattleHandler { } } setDismissTimer(teamStatus, thiz.teamMap, roleId, thiz.teamDisTimer, thiz.app); - return resResult(STATUS.SUCCESS, { teamCode, roleStatus }); + return resResult(STATUS.SUCCESS, { teamCode, roleStatus: comTeam.roleStatus }); } /** @@ -139,10 +132,11 @@ export class ComBattleHandler { */ async searchTeam(msg: {qualityArr: [number], lvRange: number}, session: BackendSession) { let roleId = session.get('roleId'); - let roleName = session.get('roleName'); let sid = session.get('sid'); const { qualityArr, lvRange = 1 } = msg; - let { lv, headHid = 19, topFiveCe = 1000, sHid = 19 } = await RoleModel.findByRoleId(roleId); + const roleInfo = await RoleModel.findByRoleId(roleId); + const { lv } = roleInfo; + let { topFiveCe = 1000 } = roleInfo; topFiveCe = reduceCe(topFiveCe); if (comBtlLvInvalid(lv, lvRange)) { @@ -185,9 +179,7 @@ export class ComBattleHandler { let { quality } = getGoodById(blueprtId); let isFrd = await getFrd(roleId, quality); // 将玩家加入队伍 - let roleInfo = new RoleStatus(roleId, roleName, false, isFrd, headHid, sHid, topFiveCe, lv); - roleStatus.push(roleInfo); - roleIds.push(roleId); + addRoleToTeam(comTeam, roleInfo, false, isFrd); // 创建并添加机器人 let { robotStArr, robotIdArr } = getRandComBtlRobots(topFiveCe, comTeam.ceLimit, lv, 2); roleStatus = roleStatus.concat(robotStArr); diff --git a/game-server/app/services/comBattleService.ts b/game-server/app/services/comBattleService.ts index 60df8ea5b..30e4c3799 100644 --- a/game-server/app/services/comBattleService.ts +++ b/game-server/app/services/comBattleService.ts @@ -1,3 +1,4 @@ +import { MemComBtlTeam } from './../domain/battleField/ComBattleTeamField'; import { ItemModel } from './../db/Item'; import { IT_TYPE } from './../consts/consts'; import { COM_BTL_QUALITY } from './../consts/constModules/itemConst'; @@ -547,6 +548,13 @@ export function createComTeamData(teamCode: string, pub: boolean, blueprtId: num }; } +/** + * @description 检查是否有足够的藏宝图,未结束的战斗也占用一张藏宝图 + * @export + * @param {string} roleId + * @param {number} blueprtId + * @returns + */ export async function hasEnoughBlueprt(roleId: string, blueprtId: number) { let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1); if (!blueprt) return false; @@ -554,4 +562,32 @@ export async function hasEnoughBlueprt(roleId: string, blueprtId: number) { let teams = await ComBattleTeamModel.getTeamByCapAndStatus(roleId, COM_TEAM_STATUS.FIGHTING); if (teams && blueprt.count <= teams.length) return false; return true; +} + +/** + * @description 将玩家加入到队伍数据结构中,需将玩家信息做转化 + * @export + * @param {MemComBtlTeam} comTeam 队伍数据结构 + * @param {RoleType} roleInfo 原始玩家信息 + * @param {boolean} isCap + * @param {boolean} isFrd + */ +export async 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); + const roleSt = new RoleStatus(roleId, roleName, isCap, isFrd, headHid, sHid, topFiveCe, lv); + addRoleStToTeam(comTeam, roleSt); +} + +/** + * @description 将玩家加入到队伍数据结构中 + * @export + * @param {MemComBtlTeam} comTeam 队伍数据结构 + * @param {RoleStatus} roleSt 要加入的玩家数据 + */ +export function addRoleStToTeam(comTeam: MemComBtlTeam, roleSt: RoleStatus) { + const { roleStatus = [], roleIds = [] } = comTeam; + comTeam.roleStatus = [roleSt, ...roleStatus]; + comTeam.roleIds = [roleSt.roleId, ...roleIds]; } \ No newline at end of file