远征:一键碾压
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
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 战斗结算
|
||||
* 结算战斗奖励,更新远征状态
|
||||
|
||||
@@ -224,4 +224,8 @@ export function getVipRegretCnt(vipStartTime: number) {
|
||||
export function vipCanSkipTower(recommendCeSum: number, heroesCeSum: number, vipStartTime: number) {
|
||||
let ratio = vipStartTime > 0? VIP.VIP_TOWER_SKIP_CE_RATIO_WITH_VIP: VIP.VIP_TOWER_SKIP_CE_RATIO_WITHOUT_VIP;
|
||||
return heroesCeSum > recommendCeSum * ratio;
|
||||
}
|
||||
|
||||
export function vipCanSkipExpedition(recommendCe: number, topLineupCe: number, vipStartTime: number) {
|
||||
return vipStartTime > 0 && topLineupCe > recommendCe;
|
||||
}
|
||||
@@ -353,7 +353,7 @@ export async function calculateCes(type: HERO_SYSTEM_TYPE, roleId: string, serve
|
||||
|
||||
let { topLineup, topLineupCe, hasTopCeChange } = calCe.getTopLineup();
|
||||
let roleCeUpdate: RoleCeUpdate = calCe.getRoleCeTable();
|
||||
if(topLineupCe > roleCe?.historyLineupCe??0) {
|
||||
if(topLineupCe > (roleCe?.historyLineupCe||0)) {
|
||||
roleCeUpdate = { ...roleCeUpdate, historyLineupCe: topLineupCe };
|
||||
}
|
||||
|
||||
@@ -416,7 +416,10 @@ async function updateRank(roleId: string, serverId: number, topLineupCe: number,
|
||||
|
||||
export async function getSumCe(roleId: string) {
|
||||
let roleCe = await RoleCeModel.findByRoleId(roleId);
|
||||
return roleCe.historyLineupCe;
|
||||
if(roleCe && roleCe.historyLineupCe) return roleCe.historyLineupCe;
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
return role.topLineupCe||0;
|
||||
}
|
||||
|
||||
export async function getHeroesAttributes(roleId: string) {
|
||||
|
||||
@@ -267,8 +267,11 @@ export function checkSystemIsOpen(role: RoleType, id: SYSTEM_OPEN_ID) {
|
||||
let dicSystemOpenTime = gameData.sysOpenTime.get(id);
|
||||
if(!dicSystemOpenTime) return false;
|
||||
|
||||
let guideId = dicSystemOpenTime.warId > 0? GuideUnloadNum.GkNewFuncNum + dicSystemOpenTime.warId: GuideUnloadNum.LvUpNum + dicSystemOpenTime.lv;
|
||||
return role.guide.indexOf(guideId) != -1;
|
||||
if(dicSystemOpenTime.warId) {
|
||||
return role.warStar.findIndex(cur => cur.id == dicSystemOpenTime.warId) != -1;
|
||||
} else {
|
||||
return role.lv >= dicSystemOpenTime.lv
|
||||
}
|
||||
}
|
||||
|
||||
function calSchoolPoint(quality: number, star: number, colorStar: number) {
|
||||
|
||||
@@ -143,6 +143,13 @@ export async function checkTaskInBattleStart(serverId: number, roleId: string, s
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkTaskInSkipExpedition(serverId: number, roleId: string, sid: string, warId: number) {
|
||||
let task = new CheckTask(serverId, roleId);
|
||||
task.setParam(TASK_TYPE.BATTLE_EXPEDITION_START, { warId, count: 1 });
|
||||
task.setParam(TASK_TYPE.BATTLE_EXPEDITION, { warId, count: 1 });
|
||||
await task.saveAndPush(sid);
|
||||
}
|
||||
|
||||
export async function checkTaskInSkipTower(serverId: number, roleId: string, sid: string, towerLv: number) {
|
||||
let task = new CheckTask(serverId, roleId);
|
||||
task.setParam(TASK_TYPE.BATTLE_TOWER_LV, { towerLv: towerLv - 1 });
|
||||
|
||||
Reference in New Issue
Block a user