✨ feat(pvp): 巅峰演武战区化
This commit is contained in:
@@ -33,9 +33,10 @@ import { loadGmDb } from './app/db';
|
||||
import { loadActivities } from './app/services/activity/activityRemoteService';
|
||||
import { checkAndSetApiIsClose } from './app/services/chatService';
|
||||
import { initGuildActivityIndexInPinus, resetJoinWoodenHorse } from './app/services/guildActivity/guildActivityService';
|
||||
import { setGVGConfig, setGVGServerGroup } from './app/services/gvg/gvgService';
|
||||
import { setGVGConfig } from './app/services/gvg/gvgService';
|
||||
import { isDevelopEnv } from './app/services/utilService';
|
||||
import { initTeamToMem } from './app/services/gvg/gvgBattleMemory';
|
||||
import { setServerGroup } from './app/services/serverService';
|
||||
|
||||
const filePath = (_pinus as any).FILEPATH;
|
||||
filePath.MASTER = '/config/master';
|
||||
@@ -203,8 +204,8 @@ async function treatStartLogic(app: _pinus.Application) {
|
||||
if(app.getServerType() != 'systimer') {
|
||||
timeTaskService.initHiddenData();
|
||||
}
|
||||
if(app.getServerType() == 'guild'|| app.getServerType() == 'chat'|| app.getServerType() == 'connector' || app.getServerType() == 'systimer' || app.getServerType() == 'gm') {
|
||||
setGVGServerGroup();
|
||||
if(app.getServerType() == 'battle'|| app.getServerType() == 'guild'|| app.getServerType() == 'chat'|| app.getServerType() == 'connector' || app.getServerType() == 'systimer' || app.getServerType() == 'gm') {
|
||||
setServerGroup();
|
||||
}
|
||||
if(app.getServerType() == 'guild') {
|
||||
setGVGConfig()
|
||||
|
||||
@@ -29,6 +29,7 @@ import { PVPConfigModel } from '../../../db/PvpConfig';
|
||||
import { getAllServerName, getServerName } from '../../../services/redisService';
|
||||
import { RoleRankInfo } from '../../../domain/rank';
|
||||
import { isHeroHidden } from '../../../services/dataService';
|
||||
import { getPVPGroupIdOfServer } from '../../../services/serverService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -42,6 +43,7 @@ export class PvpHandler {
|
||||
//1获取主界面
|
||||
async getData(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let serverId = session.get('serverId');
|
||||
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
let seasonStartTime: number = this.app.get('pvpSeasonStartTime');
|
||||
@@ -90,8 +92,9 @@ export class PvpHandler {
|
||||
result.setPvpSeasonResult(pvpSeasonResult);
|
||||
await PvpSeasonResultModel.setShow(roleId);
|
||||
}
|
||||
// 拍卖
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
// 排行榜
|
||||
let groupId = await getPVPGroupIdOfServer(serverId);
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
let myRank = await r.getMyRank({ roleId });//去redis中获取排名
|
||||
result.setMyRank(myRank);
|
||||
|
||||
@@ -285,7 +288,8 @@ export class PvpHandler {
|
||||
|
||||
if(seasonNum == pvpSeasonNum) {
|
||||
// 加入排行榜
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: pvpSeasonNum });
|
||||
let groupId = await getPVPGroupIdOfServer(serverId);
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: pvpSeasonNum, groupId });
|
||||
await r.setRankWithRoleInfo(roleId, pvpDefense.score, pvpDefense.updatedAt.getTime(), role);
|
||||
let myRank = await r.getMyRank({ roleId });
|
||||
result.setMyRank(myRank);
|
||||
@@ -482,6 +486,7 @@ export class PvpHandler {
|
||||
async getRank(msg: {}, session: BackendSession) {
|
||||
|
||||
let roleId = session.get('roleId');
|
||||
let serverId = session.get('serverId');
|
||||
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
if(checkPvpSeasonIsWaiting()) { // 休赛期
|
||||
@@ -489,7 +494,8 @@ export class PvpHandler {
|
||||
}
|
||||
|
||||
let serverNames = await getAllServerName();
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let groupId = await getPVPGroupIdOfServer(serverId);
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
r.setGenerFieldsFun(function (param: RoleRankInfo) {
|
||||
let { serverId } = param;
|
||||
return { ...param, serverName: serverNames[serverId]||'无' };
|
||||
@@ -557,7 +563,8 @@ export class PvpHandler {
|
||||
}
|
||||
heroes.sort((a, b) => b.score - a.score);
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let groupId = await getPVPGroupIdOfServer(serverId);
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
let rank = await r.getMyRank({ roleId: oppoRoleId });//去redis中获取排名
|
||||
|
||||
result = new PlayerDetail(oppoRoleId, heroes, rank);
|
||||
@@ -657,7 +664,8 @@ export class PvpHandler {
|
||||
|
||||
// 加入排行榜
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let groupId = await getPVPGroupIdOfServer(serverId);
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
await r.setRankWithRoleInfo(roleId, pvpDefense.score, pvpDefense.updatedAt.getTime(), role);
|
||||
|
||||
// 任务
|
||||
|
||||
@@ -4,8 +4,10 @@ import { reloadResources } from '../../../pubUtils/data';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setHiddenData } from '../../../services/dataService';
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { setServerGroup } from '../../../services/serverService';
|
||||
import { savePvpSeasonMemory } from '../../../services/log/memoryLogService';
|
||||
import { setKvToMemory } from '../../../services/pushService';
|
||||
import { getPvpTime } from '../../../services/pvpService';
|
||||
import { taflush } from '../../../services/sdkService';
|
||||
import { setPvpSeasonNum, setPvpSettleSeasonNum } from '../../../services/timeTaskService';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
@@ -109,6 +111,13 @@ export class BattleRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public async getPvpTime() {
|
||||
try {
|
||||
return getPvpTime();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public setServerMainten(serverIds: number[], startTime: number, endTime: number) {
|
||||
try {
|
||||
@@ -173,4 +182,12 @@ export class BattleRemote {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async setServerGroup() {
|
||||
try {
|
||||
return setServerGroup();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { checkTask } from '../../../services/task/taskService';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { getFriendRelationType } from '../../../services/friendService';
|
||||
import { GVGLeagueModel } from '../../../db/GVGLeague';
|
||||
import { getGroupIdOfServer } from '../../../services/gvg/gvgService';
|
||||
import { getGVGGroupIdOfServer } from '../../../services/serverService';
|
||||
import { getGuildCodeString } from '../../../services/gvg/gvgRecService';
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ export class ChatHandler {
|
||||
if (channel === CHANNEL_PREFIX.WORLD) channelId = `${serverId}`;
|
||||
if (channel === CHANNEL_PREFIX.GUILD) channelId = guildCode;
|
||||
if (channel === CHANNEL_PREFIX.GVG) {
|
||||
let groupId = await getGroupIdOfServer(serverId);
|
||||
let groupId = await getGVGGroupIdOfServer(serverId);
|
||||
channelId = `${groupId}`;
|
||||
}
|
||||
if (channel == CHANNEL_PREFIX.LEAGUE) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { errlogger } from '../../../util/logger';
|
||||
import { addUserToChannel, sendMessageToChannel, sendMessgeToChannelByBatch, setKvToMemory } from '../../../services/pushService';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setHiddenData } from '../../../services/dataService';
|
||||
import { setGVGServerGroup } from '../../../services/gvg/gvgService';
|
||||
import { setServerGroup } from '../../../services/serverService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -175,9 +175,9 @@ export class ChatRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public async setGVGServerGroup() {
|
||||
public async setServerGroup() {
|
||||
try {
|
||||
return setGVGServerGroup();
|
||||
return setServerGroup();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setPvpSeasonNum, setPvpSettleSeasonNum } from '../../../services/timeTaskService';
|
||||
import { setHiddenData } from '../../../services/dataService';
|
||||
import { setKvToMemory } from '../../../services/pushService';
|
||||
import { setGVGServerGroup } from '../../../services/gvg/gvgService';
|
||||
import { setServerGroup } from '../../../services/serverService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -204,9 +204,9 @@ export class ConnectorRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public async setGVGServerGroup() {
|
||||
public async setServerGroup() {
|
||||
try {
|
||||
return setGVGServerGroup();
|
||||
return setServerGroup();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@ import { sendMessageToAllWithSuc } from '../../../services/pushService';
|
||||
import { sendMailByContent, sendMailsByGmMail } from '../../../services/mailService';
|
||||
import { saveMemory } from '../../../services/log/memoryLogService';
|
||||
import { getGVGConfigFromRemote } from '../../../services/gvg/gvgService';
|
||||
import { GVGServerGroupModel } from '../../../db/GVGServerGroup';
|
||||
import { ServerGroupModel } from '../../../db/ServerGroup';
|
||||
import { isNumber } from 'underscore';
|
||||
import { group } from 'console';
|
||||
import { GVGConfigModel } from '../../../db/GVGConfig';
|
||||
import { ServerlistModel } from '../../../db/Serverlist';
|
||||
import { getPvpTimeFromRemote } from '../../../services/pvpService';
|
||||
|
||||
let timer: NodeJS.Timer;
|
||||
export default function (app: Application) {
|
||||
@@ -299,15 +300,17 @@ export class GmHandler {
|
||||
if(!isNumber(serverId)) return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let { scheduleTime } = await getGVGConfigFromRemote();
|
||||
let { seasonEndTime = 0 } = await getPvpTimeFromRemote();
|
||||
for(let serverId of serverIds) {
|
||||
await GVGServerGroupModel.updateByServerId(serverId, groupId, scheduleTime);
|
||||
await ServerGroupModel.updateByServerId(serverId, groupId, scheduleTime, seasonEndTime);
|
||||
}
|
||||
|
||||
try {
|
||||
await pinus.app.rpc.guild.guildRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.chat.chatRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.connector.connectorRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.gm.gmRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.systimer.systimerRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.guild.guildRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.chat.chatRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.connector.connectorRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.gm.gmRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.systimer.systimerRemote.setServerGroup.broadcast();
|
||||
} catch(e) {
|
||||
console.log('remote未初始完');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Application, ChannelService, HandlerService, } from 'pinus';
|
||||
import { setHiddenData } from '../../../services/dataService';
|
||||
import { setGVGServerGroup } from '../../../services/gvg/gvgService';
|
||||
import { setServerGroup } from '../../../services/serverService';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -37,9 +37,9 @@ export class GMRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public async setGVGServerGroup() {
|
||||
public async setServerGroup() {
|
||||
try {
|
||||
await setGVGServerGroup();
|
||||
await setServerGroup();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { GVGLeagueModel } from "../../../db/GVGLeague";
|
||||
import { GVGLeaguePrepareModel } from "../../../db/GVGLeaguePrepare";
|
||||
import { GuardCityInfoPage, GVGMainData, LeagueContributeInfo, LeagueMemberContributeInfo, LeagueRankInInfoPage } from "../../../domain/gvgField/returnData";
|
||||
import { getRandEelm, resResult } from "../../../pubUtils/util";
|
||||
import { calLeagueCe, getGroupIdOfServer, getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType, getServerTypeByTime } from "../../../services/gvg/gvgService";
|
||||
import { calLeagueCe, getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType, getServerTypeByTime } from "../../../services/gvg/gvgService";
|
||||
import { autoCreateLeague, checkCanChooseJob, checkCanPrepare, checkLeagueAuth, getMyAuth } from "../../../services/gvg/gvgTeamService";
|
||||
import { getAllServerName } from "../../../services/redisService";
|
||||
import { Contribute, GVGUserDataModel } from "../../../db/GVGUserData";
|
||||
|
||||
@@ -4,7 +4,7 @@ import { resResult } from "../../../pubUtils/util";
|
||||
import { GuildModel, GuildType } from "../../../db/Guild";
|
||||
import { GVGLeagueModel, GVGLeagueType } from "../../../db/GVGLeague";
|
||||
import { GVGLeagueApplyModel } from "../../../db/GVGLeagueApply";
|
||||
import { calLeagueCe, getGroupIdOfServer, getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType, getServersOfSameGroup } from "../../../services/gvg/gvgService";
|
||||
import { calLeagueCe, getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType } from "../../../services/gvg/gvgService";
|
||||
import { checkCanManage, checkGuildLeader, checkLeagueAuth, createLeague, getLeagueApplyData, getLeagueInviteData, getMyAuth, joinGuildToLeague, updateGVGBattleLeagueInfo } from "../../../services/gvg/gvgTeamService";
|
||||
import { LeagueGuildInfo, LeagueListInfo, LeagueMemberListInfo, LeagueSimpleInfo } from "../../../domain/gvgField/returnData";
|
||||
import { getAllServerName, getServerName, isRoleOnline, updateUserInfo } from "../../../services/redisService";
|
||||
@@ -19,6 +19,7 @@ import { getGVGCities } from "../../../services/gvg/gvgBattleService";
|
||||
import { addLeagueRenameRecord, changeNoticeMessage, guildQuitLeagueRecord } from "../../../services/gvg/gvgRecService";
|
||||
import { LeagueLeader } from "../../../domain/rank";
|
||||
import GVGCity from "../../../db/GVGCity";
|
||||
import { getGVGGroupIdOfServer, getGVGServersOfSameGroup } from "../../../services/serverService";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -70,7 +71,7 @@ export class GVGManageHandler {
|
||||
if(serverType == GVG_SERVER_TYPE.NO) return resResult(STATUS.GVG_NO_SERVER_TYPE);
|
||||
|
||||
const serverNames = await getAllServerName();
|
||||
let serverIds = await getServersOfSameGroup(serverType, serverId);
|
||||
let serverIds = await getGVGServersOfSameGroup(serverType, serverId);
|
||||
const leagues = await GVGLeagueModel.findByCondition(serverType, serverIds, page, name);
|
||||
const applies = await GVGLeagueApplyModel.findApplyFromGuild(guildCode);
|
||||
let result: LeagueListInfo[] = [];
|
||||
@@ -220,7 +221,7 @@ export class GVGManageHandler {
|
||||
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
|
||||
|
||||
const invitations = await GVGLeagueApplyModel.findInviteFromLeague(myLeague.leagueCode);
|
||||
const serverIds = await getServersOfSameGroup(serverType, serverId);
|
||||
const serverIds = await getGVGServersOfSameGroup(serverType, serverId);
|
||||
const serverNames = await getAllServerName();
|
||||
const guilds = await GuildModel.findGuildsForGVG(page, name, serverIds);
|
||||
let result = guilds.map(guild => {
|
||||
@@ -678,7 +679,7 @@ export class GVGManageHandler {
|
||||
if(!checkAuth) return resResult(STATUS.GVG_HAS_NO_AUTH);
|
||||
|
||||
// 发送战区频道消息
|
||||
const groupId = await getGroupIdOfServer(serverId);
|
||||
const groupId = await getGVGGroupIdOfServer(serverId);
|
||||
let channelId = `${groupId}`;
|
||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.GVG, channelId, MSG_TYPE.RICH_TEXT, MSG_SOURCE.GVG_RECURIT, JSON.stringify({ leagueCode: myLeague.leagueCode, name: myLeague.name, info: content }), '', '');
|
||||
if (!msgData) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
@@ -6,12 +6,13 @@ import { errlogger } from '../../../util/logger';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setHiddenData } from '../../../services/dataService';
|
||||
import { setKvToMemory } from '../../../services/pushService';
|
||||
import { getGVGConfig, setGVGConfig, setGVGServerGroup } from '../../../services/gvg/gvgService';
|
||||
import { getGVGConfig, setGVGConfig } from '../../../services/gvg/gvgService';
|
||||
import { GVGConfigType } from '../../../db/GVGConfig';
|
||||
import { catapultHurt, gvgBattleEnd, gvgBattleSeconds, gvgBattleStart, initCatapult, leaveCityMem } from '../../../services/gvg/gvgBattleService';
|
||||
import { clearBattleMemory } from '../../../services/gvg/gvgBattleMemory';
|
||||
import { updateLeagueNameMem, updateTeamRoleInfoMem } from '../../../services/gvg/gvgTeamService';
|
||||
import { resetPeriodTime, setPeriodTime } from '../../../services/gvg/gvgFightService';
|
||||
import { setServerGroup } from '../../../services/serverService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -115,9 +116,9 @@ export class GuildRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public async setGVGServerGroup() {
|
||||
public async setServerGroup() {
|
||||
try {
|
||||
return setGVGServerGroup();
|
||||
return setServerGroup();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import { GUILD_ACTIVITY_TYPE, LADDER_STATUS } from '../../../consts';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setHiddenData } from '../../../services/dataService';
|
||||
import { setKvToMemory } from '../../../services/pushService';
|
||||
import { setGVGServerGroup } from '../../../services/gvg/gvgService';
|
||||
import { setServerGroup } from '../../../services/serverService';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new SystimerRemote(app);
|
||||
@@ -276,9 +276,9 @@ export class SystimerRemote {
|
||||
}
|
||||
}
|
||||
|
||||
public async setGVGServerGroup() {
|
||||
public async setServerGroup() {
|
||||
try {
|
||||
await setGVGServerGroup();
|
||||
await setServerGroup();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import { sendMessageToAllWithSuc, sendMessageToCityWithSuc, sendMessageToGuildWi
|
||||
import { comBtlLvInvalid } from './comBattleService';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { RegionModel } from '../db/Region';
|
||||
import { getGroupIdOfServer, getServersByGroupId } from './gvg/gvgService';
|
||||
import { getGVGGroupIdOfServer, getGVGServersByGroupId } from './serverService';
|
||||
import { GVGLeagueModel } from '../db/GVGLeague';
|
||||
|
||||
export * from './chatChannelService';
|
||||
@@ -167,7 +167,7 @@ export async function pushGroupMsgToRoom(msg: GroupMessageType) {
|
||||
await sendMessageToCityWithSuc(parseInt(arr[0]), parseInt(arr[1]), PUSH_ROUTE.GROUP_MSG, { ...msg, roleInfo });
|
||||
} else if (msg.channel == CHANNEL_PREFIX.GVG) {
|
||||
let groupId = parseInt(msg.channelId);
|
||||
let serverIds = await getServersByGroupId(groupId);
|
||||
let serverIds = await getGVGServersByGroupId(groupId);
|
||||
for(let serverId of serverIds) {
|
||||
await sendMessageToServerWithSuc(serverId, PUSH_ROUTE.GROUP_MSG, { ...msg, roleInfo });
|
||||
}
|
||||
@@ -236,7 +236,7 @@ async function recentGroupMsgs(roomId: string, count?: number) {
|
||||
* @returns
|
||||
*/
|
||||
export async function recentServerGroupMsgs(serverId: number, count?: number) {
|
||||
let groupId = await getGroupIdOfServer(serverId);
|
||||
let groupId = await getGVGGroupIdOfServer(serverId);
|
||||
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.GVG, groupId), count);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import { isDevelopEnv } from "../utilService";
|
||||
import { addGVGReward, combinePushItem } from "./gvgItemService";
|
||||
import { calFighterContribute } from "./gvgPrepareService";
|
||||
import { addVestigeLeagueRankRec, addVestigeRankMessage } from "./gvgRecService";
|
||||
import { getGroupIdOfServer, getGroupKey, getGVGServerType, getPeriodByTime } from "./gvgService";
|
||||
import { getGroupKey, getGVGServerType, getPeriodByTime } from "./gvgService";
|
||||
|
||||
let gvgFightTime = undefined;
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { pinus } from "pinus";
|
||||
import { GVGConfigModel, GVGConfigType } from "../../db/GVGConfig";
|
||||
import { getTimeFun, getZeroPoint, getZeroPointOfTime, nowSeconds, WEEK_TO_SECOND } from "../../pubUtils/timeUtil";
|
||||
import { getAllServerCreateTime, getServerCreateTime } from "../redisService";
|
||||
import { GVG_PERIOD, GVG_SERVER_TYPE, LEAGUE_JOB, PUSH_ROUTE, SHOP_REFRESH_TYPE } from "../../consts";
|
||||
import { getTimeFun, nowSeconds, WEEK_TO_SECOND } from "../../pubUtils/timeUtil";
|
||||
import { getServerCreateTime } from "../redisService";
|
||||
import { GVG_PERIOD, GVG_SERVER_TYPE, LEAGUE_JOB, PUSH_ROUTE } from "../../consts";
|
||||
import { GVGLeagueModel, GVGLeagueType } from "../../db/GVGLeague";
|
||||
import { GVGLeaguePrepareModel } from "../../db/GVGLeaguePrepare";
|
||||
import { GVGServerGroupModel } from "../../db/GVGServerGroup";
|
||||
import { gameData } from "../../pubUtils/data";
|
||||
import { getRandSingleEelm } from "../../pubUtils/util";
|
||||
import { GVG } from "../../pubUtils/dicParam";
|
||||
import { ServerlistModel } from "../../db/Serverlist";
|
||||
import { GuildModel, GuildType } from "../../db/Guild";
|
||||
import { GVGLeagueApplyModel } from "../../db/GVGLeagueApply";
|
||||
import { GVGMainData, LeagueContributeInfo } from "../../domain/gvgField/returnData";
|
||||
@@ -26,6 +24,7 @@ import { GVGTeamModel } from "../../db/GVGTeam";
|
||||
import { sendMessageToGuildWithSuc } from "../pushService";
|
||||
import { GVGCityModel } from "../../db/GVGCity";
|
||||
import { GVGRoleDataModel } from "../../db/GVGRoleData";
|
||||
import { getGVGGroupIdOfServer } from "../serverService";
|
||||
|
||||
// 定时器相关
|
||||
export async function createNewGVGConfig() {
|
||||
@@ -33,11 +32,11 @@ export async function createNewGVGConfig() {
|
||||
const config = await GVGConfigModel.createNewConfig(teamTime, prepareTime, battleTime, scheduleTime);
|
||||
try {
|
||||
await pinus.app.rpc.guild.guildRemote.setGVGConfig.broadcast(config);
|
||||
await pinus.app.rpc.guild.guildRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.chat.chatRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.connector.connectorRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.gm.gmRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.systimer.systimerRemote.setGVGServerGroup.broadcast();
|
||||
await pinus.app.rpc.guild.guildRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.chat.chatRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.connector.connectorRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.gm.gmRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.systimer.systimerRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.guild?.guildRemote?.clearBattleMemory.broadcast();
|
||||
} catch(e) {
|
||||
console.log('remote未初始完');
|
||||
@@ -165,7 +164,7 @@ export function getGVGPeriodData() {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('######## getGVGPeriodData', configId, teamTime, prepareTime, battleTime, scheduleTime)
|
||||
// console.log('######## getGVGPeriodData', configId, teamTime, prepareTime, battleTime, scheduleTime)
|
||||
return { configId, period, countdownTime };
|
||||
}
|
||||
|
||||
@@ -203,41 +202,6 @@ export async function initLeaguePrepare() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function setGVGServerGroup() {
|
||||
const servers = await ServerlistModel.findByEnv(pinus.app.get('env'));
|
||||
const serverGroups = await GVGServerGroupModel.findByTime(nowSeconds());
|
||||
pinus.app.set('gvgServerGroup', servers.map(obj => {
|
||||
let server = serverGroups.find(cur => cur.serverId == obj.id);
|
||||
return { serverId: obj.id, groupId: server? server.groupId: obj.groupId }
|
||||
}));
|
||||
}
|
||||
|
||||
// 查询本小区所在的战区
|
||||
// gvgServerGroup: id-小区唯一id serverId-小区在大区下的id
|
||||
export async function getGroupIdOfServer(id: number) {
|
||||
let arr: { serverId: number; groupId: number }[] = pinus.app.get('gvgServerGroup')||[];
|
||||
let obj = arr.find(cur => cur.serverId == id);
|
||||
return obj?.groupId||0;
|
||||
}
|
||||
|
||||
// 查询当前和本小区同一个战区的其他小区
|
||||
export async function getServersOfSameGroup(type: GVG_SERVER_TYPE, id: number) {
|
||||
if(type == GVG_SERVER_TYPE.SINGLE) return [id];
|
||||
|
||||
let groupId = await getGroupIdOfServer(id);
|
||||
return await getServersByGroupId(groupId);
|
||||
}
|
||||
|
||||
export async function getServersByGroupId(groupId: number) {
|
||||
let arr: { serverId: number; groupId: number }[] = pinus.app.get('gvgServerGroup')||[];
|
||||
let serverCreateTimes = await getAllServerCreateTime();
|
||||
|
||||
return arr.filter(obj => {
|
||||
let openTime = parseInt(serverCreateTimes[obj.serverId]);
|
||||
return obj.groupId == groupId && getServerTypeByTime(openTime) == GVG_SERVER_TYPE.MULTI;
|
||||
}).map(obj => obj.serverId);
|
||||
}
|
||||
|
||||
export async function getGVGInfoInGuild(roleId: string, guild: GuildType) {
|
||||
let hasLeague = !!guild.leagueCode;
|
||||
let serverId = guild.serverId;
|
||||
@@ -344,7 +308,7 @@ export async function getGroupKey(serverId: number) {
|
||||
if(serverType == GVG_SERVER_TYPE.SINGLE) {
|
||||
return `s${serverId}`;
|
||||
} else {
|
||||
let groupId = await getGroupIdOfServer(serverId);
|
||||
let groupId = await getGVGGroupIdOfServer(serverId);
|
||||
return `g${groupId}`;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ import { getVipPvpChallengeMaxCnt } from './activity/monthlyTicketService';
|
||||
import { getHeroesAttributes } from './playerCeService';
|
||||
import { setPvpSettleSeasonNumToRemote } from './timeTaskService';
|
||||
import { ArtifactModel } from '../db/Artifact';
|
||||
import { getPVPGroupIdOfServer, getPvpServersByGroupId } from './serverService';
|
||||
import { findKeys } from './redisService';
|
||||
|
||||
/**
|
||||
* 返回对手三人信息
|
||||
@@ -61,15 +63,16 @@ export async function getEnemies(oppPlayers: OppPlayer[], winStreakNum: number)
|
||||
* @param pLv 我的排名
|
||||
*/
|
||||
export async function refreshEnemies(role: RoleType, seasonNum: number, sumScore: number, score: number, pLv: number) {
|
||||
let { roleId } = role;
|
||||
let { roleId, serverId } = role;
|
||||
let groupId = await getPVPGroupIdOfServer(serverId);
|
||||
let chosenOpps: string[] = [];
|
||||
let pvpHistoryOppParam: PvpOppCreateParam[] = [];
|
||||
let opp = dicPvpOpponent.values()
|
||||
for (let dicOpp of opp) {
|
||||
let pvpHistoryOpp: PvpOppCreateParam; // 是否筛选成功
|
||||
if (sumScore >= PVP.PVP_MATCH_ROBOT) {
|
||||
pvpHistoryOpp = await matchPlayer(seasonNum, chosenOpps, roleId, pLv, dicOpp); // 按照等级匹配对手
|
||||
if (!pvpHistoryOpp) pvpHistoryOpp = await matchPlayerByRank(seasonNum, chosenOpps, roleId, dicOpp.id); // 当前后分数段没有时,返回前一名的玩家
|
||||
pvpHistoryOpp = await matchPlayer(groupId, seasonNum, chosenOpps, roleId, pLv, dicOpp); // 按照等级匹配对手
|
||||
if (!pvpHistoryOpp) pvpHistoryOpp = await matchPlayerByRank(groupId, seasonNum, chosenOpps, roleId, dicOpp.id); // 当前后分数段没有时,返回前一名的玩家
|
||||
if (!pvpHistoryOpp) pvpHistoryOpp = await matchRobot(chosenOpps, role, score, dicOpp);
|
||||
} else {
|
||||
pvpHistoryOpp = await matchRobot(chosenOpps, role, score, dicOpp);
|
||||
@@ -97,9 +100,9 @@ export async function refreshEnemies(role: RoleType, seasonNum: number, sumScore
|
||||
return oppPlayers;
|
||||
}
|
||||
|
||||
export async function matchPlayerByRank(seasonNum: number, chosenOpps: string[], roleId: string, pos: number) {
|
||||
export async function matchPlayerByRank(groupId: number, seasonNum: number, chosenOpps: string[], roleId: string, pos: number) {
|
||||
// console.log('matchPlayerByRank', JSON.stringify(oppPlayers))
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
let ridRanks = new Array<number>(); // 已经被使用了的排名
|
||||
for (let curRoleId of chosenOpps) {
|
||||
let rankLv = await r.getMyRank({ roleId: robotIdComBack(curRoleId) });
|
||||
@@ -167,18 +170,19 @@ export async function matchPlayerByRank(seasonNum: number, chosenOpps: string[],
|
||||
|
||||
let pvpdefense = await PvpDefenseModel.findByRoleIdIncludeAll(oppRoleId);
|
||||
if (!pvpdefense || pvpdefense.seasonNum != seasonNum || !pvpdefense.hasDefense) return null;
|
||||
let pvpHistoryOpp = await generPlayerOppHis(pvpdefense, roleId, pos);
|
||||
let pvpHistoryOpp = await generPlayerOppHis(pvpdefense, roleId, pos, groupId);
|
||||
if (!pvpHistoryOpp) return null;
|
||||
|
||||
chosenOpps.push(pvpHistoryOpp.oppRoleId);
|
||||
return pvpHistoryOpp;
|
||||
}
|
||||
|
||||
async function matchPlayer(seasonNum: number, chosenOpps: string[], roleId: string, pLv: number, dicOpp: DicPvpOpponent) {
|
||||
async function matchPlayer(groupId: number, seasonNum: number, chosenOpps: string[], roleId: string, pLv: number, dicOpp: DicPvpOpponent) {
|
||||
// console.log('matchPlayer', JSON.stringify(oppPlayers))
|
||||
|
||||
let serverIds = await getPvpServersByGroupId(groupId);
|
||||
let { id: pos, minLv, maxLv } = dicOpp
|
||||
let range = await PvpDefenseModel.findByTeamLv(seasonNum, pLv + minLv, pLv + maxLv);
|
||||
let range = await PvpDefenseModel.findByTeamLv(serverIds, seasonNum, pLv + minLv, pLv + maxLv);
|
||||
range = range.filter(cur => {
|
||||
return chosenOpps.indexOf(makeRobotId(cur.roleId)) == -1;
|
||||
});
|
||||
@@ -193,7 +197,7 @@ async function matchPlayer(seasonNum: number, chosenOpps: string[], roleId: stri
|
||||
index = getRandSingleIndex(range.length);
|
||||
result = range[index];
|
||||
}
|
||||
let pvpHistoryOpp = await generPlayerOppHis(result, roleId, pos);
|
||||
let pvpHistoryOpp = await generPlayerOppHis(result, roleId, pos, groupId);
|
||||
if (!pvpHistoryOpp) return null;
|
||||
|
||||
chosenOpps.push(pvpHistoryOpp.oppRoleId);
|
||||
@@ -206,14 +210,14 @@ async function matchPlayer(seasonNum: number, chosenOpps: string[], roleId: stri
|
||||
* @param roleId 自己的玩家id
|
||||
* @param pos 刷新这个对手的位置
|
||||
*/
|
||||
async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos: number) {
|
||||
async function generPlayerOppHis(pvpdefense: PvpDefenseType, roleId: string, pos: number, groupId: number) {
|
||||
let { heroScores, defense } = pvpdefense;
|
||||
if(!defense) return false;
|
||||
let { warId, heroes: defenseHeroes } = defense;
|
||||
let role = <RoleType>pvpdefense.role;
|
||||
|
||||
let seasonNum: number = pinus.app.get('pvpSeasonNum');
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
let rankLv = await r.getMyRank({ roleId: role.roleId });
|
||||
let dbHeroes = await HeroModel.findByRole(role.roleId, [{ field: 'ce', sortBy: -1 }]);
|
||||
let heroes = new Array<PvpEnemies>();
|
||||
@@ -565,14 +569,18 @@ export async function generPVPOppRecInfo(isSuccess: boolean, curOpp: OppPlayer,
|
||||
let resultMaxRank = getPvpRankMaxRewardsBySeasonNum(pvpConfig.seasonNum);//根据排行榜的奖励表,获得最大排名挡位的最小值,其余不在结算中结算的玩家按照最大排名挡位在登录或进入pvp时结算
|
||||
if(!resultMaxRank) return;
|
||||
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: pvpConfig.seasonNum }, false, resultMaxRank.min - 1);
|
||||
let allRank = <RoleRankInfo[]>(await r.getRankByRange());
|
||||
console.log('******** allRank', 0, resultMaxRank.min - 2, allRank)
|
||||
for(let { rank, roleId } of allRank) {
|
||||
console.log('******** pvpSeasonEnd: ', rank, roleId);
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
let { pvpSeasonResult } = await sendPVPRewardToUser(pvpDefense, pvpConfig.seasonNum, pvpConfig.seasonEndTime);
|
||||
reportTAEvent(roleId, TA_EVENT.PVP_SEASON_END, { top_rank: rank, hero_score: pvpSeasonResult.heroScores })
|
||||
let pvpKeys = await findKeys(`${REDIS_KEY.PVP_RANK}:${pvpConfig.seasonNum}:`);
|
||||
for(let key of pvpKeys) {
|
||||
let [,, groupId] = key.split(':');
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: pvpConfig.seasonNum, groupId: parseInt(groupId) }, false, resultMaxRank.min - 1);
|
||||
let allRank = <RoleRankInfo[]>(await r.getRankByRange());
|
||||
console.log('******** allRank', 0, resultMaxRank.min - 2, allRank)
|
||||
for(let { rank, roleId } of allRank) {
|
||||
console.log('******** pvpSeasonEnd: ', rank, roleId);
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
let { pvpSeasonResult } = await sendPVPRewardToUser(pvpDefense, pvpConfig.seasonNum, pvpConfig.seasonEndTime);
|
||||
reportTAEvent(roleId, TA_EVENT.PVP_SEASON_END, { top_rank: rank, hero_score: pvpSeasonResult.heroScores })
|
||||
}
|
||||
}
|
||||
await PvpDefenseModel.resetDefense();
|
||||
let settledPvpConfig = await PVPConfigModel.setReward(pvpConfig.seasonNum);
|
||||
@@ -648,8 +656,9 @@ async function resetPvpScores(pvpDefense: PvpDefenseType, pvpSeasonResult: PvpSe
|
||||
* @param rankLv
|
||||
*/
|
||||
export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum: number, seasonEndTime: number, rankLv?: number) {
|
||||
let groupId = await getPVPGroupIdOfServer(pvpDefense.serverId);
|
||||
if (!rankLv) {
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum, groupId });
|
||||
rankLv = await r.getMyRank({ roleId: pvpDefense.roleId });// 获得排行榜排名
|
||||
}
|
||||
let pvpRankReward: DicRankRewads = getPvpRankRewardsByRank(seasonNum, rankLv);
|
||||
@@ -681,7 +690,7 @@ export async function savePvpSeasonResult(pvpDefense: PvpDefenseType, seasonNum:
|
||||
receivedBox, score, seasonWinNum, heroScores, rankLv, heroGoods, rankGoods, show: true, newScore, newHeroScores, seasonEndTime
|
||||
});//结算修改玩家pvp信息
|
||||
if(newScore > 0) {
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: seasonNum + 1 });
|
||||
let r = new Rank(REDIS_KEY.PVP_RANK, { seasonNum: seasonNum + 1, groupId });
|
||||
await r.setRankWithRoleInfo(pvpDefense.roleId, newScore, Date.now());
|
||||
}
|
||||
|
||||
@@ -719,9 +728,7 @@ export async function generPvpLineupCe(roleId: string, lineupCe: LineupCe[], att
|
||||
|
||||
|
||||
export function getPvpSeasonStatus() {
|
||||
let seasonEndTime: number = pinus.app.get('pvpSeasonEndTime');
|
||||
let seasonStartTime: number = pinus.app.get('pvpSeasonStartTime');
|
||||
let seasonRewardTime: number = pinus.app.get('pvpSeasonRewardTime');
|
||||
let { seasonEndTime, seasonStartTime, seasonRewardTime } = getPvpTime();
|
||||
let now = nowSeconds();
|
||||
if(now >= seasonStartTime && now < seasonEndTime) {
|
||||
return PVP_SEASON_STATUS.START;
|
||||
@@ -732,6 +739,28 @@ export function getPvpSeasonStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
interface PvpTime {
|
||||
seasonEndTime: number, seasonStartTime: number, seasonRewardTime: number
|
||||
}
|
||||
export function getPvpTime(): PvpTime {
|
||||
return {
|
||||
seasonEndTime: pinus.app.get('pvpSeasonEndTime'),
|
||||
seasonStartTime: pinus.app.get('pvpSeasonStartTime'),
|
||||
seasonRewardTime: pinus.app.get('pvpSeasonRewardTime')
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPvpTimeFromRemote(): Promise<PvpTime> {
|
||||
let serverType = pinus.app.getServerType();
|
||||
if(serverType == 'battle') {
|
||||
return getPvpTime();
|
||||
} else {
|
||||
let battleServers = pinus.app.getServersByType('battle');
|
||||
let server = getRandSingleEelm(battleServers);
|
||||
return await pinus.app.rpc.battle.battleRemote.getPvpTime.toServer(server.id);
|
||||
}
|
||||
}
|
||||
|
||||
export function checkPvpSeasonIsStart() {
|
||||
let status = getPvpSeasonStatus();
|
||||
return status == PVP_SEASON_STATUS.START;
|
||||
|
||||
@@ -21,6 +21,7 @@ import { GVGLeagueModel, GVGLeagueType } from "../db/GVGLeague";
|
||||
import { GVGVestigeLeagueRankModel } from "../db/GVGVestigeLeagueRank";
|
||||
import { getDayKeyInfo } from "./gvg/gvgFightService";
|
||||
import { ActivityMiniGameModel } from "../db/ActivityMiniGame";
|
||||
import { getPVPServerGroup } from "./serverService";
|
||||
|
||||
|
||||
/**
|
||||
@@ -1082,18 +1083,22 @@ export async function setRankRedisFromDb(type: string, args?: { serverId?: numbe
|
||||
} else if (type == REDIS_KEY.PVP_RANK) {
|
||||
let seasonNum = await CounterModel.getCounter(COUNTER.PVP_SEASON_NUM);
|
||||
if(seasonNum > 0) {
|
||||
let keyName = new KeyName(type, { seasonNum })
|
||||
await delKeys(keyName.getName());
|
||||
let ranks = await PvpDefenseModel.getRank(seasonNum);//获得全服前1000名的排名,加入到redis中
|
||||
|
||||
let r = new Rank(type, { seasonNum });
|
||||
r.setIsInit(true);
|
||||
for (let { roleId, role: _role, score, updatedAt } of ranks) {
|
||||
let role = <RoleType>_role;
|
||||
if (!role) {
|
||||
continue;
|
||||
let serverGroup = await getPVPServerGroup();
|
||||
for(let [groupId, serverIds] of serverGroup) {
|
||||
let keyName = new KeyName(type, { seasonNum, groupId })
|
||||
await delKeys(keyName.getName());
|
||||
let ranks = await PvpDefenseModel.getRank(serverIds, seasonNum);//获得全服前1000名的排名,加入到redis中
|
||||
|
||||
console.log('#####', seasonNum, groupId, serverIds, ranks.length)
|
||||
let r = new Rank(type, { seasonNum, groupId });
|
||||
r.setIsInit(true);
|
||||
for (let { roleId, role: _role, score, updatedAt } of ranks) {
|
||||
let role = <RoleType>_role;
|
||||
if (!role) {
|
||||
continue;
|
||||
}
|
||||
await r.setRankWithRoleInfo(roleId, score, updatedAt.getTime(), role);
|
||||
}
|
||||
await r.setRankWithRoleInfo(roleId, score, updatedAt.getTime(), role);
|
||||
}
|
||||
}
|
||||
} else if (type == REDIS_KEY.TOP_LINEUP_RANK) {
|
||||
|
||||
96
game-server/app/services/serverService.ts
Normal file
96
game-server/app/services/serverService.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import { pinus } from "pinus";
|
||||
import { GVG_SERVER_TYPE, SERVER_GROUP_FUN_TYPE } from "../consts";
|
||||
import { ServerGroupModel } from "../db/ServerGroup";
|
||||
import { ServerlistModel } from "../db/Serverlist";
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { getServerTypeByTime } from "./gvg/gvgService";
|
||||
import { getAllServerCreateTime } from "./redisService";
|
||||
|
||||
export async function setServerGroup() {
|
||||
const servers = await ServerlistModel.findByEnv(pinus.app.get('env'));
|
||||
let now = nowSeconds();
|
||||
const gvgServerGroup = await ServerGroupModel.findByTime(now, SERVER_GROUP_FUN_TYPE.GVG);
|
||||
const pvpServerGroup = await ServerGroupModel.findByTime(now, SERVER_GROUP_FUN_TYPE.PVP);
|
||||
// const arenaServerGroup = await ServerGroupModel.findByTime(now, SERVER_GROUP_FUN_TYPE.ARENA);
|
||||
pinus.app.set('gvgServerGroup', servers.map(obj => {
|
||||
let server = gvgServerGroup.find(cur => cur.serverId == obj.id);
|
||||
return [obj.id, server? server.groupId: obj.groupId]
|
||||
}));
|
||||
pinus.app.set('pvpServerGroup', servers.map(obj => {
|
||||
let server = pvpServerGroup.find(cur => cur.serverId == obj.id);
|
||||
return [obj.id, server? server.groupId: obj.groupId]
|
||||
}));
|
||||
// pinus.app.set('arenaServerGroup', servers.map(obj => {
|
||||
// let server = arenaServerGroup.find(cur => cur.serverId == obj.id);
|
||||
// return [obj.id, server? server.groupId: obj.groupId]
|
||||
// }));
|
||||
|
||||
}
|
||||
|
||||
// GVG相关:查询本小区所在战区
|
||||
export async function getGVGGroupIdOfServer(serverId: number) {
|
||||
return await getGroupIdOfServer(serverId, SERVER_GROUP_FUN_TYPE.GVG);
|
||||
}
|
||||
|
||||
// PVP相关:查询本小区所在战区
|
||||
export async function getPVPGroupIdOfServer(serverId: number) {
|
||||
return await getGroupIdOfServer(serverId, SERVER_GROUP_FUN_TYPE.PVP);
|
||||
}
|
||||
|
||||
// 查询本小区所在的战区
|
||||
export async function getGroupIdOfServer(serverId: number, fun: SERVER_GROUP_FUN_TYPE) {
|
||||
let arr: number[][] = pinus.app.get(getPinusKeyOfFun(fun))||[];
|
||||
let obj = arr.find(cur => cur[0] == serverId);
|
||||
return obj[1]||0;
|
||||
}
|
||||
|
||||
// 查询当前和本小区同一个战区的其他小区
|
||||
export async function getGVGServersOfSameGroup(type: GVG_SERVER_TYPE, id: number) {
|
||||
if(type == GVG_SERVER_TYPE.SINGLE) return [id];
|
||||
|
||||
let groupId = await getGroupIdOfServer(id, SERVER_GROUP_FUN_TYPE.GVG);
|
||||
return await getServersByGroupId(groupId, SERVER_GROUP_FUN_TYPE.GVG);
|
||||
}
|
||||
|
||||
export async function getPVPServersOfSameGroup(serverId: number) {
|
||||
let groupId = await getGroupIdOfServer(serverId, SERVER_GROUP_FUN_TYPE.PVP);
|
||||
return await getServersByGroupId(groupId, SERVER_GROUP_FUN_TYPE.PVP);
|
||||
}
|
||||
|
||||
export async function getGVGServersByGroupId(groupId: number) {
|
||||
return getServersByGroupId(groupId, SERVER_GROUP_FUN_TYPE.GVG);
|
||||
}
|
||||
|
||||
export async function getPvpServersByGroupId(groupId: number) {
|
||||
return getServersByGroupId(groupId, SERVER_GROUP_FUN_TYPE.PVP);
|
||||
}
|
||||
|
||||
export async function getServersByGroupId(groupId: number, fun: SERVER_GROUP_FUN_TYPE) {
|
||||
let arr: number[][] = pinus.app.get(getPinusKeyOfFun(fun))||[];
|
||||
let serverCreateTimes = await getAllServerCreateTime();
|
||||
|
||||
return arr.filter(obj => {
|
||||
let openTime = parseInt(serverCreateTimes[obj[0]]);
|
||||
return obj[1] == groupId && getServerTypeByTime(openTime) == GVG_SERVER_TYPE.MULTI;
|
||||
}).map(obj => obj[0]);
|
||||
}
|
||||
|
||||
function getPinusKeyOfFun(fun: SERVER_GROUP_FUN_TYPE) {
|
||||
switch(fun) {
|
||||
case SERVER_GROUP_FUN_TYPE.GVG: return 'gvgServerGroup';
|
||||
case SERVER_GROUP_FUN_TYPE.PVP: return 'pvpServerGroup';
|
||||
case SERVER_GROUP_FUN_TYPE.ARENA: return 'arenaServerGroup';
|
||||
default: return '';
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPVPServerGroup() {
|
||||
let now = nowSeconds();
|
||||
const pvpServerGroup = await ServerGroupModel.findByTime(now, SERVER_GROUP_FUN_TYPE.PVP);
|
||||
let map = new Map<number, number[]>();
|
||||
for(let { serverId, groupId } of pvpServerGroup) {
|
||||
if(!map.has(groupId)) map.set(groupId, []);
|
||||
map.get(groupId).push(serverId);
|
||||
}
|
||||
return map
|
||||
}
|
||||
@@ -202,6 +202,13 @@ export async function setPvpSeasonNumToRemote(pvpConfig: PVPConfigType) {
|
||||
await pinus.app.rpc.battle.battleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
await pinus.app.rpc.role.roleRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
await pinus.app.rpc.connector.connectorRemote.setPvpSeasonNum.broadcast(pvpConfig);
|
||||
|
||||
await pinus.app.rpc.guild.guildRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.chat.chatRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.connector.connectorRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.gm.gmRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.systimer.systimerRemote.setServerGroup.broadcast();
|
||||
await pinus.app.rpc.battle.battleRemote.setServerGroup.broadcast();
|
||||
}
|
||||
|
||||
export async function setPvpSeasonNum(pvpConfig?: PVPConfigType) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import { ChannelInfoModel } from '@db/ChannelInfo';
|
||||
import { PVPConfigModel } from '@db/PvpConfig';
|
||||
import { HiddenDataByIdModel } from '@db/HiddenDataById';
|
||||
import { isNumber } from 'util';
|
||||
import { GVGServerGroupModel } from '@db/GVGServerGroup';
|
||||
import { ServerGroupModel } from '@db/ServerGroup';
|
||||
import { GVGConfigModel } from '@db/GVGConfig';
|
||||
|
||||
/**
|
||||
@@ -353,14 +353,20 @@ export default class Game extends Service {
|
||||
public async getGVGServerGroup() {
|
||||
const { ctx } = this;
|
||||
const serverlists = await ServerlistModel.findByEnv(this.app.config.realEnv);
|
||||
const currentTypes = await GVGServerGroupModel.findByTime(nowSeconds());
|
||||
const nextTypes = await GVGServerGroupModel.findByTime(nowSeconds() + 7 * 86400);
|
||||
const currentGVGTypes = await ServerGroupModel.findByTime(nowSeconds(), 1);
|
||||
const nextGVGTypes = await ServerGroupModel.findByTime(nowSeconds() + 7 * 86400, 1);
|
||||
|
||||
const { seasonEndTime } = await PVPConfigModel.findCurPVPConfig();
|
||||
const currentPVPTypes = await ServerGroupModel.findByTime(nowSeconds(), 2);
|
||||
const nextPVPTypes = await ServerGroupModel.findByTime(seasonEndTime, 2);
|
||||
|
||||
const servers = serverlists.map(server => {
|
||||
let current = currentTypes.find(obj => obj.serverId == server.id);
|
||||
let next = nextTypes.find(obj => obj.serverId == server.id);
|
||||
let dic = gameData.serverNames.get(server.serverId);
|
||||
return { id: server.id, serverId: server.serverId, name: server.name, current: current?.groupId|| dic.groupId, next: next?.groupId|| current?.groupId || dic.groupId, env: this.app.config.realEnv }
|
||||
let curGVG = currentGVGTypes.find(obj => obj.serverId == server.id)?.groupId||dic.groupId;
|
||||
let nextGVG = nextGVGTypes.find(obj => obj.serverId == server.id)?.groupId||curGVG;
|
||||
let curPVP = currentPVPTypes.find(obj => obj.serverId == server.id)?.groupId||dic.groupId;
|
||||
let nextPVP = nextPVPTypes.find(obj => obj.serverId == server.id)?.groupId||curPVP;
|
||||
return { id: server.id, serverId: server.serverId, name: server.name, curGVG, nextGVG, curPVP, nextPVP, env: this.app.config.realEnv }
|
||||
});
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
|
||||
@@ -1265,4 +1265,11 @@ export enum PVP_SEASON_STATUS {
|
||||
START = 1, // 已开始
|
||||
SUMMIT = 2, // 结算中
|
||||
WAITING = 3, // 待新赛季
|
||||
}
|
||||
|
||||
// 战区配置类型
|
||||
export enum SERVER_GROUP_FUN_TYPE {
|
||||
GVG = 1,
|
||||
PVP = 2,
|
||||
ARENA = 3,
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 服务器分战区
|
||||
*/
|
||||
@index({ time: -1, serverId: -1 })
|
||||
export default class GVGServerGroup extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
serverId: number; // 服务器id
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
groupId: number; // 战区id
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
time: number; // 生效时间
|
||||
|
||||
public static async findByTime(time: number) {
|
||||
const serverGroup: { serverId: number, groupId: number }[] = await GVGServerGroupModel.aggregate([
|
||||
{ $match: { time: { $lte: time } } },
|
||||
{ $sort: { time: -1 } },
|
||||
{ $group: { _id: "$serverId", serverId: { $first: "$serverId" }, groupId: { $first: "$groupId" }, time: { $first: "$time" }} },
|
||||
{ $sort: { _id: -1 } },
|
||||
{ $project: { _id: 0, serverId: "$serverId", groupId: "$groupId", time: "$time" } }
|
||||
]);
|
||||
return serverGroup;
|
||||
}
|
||||
|
||||
public static async updateByServerId(serverId: number, groupId: number, time: number) {
|
||||
const result: GVGServerGroupType = await GVGServerGroupModel.findOneAndUpdate({ serverId, time }, { $set: { groupId } }, { new: true, upsert: true }).lean();
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export let GVGServerGroupModel = getModelForClass(GVGServerGroup);
|
||||
|
||||
export interface GVGServerGroupType extends Pick<DocumentType<GVGServerGroup>, keyof GVGServerGroup> {
|
||||
id: number;
|
||||
};
|
||||
export type GVGServerGroupUpdate = Partial<GVGServerGroupType>; // 将所有字段变成可选项
|
||||
@@ -5,7 +5,7 @@ import { Defense, Attack, LineupCe, OppPlayer, HeroScore, } from '../domain/batt
|
||||
import { PVP } from '../pubUtils/dicParam';
|
||||
|
||||
@index({ roleId: 1 })
|
||||
@index({ score: 1 })
|
||||
@index({ serverId: 1, score: 1 })
|
||||
export default class PvpDefense extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 区 id
|
||||
@@ -71,14 +71,6 @@ export default class PvpDefense extends BaseModel {
|
||||
const result: PvpDefenseType = await PvpDefenseModel.findOne({ roleId }).lean({ getters});
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findByScale(roleId: string, min: number, max: number) {
|
||||
const result: PvpDefenseType[] = await PvpDefenseModel.find({ roleId: { $ne: roleId }, defCe: { $lte: max, $gte: min } })
|
||||
.populate('role', 'head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('heroes.hero')
|
||||
.sort({ updatedAt: -1 }).limit(100).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async createPvpDefense(seasonNum: number, params: pvpUpdateInter) {
|
||||
const doc = new PvpDefenseModel();
|
||||
@@ -121,16 +113,16 @@ export default class PvpDefense extends BaseModel {
|
||||
|
||||
public static async findByRoleIdIncludeAll(roleId: string) {
|
||||
const result: PvpDefenseType = await PvpDefenseModel.findOne({ roleId })
|
||||
.populate('role', 'head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('role', 'serverId head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('heroes.hero')
|
||||
.populate('oppPlayers.oppDef', 'oppRoleId pos roleName head frame spine heads frames spines rankLv title lv pLv defCe heroes warId buff')
|
||||
.populate('oppBeforePlayers.oppDef', 'oppRoleId pos roleName head frame spine heads frames spines rankLv title lv pLv defCe heroes warId buff').lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findByTeamLv(seasonNum: number, min: number, max: number) {
|
||||
const result: PvpDefenseType[] = await PvpDefenseModel.find({ seasonNum, hasDefense: true, 'defense.pLv': { $gte: min, $lte: max } })
|
||||
.populate('role', '_id head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
public static async findByTeamLv(serverIds: number[], seasonNum: number, min: number, max: number) {
|
||||
const result: PvpDefenseType[] = await PvpDefenseModel.find({ serverId: {$in: serverIds}, seasonNum, hasDefense: true, 'defense.pLv': { $gte: min, $lte: max } })
|
||||
.populate('role', '_id serverId head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('heroes.hero')
|
||||
.populate('oppPlayers.oppDef', 'oppRoleId pos roleName head frame spine heads frames spines rankLv pLv title lv defCe heroes warId buff')
|
||||
.lean({ getters: true, virtuals: true });
|
||||
@@ -141,14 +133,14 @@ export default class PvpDefense extends BaseModel {
|
||||
const beforeData: PvpDefenseType[] = await PvpDefenseModel.find({
|
||||
seasonNum, hasDefense: true, score: { $lt: score }
|
||||
}).sort({ score: -1 }).limit(10)
|
||||
.populate('role', '_id head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('role', '_id serverId head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('heroes.hero')
|
||||
.populate('oppPlayers.oppDef', 'oppRoleId pos roleName head frame spine heads frames spines rankLv pLv title lv defCe heroes warId buff')
|
||||
.lean({ getters: true, virtuals: true });
|
||||
const afterData: PvpDefenseType[] = await PvpDefenseModel.find({
|
||||
seasonNum, hasDefense: true, score: { $gt: score }
|
||||
}).sort({ score: 1 }).limit(10)
|
||||
.populate('role', '_id head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('role', '_id serverId head frame spine heads frames spines topLineupCe roleId roleName lv globalCeAttr title')
|
||||
.populate('heroes.hero')
|
||||
.populate('oppPlayers.oppDef', 'oppRoleId pos roleName head frame spine heads frames spines rankLv pLv title lv defCe heroes warId buff')
|
||||
.lean({ getters: true, virtuals: true });
|
||||
@@ -159,7 +151,7 @@ export default class PvpDefense extends BaseModel {
|
||||
public static async updateInfoAndInclude(roleId: string, update: pvpUpdateInter) {
|
||||
delete update._id;
|
||||
let result: PvpDefenseType = await PvpDefenseModel.findOneAndUpdate({roleId}, {$set:update}, {new: true})
|
||||
.populate('role', 'head frame spine heads frames spines topLineupCe roleId roleName lv title')
|
||||
.populate('role', 'serverId head frame spine heads frames spines topLineupCe roleId roleName lv title')
|
||||
.populate('oppPlayers.oppDef', 'oppRoleId pos roleName head frame spine heads frames spines rankLv pLv title lv defCe heroes warId buff').lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
}
|
||||
@@ -173,10 +165,10 @@ export default class PvpDefense extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getRank(seasonNum: number, page = 1, limit = 1000) {
|
||||
public static async getRank(serverIds: number[], seasonNum: number, page = 1, limit = 1000) {
|
||||
let sortBy = { score: -1, updatedAt: 1 };
|
||||
const ranks: PvpDefenseType[] = await PvpDefenseModel.find({rankSeasonNum: seasonNum, score: { $gt: 0 }}).select('roleId role score updatedAt')
|
||||
.populate('role', 'roleId roleName head frame spine heads frames spines title lv vLv updatedAt serverId')
|
||||
const ranks: PvpDefenseType[] = await PvpDefenseModel.find({ serverId: {$in: serverIds}, rankSeasonNum: seasonNum, score: { $gt: 0 }}).select('serverId roleId role score updatedAt')
|
||||
.populate('role', 'serverId roleId roleName head frame spine heads frames spines title lv vLv updatedAt')
|
||||
.sort(sortBy).limit(limit).skip((page - 1) * limit).lean({ getters: true, virtuals: true });
|
||||
return ranks;
|
||||
}
|
||||
|
||||
52
shared/db/ServerGroup.ts
Normal file
52
shared/db/ServerGroup.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { SERVER_GROUP_FUN_TYPE } from '../consts';
|
||||
|
||||
/**
|
||||
* 服务器分战区
|
||||
*/
|
||||
@index({ serverId: -1 })
|
||||
export default class ServerGroup extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
serverId: number; // 服务器id
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
groupId: number; // 战区id
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
gvgTime: number; // gvg生效时间
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
pvpTime: number; // pvp生效时间
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
arenaTime: number; // 3v3生效时间
|
||||
|
||||
public static async findByTime(time: number, type: number) {
|
||||
let key = type == SERVER_GROUP_FUN_TYPE.GVG? 'gvgTime': (type == SERVER_GROUP_FUN_TYPE.PVP? 'pvpTime': 'arenaTime');
|
||||
let match = {}, sort = {};
|
||||
match[key] = { $lte: time, $gt: 0 };
|
||||
sort[key] = -1;
|
||||
const serverGroup: { serverId: number, groupId: number }[] = await ServerGroupModel.aggregate([
|
||||
{ $match: match },
|
||||
{ $sort: sort },
|
||||
{ $group: { _id: "$serverId", groupId: { $first: "$groupId" }, time: { $first: `$${key}` }} },
|
||||
{ $sort: { _id: -1 } },
|
||||
{ $project: { _id: 0, serverId: "$_id", groupId: "$groupId", time: "$time" } }
|
||||
]);
|
||||
return serverGroup;
|
||||
}
|
||||
|
||||
public static async updateByServerId(serverId: number, groupId: number, gvgTime: number, pvpTime: number) {
|
||||
const result: ServerGroupType = await ServerGroupModel.findOneAndUpdate({ serverId, gvgTime, pvpTime }, { $set: { groupId } }, { new: true, upsert: true }).lean();
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export let ServerGroupModel = getModelForClass(ServerGroup);
|
||||
|
||||
export interface ServerGroupType extends Pick<DocumentType<ServerGroup>, keyof ServerGroup> {
|
||||
id: number;
|
||||
};
|
||||
export type ServerGroupUpdate = Partial<ServerGroupType>; // 将所有字段变成可选项
|
||||
@@ -356,6 +356,7 @@ export class SimpleRoleRankParam {
|
||||
export class KeyName {
|
||||
key: string;
|
||||
serverId?: number;
|
||||
groupId?: number; // 战区
|
||||
guildCode?: string;
|
||||
cityId?: number;
|
||||
hid?: number;
|
||||
@@ -371,6 +372,7 @@ export class KeyName {
|
||||
constructor(key: string, param: KeyNameParam) {
|
||||
this.key = key;
|
||||
if(param.serverId) this.serverId = param.serverId;
|
||||
if(param.groupId) this.groupId = param.groupId;
|
||||
if(param.guildCode) this.guildCode = param.guildCode;
|
||||
if(param.cityId) this.cityId = param.cityId;
|
||||
if(param.hid) this.hid = param.hid;
|
||||
@@ -401,7 +403,7 @@ export class KeyName {
|
||||
case REDIS_KEY.HERO_RANK:
|
||||
return `${this.key}:${this.serverId}:${this.hid}`;
|
||||
case REDIS_KEY.PVP_RANK:
|
||||
return `${this.key}:${this.seasonNum}`;
|
||||
return `${this.key}:${this.seasonNum}:${this.groupId}`;
|
||||
case REDIS_KEY.GATE_ACTIVITY:
|
||||
case REDIS_KEY.RACE_ACTIVITY:
|
||||
return `${this.key}:${this.serverId}:${this.index}`;
|
||||
|
||||
Reference in New Issue
Block a user