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

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 { ComBattleTeamModel } from '../../../db/ComBattleTeam';
import Role, { RoleModel } from '../../../db/Role'; import Role, { RoleModel } from '../../../db/Role';
import { STATUS } from '../../../consts/statusCode'; 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 { resResult, getRandomByLen, calculateNum, getRandValue } from '../../../pubUtils/util';
import { RoleStatus } from '../../../db/ComBattleTeam'; import { RoleStatus } from '../../../db/ComBattleTeam';
import { ItemModel } from '../../../db/Item'; import { ItemModel } from '../../../db/Item';
import { handleReward } from '../../../services/rewardService'; import { handleReward } from '../../../services/rewardService';
import { getTeamSearchByQuality, setTeamSearchReq } from '../../../services/redisService'; import { getTeamSearchByQuality, setTeamSearchReq } from '../../../services/redisService';
import { getRandRobot } from '../../../services/battleService'; import { getRandRobot, transBossHpArr } from '../../../services/battleService';
import { getRandBlueprtId } from '../../../services/comBattleService'; import { getRandBlueprtId } from '../../../services/comBattleService';
export default function(app: Application) { export default function(app: Application) {
@@ -35,12 +35,16 @@ class ComTeam {
capId: string; capId: string;
// 战力限制 // 战力限制
ceLimit: number; ceLimit: number;
// boss 血量 // boss 血量
bossHp: number; bossHp: number;
// boss 当前血量
bossCurHp: number;
// 单个 boss 血量状态
bossHpArr: Array<{dataId: number, hp: number, curHp: number}>;
// 品质 // 品质
quality: 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.teamCode = teamCode;
this.pub = pub; this.pub = pub;
this.blueprtId = blueprtId; this.blueprtId = blueprtId;
@@ -48,7 +52,9 @@ class ComTeam {
this.capId = capId; this.capId = capId;
this.ceLimit = ceLimit; this.ceLimit = ceLimit;
this.bossHp = bossHp; this.bossHp = bossHp;
this.bossCurHp = bossHp;
this.quality = quality; this.quality = quality;
this.bossHpArr = bossHpArr;
} }
} }
export class ComBattleHandler { export class ComBattleHandler {
@@ -97,8 +103,9 @@ export class ComBattleHandler {
roleIds.push(roleInfo.roleId); 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.roleStatus = roleStatus;
comTeam.roleIds = roleIds; comTeam.roleIds = roleIds;
@@ -149,7 +156,8 @@ export class ComBattleHandler {
roleIds.push(roleId); roleIds.push(roleId);
let blueprtId = (await getRandBlueprtId(qualityArr)).pop(); let blueprtId = (await getRandBlueprtId(qualityArr)).pop();
let { quality } = getGoodById(blueprtId); 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) { for (let robot of robotHeroes) {
const robotCe = getRandValue(topFiveCe, COM_BATTLE_ROBOT_CE_RATIO, 0); const robotCe = getRandValue(topFiveCe, COM_BATTLE_ROBOT_CE_RATIO, 0);
const robotLv = getRandValue(lv, 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); 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 roleId = session.get('roleId');
let { teamCode, heroes, killed } = msg; let { teamCode, heroes, killed, bossHurts } = msg;
let teamStatus = this.teamMap.get(teamCode); let teamStatus = this.teamMap.get(teamCode);
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID); 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); if (teamStatus.status !== COM_TEAM_STATUS.FIGHTING) return resResult(STATUS.COM_BATTLE_NOT_START);
let totalHurtHp = 0; let totalHurtHp = 0;
let totalBossHurt = 0;
if (heroes && heroes.length) { if (heroes && heroes.length) {
heroes.forEach(hero => { heroes.forEach(hero => {
if (hero.hurtHp > 0) { 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; let curRoleSt = null;
teamStatus.roleStatus.forEach(roleSt => { teamStatus.roleStatus.forEach(roleSt => {
@@ -377,12 +394,20 @@ export class ComBattleHandler {
} }
roleSt.totalDmg += totalHurtHp; roleSt.totalDmg += totalHurtHp;
curRoleSt = roleSt; 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 channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false); 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); return resResult(STATUS.SUCCESS);
} }
@@ -394,7 +419,7 @@ export class ComBattleHandler {
let channelService = this.app.get('channelService'); let channelService = this.app.get('channelService');
let channel = channelService.getChannel(teamCode, false); let channel = channelService.getChannel(teamCode, false);
if (isSuccess && teamStatus.bossHp <= 0) { if (isSuccess && teamStatus.bossCurHp <= 0) {
let team = await ComBattleTeamModel.updateResult(teamCode, roleId, isSuccess); let team = await ComBattleTeamModel.updateResult(teamCode, roleId, isSuccess);
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR); if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
// TODO: 根据策划结论考虑是否在推送中添加掉落 // TODO: 根据策划结论考虑是否在推送中添加掉落
@@ -406,10 +431,10 @@ export class ComBattleHandler {
if (team.status === COM_TEAM_STATUS.LOOSE) { if (team.status === COM_TEAM_STATUS.LOOSE) {
channel.pushMessage('onTeamComplete', {teamCode, result: isSuccess}); channel.pushMessage('onTeamComplete', {teamCode, result: isSuccess});
} else { } 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) { async getTeamRec(msg: {}, session: BackendSession) {
@@ -437,7 +462,7 @@ export class ComBattleHandler {
// users = channel.getMembers(); // users = channel.getMembers();
// channel.pushMessage('onAdd', {users}); // channel.pushMessage('onAdd', {users});
// let tsid = channel.getMember(roleId)['sid']; // let tsid = channel.getMember(roleId)['sid'];
// channelService.pushMessageByUids('bossHp', {data: 'datadata'}, [{ // channelService.pushMessageByUids('bossCurHp', {data: 'datadata'}, [{
// uid: roleId, // uid: roleId,
// sid: tsid // sid: tsid
// }]); // }]);
@@ -479,14 +504,14 @@ export class ComBattleHandler {
// let channelService = this.app.get('channelService'); // let channelService = this.app.get('channelService');
// let channel = channelService.getChannel(msg.battleId, false); // let channel = channelService.getChannel(msg.battleId, false);
// this.bossHp -= msg.bossHurt; // this.bossCurHp -= msg.bossHurt;
// if (this.bossHp < 0) { // if (this.bossCurHp < 0) {
// this.bossHp = 0; // this.bossCurHp = 0;
// channel.pushMessage('bossHp', {data: 'boss 挂啦!!!!!'}, undefined); // 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

@@ -373,4 +373,17 @@ export function getRandRobot(cnt = 1, withAttr = false) {
robots.push(heroes); robots.push(heroes);
} }
return robots; 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

@@ -15,4 +15,4 @@ export async function getRandBlueprtId(qualityArr: Array<number>, cnt = 1) {
if (blueprtIdArr.length === 0) return null; if (blueprtIdArr.length === 0) return null;
const res = getRandEelm(blueprtIdArr, cnt); const res = getRandEelm(blueprtIdArr, cnt);
return res; return res;
} }

View File

@@ -96,6 +96,7 @@ export const STATUS = {
COM_BATTLE_CAN_NOT_RM: { code: 20622, simStr: '没有移除成员的权限' }, COM_BATTLE_CAN_NOT_RM: { code: 20622, simStr: '没有移除成员的权限' },
COM_BATTLE_DISSMISS_ERR: { code: 20623, simStr: '解散队伍异常' }, COM_BATTLE_DISSMISS_ERR: { code: 20623, simStr: '解散队伍异常' },
COM_BATTLE_NO_RECENT_REC: { code: 20624, 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: '该品质藏宝图不可合成' }, 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 olySeidInfo = new Map<number, any>();
const expeditionInfo = new Map<number, any> (); const expeditionInfo = new Map<number, any> ();
const comBtlInfo = new Map<number, {quality: number, name: string, assistanceTime: number, assistanceLevel: number}>(); const comBtlInfo = new Map<number, {quality: number, name: string, assistanceTime: number, assistanceLevel: number}>();
const btlBossHp = new Map<number, number>(); const btlBossHpSum = new Map<number, number>();
const blueprtBossHp = 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 goodInfo = new Map<number, any>();
const blueprt = new Map<number, Array<number>>(); const blueprt = new Map<number, Array<number>>();
const blueprtCompose = new Map<number, any>(); const blueprtCompose = new Map<number, any>();
@@ -357,37 +358,45 @@ export function getComBtlSetByQuality(quality: number) {
} }
export function getBossHpByWarId(warId: number) { export function getBossHpByWarId(warId: number) {
let bossHp = btlBossHp.get(warId) || 0; let bossHpSum = btlBossHpSum.get(warId) || 0;
if (!bossHp) { let bossHpArr = btlBossHp.get(warId) || [];
if (!bossHpSum || !bossHpArr) {
const warInfo = getWarJsons(warId).json; const warInfo = getWarJsons(warId).json;
if (warInfo && warInfo.length) { if (warInfo && warInfo.length) {
warInfo.forEach(hero => { warInfo.forEach(hero => {
if (hero.relation === 2) { let { attribute, dataId, relation } = hero;
let { attribute } = hero; if (relation === 2) {
let attriData = decodeIdCntArrayStr(attribute, 1); let attriData = decodeIdCntArrayStr(attribute, 1);
const hp = parseInt(attriData.get('1')); const hp = parseInt(attriData.get('1'));
if (hp > 0) { 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) { export function getBossHpByBlueprtId(blueprtId: number) {
let bossHp = blueprtBossHp.get(blueprtId) || 0; let bossHpInfo = getBossHpByWarId(getWarIdByBlueprtId(blueprtId));
if (!bossHp) { return bossHpInfo;
const { specialAttr } = getGoodById(blueprtId);
const attrData = decodeIdCntArrayStr(specialAttr, 1);
const warId = parseInt(attrData.get('1'));
bossHp = getBossHpByWarId(warId);
blueprtBossHp.set(blueprtId, bossHp);
}
return bossHp;
} }
export function hasExpeditionById(id: number) { export function hasExpeditionById(id: number) {
return expeditionInfo.has(id); return expeditionInfo.has(id);
} }