✨ feat(gvg): 激战期获取挑战对手阵容
This commit is contained in:
@@ -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, calLeagueScore, checkAreaIsInCity, checkMoveStatus, getBirthAreaOfCity, initRobots, teamBreak } from '../../../services/gvg/gvgBattleService';
|
||||
import { calBattleScoreByCe, checkAreaIsInCity, 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';
|
||||
@@ -198,7 +198,7 @@ export class GVGBattleHandler {
|
||||
teams = await GVGTeamModel.findByRole(roleId, '-_id');
|
||||
// 更新内存队伍信息
|
||||
let teamObj = getGVGBattleData(groupId, serverType);
|
||||
teamObj.enterCity(teams);
|
||||
teamObj.enterCity(...teams);
|
||||
}
|
||||
|
||||
const recs = await GVGRecModel.findByCity(cityId, configId);
|
||||
@@ -289,10 +289,8 @@ export class GVGBattleHandler {
|
||||
let teams = await GVGTeamModel.findByAreaId(groupId, serverType, cityId, myTeam.areaId);
|
||||
let points: GVGTeamInListOnPoint[] = [], players: GVGTeamInList[] = [];
|
||||
let pointIds = gameData.gvgPointByAreaId.get(myTeam.areaId)||[];
|
||||
console.log('#### teams', teams, teams.length);
|
||||
for(let pointId of pointIds) {
|
||||
let team = teams.find(cur => cur.pointId == pointId);
|
||||
console.log('#### point', pointId, team);
|
||||
let obj = new GVGTeamInListOnPoint(pointId, !!team, team);
|
||||
points.push(obj);
|
||||
}
|
||||
@@ -387,16 +385,18 @@ export class GVGBattleHandler {
|
||||
if(attackTeam.durability <= 0) return resResult(STATUS.GVG_ATTACK_TEAM_BROKEN);
|
||||
if(defenseTeam.durability <= 0) return resResult(STATUS.GVG_DEFENSE_TEAM_BROKEN);
|
||||
|
||||
const battleRecord = await GVGBattleRecModel.createRec(attackTeam, defenseTeam);
|
||||
const warId = getGVGWarId(defenseTeam);
|
||||
const battleRecord = await GVGBattleRecModel.createRec(warId, attackTeam, defenseTeam);
|
||||
|
||||
attackTeam = await GVGTeamModel.battleStartLockAttack(teamCode);
|
||||
defenseTeam = await GVGTeamModel.battleStartLockDefense(oppoTeamCode, teamCode);
|
||||
// 内存处理
|
||||
let teamObj = getGVGBattleData(groupId, serverType);
|
||||
teamObj.setTime(teamCode, attackTeam);
|
||||
teamObj.setTime(teamCode, defenseTeam);
|
||||
teamObj.setTime(attackTeam.teamCode, attackTeam);
|
||||
teamObj.setTime(defenseTeam.teamCode, defenseTeam);
|
||||
let heroes = getOppHeroes(warId, defenseTeam.isRobot, defenseTeam.lineup)
|
||||
|
||||
return resResult(STATUS.SUCCESS, { battleCode: battleRecord.battleCode, curTeam: attackTeam });
|
||||
return resResult(STATUS.SUCCESS, { battleCode: battleRecord.battleCode, warId, isRobot: defenseTeam.isRobot, heroes, curTeam: attackTeam });
|
||||
}
|
||||
|
||||
// 队伍停止攻击
|
||||
@@ -417,17 +417,17 @@ export class GVGBattleHandler {
|
||||
|
||||
// 计算并更新两支队伍耐久
|
||||
let { win, fail } = gameData.gvgBattleDurabilityMinus;
|
||||
attackTeam = await GVGTeamModel.battleEndAttack(attackTeam.teamCode, isSuccess? -win: -fail, calBattleScoreByCe(isSuccess, attackTeam.lineupCe), calLeagueScore(defenseTeam));
|
||||
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);
|
||||
|
||||
// ! 推送战斗结果给对手队伍
|
||||
// const channel = this.channelService.getChannel(teamCode, false);
|
||||
// if (!!channel) {
|
||||
// channel.pushMessage('onBattleResult', { isSuccess });
|
||||
// }
|
||||
// 更新内存
|
||||
let teamObj = getGVGBattleData(groupId, serverType);
|
||||
teamObj.battleEnd([attackTeam, defenseTeam]);
|
||||
// 更新rec
|
||||
await GVGBattleRecModel.battleEnd(battleCode, isSuccess);
|
||||
// TODO 完善推送
|
||||
if(!defenseTeam.isRobot) {
|
||||
sendMessageToUserWithSuc(defenseTeam.roleId, PUSH_ROUTE.GVG_TEAM_ATTACKED, { cityId, areaId: defenseTeam.areaId, teams: [defenseTeam] });
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@ class GVGBattleData {
|
||||
public serverType: number; // 单服还是跨服
|
||||
|
||||
private teams: Map<string, GVGTeamMem> = new Map(); // 队伍, teamCode => team
|
||||
private rolePoints: Map<string, number[]> = new Map(); // roleId => pointId[],用于更新玩家的积分
|
||||
private rolePoints: Map<string, Set<number>> = new Map(); // roleId => pointId[],用于更新玩家的积分
|
||||
private roleToTeam: Map<string, string[]> = new Map(); // roleId => teamCode
|
||||
private areaToTeams: Map<number, Set<string>> = new Map(); // areaId => teamCode set,用于定时下发地图玩家数据
|
||||
private hasRobot: Map<number, boolean> = new Map(); // cityId => boolean
|
||||
|
||||
constructor(groupId: number, serverType: number) {
|
||||
this.groupId = groupId;
|
||||
@@ -44,7 +43,7 @@ class GVGBattleData {
|
||||
this.rolePoints.delete(roleId);
|
||||
}
|
||||
|
||||
public enterCity(teams: GVGTeamType[]) {
|
||||
public enterCity(...teams: GVGTeamType[]) {
|
||||
for(let team of teams) {
|
||||
let fromAreaId = this.teams.get(team.teamCode)?.areaId||0;
|
||||
|
||||
@@ -53,15 +52,13 @@ class GVGBattleData {
|
||||
}
|
||||
this.teams.get(team.teamCode).setCity(team.cityId, team.areaId, team.pointId);
|
||||
if(team.pointId > 0) {
|
||||
if(!this.rolePoints.has(team.roleId)) this.rolePoints.set(team.roleId, []);
|
||||
this.rolePoints.get(team.roleId).push(team.pointId);
|
||||
if(!this.rolePoints.has(team.roleId)) this.rolePoints.set(team.roleId, new Set());
|
||||
this.rolePoints.get(team.roleId).add(team.pointId);
|
||||
}
|
||||
let teamCodesOfRole = this.roleToTeam.get(team.roleId)||[];
|
||||
if(teamCodesOfRole.indexOf(team.teamCode) == -1) teamCodesOfRole.push(team.teamCode);
|
||||
this.roleToTeam.set(team.roleId, teamCodesOfRole);
|
||||
this.setAreaMap(team.teamCode, fromAreaId, team.areaId);
|
||||
|
||||
if(team.isRobot) this.hasRobot.set(team.cityId, team.isRobot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +96,22 @@ class GVGBattleData {
|
||||
team.pointId = pointId;
|
||||
}
|
||||
|
||||
public checkHasRobot(cityId: number) {
|
||||
return this.hasRobot.get(cityId)||false;
|
||||
// 关卡结算
|
||||
public battleEnd(teams: GVGTeamType[]) {
|
||||
for(let team of teams) {
|
||||
let teamMem = this.teams.get(team.teamCode);
|
||||
if(!teamMem) { // 基本不会有没有这个内存的情况,有的话就让他重新计算一次吧
|
||||
this.enterCity(team); continue;
|
||||
}
|
||||
let { areaId: fromAreaId, pointId: fromPointId } = teamMem;
|
||||
teamMem.battleEnd(team);
|
||||
if(fromPointId > 0 && team.pointId == 0) { // 被打得撤离积分点
|
||||
if(this.rolePoints.has(team.roleId) && this.rolePoints.get(team.roleId).has(team.pointId)) {
|
||||
this.rolePoints.get(team.roleId).delete(team.pointId);
|
||||
}
|
||||
}
|
||||
this.setAreaMap(team.teamCode, fromAreaId, team.areaId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +132,7 @@ export async function initTeamToMem() {
|
||||
for(let team of teams) {
|
||||
if(dispatch(team.cityId.toString(), servers)?.id == sid) {
|
||||
let teamObj = getGVGBattleData(team.groupId, team.serverType);
|
||||
teamObj.enterCity([team]);
|
||||
teamObj.enterCity(team);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { getGVGBattleData } from "./gvgBattleMemory";
|
||||
import { GVGCityMapInfo } from "../../domain/gvgField/returnData";
|
||||
import { pick } from "underscore";
|
||||
import { GVG } from "../../pubUtils/dicParam";
|
||||
import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
|
||||
|
||||
|
||||
/**
|
||||
@@ -88,7 +89,7 @@ export async function initRobots(confidId: number, groupId: number, serverType:
|
||||
robotTeams = await GVGTeamModel.initRobots(confidId, groupId, serverType, cityId, updateDicPoints);
|
||||
// 存入内存
|
||||
let teamObj = getGVGBattleData(groupId, serverType);
|
||||
teamObj.enterCity(robotTeams);
|
||||
teamObj.enterCity(...robotTeams);
|
||||
}
|
||||
return robotTeams;
|
||||
}
|
||||
@@ -108,14 +109,40 @@ export function calBattleScoreByCe(isSuccess: boolean, lineupCe: number) {
|
||||
return isSuccess? winScore: 0;
|
||||
}
|
||||
|
||||
// 计算打投石车/守卫的得分
|
||||
export function calLeagueScore(team: GVGTeamType) {
|
||||
return 0
|
||||
}
|
||||
|
||||
export async function teamBreak(city: GVGCityType, team: GVGTeamType) {
|
||||
if(team.durability > 0) return team
|
||||
let areaId = getBirthAreaOfCity(city, team.leagueCode);
|
||||
team = await GVGTeamModel.teamBreak(team.teamCode, team.isRobot, team.maxDurability, areaId);
|
||||
return team;
|
||||
}
|
||||
|
||||
export function getGVGWarId(defenseTeam: GVGTeamType) {
|
||||
if(!defenseTeam.isRobot) return GVG.GVG_CITY_BGMAP_GKID; // 玩家防守地图
|
||||
if(!defenseTeam.isCatapult) return GVG.GVG_CATAPULT_WARJSON; // 投石车使用
|
||||
return GVG.GVG_ROBOT_WARJSON; // 据点守卫使用
|
||||
}
|
||||
|
||||
export function getOppHeroes(warId: number, isRobot: boolean, lineup: GVGHeroInfo[]) {
|
||||
let heroes: PvpEnemies[] = [];
|
||||
const dicWar = gameData.war.get(warId);
|
||||
if(!dicWar) { console.error(`warId ${warId} not found`); return [] }
|
||||
const dicWarJson = gameData.warJson.get(dicWar.dispatchJsonId)||[];
|
||||
for(let warJson of dicWarJson) {
|
||||
if(!isRobot) {
|
||||
let heroInfo = lineup.find(cur => cur.dataId == warJson.dataId);
|
||||
if(!heroInfo) continue;
|
||||
let hero = new PvpEnemies(warJson, heroInfo);
|
||||
heroes.push(hero);
|
||||
} else {
|
||||
if(warJson.relation == 2) {
|
||||
let dicHero = gameData.hero.get(warJson.actorId);
|
||||
if(!dicHero) continue;
|
||||
let heroInfo = new PvpHeroInfo();
|
||||
heroInfo.setRobotInfo(dicHero, warJson.lv);
|
||||
let hero = new PvpEnemies(warJson, heroInfo);
|
||||
heroes.push(hero);
|
||||
}
|
||||
}
|
||||
}
|
||||
return heroes
|
||||
}
|
||||
Reference in New Issue
Block a user