寻宝:修改掉落bug;修改战斗结果判断
This commit is contained in:
@@ -2,23 +2,25 @@
|
||||
* @Author: 梁桐川
|
||||
* @Date: 2020-11-30 15:05:48
|
||||
* @Last Modified by: 梁桐川
|
||||
* @Last Modified time: 2020-12-02 00:51:27
|
||||
* @Last Modified time: 2020-12-02 13:08:30
|
||||
*/
|
||||
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 } from './../../../consts/consts';
|
||||
import { getGoodById, getBossHpByBlueprtId, getComBtlSetByQuality, getBlueprtComposeByQuality, getBluePrtByQuality } from '../../../pubUtils/gamedata';
|
||||
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 Role, { RoleModel } from '../../../db/Role';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult, getRandomByLen, calculateNum, getRandValue } from '../../../pubUtils/util';
|
||||
import { resResult, getRandomByLen, calculateNum, getRandValue, ratioReward } from '../../../pubUtils/util';
|
||||
import { RoleStatus } from '../../../db/ComBattleTeam';
|
||||
import { ItemModel } from '../../../db/Item';
|
||||
import { handleReward } from '../../../services/rewardService';
|
||||
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 { setAp } from '../../../services/actionPointService';
|
||||
import { roleLevelup } from '../../../services/normalBattleService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ComBattleHandler(app);
|
||||
@@ -381,7 +383,8 @@ export class ComBattleHandler {
|
||||
*/
|
||||
async setupHeroes(msg: {teamCode: string, heroes: Array<number>, battleCode: string}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { teamCode, heroes, battleCode } = msg;
|
||||
let { teamCode, heroes, battleCode = 'default' } = msg;
|
||||
if (!heroes || heroes.length === 0) return resResult(STATUS.COM_BATTLE_HEROES_ERR);
|
||||
let teamStatus = this.teamMap.get(teamCode);
|
||||
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||
|
||||
@@ -532,8 +535,8 @@ export class ComBattleHandler {
|
||||
if (boss.curHp >= deltaHp) {
|
||||
totalHurtHp += deltaHp;
|
||||
boss.curHp -= deltaHp;
|
||||
} else {
|
||||
totalHurtHp += deltaHp;
|
||||
} else if (boss.curHp > 0) {
|
||||
totalHurtHp += boss.curHp;
|
||||
boss.curHp = 0;
|
||||
}
|
||||
}
|
||||
@@ -585,18 +588,13 @@ export class ComBattleHandler {
|
||||
let result = battleSt === COM_TEAM_STATUS.WIN;
|
||||
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: battleSt, roleStatus: teamStatus.roleStatus});
|
||||
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
||||
let battleCode = 'default';
|
||||
teamStatus.roleStatus.forEach(st => {
|
||||
if (st.roleId === roleId) {
|
||||
battleCode = st.battleCode;
|
||||
}
|
||||
});
|
||||
|
||||
// 战斗胜利扣减藏宝图
|
||||
if (result) {
|
||||
let res = await ItemModel.decreaseItems(roleId, [{id: teamStatus.blueprtId, count: 1}]);
|
||||
let res = await ItemModel.decreaseItems(teamStatus.capId, [{id: teamStatus.blueprtId, count: 1}]);
|
||||
if (!res) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
||||
}
|
||||
channel.pushMessage('onTeamComplete', {teamCode, battleCode, result});
|
||||
channel.pushMessage('onTeamComplete', {teamCode, result});
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
@@ -630,6 +628,53 @@ export class ComBattleHandler {
|
||||
return resResult(STATUS.SUCCESS, { bossCurHp: teamStatus.bossCurHp });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 寻宝结算
|
||||
* @param {{teamCode: string}} msg 寻宝队伍编号
|
||||
* @param {BackendSession} session
|
||||
* @returns 掉落物品和玩家升级信息
|
||||
* @memberof ComBattleHandler
|
||||
*/
|
||||
async comBattleEnd(msg: {teamCode: string}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleId');
|
||||
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 roleSt: RoleStatus = null;
|
||||
team.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));
|
||||
if (!warInfo) return resResult(STATUS.BATTLE_MISS_INFO);
|
||||
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
warInfo['cost'] = 0;
|
||||
}
|
||||
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, -1 * warInfo.cost); // 扣除体力
|
||||
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);
|
||||
let actordata = await roleLevelup(roleId, warInfo.kingExp, this.app, session);// 主公升级经验
|
||||
|
||||
return resResult(STATUS.SUCCESS, { ...goods, ...actordata });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取自己一段时间内的寻宝记录
|
||||
* @param {{}} msg
|
||||
|
||||
Reference in New Issue
Block a user