关卡:添加扫荡次数

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