初步加入寻宝匹配,逻辑还不全
This commit is contained in:
@@ -9,6 +9,7 @@ import { resResult, getRandomByLen, calculateNum } from '../../../pubUtils/util'
|
||||
import { RoleStatus } from '../../../db/ComBattleTeam';
|
||||
import { ItemModel } from '../../../db/Item';
|
||||
import { handleReward } from '../../../services/rewardService';
|
||||
import { getTeamSearchByQuality, setTeamSearchReq } from '../../../services/redisService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -35,6 +36,17 @@ class ComTeam {
|
||||
bossHp: number;
|
||||
// 品质
|
||||
quality: number;
|
||||
|
||||
constructor(teamCode: string, pub: boolean, blueprtId: number, status: number, capId: string, ceLimit: number, bossHp: number, quality: number) {
|
||||
this.teamCode = teamCode;
|
||||
this.pub = pub;
|
||||
this.blueprtId = blueprtId;
|
||||
this.status = status;
|
||||
this.capId = capId;
|
||||
this.ceLimit = ceLimit;
|
||||
this.bossHp = bossHp;
|
||||
this.quality = quality;
|
||||
}
|
||||
}
|
||||
export class ComBattleHandler {
|
||||
constructor(private app: Application) {
|
||||
@@ -54,7 +66,7 @@ export class ComBattleHandler {
|
||||
if (!goodData || goodData.itid !== IT_TYPE.BLUEPRT) return resResult(STATUS.COM_BATTLE_BLUEPRT_INVALID);
|
||||
|
||||
// 检查藏宝图是否足够
|
||||
let { lv, headHid, topFiveCe, sHid } = await RoleModel.findByRoleId(roleId);
|
||||
let { lv, headHid = 19, topFiveCe, sHid = 19 } = await RoleModel.findByRoleId(roleId);
|
||||
if (lv < COM_TEAM_ENABLE_LV) return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
|
||||
|
||||
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
|
||||
@@ -62,48 +74,68 @@ export class ComBattleHandler {
|
||||
// 检查是否有已创建未结束的寻宝,预先占用一张藏宝图
|
||||
let teams = await ComBattleTeamModel.getTeamByCapAndStatus(roleId, COM_TEAM_STATUS.FIGHTING);
|
||||
if (teams && blueprt.count <= teams.length) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
||||
// TODO: 检查武将是否拥有
|
||||
|
||||
let roleStatus = [];
|
||||
let roleIds = [];
|
||||
roleIds.push(roleId);
|
||||
let capStatus = new RoleStatus(roleId, roleName, true, false, headHid, sHid, topFiveCe, lv);
|
||||
roleStatus.push(capStatus);
|
||||
let teammates = await getTeamSearchByQuality(goodData.quality);
|
||||
console.log('teammates: ', teammates);
|
||||
if (teammates) {
|
||||
for (let teammate of teammates) {
|
||||
let roleInfo = await RoleModel.findByRoleId(teammate.roleId);
|
||||
if (!roleInfo) continue;
|
||||
// TODO: 没处理情谊助战
|
||||
roleStatus.push(new RoleStatus(roleInfo.roleId, roleInfo.roleName, false, false, roleInfo.headHid, roleInfo.sHid, roleInfo.topFiveCe, roleInfo.lv));
|
||||
roleIds.push(roleInfo.roleId);
|
||||
}
|
||||
}
|
||||
// 创建队伍数据结构
|
||||
let comTeam = new ComTeam();
|
||||
comTeam.blueprtId = blueprtId;
|
||||
comTeam.quality = goodData.quality;
|
||||
comTeam.capId = roleId;
|
||||
comTeam.pub = pub;
|
||||
comTeam.teamCode = teamCode;
|
||||
comTeam.roleIds = [roleId];
|
||||
comTeam.status = COM_TEAM_STATUS.DEFAULT;
|
||||
comTeam.ceLimit = ceLimit;
|
||||
comTeam.bossHp = getBossHpByBlueprtId(blueprtId) || 10000;
|
||||
|
||||
let roleStatus = new RoleStatus();
|
||||
roleStatus.heroes = heroes;
|
||||
roleStatus.isCap = true;
|
||||
roleStatus.headHid = headHid || 19;
|
||||
roleStatus.topFiveCe = topFiveCe;
|
||||
roleStatus.roleId = roleId;
|
||||
roleStatus.isReady = true;
|
||||
roleStatus.totalDmg = 0;
|
||||
roleStatus.roleName = roleName;
|
||||
roleStatus.lv = lv;
|
||||
roleStatus.sHid = sHid || 19;
|
||||
comTeam.roleStatus = [roleStatus];
|
||||
let comTeam = new ComTeam(teamCode, pub, blueprtId, 0, roleId, ceLimit, getBossHpByBlueprtId(blueprtId) || 10000, goodData.quality);
|
||||
comTeam.roleStatus = roleStatus;
|
||||
comTeam.roleIds = roleIds;
|
||||
|
||||
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);
|
||||
for (let roleId of roleIds) {
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
}
|
||||
|
||||
if (teammates) {
|
||||
let uids = [];
|
||||
for (let teammate of teammates) {
|
||||
let { roleId, sid } = teammate;
|
||||
uids.push({uid: roleId, sid});
|
||||
}
|
||||
// TODO: 处理助战 timer
|
||||
channelService.pushMessageByUids('onTeamJoin', {teamInfo: comTeam}, uids);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { teamCode, roleStatus });
|
||||
}
|
||||
|
||||
async searchTeam(msg: {qualityArr: [number]}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let sid = session.get('sid');
|
||||
const { qualityArr } = msg;
|
||||
let { lv, headHid = 19, topFiveCe, sHid = 19 } = await RoleModel.findByRoleId(roleId);
|
||||
|
||||
await setTeamSearchReq(roleId, sid, qualityArr);
|
||||
setTimeout(() => {
|
||||
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
async joinTeam(msg: {teamCode: string, isFrd: boolean}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
@@ -113,7 +145,7 @@ export class ComBattleHandler {
|
||||
let teamStatus = this.teamMap.get(teamCode);
|
||||
if (!teamStatus || teamStatus.status !== 0 || teamStatus.roleIds.length === 3) return resResult(STATUS.COM_BATTLE_MEMBER_LIMIT);
|
||||
if (teamStatus.roleIds.indexOf(roleId) !== -1) return resResult(STATUS.COM_BATTLE_DUP_ENTER);
|
||||
let { lv, headHid, topFiveCe, sHid } = await Role.findByRoleId(roleId);
|
||||
let { lv, headHid = 19, topFiveCe = 0, sHid = 19 } = await Role.findByRoleId(roleId);
|
||||
let { quality } = getGoodById(teamStatus.blueprtId);
|
||||
let { assistanceLevel, assistanceTime } = getComBtlSetByQuality(quality);
|
||||
if (lv < COM_TEAM_ENABLE_LV) {
|
||||
@@ -127,18 +159,7 @@ export class ComBattleHandler {
|
||||
let teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, teamStatus.quality, new Date(new Date().setHours(0, 0, 0, 0)), true);
|
||||
if (teams.length >= assistanceTime) resResult(STATUS.COM_BATTLE_ASSIST_NOT_ENOUGH);
|
||||
|
||||
let roleStatus = new RoleStatus();
|
||||
roleStatus.heroes = [];
|
||||
roleStatus.isCap = false;
|
||||
roleStatus.headHid = headHid || 19; // 默认给赵云
|
||||
roleStatus.topFiveCe = topFiveCe || 0;
|
||||
roleStatus.roleId = roleId;
|
||||
roleStatus.roleName = roleName;
|
||||
roleStatus.isFrd = isFrd;
|
||||
roleStatus.isReady = false;
|
||||
roleStatus.totalDmg = 0;
|
||||
roleStatus.lv = lv;
|
||||
roleStatus.sHid = sHid || 19;
|
||||
let roleStatus = new RoleStatus(roleId, roleName, false, isFrd, headHid, sHid, topFiveCe, lv);
|
||||
const team = await ComBattleTeamModel.addRole(teamCode, roleStatus);
|
||||
if (!team) {
|
||||
return resResult(STATUS.COM_BATTLE_CREATE_ERR);
|
||||
|
||||
Reference in New Issue
Block a user