From ef86623241e140798d02da2bc954939baeaca6c6 Mon Sep 17 00:00:00 2001 From: liangtongchuan Date: Wed, 2 Dec 2020 21:22:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BB=E5=AE=9D=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20boss=20=E8=BF=94=E5=9B=9E=E5=AD=97=E6=AE=B5=EF=BC=9B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=86=E5=8F=96=E5=A5=96=E5=8A=B1=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/handler/comBattleHandler.ts | 24 +++++++++++------ game-server/app/services/battleService.ts | 2 +- game-server/app/services/comBattleService.ts | 2 +- shared/db/ComBattleTeam.ts | 26 +++++++++++++++---- shared/pubUtils/gamedata.ts | 6 ++--- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/game-server/app/servers/battle/handler/comBattleHandler.ts b/game-server/app/servers/battle/handler/comBattleHandler.ts index c80f8d53b..571db9da8 100644 --- a/game-server/app/servers/battle/handler/comBattleHandler.ts +++ b/game-server/app/servers/battle/handler/comBattleHandler.ts @@ -2,13 +2,13 @@ * @Author: 梁桐川 * @Date: 2020-11-30 15:05:48 * @Last Modified by: 梁桐川 - * @Last Modified time: 2020-12-02 17:33:14 + * @Last Modified time: 2020-12-02 21:05:48 */ import { COM_BATTLE_ASSIST_TIME, COM_BATTLE_ROBOT_ROUND_LMT, COM_BATTLE_ROBOT_HURT_RATIO, COM_BATTLE_ROBOT_HURT_CH_RATIO, COM_TEAM_STATUS } from './../../../consts/consts'; import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_BATTLE_CAP_TIME, COM_BATTLE_TIME_LMT, COM_BATTLE_CAP_START_TIME, COM_BATTLE_ASSIST_REWARD_RATIO } from './../../../consts/consts'; import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality, getBlueprtComposeByQuality, getBluePrtByQuality, getWarById, getWarIdByBlueprtId } from '../../../pubUtils/gamedata'; import { COM_TEAM_ENABLE_LV } from '../../../consts/consts'; -import { ComBattleTeamModel } from '../../../db/ComBattleTeam'; +import { ComBattleTeamModel, BossHp } from '../../../db/ComBattleTeam'; import Role, { RoleModel } from '../../../db/Role'; import { STATUS } from '../../../consts/statusCode'; import { Application, BackendSession } from 'pinus'; @@ -48,14 +48,14 @@ class ComTeam { // boss 当前血量 bossCurHp: number; // 单个 boss 血量状态 - bossHpArr: Array<{dataId: number, hp: number, curHp: number}>; + bossHpArr: Array; // 品质 quality: number; // 当前回合 curRnd: number; // 队伍中人数 roleCnt: number; - constructor(teamCode: string, pub: boolean, blueprtId: number, status: number, capId: string, ceLimit: number, bossHp: number, quality: number, bossHpArr:Array<{dataId: number, hp: number, curHp: number}> ) { + constructor(teamCode: string, pub: boolean, blueprtId: number, status: number, capId: string, ceLimit: number, bossHp: number, quality: number, bossHpArr:Array ) { this.teamCode = teamCode; this.pub = pub; this.blueprtId = blueprtId; @@ -170,7 +170,7 @@ export class ComBattleHandler { channel.pushMessage('onTeamJoin', {teamInfo: team}); } // TODO: 代码抽象 - if (team.roleIds && team.roleIds.length === 3) { + if (team && team.roleIds && team.roleIds.length === 3) { let timer = setTimeout(async () => { thiz.dismiss({teamCode}, session); }, COM_BATTLE_CAP_START_TIME); @@ -503,7 +503,7 @@ export class ComBattleHandler { let thiz = this; setTimeout(async () => { let teamStatus = thiz.teamMap.get(teamCode); - if (teamStatus.status === COM_TEAM_STATUS.FIGHTING) { + if (teamStatus && teamStatus.status === COM_TEAM_STATUS.FIGHTING) { let channelService = thiz.app.get('channelService'); let channel = channelService.getChannel(teamCode, false); let team = await ComBattleTeamModel.syncTeamData({teamCode, status: COM_TEAM_STATUS.LOOSE, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr}); @@ -672,11 +672,19 @@ export class ComBattleHandler { return resResult(STATUS.BATTLE_ACTION_POINT_LACK); } - await ComBattleTeamModel.updateRewardSt(roleId, true); + await ComBattleTeamModel.updateRewardSt(teamCode, roleId, true); const goods = await handleFixedReward(roleId, roleName, roleSt.fixReward, 1); let actordata = await roleLevelup(roleId, warInfo.kingExp, this.app, session);// 主公升级经验 - return resResult(STATUS.SUCCESS, { ...goods, ...actordata, teamInfo: {status, roleStatus, bossHpArr} }); + return resResult(STATUS.SUCCESS, { ...goods, ...actordata, teamInfo: {status, teamCode, roleStatus, bossHpArr} }); + } + + async getComBtlStatus(msg: {teamCode: string}, session: BackendSession) { + let { teamCode } = msg; + let team = await ComBattleTeamModel.getTeamByCode(teamCode); + let { roleStatus, status, bossHpArr } = team; + + return resResult(STATUS.SUCCESS, { teamInfo: {status, teamCode, roleStatus, bossHpArr} }); } /** diff --git a/game-server/app/services/battleService.ts b/game-server/app/services/battleService.ts index 45c65a157..c65a53b32 100644 --- a/game-server/app/services/battleService.ts +++ b/game-server/app/services/battleService.ts @@ -379,7 +379,7 @@ export function getRandRobot(cnt = 1, withAttr = false) { * 拷贝敌军数组并添加当前血量字段 * @param source 原敌军数组,不包含当前血量字段 */ -export function transBossHpArr(source: Array<{dataId: number, hp: number}>): Array<{dataId: number, hp: number, curHp: number}> { +export function transBossHpArr(source: Array<{dataId: number, hp: number, actorId: number}>): Array<{dataId: number, hp: number, curHp: number, actorId: number}> { let desArr = []; source.forEach(elem => { let { hp } = elem; diff --git a/game-server/app/services/comBattleService.ts b/game-server/app/services/comBattleService.ts index 6aea409ea..95ec4f096 100644 --- a/game-server/app/services/comBattleService.ts +++ b/game-server/app/services/comBattleService.ts @@ -100,7 +100,7 @@ export async function checkComBattleDrop(roleId: string, battleCode: string) { fixReward = ratioReward(fixReward, COM_BATTLE_ASSIST_REWARD_RATIO); } } - await ComBattleTeamModel.updateRewardSt(roleId, true); + await ComBattleTeamModel.updateRewardSt(team.teamCode, roleId, true); return {status: 0, fixReward}; } diff --git a/shared/db/ComBattleTeam.ts b/shared/db/ComBattleTeam.ts index 13660cbd2..d2b1bc096 100644 --- a/shared/db/ComBattleTeam.ts +++ b/shared/db/ComBattleTeam.ts @@ -63,6 +63,21 @@ export class RoleStatus { } } +export class BossHp { + // boss 战场标识 + @prop({ required: true, default: 0 }) + dataId: number; + // boss 战场标识 + @prop({ required: true, default: 0 }) + actorId: number; + // 总血量 + @prop({ required: true, default: 0 }) + hp: number; + // 当前血量 + @prop({ required: true, default: 0 }) + curHp: number; +} + @index({ teamCode: 1 }) @index({ roleIds: 1 }) @index({ status: 1, blueprtId: 1, pub: 1}) @@ -107,8 +122,8 @@ export default class ComBattleTeam extends BaseModel { roleCnt: number; // 单个 boss 血量状态 - @prop({ required: false, default: [] }) - bossHpArr: Array<{dataId: number, hp: number, curHp: number}>; + @prop({ required: false, type: BossHp, default: [] }) + bossHpArr: Array; public static async createTeam(teamData: {teamCode: string, roleIds: Array, pub: boolean, blueprtId: number, quality: number, status: number, roleStatus: Array, capId: string, ceLimit: number}, lean = true) { const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData, roleCnt: teamData.roleIds.length}}, {upsert: true, new: true}).lean(lean); @@ -140,12 +155,13 @@ export default class ComBattleTeam extends BaseModel { return team; } - public static async updateRewardSt(roleId: string, gotReward: boolean, lean = true) { - const team = await ComBattleTeamModel.findOneAndUpdate({ roleIds: roleId, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.gotReward': gotReward}}).lean(lean); + public static async updateRewardSt(teamCode: string, roleId: string, gotReward: boolean, lean = true) { + const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.gotReward': gotReward}}).lean(lean); return team; } - public static async syncTeamData(teamData: {teamCode: string, status: number, roleStatus: Array, bossHpArr: Array<{dataId: number, hp: number, curHp: number}>}, lean = true) { + public static async syncTeamData(teamData: {teamCode: string, status: number, roleStatus: Array, bossHpArr: Array}, lean = true) { + console.log('syncTeamData bossHpArr: ', teamData.bossHpArr); const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData, roleCnt: teamData.roleStatus.length}}, {new: true}).lean(lean); return team; } diff --git a/shared/pubUtils/gamedata.ts b/shared/pubUtils/gamedata.ts index 67faebbaf..2061e6503 100644 --- a/shared/pubUtils/gamedata.ts +++ b/shared/pubUtils/gamedata.ts @@ -19,7 +19,7 @@ const olySeidInfo = new Map(); const expeditionInfo = new Map (); const comBtlInfo = new Map(); const btlBossHpSum = new Map(); -const btlBossHp = new Map>(); +const btlBossHp = new Map>(); const blueprtToWar = new Map(); const goodInfo = new Map(); const blueprt = new Map>(); @@ -364,12 +364,12 @@ export function getBossHpByWarId(warId: number) { const warInfo = getWarJsons(warId).json; if (warInfo && warInfo.length) { warInfo.forEach(hero => { - let { attribute, dataId, relation } = hero; + let { attribute, dataId, relation, actorId } = hero; if (relation === 2) { let attriData = decodeIdCntArrayStr(attribute, 1); const hp = parseInt(attriData.get('1')); if (hp > 0) { - bossHpArr.push({dataId, hp}); + bossHpArr.push({dataId, hp, actorId}); bossHpSum += hp; } }