寻宝战场同步加入单个敌军血量
This commit is contained in:
@@ -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});
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@@ -373,4 +373,17 @@ export function getRandRobot(cnt = 1, withAttr = false) {
|
||||
robots.push(heroes);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -15,4 +15,4 @@ export async function getRandBlueprtId(qualityArr: Array<number>, cnt = 1) {
|
||||
if (blueprtIdArr.length === 0) return null;
|
||||
const res = getRandEelm(blueprtIdArr, cnt);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user