寻宝:修改匹配后的channel处理;掉落中增加字段;修改伤害计算
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: 梁桐川
|
||||
* @Date: 2020-11-30 15:05:48
|
||||
* @Last Modified by: 梁桐川
|
||||
* @Last Modified time: 2020-12-02 13:08:30
|
||||
* @Last Modified time: 2020-12-02 17:33:14
|
||||
*/
|
||||
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';
|
||||
@@ -18,7 +18,7 @@ import { ItemModel } from '../../../db/Item';
|
||||
import { handleFixedReward, handleReward } from '../../../services/rewardService';
|
||||
import { checkRoleInQueue, getTeamSearchByQuality, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService';
|
||||
import { transBossHpArr } from '../../../services/battleService';
|
||||
import { getRandBlueprtId, getRandComBtlRobots, checkComBattleResult, clearComBtlTimer } from '../../../services/comBattleService';
|
||||
import { getRandBlueprtId, getRandComBtlRobots, checkComBattleResult, clearComBtlTimer, getRealReward } from '../../../services/comBattleService';
|
||||
import { setAp } from '../../../services/actionPointService';
|
||||
import { roleLevelup } from '../../../services/normalBattleService';
|
||||
|
||||
@@ -140,10 +140,8 @@ export class ComBattleHandler {
|
||||
let channelService = this.app.get('channelService');
|
||||
let channel = channelService.getChannel(teamCode, true);
|
||||
let users = channel.getMembers();
|
||||
for (let roleId of roleIds) {
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
let uids = [];
|
||||
uids.push({roleId, sid});
|
||||
@@ -151,6 +149,10 @@ export class ComBattleHandler {
|
||||
for (let teammate of teammates) {
|
||||
let { roleId, sid } = teammate;
|
||||
uids.push({uid: roleId, sid});
|
||||
let users = channel.getMembers();
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
}
|
||||
channelService.pushMessageByUids('onTeamJoin', {teamInfo: comTeam}, uids);
|
||||
}
|
||||
@@ -204,7 +206,7 @@ export class ComBattleHandler {
|
||||
}
|
||||
}
|
||||
|
||||
const team = await ComBattleTeamModel.getOneTeamByQualityAndSt(qualityArr, COM_TEAM_STATUS.DEFAULT, topFiveCe);
|
||||
const team = await ComBattleTeamModel.getOtherTeamByQualityAndSt(roleId, qualityArr, COM_TEAM_STATUS.DEFAULT, topFiveCe);
|
||||
// TODO: 有匹配的队伍还需要重新 joinTeam 加入,有失败可能,体验不好,需优化
|
||||
if (team && team.roleIds.length < 3 && team.status === COM_TEAM_STATUS.DEFAULT && team.roleIds.indexOf(roleId) === -1) {
|
||||
return resResult(STATUS.SUCCESS, {teamCode: team.teamCode});
|
||||
@@ -292,16 +294,16 @@ export class ComBattleHandler {
|
||||
return resResult(STATUS.COM_BATTLE_JOIN_ERR);
|
||||
}
|
||||
|
||||
// 推送加入信息给其他玩家
|
||||
// 推送队伍信息给所有玩家
|
||||
let channelService = this.app.get('channelService');
|
||||
let channel = channelService.getChannel(teamCode, false);
|
||||
teamStatus.roleIds.push(roleId);
|
||||
teamStatus.roleStatus.push(roleStatus);
|
||||
channel.pushMessage('onTeamJoin', {teamInfo: teamStatus});
|
||||
let users = channel.getMembers();
|
||||
if (users.indexOf(roleId) === -1) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
channel.pushMessage('onTeamJoin', {teamInfo: teamStatus});
|
||||
|
||||
if (teamStatus.roleIds && teamStatus.roleIds.length === 3) {
|
||||
let thiz = this;
|
||||
@@ -504,7 +506,7 @@ export class ComBattleHandler {
|
||||
if (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});
|
||||
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: COM_TEAM_STATUS.LOOSE, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr});
|
||||
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
||||
channel.pushMessage('onTeamComplete', {teamCode, result: false});
|
||||
}
|
||||
@@ -561,7 +563,7 @@ export class ComBattleHandler {
|
||||
if (boss.curHp >= eachHurtHp) {
|
||||
robotTotalHurt += eachHurtHp;
|
||||
boss.curHp -= eachHurtHp;
|
||||
} else { // 丢弃溢出的伤害
|
||||
} else if (boss.curHp > 0) { // 丢弃溢出的伤害
|
||||
robotTotalHurt += boss.curHp;
|
||||
boss.curHp = 0;
|
||||
}
|
||||
@@ -586,7 +588,15 @@ export class ComBattleHandler {
|
||||
let battleSt = checkComBattleResult(teamStatus);
|
||||
if (battleSt === COM_TEAM_STATUS.WIN || battleSt === COM_TEAM_STATUS.LOOSE) {
|
||||
let result = battleSt === COM_TEAM_STATUS.WIN;
|
||||
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: battleSt, roleStatus: teamStatus.roleStatus});
|
||||
if (result) {
|
||||
teamStatus.bossHpArr.forEach(bs => {
|
||||
bs.curHp = 0;
|
||||
});
|
||||
teamStatus.roleStatus.forEach(st => {
|
||||
st.fixReward = getRealReward(teamStatus.blueprtId, st);
|
||||
});
|
||||
}
|
||||
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: battleSt, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr});
|
||||
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
||||
|
||||
// 战斗胜利扣减藏宝图
|
||||
@@ -641,14 +651,15 @@ export class ComBattleHandler {
|
||||
let { teamCode } = msg;
|
||||
let team = await ComBattleTeamModel.getTeamByCode(teamCode);
|
||||
if (!team || team.status !== COM_TEAM_STATUS.WIN) return resResult(STATUS.COM_BATTLE_REWARD_ERR);
|
||||
let { roleStatus, blueprtId, status, bossHpArr } = team;
|
||||
let roleSt: RoleStatus = null;
|
||||
team.roleStatus.forEach(st => {
|
||||
roleStatus.forEach(st => {
|
||||
if (st && st.roleId === roleId) {
|
||||
roleSt = st;
|
||||
}
|
||||
});
|
||||
if (roleSt.gotReward) return resResult(STATUS.COM_BATTLE_REWARDED);
|
||||
let warInfo = getWarById(getWarIdByBlueprtId(team.blueprtId));
|
||||
let warInfo = getWarById(getWarIdByBlueprtId(blueprtId));
|
||||
if (!warInfo) return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
@@ -660,19 +671,12 @@ export class ComBattleHandler {
|
||||
if(!apJson) {
|
||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||
}
|
||||
let fixRewardStr = warInfo['fixReward'];
|
||||
if (!roleSt.isCap) {
|
||||
if (roleSt.isFrd) {
|
||||
fixRewardStr = '&';
|
||||
} else {
|
||||
fixRewardStr = ratioReward(fixRewardStr, COM_BATTLE_ASSIST_REWARD_RATIO);
|
||||
}
|
||||
}
|
||||
|
||||
await ComBattleTeamModel.updateRewardSt(roleId, true);
|
||||
const goods = await handleFixedReward(roleId, roleName, fixRewardStr, 1);
|
||||
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 });
|
||||
return resResult(STATUS.SUCCESS, { ...goods, ...actordata, teamInfo: {status, roleStatus, bossHpArr} });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { STATUS } from './../consts/statusCode';
|
||||
import { COM_BATTLE_ROBOT_ID_NAME, COM_BATTLE_ROBOT_CE_RATIO, COM_BATTLE_ROBOT_ROUND_LMT, COM_BATTLE_ROBOT_HURT_RATIO, COM_BATTLE_ROBOT_HURT_CH_RATIO, COM_TEAM_STATUS, COM_BATTLE_ASSIST_REWARD_RATIO } from './../consts/consts';
|
||||
import { RoleStatus, ComBattleTeamModel } from './../db/ComBattleTeam';
|
||||
import { getBluePrtByQuality, getRewardByBlueprtId } from "../pubUtils/gamedata";
|
||||
import { getBluePrtByQuality, getRewardByBlueprtId, getWarById, getWarIdByBlueprtId } from "../pubUtils/gamedata";
|
||||
import { getRandEelm, getRandValue, resResult, ratioReward } from "../pubUtils/util";
|
||||
import { getRandRobot } from "./battleService";
|
||||
|
||||
@@ -118,3 +118,16 @@ export function setComBtlTimer(teamCode: string, timer: NodeJS.Timer, timerMap:
|
||||
}
|
||||
timerMap.set(teamCode, timer);
|
||||
}
|
||||
|
||||
export function getRealReward(blueprtId: number, roleSt: RoleStatus) {
|
||||
let warInfo = getWarById(getWarIdByBlueprtId(blueprtId));
|
||||
let fixRewardStr = warInfo['fixReward'];
|
||||
if (!roleSt.isCap) {
|
||||
if (roleSt.isFrd) {
|
||||
fixRewardStr = '&';
|
||||
} else {
|
||||
fixRewardStr = ratioReward(fixRewardStr, COM_BATTLE_ASSIST_REWARD_RATIO);
|
||||
}
|
||||
}
|
||||
return fixRewardStr;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ export class RoleStatus {
|
||||
// 是否领奖
|
||||
@prop({ required: true, default: false })
|
||||
gotReward: boolean;
|
||||
// 固定奖励
|
||||
@prop({ required: true, default: '&' })
|
||||
fixReward: string;
|
||||
|
||||
constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, headHid: number, sHid: number, topFiveCe: number, lv: number, heroes = [], isRobot = false) {
|
||||
this.roleId = roleId;
|
||||
@@ -103,6 +106,10 @@ export default class ComBattleTeam extends BaseModel {
|
||||
@prop({ required: true, default: 1 })
|
||||
roleCnt: number;
|
||||
|
||||
// 单个 boss 血量状态
|
||||
@prop({ required: false, default: [] })
|
||||
bossHpArr: Array<{dataId: number, hp: number, curHp: number}>;
|
||||
|
||||
public static async createTeam(teamData: {teamCode: string, roleIds: Array<string>, pub: boolean, blueprtId: number, quality: number, status: number, roleStatus: Array<RoleStatus>, 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);
|
||||
return team;
|
||||
@@ -138,7 +145,7 @@ export default class ComBattleTeam extends BaseModel {
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async syncTeamData(teamData: {teamCode: string, status: number, roleStatus: Array<RoleStatus>}, lean = true) {
|
||||
public static async syncTeamData(teamData: {teamCode: string, status: number, roleStatus: Array<RoleStatus>, bossHpArr: Array<{dataId: number, hp: number, curHp: number}>}, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData, roleCnt: teamData.roleStatus.length}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
@@ -190,6 +197,11 @@ export default class ComBattleTeam extends BaseModel {
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async getOtherTeamByQualityAndSt(roleId: string, qualityArr: Array<number>, status: number, ce = 0, pub = true, cntLmt = 2, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOne({quality: {$in: qualityArr}, status, ceLimit: {$lte: ce}, pub, roleCnt: {$lte: cntLmt}, roleIds: {$nin: [roleId]}}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async getTeamByRoleAndTime(roleId: string, qualityArr?: Array<number>, time?: Date, isAssist?: boolean, limitCnt = 50, lean = true) {
|
||||
let query = {roleIds: roleId};
|
||||
if (qualityArr) {
|
||||
|
||||
Reference in New Issue
Block a user