feat(gvg): 便捷管理页面

This commit is contained in:
luying
2023-03-28 13:35:27 +08:00
parent 6218378030
commit 5bd61ed0b3
9 changed files with 134 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ import { gameData, getReviveGold } from '../../../pubUtils/data';
import { getAllServerName } from '../../../services/redisService';
import { checkBattleHeroesByHid } from '../../../services/normalBattleService';
import { SaveTeamParam, SaveTeamUpdateParam } from '../../../domain/gvgField/gvgDb';
import { GVG_AREA_TYPE, GVG_ATTACK_TYPE, GVG_ITEM, GVG_PERIOD, GVG_POINT_TYPE, GVG_REC_TYPE, ITEM_CHANGE_REASON, PUSH_ROUTE, REDIS_KEY, STATUS } from '../../../consts';
import { GVG_AREA_TYPE, GVG_ATTACK_TYPE, GVG_ITEM, GVG_PERIOD, GVG_POINT_TYPE, GVG_REC_TYPE, ITEM_CHANGE_REASON, LEAGUE_MANAGE_TYPE, PUSH_ROUTE, REDIS_KEY, STATUS } from '../../../consts';
import { addRoleToAreaChannel, addRoleToAreaTeamChannel, addRoleToGVGCityChannel, leaveGVGAreaChannel, leaveGVGAreaTeamChannel, leaveGVGCityTeamChannel } from '../../../services/chatChannelService';
import { nowSeconds } from '../../../pubUtils/timeUtil';
import { GVGUserItemModel } from '../../../db/GVGUserItem';
@@ -27,7 +27,9 @@ import { LeagueRankInfo, RoleRankInfo } from '../../../domain/rank';
import { addBattleEndRec } from '../../../services/gvg/gvgRecService';
import { RoleModel } from '../../../db/Role';
import { EXTERIOR, GVG } from '../../../pubUtils/dicParam';
import { sendMessageToGVGAreaByTeamWithSuc, sendMessageToUserWithSuc } from '../../../services/pushService';
import { sendMessageToGuildWithSuc, sendMessageToGVGAreaByTeamWithSuc, sendMessageToUserWithSuc } from '../../../services/pushService';
import { checkLeagueAuth } from '../../../services/gvg/gvgTeamService';
import { GVGLeaguePrepareModel } from '../../../db/GVGLeaguePrepare';
export default function (app: Application) {
new HandlerService(app, {});
@@ -715,6 +717,89 @@ export class GVGBattleHandler {
})
}
// 设置目标城池
async setTargetCity(msg: { cityId: number, isTarget: boolean }, session: BackendSession) {
const guildCode = session.get('guildCode');
const roleId = session.get('roleId');
const { cityId, isTarget } = msg;
let { configId, period } = getGVGPeriodData();
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
let dicCity = gameData.gvgCity.get(cityId);
if(!dicCity) return resResult(STATUS.GVG_CITY_NOT_FOUND);
let targetCities: number[] = [];
// 权限
const checkAuth = await checkLeagueAuth(roleId, myLeague, LEAGUE_MANAGE_TYPE.SET_TARGET_CITY);
if(!checkAuth) return resResult(STATUS.GVG_HAS_NO_AUTH);
if(isTarget) {
let leaguePrepare = await GVGLeaguePrepareModel.findByLeague(configId, myLeague.leagueCode);
targetCities = leaguePrepare?.targetCities||[];
if(targetCities.indexOf(cityId) != -1) return resResult(STATUS.GVG_TARGET_CITY_HAS_SET);
if(targetCities.length >= 2) return resResult(STATUS.GVG_TARGET_CITY_CNT_MAX);
leaguePrepare = await GVGLeaguePrepareModel.setTargetCity(configId, myLeague.leagueCode, cityId);
targetCities = leaguePrepare?.targetCities||[];
} else {
let leaguePrepare = await GVGLeaguePrepareModel.cancelTargetCity(configId, myLeague.leagueCode, cityId);
targetCities = leaguePrepare?.targetCities||[];
}
// 发送消息
for(let guildCode of myLeague.guildCodes) {
await sendMessageToGuildWithSuc(guildCode, PUSH_ROUTE.GVG_TARGET_CITY_UPDATE, { targetCities });
}
return resResult(STATUS.SUCCESS, {
configId, targetCities
});
}
// 设置管理信息
async setNotice(msg: { notice: string }, session: BackendSession) {
const guildCode = session.get('guildCode');
const roleId = session.get('roleId');
const { notice = '' } = msg;
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
let { configId, period } = getGVGPeriodData();
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
// 权限
const checkAuth = await checkLeagueAuth(roleId, myLeague, LEAGUE_MANAGE_TYPE.SET_NOTICE);
if(!checkAuth) return resResult(STATUS.GVG_HAS_NO_AUTH);
let leaguePrepare = await GVGLeaguePrepareModel.setNotice(configId, myLeague.leagueCode, notice);
if(!leaguePrepare) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
for(let guildCode of myLeague.guildCodes) {
await sendMessageToGuildWithSuc(guildCode, PUSH_ROUTE.GVG_TARGET_CITY_UPDATE, { notice: leaguePrepare.notice });
}
return resResult(STATUS.SUCCESS, {
configId, notice: leaguePrepare.notice
});
}
// enterCity里返回的那个ranks
async getRankByCity(msg: { cityId: number }, session: BackendSession) {
const guildCode = session.get('guildCode');
const serverId = session.get('serverId');
const { cityId } = msg;
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
let { configId } = getGVGPeriodData();
const groupKey = await getGroupKey(serverId);
const { ranks, myRank } = await getBattleRanksByCity(configId, groupKey, cityId, myLeague);
return resResult(STATUS.SUCCESS, {
cityId, ranks, myRank
})
}
async debugStartSchedule() {
let { countdownTime } = getGVGPeriodData();
pinus.app.rpc.guild.guildRemote.setPeriodTime.broadcast(nowSeconds(), countdownTime);

View File

@@ -97,6 +97,8 @@ export class GVGHandler {
let { configId, period, countdownTime } = getGVGPeriodData();
let { startFightTime, endFightTime } = getFightTimeByPeriod(period);
let leaguePrepare = await GVGLeaguePrepareModel.findByLeague(configId, myLeague.leagueCode);
let groupKey = await getGroupKey(serverId);
let cities = await getGVGCitiesInfo(configId, groupKey, myLeague);
let vestiges = await getMyVestiges(serverId, roleId);
@@ -105,6 +107,8 @@ export class GVGHandler {
return resResult(STATUS.SUCCESS, {
configId, period, countdownTime, startFightTime, endFightTime,
targetCities: leaguePrepare?.targetCities||[],
notice: leaguePrepare?.notice||'',
cities,
vestiges
});