远征:一键碾压
This commit is contained in:
@@ -13,12 +13,14 @@ import { getAp, setAp } from '../../../services/actionPointService';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { calculateWarStar, checkBattleHeroes, roleLevelup } from '../../../services/normalBattleService';
|
||||
import { checkTask, checkTaskInBattleEnd, checkTaskInBattleStart } from '../../../services/task/taskService';
|
||||
import { checkTask, checkTaskInBattleEnd, checkTaskInBattleStart, checkTaskInSkipExpedition } from '../../../services/task/taskService';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
import * as dicParam from '../../../pubUtils/dicParam';
|
||||
import { getSeconds, nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { reportTAEvent } from '../../../services/sdkService';
|
||||
import { getSumCe } from '../../../services/playerCeService';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
import { vipCanSkipExpedition } from '../../../services/activity/monthlyTicketService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -180,6 +182,71 @@ export class ExpeditionBattleHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳过
|
||||
*/
|
||||
async skipExpedition(msg: { expeditionCode: string, expeditionId: number, battleId: number }, session: BackendSession) {
|
||||
const { expeditionCode, expeditionId, battleId } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let serverId = session.get('serverId');
|
||||
let sid = session.get('sid');
|
||||
|
||||
let dicExpedition = gameData.expedition.get(expeditionId);
|
||||
if(dicExpedition.warId != battleId) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let dicWar = gameData.war.get(battleId);
|
||||
if(!dicWar) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
// 前置关卡是否挑战过
|
||||
let role = await RoleModel.findByRoleId(roleId, 'warStar topLineupCe vipStartTime')
|
||||
let { warStar, topLineupCe, vipStartTime } = role;
|
||||
let previousGk = dicWar.previousGk;
|
||||
if (previousGk) {
|
||||
let preBattle = warStar.findIndex(cur => cur.id == previousGk);
|
||||
if (preBattle == -1) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||
}
|
||||
|
||||
// 检查战力是否足够
|
||||
if(!vipCanSkipExpedition(dicWar.recommendedPower, topLineupCe, vipStartTime)) {
|
||||
return resResult(STATUS.EXPEDITION_SKIP_POWER_NOT_ENOUGH)
|
||||
}
|
||||
|
||||
// 检查record
|
||||
let expeditionRecord = await ExpeditionRecordModel.getExpeditionRecordByCode(expeditionCode);
|
||||
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCodeAndId(expeditionCode, expeditionId);
|
||||
if (!expeditionRecord || !expeditionWarRecord) {
|
||||
return resResult(STATUS.EXPEDITION_MISS_WAR_RECORD);
|
||||
}
|
||||
// 更新敌人剩余状态及战斗状态
|
||||
expeditionWarRecord = await ExpeditionWarRecordModel.updateEnemiesStatus(expeditionCode, expeditionId, EXPEDITION_WAR_RECORD_STATUS.SUCCESS, []);
|
||||
// 更新点数
|
||||
role = await RoleModel.increaseExpeditionPoint(roleId, dicParam.EXPEDITION_CONST.EXPEDITION_CONST_POINTS);
|
||||
|
||||
// 关卡奖励
|
||||
let warReward = new WarReward(roleId, roleName, sid, battleId, true);
|
||||
let reward = await warReward.saveReward(1);
|
||||
|
||||
let curWarStar = warStar.find(cur => cur.id == battleId);
|
||||
let { newWarStars, newStar } = calculateWarStar(warStar, battleId, []);
|
||||
if (!curWarStar || newStar > curWarStar.star) {
|
||||
role = await RoleModel.updateRoleInfo(roleId, { warStar: newWarStars });
|
||||
}
|
||||
|
||||
// 更新下一关状态
|
||||
if (gameData.expedition.has(expeditionId + 1)) {
|
||||
await findOrCreateEnemies(roleId, expeditionRecord.myCe, expeditionCode, expeditionId + 1, EXPEDITION_WAR_RECORD_STATUS.WAITING);
|
||||
}
|
||||
await checkTaskInSkipExpedition(serverId, roleId, sid, battleId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
expeditionId,
|
||||
battleId,
|
||||
goods: reward,
|
||||
expeditionPoint: role.expeditionPoint
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 战斗结算
|
||||
* 结算战斗奖励,更新远征状态
|
||||
|
||||
Reference in New Issue
Block a user