聊天:组队聊天和测试
This commit is contained in:
@@ -6,7 +6,7 @@ import { difference } from 'underscore';
|
||||
* @Last Modified by: 梁桐川
|
||||
* @Last Modified time: 2020-12-03 21:36:00
|
||||
*/
|
||||
import { IT_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_TEAM_STATUS, COM_BTL_CONST, CONSUME_TYPE, COM_BTL_QUALITY } from './../../../consts';
|
||||
import { IT_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_TEAM_STATUS, COM_BTL_CONST, CONSUME_TYPE, COM_BTL_QUALITY, MSG_SOURCE } from './../../../consts';
|
||||
import { getGoodById, getBlueprtComposeByQuality, getBluePrtByQuality, getWarById, getWarIdByBlueprtId } from '../../../pubUtils/gamedata';
|
||||
import Role, { RoleModel } from '../../../db/Role';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
@@ -21,6 +21,7 @@ import { setAp } from '../../../services/actionPointService';
|
||||
import { roleLevelup } from '../../../services/normalBattleService';
|
||||
import { addUserToChannel } from '../../../services/roleService';
|
||||
import { ChannelUser } from '../../../domain/ChannelUser';
|
||||
import { pushComBtlTeamMsg } from '../../../services/chatService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -650,6 +651,18 @@ export class ComBattleHandler {
|
||||
return resResult(STATUS.SUCCESS, { blueprts, assistCnt: cnt });
|
||||
}
|
||||
|
||||
async sendTeamMsg(msg: { teamCode: string, type: number, content: string, targetRoleId: string, targetMsgCode: string }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
|
||||
const { teamCode, type, content, targetRoleId, targetMsgCode } = msg;
|
||||
const result = await pushComBtlTeamMsg(teamCode, roleId, roleName, type, MSG_SOURCE.TEAM, content, targetRoleId, targetMsgCode);
|
||||
if (!result) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 藏宝图合成
|
||||
* @param {{original: Array<{id: number, count: number}>}} msg
|
||||
|
||||
@@ -7,7 +7,7 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './
|
||||
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
||||
import { genCode, resResult } from '../pubUtils/util';
|
||||
import { pinus } from 'pinus';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_SOURCE, MSG_STATUS, MSG_TYPE, ON_MSG_ROUTE, RICH_TEXT_TABLE } from '../consts';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_SOURCE, MSG_STATUS, MSG_TYPE, ON_GROUP_MSG_ROUTE, ON_MSG_ROUTE, RICH_TEXT_TABLE } from '../consts';
|
||||
import { addRedisChannel, getRoleOnlineInfo, redisChannelServer } from './redisService';
|
||||
import { crc32 } from 'crc';
|
||||
import { HeroType } from '../db/Hero';
|
||||
@@ -222,3 +222,11 @@ export async function pushComposeOrangeHero(roleId: string, roleName: string, se
|
||||
export async function pushHeroStarMax(roleId: string, roleName: string, serverId: number | string, heroInfo: Partial<HeroType>) {
|
||||
await pushNormalHeroInfoBySource(roleId, roleName, serverId, MSG_SOURCE.HERO_STAR_MAX, heroInfo);
|
||||
}
|
||||
|
||||
export async function pushComBtlTeamMsg(teamCode: string, roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.TEAM, teamCode, type, source, content, targetRoleId, targetMsgCode);
|
||||
if (!msgData) return null;
|
||||
const channel = pinus.app.get('channelService').getChannel(teamCode);
|
||||
channel.pushMessage(ON_GROUP_MSG_ROUTE, resResult(STATUS.SUCCESS, msgData));
|
||||
return msgData;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { indexOf } from 'underscore';
|
||||
import { COM_TEAM_STATUS, DEFAULT_HEROES } from './../../shared/consts/consts';
|
||||
import { Client } from './Client';
|
||||
import { COM_BTL_QUALITY } from './../app/consts/constModules/itemConst';
|
||||
import 'mocha';
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { checkDisplayItems, checkSuccessResponse } from './CheckPatten';
|
||||
import { COM_TEAM_STATUS, DEFAULT_HEROES, MSG_TYPE, ON_GROUP_MSG_ROUTE } from '../app/consts';
|
||||
|
||||
/**
|
||||
* @description 组队后的战斗过程:队长开战 -> 设置阵容 -> 对默认敌人造成伤害 -> 获取战斗状态 -> 结算
|
||||
@@ -198,4 +197,55 @@ describe('寻宝创建队伍', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('组队文字聊天', function(done) {
|
||||
let msgReceiveCnt = 0;
|
||||
const MSG_CONTENT = 'hello teammate';
|
||||
|
||||
function checkMsg(msg) {
|
||||
expect(msg).to.be.an('object');
|
||||
expect(msg.content).to.be.equal(MSG_CONTENT);
|
||||
}
|
||||
|
||||
pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
checkMsg(res.data);
|
||||
msgReceiveCnt += 1;
|
||||
});
|
||||
pinusClient.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
checkMsg(res.data);
|
||||
msgReceiveCnt += 1;
|
||||
});
|
||||
|
||||
pinusClientT.request('battle.comBattleHandler.searchTeam', searchTeamParms, (searchRes) => {
|
||||
checkSuccessResponse(searchRes, false);
|
||||
if (!searchRes.data) {
|
||||
pinusClient.request('battle.comBattleHandler.createTeam', createTeamParms, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.teamCode).to.be.a('string');
|
||||
expect(res.data.roleStatus).to.be.an('array');
|
||||
res.data.roleStatus.forEach(roleSt => {
|
||||
expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'headHid', 'sHid', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio');
|
||||
});
|
||||
const roleIds = res.data.roleStatus.map(roleSt => { return roleSt.roleId });
|
||||
if (roleIds.indexOf(roleInfoT.roleId) === -1) {
|
||||
console.warn('未测试到组队后的聊天');
|
||||
done();
|
||||
}
|
||||
pinusClient.request('battle.comBattleHandler.sendTeamMsg', {teamCode: res.data.teamCode, type: MSG_TYPE.TEXT, content: MSG_CONTENT}, (msgRes) => {
|
||||
checkSuccessResponse(msgRes, false);
|
||||
setTimeout(() => {
|
||||
expect(msgReceiveCnt).to.be.equal(2);
|
||||
comBattleProcess(pinusClient, res.data.teamCode, done);
|
||||
}, 50);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.warn('未测试到组队后的聊天');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,15 +15,17 @@ export const CHANNEL_PREFIX = {
|
||||
SYS: 'sys',
|
||||
WORLD: 'new_world',
|
||||
GUILD: 'new_guild',
|
||||
TEAM: 'com_btl_team',
|
||||
}
|
||||
|
||||
// 消息来源
|
||||
export const MSG_SOURCE = {
|
||||
ROLE_SEND_TEXT: 0,
|
||||
PRIVATE_SEND_GIFT: 1,
|
||||
HERO_QUALITY_UP: 2,
|
||||
COMPOSE_ORANGE_HERO: 3,
|
||||
HERO_STAR_MAX: 4,
|
||||
TEAM: 2,
|
||||
HERO_QUALITY_UP: 3,
|
||||
COMPOSE_ORANGE_HERO: 4,
|
||||
HERO_STAR_MAX: 5,
|
||||
}
|
||||
|
||||
export const ON_MSG_ROUTE = 'onMessage';
|
||||
|
||||
Reference in New Issue
Block a user