寻宝战场同步加入单个敌军血量

This commit is contained in:
liangtongchuan
2020-11-28 17:06:59 +08:00
parent 3e499de1bc
commit d41e348b93
5 changed files with 88 additions and 40 deletions

View File

@@ -5,13 +5,13 @@ import { COM_TEAM_STATUS, COM_TEAM_ENABLE_LV } from '../../../consts/consts';
import { ComBattleTeamModel } from '../../../db/ComBattleTeam';
import Role, { RoleModel } from '../../../db/Role';
import { STATUS } from '../../../consts/statusCode';
import { Application, BackendSession, BlackListFunction } from 'pinus';
import { Application, BackendSession } from 'pinus';
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 { getRandRobot, transBossHpArr } from '../../../services/battleService';
import { getRandBlueprtId } from '../../../services/comBattleService';
export default function(app: Application) {
@@ -35,12 +35,16 @@ class ComTeam {
capId: string;
// 战力限制
ceLimit: number;
// boss 血量
// boss 血量
bossHp: number;
// boss 当前血量
bossCurHp: number;
// 单个 boss 血量状态
bossHpArr: Array<{dataId: number, hp: number, curHp: number}>;
// 品质
quality: number;
constructor(teamCode: string, pub: boolean, blueprtId: number, status: number, capId: string, ceLimit: number, bossHp: number, quality: 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}> ) {
this.teamCode = teamCode;
this.pub = pub;
this.blueprtId = blueprtId;
@@ -48,7 +52,9 @@ class ComTeam {
this.capId = capId;
this.ceLimit = ceLimit;
this.bossHp = bossHp;
this.bossCurHp = bossHp;
this.quality = quality;
this.bossHpArr = bossHpArr;
}
}
export class ComBattleHandler {
@@ -97,8 +103,9 @@ export class ComBattleHandler {
roleIds.push(roleInfo.roleId);
}
}
let { bossHpSum, bossHpArr } = getBossHpByBlueprtId(blueprtId);
// 创建队伍数据结构
let comTeam = new ComTeam(teamCode, pub, blueprtId, COM_TEAM_STATUS.DEFAULT, roleId, ceLimit, getBossHpByBlueprtId(blueprtId) || 10000, goodData.quality);
let comTeam = new ComTeam(teamCode, pub, blueprtId, COM_TEAM_STATUS.DEFAULT, roleId, ceLimit, bossHpSum || 10000, goodData.quality, transBossHpArr(bossHpArr));
comTeam.roleStatus = roleStatus;
comTeam.roleIds = roleIds;
@@ -149,7 +156,8 @@ export class ComBattleHandler {
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);
let { bossHpSum, bossHpArr } = getBossHpByBlueprtId(blueprtId);
let comTeam = new ComTeam(teamCode, false, blueprtId, COM_TEAM_STATUS.DEFAULT, 'robot', 0, bossHpSum || 10000, quality, transBossHpArr(bossHpArr));
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);
@@ -349,14 +357,15 @@ export class ComBattleHandler {
return resResult(STATUS.SUCCESS);
}
async action(msg: {teamCode: string, heroes: Array<{hid: number, hurtHp: number}>, killed: Array<number>}, session: BackendSession) {
async action(msg: {teamCode: string, heroes: Array<{hid: number, hurtHp: number}>, bossHurts: Array<{dataId: number, hurtHp: number}>, killed: Array<number>}, session: BackendSession) {
let roleId = session.get('roleId');
let { teamCode, heroes, killed } = msg;
let { teamCode, heroes, killed, bossHurts } = msg;
let teamStatus = this.teamMap.get(teamCode);
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
if (teamStatus.status !== COM_TEAM_STATUS.FIGHTING) return resResult(STATUS.COM_BATTLE_NOT_START);
let totalHurtHp = 0;
let totalBossHurt = 0;
if (heroes && heroes.length) {
heroes.forEach(hero => {
if (hero.hurtHp > 0) {
@@ -364,6 +373,14 @@ export class ComBattleHandler {
}
});
}
if (bossHurts && bossHurts.length) {
bossHurts.forEach(boss => {
if (boss.hurtHp > 0) {
totalBossHurt += boss.hurtHp;
}
});
}
if (totalHurtHp !== totalBossHurt) return resResult(STATUS.COM_BATTLE_HURT_NUM_ERR);
let curRoleSt = null;
teamStatus.roleStatus.forEach(roleSt => {
@@ -377,12 +394,20 @@ export class ComBattleHandler {
}
roleSt.totalDmg += totalHurtHp;
curRoleSt = roleSt;
teamStatus.bossHp -= totalHurtHp;
}
});
teamStatus.bossCurHp -= totalHurtHp;
teamStatus.bossHpArr.forEach(boss => {
bossHurts.forEach(bh => {
if (boss.dataId === bh.dataId) {
boss.curHp -= bh.hurtHp;
if (boss.curHp < 0) boss.curHp = 0;
}
})
});
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false);
channel.pushMessage('onTeammateAct', {teamCode, bossHp: teamStatus.bossHp, roleStatus: {roleId, totalDmg: curRoleSt.totalDmg, killed}});
channel.pushMessage('onTeammateAct', {teamCode, bossCurHp: teamStatus.bossCurHp, bossHpArr: teamStatus.bossHpArr, roleStatus: {roleId, totalDmg: curRoleSt.totalDmg, killed}});
return resResult(STATUS.SUCCESS);
}
@@ -394,7 +419,7 @@ export class ComBattleHandler {
let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false);
if (isSuccess && teamStatus.bossHp <= 0) {
if (isSuccess && teamStatus.bossCurHp <= 0) {
let team = await ComBattleTeamModel.updateResult(teamCode, roleId, isSuccess);
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
// TODO: 根据策划结论考虑是否在推送中添加掉落
@@ -406,10 +431,10 @@ export class ComBattleHandler {
if (team.status === COM_TEAM_STATUS.LOOSE) {
channel.pushMessage('onTeamComplete', {teamCode, result: isSuccess});
} else {
channel.pushMessage('onTeammateAct', {teamCode, bossHp: teamStatus.bossHp, roleStatus: {roleId, battleStatus: 2}});
channel.pushMessage('onTeammateAct', {teamCode, bossCurHp: teamStatus.bossCurHp, roleStatus: {roleId, battleStatus: 2}});
}
}
return resResult(STATUS.SUCCESS, { bossHp: teamStatus.bossHp });
return resResult(STATUS.SUCCESS, { bossCurHp: teamStatus.bossCurHp });
}
async getTeamRec(msg: {}, session: BackendSession) {
@@ -437,7 +462,7 @@ export class ComBattleHandler {
// users = channel.getMembers();
// channel.pushMessage('onAdd', {users});
// let tsid = channel.getMember(roleId)['sid'];
// channelService.pushMessageByUids('bossHp', {data: 'datadata'}, [{
// channelService.pushMessageByUids('bossCurHp', {data: 'datadata'}, [{
// uid: roleId,
// sid: tsid
// }]);
@@ -479,14 +504,14 @@ export class ComBattleHandler {
// let channelService = this.app.get('channelService');
// let channel = channelService.getChannel(msg.battleId, false);
// this.bossHp -= msg.bossHurt;
// if (this.bossHp < 0) {
// this.bossHp = 0;
// channel.pushMessage('bossHp', {data: 'boss 挂啦!!!!!'}, undefined);
// this.bossCurHp -= msg.bossHurt;
// if (this.bossCurHp < 0) {
// this.bossCurHp = 0;
// channel.pushMessage('bossCurHp', {data: 'boss 挂啦!!!!!'}, undefined);
// }
// channel.pushMessage('bossHp', {bossHp: this.bossHp}, undefined);
// channel.pushMessage('bossCurHp', {bossCurHp: this.bossCurHp}, undefined);
// return resResult(STATUS.SUCCESS, { bossHp: this.bossHp});
// return resResult(STATUS.SUCCESS, { bossCurHp: this.bossCurHp});
// }

View File

@@ -374,3 +374,16 @@ export function getRandRobot(cnt = 1, withAttr = false) {
}
return robots;
}
/**
* 拷贝敌军数组并添加当前血量字段
* @param source 原敌军数组,不包含当前血量字段
*/
export function transBossHpArr(source: Array<{dataId: number, hp: number}>): Array<{dataId: number, hp: number, curHp: number}> {
let desArr = [];
source.forEach(elem => {
let { hp } = elem;
desArr.push(Object.assign(elem, {curHp: hp}));
});
return desArr;
}

View File

@@ -96,6 +96,7 @@ export const STATUS = {
COM_BATTLE_CAN_NOT_RM: { code: 20622, simStr: '没有移除成员的权限' },
COM_BATTLE_DISSMISS_ERR: { code: 20623, simStr: '解散队伍异常' },
COM_BATTLE_NO_RECENT_REC: { code: 20624, simStr: '没有最近的寻宝记录' },
COM_BATTLE_HURT_NUM_ERR: { code: 20625, simStr: '血量计算错误' },
// 共斗藏宝图合成
COM_BLUEPRT_QUALITY_CANNOT_COMPOSE: { code: 20630, simStr: '该品质藏宝图不可合成' },

View File

@@ -18,8 +18,9 @@ const seidInfo = new Map<number, any>();
const olySeidInfo = new Map<number, any>();
const expeditionInfo = new Map<number, any> ();
const comBtlInfo = new Map<number, {quality: number, name: string, assistanceTime: number, assistanceLevel: number}>();
const btlBossHp = new Map<number, number>();
const blueprtBossHp = new Map<number, number>();
const btlBossHpSum = new Map<number, number>();
const btlBossHp = new Map<number, Array<{dataId: number, hp: number}>>();
const blueprtToWar = new Map<number, number>();
const goodInfo = new Map<number, any>();
const blueprt = new Map<number, Array<number>>();
const blueprtCompose = new Map<number, any>();
@@ -357,37 +358,45 @@ export function getComBtlSetByQuality(quality: number) {
}
export function getBossHpByWarId(warId: number) {
let bossHp = btlBossHp.get(warId) || 0;
if (!bossHp) {
let bossHpSum = btlBossHpSum.get(warId) || 0;
let bossHpArr = btlBossHp.get(warId) || [];
if (!bossHpSum || !bossHpArr) {
const warInfo = getWarJsons(warId).json;
if (warInfo && warInfo.length) {
warInfo.forEach(hero => {
if (hero.relation === 2) {
let { attribute } = hero;
let { attribute, dataId, relation } = hero;
if (relation === 2) {
let attriData = decodeIdCntArrayStr(attribute, 1);
const hp = parseInt(attriData.get('1'));
if (hp > 0) {
bossHp += hp;
bossHpArr.push({dataId, hp});
bossHpSum += hp;
}
}
})
btlBossHp.set(warId, bossHpArr);
btlBossHpSum.set(warId, bossHpSum);
}
btlBossHp.set(warId, bossHp);
}
return bossHp;
return { bossHpSum, bossHpArr };
}
export function getWarIdByBlueprtId(blueprtId: number) {
let warId = blueprtToWar.get(blueprtId);
if (!warId) {
const { specialAttr } = getGoodById(blueprtId);
const attrData = decodeIdCntArrayStr(specialAttr, 1);
warId = parseInt(attrData.get('1'));
blueprtToWar.set(blueprtId, warId);
}
return warId;
}
export function getBossHpByBlueprtId(blueprtId: number) {
let bossHp = blueprtBossHp.get(blueprtId) || 0;
if (!bossHp) {
const { specialAttr } = getGoodById(blueprtId);
const attrData = decodeIdCntArrayStr(specialAttr, 1);
const warId = parseInt(attrData.get('1'));
bossHp = getBossHpByWarId(warId);
blueprtBossHp.set(blueprtId, bossHp);
}
return bossHp;
let bossHpInfo = getBossHpByWarId(getWarIdByBlueprtId(blueprtId));
return bossHpInfo;
}
export function hasExpeditionById(id: number) {
return expeditionInfo.has(id);
}