关卡:添加扫荡次数

This commit is contained in:
luying
2022-07-14 13:57:59 +08:00
parent a93e8c95f1
commit 8eaadb5245
5 changed files with 102 additions and 21 deletions
@@ -12,7 +12,7 @@ import { STATUS } from '../../../consts/statusCode';
import { resResult } from '../../../pubUtils/util';
import { RoleModel } from '../../../db/Role';
import { RScriptRecordModel } from '../../../db/RScriptRecord';
import { checkBattleHeroes, roleLevelup, getBattleList, calculateWarStar, getBattleListOfTypes, getMainChapter, getStarOfChapter } from '../../../services/normalBattleService';
import { checkBattleHeroes, roleLevelup, getBattleList, calculateWarStar, getBattleListOfTypes, getMainChapter, getStarOfChapter, checkWarCountAndInc } from '../../../services/normalBattleService';
import { checkDungeonNum, checkDungeonAndIncrease, saveDungeonFirst } from '../../../services/dungeonService';
// import { switchOnFunc } from '../../../services/funcSwitchService';
import { gameData } from '../../../pubUtils/data';
@@ -53,7 +53,7 @@ export class NormalBattleHandler {
if (!warInfo) {
return resResult(STATUS.BATTLE_MISS_INFO);
}
let role = await RoleModel.findByRoleId(roleId, 'lv');
let role = await RoleModel.findByRoleId(roleId, 'lv warStar warCount roleId refWarCount');
let apJson = await getAp(roleId, ip, role.lv);
let { ap } = apJson;
if (ap < warInfo.cost) {
@@ -62,10 +62,11 @@ export class NormalBattleHandler {
if(role.lv < warInfo.lvLimited) {
return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
}
// 前置关卡是否挑战过
// 前置关卡是否挑战过
let { warStar } = role;
let previousGk = warInfo.previousGk;
if (previousGk) {
let { warStar } = await RoleModel.findByRoleId(roleId);
let preBattle = warStar.findIndex(cur => cur.id == previousGk);
if (preBattle == -1) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
}
@@ -77,7 +78,12 @@ export class NormalBattleHandler {
let dailyNum = {};
let towerData = {};
let dungeonNum = {};
if (warInfo.warType == WAR_TYPE.DAILY) {
if (warInfo.warType == WAR_TYPE.NORMAL || warInfo.warType == WAR_TYPE.MAIN_ELITE) {
let checkResult = await checkWarCountAndInc(battleId, 0, role, true);
if (checkResult.code != 0) {
return checkResult
}
} else if (warInfo.warType == WAR_TYPE.DAILY) {
let checkResult = await checkDaily(roleId, battleId, 1);
if (checkResult.status == -1) {
return checkResult.resResult
@@ -169,7 +175,7 @@ export class NormalBattleHandler {
return resResult(STATUS.BATTLE_INFO_VALIDATE_ERR);
}
let role = await RoleModel.findByRoleId(roleId, 'lv vipStartTime warStar');
let role = await RoleModel.findByRoleId(roleId, 'lv vipStartTime warStar warCount refWarCount roleId');
let apJson = await setAp(serverId, roleId, ip, role.lv, isSuccess? -1 * warInfo.cost: 0, sid, getReasonByWarType(warInfo.warType)); // 扣除体力
if (!apJson) {
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
@@ -181,8 +187,15 @@ export class NormalBattleHandler {
let dailyNum = {};
let towerStatus = null;
let dungeonNum = {};
if (warInfo.warType == WAR_TYPE.DAILY) {
if(warInfo.warType == WAR_TYPE.NORMAL || warInfo.warType == WAR_TYPE.MAIN_ELITE) {
let isFirst = warStar.findIndex(cur => cur.id == battleId) == -1;
if(!isFirst) {
let checkResult = await checkWarCountAndInc(battleId, 1, role, false);
if (checkResult.code != 0) {
return checkResult
}
}
} else if (warInfo.warType == WAR_TYPE.DAILY) {
let checkResult = await checkDailyAndIncrease(roleId, warStar, battleId, isSuccess?1:0, false, stars, role);
if (checkResult.status == -1) {
return checkResult.resResult;
@@ -312,18 +325,16 @@ export class NormalBattleHandler {
if (!curWar || curWar.star < 3) {
return resResult(STATUS.BATTLE_SWEEP_CONDITION_STAR);
}
// 扣体力
let role = await RoleModel.findByRoleId(roleId, 'lv');
let apJson = await setAp(serverId, roleId, ip, role.lv, -1 * warInfo.cost * count, sid, getReasonByWarType(warInfo.warType)); // 扣除体力
if (!apJson) {
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
}
let role = await RoleModel.findByRoleId(roleId, 'lv warCount refWarCount roleId');
// 扫荡次数
let dailyNum = {};
let dungeonNum = {};
if (warInfo.warType == WAR_TYPE.DAILY) {
if(warInfo.warType == WAR_TYPE.NORMAL || warInfo.warType == WAR_TYPE.MAIN_ELITE) {
let checkResult = await checkWarCountAndInc(battleId, count, role, true);
if (checkResult.code != 0) {
return checkResult
}
} else if (warInfo.warType == WAR_TYPE.DAILY) {
let checkResult = await checkDailyAndIncrease(roleId, warStar, battleId, count, true);
if (checkResult.status == -1) {
return checkResult.resResult
@@ -337,6 +348,13 @@ export class NormalBattleHandler {
dungeonNum = Object.assign(dungeonNum, checkResult.data)
}
// 扣体力
let apJson = await setAp(serverId, roleId, ip, role.lv, -1 * warInfo.cost * count, sid, getReasonByWarType(warInfo.warType)); // 扣除体力
if (!apJson) {
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
}
// 发奖励
let warReward = new WarReward(roleId, roleName, sid, battleId, true);
let result = await warReward.saveReward(count, true);
@@ -1,6 +1,6 @@
import { HeroModel, HeroType } from '../db/Hero';
import Role, { RoleModel, RoleType } from '../db/Role'
import Role, { RoleModel, RoleType, WarCount } from '../db/Role'
import { getLvByExp, getExpByLv, gameData, getDicApByLv } from '../pubUtils/data';
import { updateRoleOnlineInfo, updateUserInfo } from './redisService';
// import { switchOnFunc } from './funcSwitchService';
@@ -11,7 +11,7 @@ import { Rank } from './rankService';
import { checkTask } from './task/taskService';
import { RScriptRecordModel } from '../db/RScriptRecord';
import { setAp } from './actionPointService';
import { resResult } from '../pubUtils/util';
import { resResult, shouldRefresh } from '../pubUtils/util';
import { GuildLeader, LineupParam } from '../domain/rank';
import { WarStar } from '../domain/dbGeneral';
import { uniq } from 'underscore';
@@ -19,6 +19,7 @@ import { checkPopUpCondition } from './activity/popUpShopService';
import { calculateCeWithRole } from './playerCeService';
import { sendMessageToUserWithSuc } from './pushService';
import { ActionPointModel } from '../db/ActionPoint';
import { GK_MAIN, GK_MAINELITE } from '../pubUtils/dicParam';
export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kingExp: number = 0, session: BackendSession) {
const serverId = session.get('serverId');
@@ -155,7 +156,10 @@ export async function getBattleListOfTypes(role: RoleType, types: number[]) {
}
export async function getBattleList(role: RoleType, type: number) {
let { roleId, warStar } = role;
let { roleId, warStar, warCount = [], refWarCount } = role;
if(shouldRefresh(refWarCount, new Date())) {
warCount = [];
}
let scripts = await RScriptRecordModel.findbyRole(roleId, type);
@@ -190,10 +194,42 @@ export async function getBattleList(role: RoleType, type: number) {
}
}
}
if(type == WAR_TYPE.NORMAL || type == WAR_TYPE.MAIN_ELITE) {
for(let data of result) {
let curWarCount = warCount.find(cur => cur.warId == data.battleId);
data.count = curWarCount? curWarCount.count: 0;
}
}
result = result.sort((a, b) => { return a.battleId - b.battleId });
return result;
}
export async function checkWarCountAndInc(warId: number, inc: number, role: RoleType, needRefresh: boolean) {
let { roleId, warCount, refWarCount } = role;
let dicWar = gameData.war.get(warId);
let max = dicWar.warType == WAR_TYPE.NORMAL? GK_MAIN.GK_MAIN_SWEEP_TIMES: GK_MAINELITE.GK_MAINELITE_SWEEP_TIMES;
if(needRefresh && shouldRefresh(refWarCount, new Date())) {
let role = await RoleModel.updateRoleInfo(roleId, { refWarCount: new Date(), warCount: [] });
warCount = role.warCount;
}
let curWarCount = warCount.find(cur => cur.warId == warId);
let count = curWarCount? curWarCount.count: 0;
if(inc <= 0) { // checkBattle
if(count >= max) return resResult(STATUS.BATTLE_OR_SWEEP_CNT_NOT_ENOUGH);
} else { // battleEnd & battleSweep
if(count + inc > max) return resResult(STATUS.BATTLE_OR_SWEEP_CNT_NOT_ENOUGH);
}
if(inc > 0) {
if(curWarCount) {
curWarCount.count += inc;
} else {
warCount.push({ warId, count: inc });
}
await RoleModel.updateRoleInfo(roleId, { warCount });
}
return resResult(STATUS.SUCCESS);
}
export function getStarOfChapter(warStar: WarStar[], warTye: number, chapter: number) {
let starOfChapter = 0
for(let { id, star } of warStar ) {