寻宝助战匹配简单机器人
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { COM_BATTLE_ROBOT_CE_RATIO, COM_BATTLE_ROBOT_ID_NAME, COM_BATTLE_ASSIST_TIME } from './../../../consts/consts';
|
||||
import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/consts';
|
||||
import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality, getBlueprtComposeByQuality, getBluePrtByQuality } from '../../../pubUtils/gamedata';
|
||||
import { COM_TEAM_STATUS, COM_TEAM_ENABLE_LV } from '../../../consts/consts';
|
||||
@@ -5,11 +6,13 @@ import { ComBattleTeamModel } from '../../../db/ComBattleTeam';
|
||||
import Role, { RoleModel } from '../../../db/Role';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { Application, BackendSession, BlackListFunction } from 'pinus';
|
||||
import { resResult, getRandomByLen, calculateNum } from '../../../pubUtils/util';
|
||||
import { resResult, getRandomByLen, calculateNum, getRandValue } from '../../../pubUtils/util';
|
||||
import { RoleStatus } from '../../../db/ComBattleTeam';
|
||||
import { ItemModel } from '../../../db/Item';
|
||||
import { handleReward } from '../../../services/rewardService';
|
||||
import { getTeamSearchByQuality, setTeamSearchReq } from '../../../services/redisService';
|
||||
import { getRandRobot } from '../../../services/battleService';
|
||||
import { getRandBlueprtId } from '../../../services/comBattleService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -84,16 +87,18 @@ export class ComBattleHandler {
|
||||
console.log('teammates: ', teammates);
|
||||
if (teammates) {
|
||||
for (let teammate of teammates) {
|
||||
// TODO: 要判断战力
|
||||
let roleInfo = await RoleModel.findByRoleId(teammate.roleId);
|
||||
if (!roleInfo) continue;
|
||||
let {roleId, roleName, headHid = 19, sHid = 19, topFiveCe, lv} = roleInfo;
|
||||
// TODO: 没处理情谊助战
|
||||
roleStatus.push(new RoleStatus(roleId, roleName, false, false, headHid, sHid, topFiveCe, lv));
|
||||
const st = new RoleStatus(roleId, roleName, false, false, headHid, sHid, topFiveCe, lv);
|
||||
roleStatus.push(st);
|
||||
roleIds.push(roleInfo.roleId);
|
||||
}
|
||||
}
|
||||
// 创建队伍数据结构
|
||||
let comTeam = new ComTeam(teamCode, pub, blueprtId, 0, roleId, ceLimit, getBossHpByBlueprtId(blueprtId) || 10000, goodData.quality);
|
||||
let comTeam = new ComTeam(teamCode, pub, blueprtId, COM_TEAM_STATUS.DEFAULT, roleId, ceLimit, getBossHpByBlueprtId(blueprtId) || 10000, goodData.quality);
|
||||
comTeam.roleStatus = roleStatus;
|
||||
comTeam.roleIds = roleIds;
|
||||
|
||||
@@ -127,14 +132,46 @@ export class ComBattleHandler {
|
||||
|
||||
async searchTeam(msg: {qualityArr: [number]}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
let teamCode = session.get('teamCode');
|
||||
const { qualityArr } = msg;
|
||||
let { lv, headHid = 19, topFiveCe, sHid = 19 } = await RoleModel.findByRoleId(roleId);
|
||||
let { lv, headHid = 19, topFiveCe = 1000, sHid = 19 } = await RoleModel.findByRoleId(roleId);
|
||||
|
||||
await setTeamSearchReq(roleId, sid, qualityArr);
|
||||
setTimeout(() => {
|
||||
|
||||
}, 10000);
|
||||
let thiz = this;
|
||||
setTimeout(async () => {
|
||||
let roleStatus = [];
|
||||
let roleIds = []
|
||||
let robotHeroes = getRandRobot(2);
|
||||
let roleInfo = new RoleStatus(roleId, roleName, false, false, headHid, sHid, topFiveCe, lv);
|
||||
roleStatus.push(roleInfo);
|
||||
roleIds.push(roleId);
|
||||
let blueprtId = (await getRandBlueprtId(qualityArr)).pop();
|
||||
let { quality } = getGoodById(blueprtId);
|
||||
let comTeam = new ComTeam(teamCode, false, blueprtId, COM_TEAM_STATUS.DEFAULT, 'robot', 0, getBossHpByBlueprtId(blueprtId) || 10000, quality);
|
||||
for (let robot of robotHeroes) {
|
||||
const robotCe = getRandValue(topFiveCe, COM_BATTLE_ROBOT_CE_RATIO, 0);
|
||||
const robotLv = getRandValue(lv, COM_BATTLE_ROBOT_CE_RATIO, 0);
|
||||
const imgHid = robot[Math.floor(Math.random() * robot.length)];
|
||||
const { robotRoleId, robotRoleName } = COM_BATTLE_ROBOT_ID_NAME[Math.floor(Math.random() * COM_BATTLE_ROBOT_ID_NAME.length)];
|
||||
let robotStatus = new RoleStatus(robotRoleId, robotRoleName, false, false, imgHid, imgHid, robotCe, robotLv, robot, true);
|
||||
roleStatus.push(robotStatus);
|
||||
roleIds.push(robotRoleId);
|
||||
}
|
||||
comTeam.roleStatus = roleStatus;
|
||||
comTeam.roleIds = roleIds;
|
||||
let channelService = thiz.app.get('channelService');
|
||||
const team = await ComBattleTeamModel.createTeam(comTeam);
|
||||
// if (!team) channelService.pushMessageByUids('onTeamJoin', {teamInfo: null}, [{uid: roleId, sid}]);
|
||||
thiz.teamMap.set(teamCode, comTeam);
|
||||
channelService.pushMessageByUids('onTeamJoin', {teamInfo: comTeam}, [{uid: roleId, sid}]);
|
||||
let channel = channelService.getChannel(teamCode, true);
|
||||
let users = channel.getMembers();
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
}, COM_BATTLE_ASSIST_TIME);
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -215,7 +252,27 @@ export class ComBattleHandler {
|
||||
teamStatus.roleStatus.forEach(st => {
|
||||
if (st && st.roleId === roleId) {
|
||||
st.heroes = heroes;
|
||||
st.isReady = true;
|
||||
}
|
||||
});
|
||||
|
||||
let channelService = this.app.get('channelService');
|
||||
let channel = channelService.getChannel(teamCode, false);
|
||||
channel.pushMessage('onTeammateReady', {teamCode, roleId, heroes});
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
async setupHeroes(msg: {teamCode: string, heroes: Array<number>}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { teamCode, heroes } = msg;
|
||||
let teamStatus = this.teamMap.get(teamCode);
|
||||
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||
|
||||
let team = await ComBattleTeamModel.updateHeroes(teamCode, roleId, heroes);
|
||||
if (!team) return resResult(STATUS.COM_BATTLE_UPDATE_HEROES_ERR);
|
||||
|
||||
teamStatus.roleStatus.forEach(st => {
|
||||
if (st && st.roleId === roleId) {
|
||||
st.heroes = heroes;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -284,11 +341,6 @@ export class ComBattleHandler {
|
||||
if (teamStatus.capId !== roleId) return resResult(STATUS.COM_BATTLE_CAP_ONLY);
|
||||
if (teamStatus.status !== COM_TEAM_STATUS.DEFAULT) return resResult(STATUS.COM_BATTLE_ALREADY_START);
|
||||
|
||||
for (let roleSt of teamStatus.roleStatus) {
|
||||
if (!roleSt.isReady) {
|
||||
return resResult(STATUS.COM_BATTLE_TEAM_NO_READY);
|
||||
}
|
||||
}
|
||||
teamStatus.status = COM_TEAM_STATUS.FIGHTING;
|
||||
|
||||
let channelService = this.app.get('channelService');
|
||||
|
||||
Reference in New Issue
Block a user