feat(gvg): 进驻积分点

This commit is contained in:
luying
2023-02-15 15:12:16 +08:00
parent 6815bf316a
commit 4359bfd9cc
10 changed files with 129 additions and 39 deletions

View File

@@ -8,7 +8,7 @@ import { Application, BackendSession, ChannelService, HandlerService } from "pin
import { resResult, genCode } from "../../../pubUtils/util";
import { GVGLeagueModel } from '../../../db/GVGLeague';
import { checkGVGPeriod, getGroupIdOfServer, getGVGConfig, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
import { calBattleScoreByCe, checkAreaIsInCity, checkMoveStatus, getBirthAreaOfCity, getGVGWarId, getOppHeroes, initRobots, teamBreak } from '../../../services/gvg/gvgBattleService';
import { calBattleScoreByCe, checkAreaIsInCity, checkGVGBattleStart, checkMoveStatus, getBirthAreaOfCity, getGVGWarId, getOppHeroes, initRobots, teamBreak } from '../../../services/gvg/gvgBattleService';
import { getGVGBattleData } from '../../../services/gvg/gvgBattleMemory';
import { nowSeconds } from '../../../pubUtils/timeUtil';
import { GVGBattleRecModel } from '../../../db/GVGBattleRec';
@@ -347,24 +347,55 @@ export class GVGBattleHandler {
let teamObj = getGVGBattleData(groupId, serverType);
teamObj.move(teamCode, areaId, 0, team.startMoveTime, team.stopMoveTime);
return resResult(STATUS.SUCCESS, { areaId, cityId, curTeam: team });
return resResult(STATUS.SUCCESS, { areaId, cityId, curTeam: new MyTeamInfo(team) });
}
// 队伍入驻积分点
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 curTeam = await GVGTeamModel.findOneAndUpdate({ teamCode }, { pointId }).lean();
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);
let myTeam = await GVGTeamModel.findByTeamCode(roleId, teamCode);
if(!myTeam) return resResult(STATUS.GVG_TEAM_NOT_FOUND);
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);
const curTeam = await GVGTeamModel.settlePoint(teamCode, pointId);
let teamObj = getGVGBattleData(groupId, serverType);
teamObj.teamSettle(teamCode, pointId);
return resResult(STATUS.SUCCESS, { curTeam });
teamObj.teamSettle(roleId, teamCode, pointId);
return resResult(STATUS.SUCCESS, { curTeam: new MyTeamInfo(curTeam) });
}
// 队伍离开积分点
async teamLeave(msg: any, session: BackendSession) {
return resResult(STATUS.SUCCESS);
async teamLeave(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;
let groupId = await getGroupIdOfServer(serverId);
let serverType = await getGVGServerType(serverId);
let myTeam = await GVGTeamModel.findByTeamCode(roleId, teamCode);
if(!myTeam) return resResult(STATUS.GVG_TEAM_NOT_FOUND);
let dicAreaPoint = gameData.gvgAreaPoint.get(pointId);
if(dicAreaPoint.areaId != myTeam.areaId) return resResult(STATUS.GVG_POINT_NOT_AREA);
const curTeam = await GVGTeamModel.settlePoint(teamCode, 0);
let teamObj = getGVGBattleData(groupId, serverType);
teamObj.teamSettle(roleId, teamCode, pointId);
return resResult(STATUS.SUCCESS, { curTeam: new MyTeamInfo(curTeam) });
}
// 队伍开始攻击
@@ -375,18 +406,18 @@ export class GVGBattleHandler {
const serverId = session.get('serverId');
const { teamCode, oppoTeamCode } = 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);
let { attackTeam, defenseTeam } = await GVGTeamModel.findBattleTeams(teamCode, oppoTeamCode);
if(!attackTeam || !defenseTeam) return resResult(STATUS.GVG_BATTLE_TEAM_INVALID);
if(attackTeam.attackTime > nowSeconds()) return resResult(STATUS.GVG_TEAM_ATTACKING);
if(defenseTeam.defenseTime > nowSeconds() || defenseTeam.lockTime > nowSeconds()) return resResult(STATUS.GVG_TEAM_DEFENSEING);
if(attackTeam.durability <= 0) return resResult(STATUS.GVG_ATTACK_TEAM_BROKEN);
if(defenseTeam.durability <= 0) return resResult(STATUS.GVG_DEFENSE_TEAM_BROKEN);
let checkStatus = checkGVGBattleStart(roleId, attackTeam, defenseTeam);
if(checkStatus.code != 0) return resResult(checkStatus);
const warId = getGVGWarId(defenseTeam);
const battleRecord = await GVGBattleRecModel.createRec(warId, attackTeam, defenseTeam);
const battleRecord = await GVGBattleRecModel.createRec(configId, groupId, serverType, warId, attackTeam, defenseTeam);
attackTeam = await GVGTeamModel.battleStartLockAttack(teamCode);
defenseTeam = await GVGTeamModel.battleStartLockDefense(oppoTeamCode, teamCode);
@@ -396,7 +427,7 @@ export class GVGBattleHandler {
teamObj.setTime(defenseTeam.teamCode, defenseTeam);
let heroes = getOppHeroes(warId, defenseTeam.isRobot, defenseTeam.lineup)
return resResult(STATUS.SUCCESS, { battleCode: battleRecord.battleCode, warId, isRobot: defenseTeam.isRobot, heroes, curTeam: attackTeam });
return resResult(STATUS.SUCCESS, { battleCode: battleRecord.battleCode, warId, isRobot: defenseTeam.isRobot, heroes, curTeam: new MyTeamInfo(attackTeam) });
}
// 队伍停止攻击
@@ -407,8 +438,9 @@ export class GVGBattleHandler {
let { configId, period } = getGVGPeriodData();
const record = await GVGBattleRecModel.findByBattleCode(battleCode);
if(!record) return resResult(STATUS.GVG_BATTLEREC_NOT_FOUND);
if(record.battleEndTime > 0) return resResult(STATUS.GVG_BATTLEREC_HAS_SUMMIT);
let { attackTeam, defenseTeam } = await GVGTeamModel.findBattleTeams(record.attackTeam.teamCode, record.defenseTeam.teamCode);
if(defenseTeam.attackTeam != attackTeam.teamCode) return resResult(STATUS.GVG_LOCK_TIME_OUT)
if(defenseTeam.lockTeamCode != attackTeam.teamCode) return resResult(STATUS.GVG_LOCK_TIME_OUT)
let groupId = await getGroupIdOfServer(serverId);
let serverType = await getGVGServerType(serverId);
@@ -420,8 +452,16 @@ export class GVGBattleHandler {
attackTeam = await GVGTeamModel.battleEndAttack(attackTeam.teamCode, isSuccess? -win: -fail, calBattleScoreByCe(isSuccess, attackTeam.lineupCe));
defenseTeam = await GVGTeamModel.battleEndDefense(defenseTeam.teamCode, isSuccess? -fail: -win, calBattleScoreByCe(isSuccess, defenseTeam.lineupCe));
if(attackTeam.durability <= 0) attackTeam = await teamBreak(city, attackTeam);
if(defenseTeam.durability <= 0) defenseTeam = await teamBreak(city, defenseTeam);
if(attackTeam.durability <= 0) {
attackTeam = await teamBreak(city, attackTeam);
}
if(defenseTeam.durability <= 0) {
if(defenseTeam.pointId > 0 && attackTeam.durability > 0) { // 打败的对手原来占领着一个位置,现在这个位置是你的了
attackTeam = await GVGTeamModel.settlePoint(attackTeam.teamCode, defenseTeam.pointId);
}
defenseTeam = await teamBreak(city, defenseTeam);
}
// 更新内存
let teamObj = getGVGBattleData(groupId, serverType);
teamObj.battleEnd([attackTeam, defenseTeam]);