远征:一键碾压

This commit is contained in:
luying
2022-07-20 14:10:12 +08:00
parent c410727430
commit 220c635ff1
6 changed files with 90 additions and 5 deletions

View File

@@ -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
});
}
/**
* 战斗结算
* 结算战斗奖励,更新远征状态

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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 });

View File

@@ -86,6 +86,7 @@ export const STATUS = {
EXPEDITION_POINT_RECORD_NOT_FOUND: { code: 20409, simStr: '点数宝箱已刷新' },
EXPEDITION_POINT_NEED_ALL_RECEIVED: { code: 20410, simStr: '宝箱需要领取完才可以刷新' },
EXPEDITION_RESET_NUM_NOT_ENOUGH: { code: 20411, simStr: '重置次数不足' },
EXPEDITION_SKIP_POWER_NOT_ENOUGH: { code: 20412, simStr: '未购买月卡或战力不足不可跳过' },
// 天梯 20500 - 20599
TOWER_RESET_ERR: { code: 20501, simStr: '只能重置当前层' },
TOWER_INFO_NOT_FOUND: { code: 20502, simStr: '镇念塔层数异常' },