关卡:添加扫荡次数
This commit is contained in:
@@ -12,7 +12,7 @@ import { STATUS } from '../../../consts/statusCode';
|
|||||||
import { resResult } from '../../../pubUtils/util';
|
import { resResult } from '../../../pubUtils/util';
|
||||||
import { RoleModel } from '../../../db/Role';
|
import { RoleModel } from '../../../db/Role';
|
||||||
import { RScriptRecordModel } from '../../../db/RScriptRecord';
|
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 { checkDungeonNum, checkDungeonAndIncrease, saveDungeonFirst } from '../../../services/dungeonService';
|
||||||
// import { switchOnFunc } from '../../../services/funcSwitchService';
|
// import { switchOnFunc } from '../../../services/funcSwitchService';
|
||||||
import { gameData } from '../../../pubUtils/data';
|
import { gameData } from '../../../pubUtils/data';
|
||||||
@@ -53,7 +53,7 @@ export class NormalBattleHandler {
|
|||||||
if (!warInfo) {
|
if (!warInfo) {
|
||||||
return resResult(STATUS.BATTLE_MISS_INFO);
|
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 apJson = await getAp(roleId, ip, role.lv);
|
||||||
let { ap } = apJson;
|
let { ap } = apJson;
|
||||||
if (ap < warInfo.cost) {
|
if (ap < warInfo.cost) {
|
||||||
@@ -62,10 +62,11 @@ export class NormalBattleHandler {
|
|||||||
if(role.lv < warInfo.lvLimited) {
|
if(role.lv < warInfo.lvLimited) {
|
||||||
return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
|
return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
|
||||||
}
|
}
|
||||||
// 前置关卡是否挑战过
|
// 前置关卡是否挑战过
|
||||||
|
let { warStar } = role;
|
||||||
|
|
||||||
let previousGk = warInfo.previousGk;
|
let previousGk = warInfo.previousGk;
|
||||||
if (previousGk) {
|
if (previousGk) {
|
||||||
let { warStar } = await RoleModel.findByRoleId(roleId);
|
|
||||||
let preBattle = warStar.findIndex(cur => cur.id == previousGk);
|
let preBattle = warStar.findIndex(cur => cur.id == previousGk);
|
||||||
if (preBattle == -1) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
if (preBattle == -1) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,12 @@ export class NormalBattleHandler {
|
|||||||
let dailyNum = {};
|
let dailyNum = {};
|
||||||
let towerData = {};
|
let towerData = {};
|
||||||
let dungeonNum = {};
|
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);
|
let checkResult = await checkDaily(roleId, battleId, 1);
|
||||||
if (checkResult.status == -1) {
|
if (checkResult.status == -1) {
|
||||||
return checkResult.resResult
|
return checkResult.resResult
|
||||||
@@ -169,7 +175,7 @@ export class NormalBattleHandler {
|
|||||||
return resResult(STATUS.BATTLE_INFO_VALIDATE_ERR);
|
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)); // 扣除体力
|
let apJson = await setAp(serverId, roleId, ip, role.lv, isSuccess? -1 * warInfo.cost: 0, sid, getReasonByWarType(warInfo.warType)); // 扣除体力
|
||||||
if (!apJson) {
|
if (!apJson) {
|
||||||
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
|
||||||
@@ -181,8 +187,15 @@ export class NormalBattleHandler {
|
|||||||
let dailyNum = {};
|
let dailyNum = {};
|
||||||
let towerStatus = null;
|
let towerStatus = null;
|
||||||
let dungeonNum = {};
|
let dungeonNum = {};
|
||||||
|
if(warInfo.warType == WAR_TYPE.NORMAL || warInfo.warType == WAR_TYPE.MAIN_ELITE) {
|
||||||
if (warInfo.warType == WAR_TYPE.DAILY) {
|
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);
|
let checkResult = await checkDailyAndIncrease(roleId, warStar, battleId, isSuccess?1:0, false, stars, role);
|
||||||
if (checkResult.status == -1) {
|
if (checkResult.status == -1) {
|
||||||
return checkResult.resResult;
|
return checkResult.resResult;
|
||||||
@@ -312,18 +325,16 @@ export class NormalBattleHandler {
|
|||||||
if (!curWar || curWar.star < 3) {
|
if (!curWar || curWar.star < 3) {
|
||||||
return resResult(STATUS.BATTLE_SWEEP_CONDITION_STAR);
|
return resResult(STATUS.BATTLE_SWEEP_CONDITION_STAR);
|
||||||
}
|
}
|
||||||
|
let role = await RoleModel.findByRoleId(roleId, 'lv warCount refWarCount roleId');
|
||||||
// 扣体力
|
|
||||||
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 dailyNum = {};
|
let dailyNum = {};
|
||||||
let dungeonNum = {};
|
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);
|
let checkResult = await checkDailyAndIncrease(roleId, warStar, battleId, count, true);
|
||||||
if (checkResult.status == -1) {
|
if (checkResult.status == -1) {
|
||||||
return checkResult.resResult
|
return checkResult.resResult
|
||||||
@@ -337,6 +348,13 @@ export class NormalBattleHandler {
|
|||||||
dungeonNum = Object.assign(dungeonNum, checkResult.data)
|
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 warReward = new WarReward(roleId, roleName, sid, battleId, true);
|
||||||
let result = await warReward.saveReward(count, true);
|
let result = await warReward.saveReward(count, true);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { HeroModel, HeroType } from '../db/Hero';
|
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 { getLvByExp, getExpByLv, gameData, getDicApByLv } from '../pubUtils/data';
|
||||||
import { updateRoleOnlineInfo, updateUserInfo } from './redisService';
|
import { updateRoleOnlineInfo, updateUserInfo } from './redisService';
|
||||||
// import { switchOnFunc } from './funcSwitchService';
|
// import { switchOnFunc } from './funcSwitchService';
|
||||||
@@ -11,7 +11,7 @@ import { Rank } from './rankService';
|
|||||||
import { checkTask } from './task/taskService';
|
import { checkTask } from './task/taskService';
|
||||||
import { RScriptRecordModel } from '../db/RScriptRecord';
|
import { RScriptRecordModel } from '../db/RScriptRecord';
|
||||||
import { setAp } from './actionPointService';
|
import { setAp } from './actionPointService';
|
||||||
import { resResult } from '../pubUtils/util';
|
import { resResult, shouldRefresh } from '../pubUtils/util';
|
||||||
import { GuildLeader, LineupParam } from '../domain/rank';
|
import { GuildLeader, LineupParam } from '../domain/rank';
|
||||||
import { WarStar } from '../domain/dbGeneral';
|
import { WarStar } from '../domain/dbGeneral';
|
||||||
import { uniq } from 'underscore';
|
import { uniq } from 'underscore';
|
||||||
@@ -19,6 +19,7 @@ import { checkPopUpCondition } from './activity/popUpShopService';
|
|||||||
import { calculateCeWithRole } from './playerCeService';
|
import { calculateCeWithRole } from './playerCeService';
|
||||||
import { sendMessageToUserWithSuc } from './pushService';
|
import { sendMessageToUserWithSuc } from './pushService';
|
||||||
import { ActionPointModel } from '../db/ActionPoint';
|
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) {
|
export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kingExp: number = 0, session: BackendSession) {
|
||||||
const serverId = session.get('serverId');
|
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) {
|
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);
|
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 });
|
result = result.sort((a, b) => { return a.battleId - b.battleId });
|
||||||
return result;
|
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) {
|
export function getStarOfChapter(warStar: WarStar[], warTye: number, chapter: number) {
|
||||||
let starOfChapter = 0
|
let starOfChapter = 0
|
||||||
for(let { id, star } of warStar ) {
|
for(let { id, star } of warStar ) {
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export const STATUS = {
|
|||||||
BATTLE_SWEEP_CONDITION_STAR: { code: 20102, simStr: '需要3星通过关卡才可以扫荡' },
|
BATTLE_SWEEP_CONDITION_STAR: { code: 20102, simStr: '需要3星通过关卡才可以扫荡' },
|
||||||
BATTLE_NO_BOX_CAN_RECEIVE: { code: 20103, simStr: '宝箱不可领取' },
|
BATTLE_NO_BOX_CAN_RECEIVE: { code: 20103, simStr: '宝箱不可领取' },
|
||||||
BATTLE_NO_WAR_REWARD_CAN_RECEIVE: { code: 20104, simStr: '没有可领取的关卡奖励' },
|
BATTLE_NO_WAR_REWARD_CAN_RECEIVE: { code: 20104, simStr: '没有可领取的关卡奖励' },
|
||||||
|
BATTLE_OR_SWEEP_CNT_NOT_ENOUGH: { code: 20105, simStr: '挑战或扫荡次数不足' },
|
||||||
// 每日 20200 - 20299
|
// 每日 20200 - 20299
|
||||||
DAILY_WAR_NOT_FOUND: { code: 20201, simStr: '未找到该关卡' },
|
DAILY_WAR_NOT_FOUND: { code: 20201, simStr: '未找到该关卡' },
|
||||||
DAILY_TYPE_NOT_FOUND: { code: 20202, simStr: '未找到该类型' },
|
DAILY_TYPE_NOT_FOUND: { code: 20202, simStr: '未找到该类型' },
|
||||||
|
|||||||
@@ -44,6 +44,13 @@ export class WarStar {
|
|||||||
stars: number[]; // 星级
|
stars: number[]; // 星级
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class WarCount {
|
||||||
|
@prop({ required: true })
|
||||||
|
warId: number; // 关卡 id
|
||||||
|
@prop({ required: true })
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class Teraph {
|
export class Teraph {
|
||||||
@prop({ required: true, default: 1 })
|
@prop({ required: true, default: 1 })
|
||||||
id: number; // 神像的id
|
id: number; // 神像的id
|
||||||
@@ -190,6 +197,10 @@ export default class Role extends BaseModel {
|
|||||||
|
|
||||||
@prop({ required: true, type: WarStar, default: [], _id: false })
|
@prop({ required: true, type: WarStar, default: [], _id: false })
|
||||||
warStar: WarStar[]; // 关卡星级
|
warStar: WarStar[]; // 关卡星级
|
||||||
|
@prop({ required: true, type: WarCount, default: [], _id: false })
|
||||||
|
warCount: WarCount[]; // 关卡星级
|
||||||
|
@prop({ required: true })
|
||||||
|
refWarCount: Date; // 刷新关卡次数
|
||||||
|
|
||||||
@prop({ required: true, default: 1 })
|
@prop({ required: true, default: 1 })
|
||||||
loginCnt: number; // 登录次数
|
loginCnt: number; // 登录次数
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export const PVP = {
|
|||||||
PVP_CHALLENGE_COUNTS: 5, // pvp初始挑战次数
|
PVP_CHALLENGE_COUNTS: 5, // pvp初始挑战次数
|
||||||
PVP_CHALLENGE_NORMALTIMES: 240, // pvp日常挑战次数刷新时间(分钟)
|
PVP_CHALLENGE_NORMALTIMES: 240, // pvp日常挑战次数刷新时间(分钟)
|
||||||
PVP_CHALLENGE_FINALTIMES: 240, // PVP赛季最后一天挑战次数刷新时间(分钟)
|
PVP_CHALLENGE_FINALTIMES: 240, // PVP赛季最后一天挑战次数刷新时间(分钟)
|
||||||
PVP_SEASON_DAYS: '1&7|2&30|3&30|4&30', // PVP一个赛季的时间
|
PVP_SEASON_DAYS: '1&30|2&30|3&30|4&30', // PVP一个赛季的时间
|
||||||
PVP_OPPONENT_FREEREFRESH: 3, // pvp挑战对手每日免费刷新次数
|
PVP_OPPONENT_FREEREFRESH: 3, // pvp挑战对手每日免费刷新次数
|
||||||
PVP_WINREWARD_UPLIMIT: 10, // 连胜奖励军功加成上限
|
PVP_WINREWARD_UPLIMIT: 10, // 连胜奖励军功加成上限
|
||||||
PVP_LINEUP_HEROS: 6, // pvp最多上阵人数
|
PVP_LINEUP_HEROS: 6, // pvp最多上阵人数
|
||||||
@@ -238,6 +238,7 @@ export const NAMEPLATE = {
|
|||||||
};
|
};
|
||||||
export const GK_MAINELITE = {
|
export const GK_MAINELITE = {
|
||||||
GKMAINELITE_OPEN_CONDITION: 424, // 梦魇模式开启时间:通过某关卡id
|
GKMAINELITE_OPEN_CONDITION: 424, // 梦魇模式开启时间:通过某关卡id
|
||||||
|
GK_MAINELITE_SWEEP_TIMES: 6, // 梦魇每个主城扫荡次数上限
|
||||||
};
|
};
|
||||||
export const SERVER_DEBUG_MODE = {
|
export const SERVER_DEBUG_MODE = {
|
||||||
CURRENT_TIME: 1, // 服务器是否打开推送时间debug模式
|
CURRENT_TIME: 1, // 服务器是否打开推送时间debug模式
|
||||||
@@ -306,3 +307,17 @@ export const INFO_WINDOW = {
|
|||||||
REFRESH_TIME: 10, // 刷新冷却时间(s)
|
REFRESH_TIME: 10, // 刷新冷却时间(s)
|
||||||
TEAM_INFORMATION_TIME: 60, // 显示的组队信息时间(s)
|
TEAM_INFORMATION_TIME: 60, // 显示的组队信息时间(s)
|
||||||
};
|
};
|
||||||
|
export const GK_MAIN = {
|
||||||
|
GK_MAIN_SWEEP_TIMES: 5, // 主线每个主城扫荡次数上限
|
||||||
|
};
|
||||||
|
export const LADDER = {
|
||||||
|
LADDER_INITIAL_POSITION: 3001, // 名将擂台玩家初次匹配的默认名次
|
||||||
|
LADDER_BATTLE_PREPARE_COUNTDOWN: 120, // 名将擂台战场出战准备界面倒计时(s)
|
||||||
|
LADDER_BATTLE_COUNTDOWN: 300, // 名将擂台战场出战准备界面倒计时(s)
|
||||||
|
LADDER_REFRESH_TIMES: 5, // 名将擂台每天刷新次数限制
|
||||||
|
LADDER_CHALLENGE_FREE_TIMES: 5, // 名将擂台每天免费挑战次数
|
||||||
|
LADDER_CHALLENGE_COST_TIMES: 50, // 名将擂台每天购买挑战次数上限
|
||||||
|
LADDER_CHALLENGE_BUY_TIMES_COST: '31002&20&20|31002&50&10|31002&100&10|31002&200&10', // 名将擂台每天购买挑战次数花费 物品id&数量&购买次数
|
||||||
|
LADDER_ROBOT_NAME: '擂台守卫者', // 机器人默认名
|
||||||
|
LADDER_INITIAL_CHALLENGE_TIMES: 5, // 战5次
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user