寻宝中移除队友或者队友离开队伍
This commit is contained in:
@@ -174,6 +174,36 @@ export class ComBattleHandler {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
async rmTeammate(msg: {teamCode: string, roleIdToRm: string}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { teamCode, roleIdToRm } = msg;
|
||||
let teamStatus = this.teamMap.get(teamCode);
|
||||
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||
if (roleId === teamStatus.capId && roleId === roleIdToRm) return resResult(STATUS.COM_BATTLE_RM_SELF);
|
||||
if (roleId !== teamStatus.capId && roleId !== roleIdToRm) return resResult(STATUS.COM_BATTLE_CAN_NOT_RM);
|
||||
|
||||
let team = await ComBattleTeamModel.removeRole(teamCode, roleIdToRm);
|
||||
if (!team) return resResult(STATUS.COM_BATTLE_RM_TEAMMATE_ERR);
|
||||
|
||||
let roleIdx = teamStatus.roleIds.indexOf(roleIdToRm);
|
||||
teamStatus.roleIds.splice(roleIdx, 1);
|
||||
|
||||
teamStatus.roleStatus.some((elem, idx) => {
|
||||
if (elem.roleId === roleIdToRm) {
|
||||
teamStatus.roleStatus.splice(idx, 1);
|
||||
}
|
||||
});
|
||||
|
||||
let channelService = this.app.get('channelService');
|
||||
let channel = channelService.getChannel(teamCode, false);
|
||||
let users = channel.getMembers();
|
||||
if (users.indexOf(roleIdToRm) !== -1) {
|
||||
channel.removeMember(roleIdToRm);
|
||||
}
|
||||
channel.pushMessage('onLeaveTeam', {teamCode, roleId: roleIdToRm});
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
async startBattle(msg: {teamCode: string}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { teamCode } = msg;
|
||||
|
||||
@@ -88,7 +88,10 @@ export const STATUS = {
|
||||
COM_BATTLE_NOT_START: { code: 20616, simStr: '寻宝未开始' },
|
||||
COM_BATTLE_ALREADY_START: { code: 20617, simStr: '寻宝已开始' },
|
||||
COM_BATTLE_ASSIST_NOT_ENOUGH: { code: 20618, simStr: '助战次数不足' },
|
||||
COM_BATTLE_ASSIST_LV_NOT_ENOUGH: { code: 20618, simStr: '助阵等级不够' },
|
||||
COM_BATTLE_ASSIST_LV_NOT_ENOUGH: { code: 20619, simStr: '助阵等级不够' },
|
||||
COM_BATTLE_RM_SELF: { code: 20620, simStr: '队长移除自己会解散队伍' },
|
||||
COM_BATTLE_RM_TEAMMATE_ERR: { code: 20620, simStr: '移除队友失败' },
|
||||
COM_BATTLE_CAN_NOT_RM: { code: 20620, simStr: '没有移除成员的权限' },
|
||||
|
||||
// 秘境 20700 - 20799
|
||||
DUNGEON_REFRESH_TIMES_LACK: { code: 20701, simStr: '购买次数不足' },
|
||||
|
||||
@@ -79,6 +79,11 @@ export default class ComBattleTeam extends BaseModel {
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async removeRole(teamCode: string, roleIdToRm: string, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamCode }, {$pull: {roleIds: roleIdToRm, roleStatus: {roleId: roleIdToRm}}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async updateHeroes(teamCode: string, roleId: string, heroes: Array<number>, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.heroes': heroes}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
|
||||
Reference in New Issue
Block a user