寻宝:抽象把玩家数据加入队伍的逻辑
This commit is contained in:
@@ -16,7 +16,7 @@ import { RoleStatus, ComBattleTeamModel, ComBattleTeamType } from '../../../db/C
|
|||||||
import { ItemModel } from '../../../db/Item';
|
import { ItemModel } from '../../../db/Item';
|
||||||
import { handleFixedReward, addItems, handleCost } from '../../../services/rewardService';
|
import { handleFixedReward, addItems, handleCost } from '../../../services/rewardService';
|
||||||
import { checkRoleInQueue, getTeamSearchByQuality, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService';
|
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 { setAp } from '../../../services/actionPointService';
|
||||||
import { roleLevelup } from '../../../services/normalBattleService';
|
import { roleLevelup } from '../../../services/normalBattleService';
|
||||||
|
|
||||||
@@ -39,7 +39,6 @@ export class ComBattleHandler {
|
|||||||
*/
|
*/
|
||||||
async createTeam(msg: {blueprtId: number, pub: boolean, ceLimit: number}, session: BackendSession) {
|
async createTeam(msg: {blueprtId: number, pub: boolean, ceLimit: number}, session: BackendSession) {
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
let roleName = session.get('roleName');
|
|
||||||
let sid = session.get('sid');
|
let sid = session.get('sid');
|
||||||
let teamCode = session.get('teamCode');
|
let teamCode = session.get('teamCode');
|
||||||
const { blueprtId, pub, ceLimit } = msg;
|
const { blueprtId, pub, ceLimit } = msg;
|
||||||
@@ -51,32 +50,26 @@ export class ComBattleHandler {
|
|||||||
const enoughBlueprt = await hasEnoughBlueprt(roleId, blueprtId);
|
const enoughBlueprt = await hasEnoughBlueprt(roleId, blueprtId);
|
||||||
if (!enoughBlueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
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);
|
if (lv < COM_BTL_CONST.ENABLE_LV) return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
|
||||||
|
|
||||||
let roleStatus = [];
|
// 创建队伍数据结构
|
||||||
let roleIds = [];
|
let comTeam: MemComBtlTeam = createComTeamData(teamCode, pub, blueprtId, roleId, ceLimit);
|
||||||
roleIds.push(roleId);
|
addRoleToTeam(comTeam, roleInfo, true, false);
|
||||||
topFiveCe = reduceCe(topFiveCe);
|
|
||||||
let capStatus = new RoleStatus(roleId, roleName, true, false, headHid, sHid, topFiveCe, lv);
|
|
||||||
roleStatus.push(capStatus);
|
|
||||||
|
|
||||||
// 检查是否有正在匹配的符合要求的玩家
|
// 检查是否有正在匹配的符合要求的玩家
|
||||||
let teammates = await getTeamSearchByQuality(goodData.quality, comBtlRangeByLv(goodData.lvLimited));
|
let teammates = await getTeamSearchByQuality(goodData.quality, comBtlRangeByLv(goodData.lvLimited));
|
||||||
if (teammates && teammates.length) {
|
if (teammates && teammates.length) {
|
||||||
for (let teammate of teammates) {
|
for (let teammate of teammates) {
|
||||||
const { roleId: teammateRoleId } = teammate;
|
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;
|
if (!st) continue;
|
||||||
await rmRoleFromQueue(teammateRoleId, sid, COM_BTL_QUALITY, null); // 匹配成功后删除redis中该用户的匹配记录
|
await rmRoleFromQueue(teammateRoleId, sid, COM_BTL_QUALITY, null); // 匹配成功后删除redis中该用户的匹配记录
|
||||||
roleStatus.push(st);
|
addRoleStToTeam(comTeam, st);
|
||||||
roleIds.push(teammateRoleId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 创建队伍数据结构
|
|
||||||
let comTeam: MemComBtlTeam = createComTeamData(teamCode, pub, blueprtId, roleId, ceLimit);
|
|
||||||
comTeam.roleStatus = roleStatus;
|
|
||||||
comTeam.roleIds = roleIds;
|
|
||||||
|
|
||||||
this.teamMap.set(teamCode, comTeam);
|
this.teamMap.set(teamCode, comTeam);
|
||||||
|
|
||||||
@@ -127,7 +120,7 @@ export class ComBattleHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setDismissTimer(teamStatus, thiz.teamMap, roleId, thiz.teamDisTimer, thiz.app);
|
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) {
|
async searchTeam(msg: {qualityArr: [number], lvRange: number}, session: BackendSession) {
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
let roleName = session.get('roleName');
|
|
||||||
let sid = session.get('sid');
|
let sid = session.get('sid');
|
||||||
const { qualityArr, lvRange = 1 } = msg;
|
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);
|
topFiveCe = reduceCe(topFiveCe);
|
||||||
|
|
||||||
if (comBtlLvInvalid(lv, lvRange)) {
|
if (comBtlLvInvalid(lv, lvRange)) {
|
||||||
@@ -185,9 +179,7 @@ export class ComBattleHandler {
|
|||||||
let { quality } = getGoodById(blueprtId);
|
let { quality } = getGoodById(blueprtId);
|
||||||
let isFrd = await getFrd(roleId, quality);
|
let isFrd = await getFrd(roleId, quality);
|
||||||
// 将玩家加入队伍
|
// 将玩家加入队伍
|
||||||
let roleInfo = new RoleStatus(roleId, roleName, false, isFrd, headHid, sHid, topFiveCe, lv);
|
addRoleToTeam(comTeam, roleInfo, false, isFrd);
|
||||||
roleStatus.push(roleInfo);
|
|
||||||
roleIds.push(roleId);
|
|
||||||
// 创建并添加机器人
|
// 创建并添加机器人
|
||||||
let { robotStArr, robotIdArr } = getRandComBtlRobots(topFiveCe, comTeam.ceLimit, lv, 2);
|
let { robotStArr, robotIdArr } = getRandComBtlRobots(topFiveCe, comTeam.ceLimit, lv, 2);
|
||||||
roleStatus = roleStatus.concat(robotStArr);
|
roleStatus = roleStatus.concat(robotStArr);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { MemComBtlTeam } from './../domain/battleField/ComBattleTeamField';
|
||||||
import { ItemModel } from './../db/Item';
|
import { ItemModel } from './../db/Item';
|
||||||
import { IT_TYPE } from './../consts/consts';
|
import { IT_TYPE } from './../consts/consts';
|
||||||
import { COM_BTL_QUALITY } from './../consts/constModules/itemConst';
|
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) {
|
export async function hasEnoughBlueprt(roleId: string, blueprtId: number) {
|
||||||
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
|
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
|
||||||
if (!blueprt) return false;
|
if (!blueprt) return false;
|
||||||
@@ -555,3 +563,31 @@ export async function hasEnoughBlueprt(roleId: string, blueprtId: number) {
|
|||||||
if (teams && blueprt.count <= teams.length) return false;
|
if (teams && blueprt.count <= teams.length) return false;
|
||||||
return true;
|
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];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user