feat(gvg): 概览

This commit is contained in:
luying
2023-02-17 21:13:04 +08:00
parent 0a65a0863d
commit 295128d668
5 changed files with 136 additions and 16 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_ITEM, ITEM_CHANGE_REASON, STATUS } from '../../../consts';
import { GVG_AREA_TYPE, GVG_ITEM, ITEM_CHANGE_REASON, STATUS } from '../../../consts';
import { GVGHeroInfo } from '../../../domain/dbGeneral';
import { ArtifactModel } from '../../../db/Artifact';
import { getHeroesAttributes } from '../../../services/playerCeService';
@@ -24,6 +24,7 @@ import { nowSeconds } from '../../../pubUtils/timeUtil';
import { GVGUserItemModel } from '../../../db/GVGUserItem';
import { handleGVGCost } from '../../../services/gvg/gvgItemService';
import { getGoldObject, handleCost } from '../../../services/role/rewardService';
import { GVGCityAreaPointModel } from '../../../db/GVGCityAreaPoint';
export default function (app: Application) {
new HandlerService(app, {});
@@ -380,7 +381,7 @@ export class GVGBattleHandler {
async teamSettle(msg: { cityId: number, areaId: number, pointId: number, teamCode: string }, session: BackendSession) {
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const { pointId, teamCode } = msg;
const { cityId, areaId, pointId, teamCode } = msg;
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
@@ -394,8 +395,8 @@ export class GVGBattleHandler {
let dicAreaPoint = gameData.gvgAreaPoint.get(pointId);
if(dicAreaPoint.areaId != myTeam.areaId) return resResult(STATUS.GVG_POINT_NOT_AREA);
let hasOtherTeam = await GVGTeamModel.checkPoint(configId, groupId, serverType, pointId);
if(hasOtherTeam) return resResult(STATUS.GVG_POINT_HAS_SETTLED);
let point = await GVGCityAreaPointModel.settlePoint(cityId, areaId, pointId, myTeam);
if(!point) return resResult(STATUS.GVG_POINT_HAS_SETTLED);
const curTeam = await GVGTeamModel.settlePoint(teamCode, pointId);
let teamObj = getGVGBattleData(groupId, serverType);
@@ -409,6 +410,9 @@ export class GVGBattleHandler {
const serverId = session.get('serverId');
const { pointId, teamCode } = msg;
let { configId, period } = getGVGPeriodData();
// if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD); // TODO 测试临时注
let groupId = await getGroupIdOfServer(serverId);
let serverType = await getGVGServerType(serverId);
@@ -418,6 +422,7 @@ export class GVGBattleHandler {
if(dicAreaPoint.areaId != myTeam.areaId) return resResult(STATUS.GVG_POINT_NOT_AREA);
const curTeam = await GVGTeamModel.settlePoint(teamCode, 0);
await GVGCityAreaPointModel.leavePoint(configId, groupId, serverType, pointId);
let teamObj = getGVGBattleData(groupId, serverType);
teamObj.teamSettle(roleId, teamCode, pointId);
@@ -477,8 +482,13 @@ export class GVGBattleHandler {
let { win, fail } = gameData.gvgBattleDurabilityMinus;
attackTeam = await GVGTeamModel.battleEndAttack(attackTeam.teamCode, isSuccess? -win: -fail, getBirthAreaOfCity(city, attackTeam.leagueCode), await getTechReviveMinus(configId, attackTeam.leagueCode));
defenseTeam = await GVGTeamModel.battleEndDefense(defenseTeam.teamCode, isSuccess? -fail: -win, getBirthAreaOfCity(city, defenseTeam.leagueCode), await getTechReviveMinus(configId, defenseTeam.leagueCode));
if(defenseTeam.curTeamBreak && defenseTeam.originPointId > 0 && !attackTeam.curTeamBreak) { // 打败的对手原来占领着一个位置,现在这个位置是你的了
attackTeam = await GVGTeamModel.settlePoint(attackTeam.teamCode, defenseTeam.originPointId);
if(defenseTeam.curTeamBreak && defenseTeam.originPointId > 0) { // 打败的对手原来占领着一个位置,现在这个位置是你的了
if(!attackTeam.curTeamBreak) {
attackTeam = await GVGTeamModel.settlePoint(attackTeam.teamCode, defenseTeam.originPointId);
await GVGCityAreaPointModel.settlePoint(cityId, attackTeam.areaId, defenseTeam.originPointId, attackTeam);
} else {
await GVGCityAreaPointModel.leavePoint(configId, groupId, serverType, defenseTeam.originPointId);
}
}
if(defenseTeam.curTeamBreak) {
let attackScore = calBattleScoreByCe(isSuccess, defenseTeam.lineupCe);
@@ -526,8 +536,14 @@ export class GVGBattleHandler {
if (!city) return resResult(STATUS.GVG_CITY_NOT_FOUND);
defenseTeam = await GVGTeamModel.battleEndDefense(teamCode, await getTechKnifeHurt(configId, attackTeam.leagueCode), getBirthAreaOfCity(city, defenseTeam.leagueCode), await getTechReviveMinus(configId, defenseTeam.leagueCode));
if(defenseTeam.curTeamBreak && defenseTeam.originPointId > 0 && !attackTeam.curTeamBreak) { // 打败的对手原来占领着一个位置,现在这个位置是你的了
attackTeam = await GVGTeamModel.settlePoint(attackTeam.teamCode, defenseTeam.originPointId);
if(defenseTeam.curTeamBreak && defenseTeam.originPointId > 0) { // 打败的对手原来占领着一个位置,现在这个位置是你的了
if(!attackTeam.curTeamBreak) {
attackTeam = await GVGTeamModel.settlePoint(attackTeam.teamCode, defenseTeam.originPointId);
await GVGCityAreaPointModel.settlePoint(cityId, attackTeam.areaId, defenseTeam.originPointId, attackTeam);
} else {
await GVGCityAreaPointModel.leavePoint(configId, groupId, serverType, defenseTeam.originPointId);
}
}
if(defenseTeam.curTeamBreak) {
let attackScore = calBattleScoreByCe(true, defenseTeam.lineupCe);
@@ -597,9 +613,34 @@ export class GVGBattleHandler {
// 获取概况
async getOverview(msg: {}, session: BackendSession) {
const cities = await GVGCityModel.find({}).lean();
// ! 重新组织每个城市的数据,添加据点和积分点的信息
return resResult(STATUS.SUCCESS, { cities });
const serverId = session.get('serverId');
let { configId } = getGVGPeriodData();
let groupId = await getGroupIdOfServer(serverId);
let serverType = await getGVGServerType(serverId);
const cities = await GVGCityModel.findByConfig(configId, groupId, serverType);
const points = await GVGCityAreaPointModel.findByConfig(configId, groupId, serverType);
let result: { cityId: number, guardLeagueName: string, areas: { areaId: number, points: { pointId: number, guardLeagueName: string }[] }[] }[] = [];
for(let [ cityId, { areaIds }] of gameData.gvgCity) {
let areas: { areaId: number, points: {pointId: number, guardLeagueName: string }[]}[] = [];
for(let areaId of areaIds) {
let dicArea = gameData.gvgArea.get(areaId);
if(!dicArea || (dicArea.areaType != GVG_AREA_TYPE.BIG && dicArea.areaType != GVG_AREA_TYPE.MIDDLE && dicArea.areaType == GVG_AREA_TYPE.SMALL) ) continue;
let pointIds = gameData.gvgPointByAreaId.get(areaId)||[];
let pointArrs: { pointId: number, guardLeagueName: string }[] = [];
for(let pointId of pointIds) {
let playerPoint = points.find(cur => cur.pointId == pointId);
pointArrs.push({ pointId, guardLeagueName: playerPoint? playerPoint.leagueName: '' });
}
if(pointArrs.length > 0) areas.push({ areaId, points: pointArrs });
}
let city = cities.find(cur => cur.cityId == cityId);
result.push({ cityId, guardLeagueName: city?.guardLeagueName||'', areas });
}
return resResult(STATUS.SUCCESS, { cities: result });
}
async debugStartSchedule() {