✨ feat(pvp): 巅峰演武战区化
This commit is contained in:
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
|
||||
}
|
||||
Reference in New Issue
Block a user