rpc优化:所有remote加上try catch

This commit is contained in:
luying
2022-01-26 17:41:30 +08:00
parent c909d899ba
commit 6d2cafc119
11 changed files with 920 additions and 372 deletions
@@ -3,6 +3,7 @@ import { resResult } from '../../../pubUtils/util';
import { STATUS } from '../../../consts';
import { handleComBtlProgress } from '../../../services/comBattleService';
import { MemComBtlTeam } from '../../../domain/battleField/ComBattleTeamField';
import { errlogger } from '../../../util/logger';
export default function (app: Application) {
new HandlerService(app, {});
@@ -117,32 +118,40 @@ export class ComBattleRemote {
}
public async hurt(uid: string, sid: string, name: string, bossHurt: number, actorHurt: [{ actorId: number, actorHurt: number }]) {
console.log('hurt channel name: ', name);
let channelService = this.app.get('channelService');
this.bossHp -= bossHurt;
let channel = channelService.getChannel(name, false);
if (!!channel) {
if (this.bossHp < 0) {
this.bossHp = 0;
try {
console.log('hurt channel name: ', name);
let channelService = this.app.get('channelService');
this.bossHp -= bossHurt;
let channel = channelService.getChannel(name, false);
if (!!channel) {
if (this.bossHp < 0) {
this.bossHp = 0;
}
channel.pushMessage('bossHp', resResult(STATUS.SUCCESS, { bossHp: this.bossHp }));
}
channel.pushMessage('bossHp', resResult(STATUS.SUCCESS, { bossHp: this.bossHp }));
return this.bossHp;
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
return this.bossHp;
}
public async leaveFromBattle(roleId: string, teamCode: string ) {
let teamMap: Map<string, MemComBtlTeam> = this.app.get('teamMap');
if(teamMap && teamMap.has(teamCode)) {
let myTeam = teamMap.get(teamCode);
for(let roleStatus of myTeam.roleStatus) {
if(roleStatus.roleId == roleId) {
roleStatus.battleStatus = 2; // 自己失败了
try {
let teamMap: Map<string, MemComBtlTeam> = this.app.get('teamMap');
if(teamMap && teamMap.has(teamCode)) {
let myTeam = teamMap.get(teamCode);
for(let roleStatus of myTeam.roleStatus) {
if(roleStatus.roleId == roleId) {
roleStatus.battleStatus = 2; // 自己失败了
}
}
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false);
await handleComBtlProgress(myTeam, this.app.get('robotHurtTimer'), teamMap, channel); // 结算
}
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false);
await handleComBtlProgress(myTeam, this.app.get('robotHurtTimer'), teamMap, channel); // 结算
} catch(e) {
errlogger.error(`remote ${__filename} \n ${e.stack}`);
}
}
}