✨ feat(gvg): 激战期接口详细返回
This commit is contained in:
@@ -14,29 +14,41 @@ class GVGBattleData {
|
||||
private rolePoints: Map<string, 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;
|
||||
this.serverType = serverType;
|
||||
}
|
||||
|
||||
public findTeamsByArea(areaId: number) {
|
||||
let teamCodes = this.areaToTeams.get(areaId)||new Set();
|
||||
let teams: GVGTeamMem[] = [];
|
||||
for(let teamCode of teamCodes) {
|
||||
let team = this.teams.get(teamCode);
|
||||
if(team) teams.push(team);
|
||||
}
|
||||
return teams.slice(0, 20);
|
||||
}
|
||||
|
||||
public leaveCity(roleId: string) {
|
||||
let teamCodes = this.roleToTeam.get(roleId)||[];
|
||||
for(let teamCode of teamCodes) {
|
||||
let team = this.teams.get(teamCode);
|
||||
if(team) team.setCity(0, 0);
|
||||
if(team) team.setCity(0);
|
||||
}
|
||||
this.rolePoints.delete(roleId);
|
||||
}
|
||||
|
||||
public enterCity(teams: GVGTeamType[]) {
|
||||
for(let team of teams) {
|
||||
let fromAreaId = this.teams.get(team.teamCode)?.areaId||0;
|
||||
|
||||
console.log('#### team', team.teamCode)
|
||||
if(!this.teams.has(team.teamCode)) {
|
||||
this.teams.set(team.teamCode, new GVGTeamMem(team))
|
||||
}
|
||||
let originTeam = this.teams.get(team.teamCode);
|
||||
let fromAreaId = originTeam.areaId;
|
||||
originTeam.setCity(team.cityId, team.areaId);
|
||||
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);
|
||||
@@ -45,6 +57,8 @@ class GVGBattleData {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,11 +75,10 @@ class GVGBattleData {
|
||||
}
|
||||
}
|
||||
|
||||
public move(teamCode: string, areaId: number, startMoveTime: number, stopMoveTime: number) {
|
||||
public move(teamCode: string, areaId: number, fromAreaId: number, startMoveTime: number, stopMoveTime: number) {
|
||||
let team = this.teams.get(teamCode);
|
||||
if(!team) return;
|
||||
let fromAreaId = team.areaId;
|
||||
team.moveToArea(areaId, startMoveTime, stopMoveTime);
|
||||
team.moveToArea(areaId, fromAreaId, startMoveTime, stopMoveTime);
|
||||
this.setAreaMap(teamCode, fromAreaId, areaId);
|
||||
}
|
||||
|
||||
@@ -82,6 +95,10 @@ class GVGBattleData {
|
||||
if(!team) return;
|
||||
team.pointId = pointId;
|
||||
}
|
||||
|
||||
public checkHasRobot(cityId: number) {
|
||||
return this.hasRobot.get(cityId)||false;
|
||||
}
|
||||
}
|
||||
|
||||
export function getGVGBattleData(groupId: number, serverType: number) {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { GVGTeamMem } from "../../domain/battleField/gvgBattle";
|
||||
import { GVGLeagueType } from "../../db/GVGLeague";
|
||||
import { GVGTeamModel, GVGTeamType } from "../../db/GVGTeam";
|
||||
import { GVGCityType } from "../../db/GVGCity";
|
||||
import { GVGCityModel, GVGCityType } from "../../db/GVGCity";
|
||||
import { gameData } from "../../pubUtils/data";
|
||||
import { STATUS } from "../../consts";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
|
||||
import { getGVGBattleData } from "./gvgBattleMemory";
|
||||
import { GVGCityMapInfo } from "../../domain/gvgField/returnData";
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,11 +29,18 @@ export async function getGVGCities(league: GVGLeagueType) {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取当前城池状态
|
||||
* 获取当前城池状态
|
||||
* @returns [{cityId: number, guardLeagueCode: string, guardLeagueName: string, teamCnt: number }]
|
||||
*/
|
||||
export async function getGVGCitiesInfo(league: GVGLeagueType): Promise<{cityId: number, guardLeagueName: string, teamCnt: number }[]> {
|
||||
return [];
|
||||
export async function getGVGCitiesInfo(configId: number, groupId: number, serverType: number, league: GVGLeagueType): Promise<{cityId: number, guardLeagueName: string, teamCnt: number }[]> {
|
||||
let cities = await GVGCityModel.findGuardCityByLeague(configId, groupId, serverType);
|
||||
let result: GVGCityMapInfo[] = [];
|
||||
for(let city of cities) {
|
||||
let players = (city.players||[]).filter(cur => cur.leagueCode == league.leagueCode);
|
||||
let obj = new GVGCityMapInfo(city, players.length);
|
||||
result.push(obj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,13 +72,23 @@ export function checkMoveStatus(team: GVGTeamType, cityId: number, areaId: numbe
|
||||
}
|
||||
|
||||
export async function initRobots(groupId: number, serverType: number, cityId: number) {
|
||||
let hasRobot = await GVGTeamModel.checkRobot(groupId, serverType, cityId);
|
||||
if(!hasRobot) {
|
||||
let teamObj = getGVGBattleData(groupId, serverType);
|
||||
if(!teamObj.checkHasRobot(cityId)) {
|
||||
let dicPoints: DicGVGAreaPoint[] = [];
|
||||
let { areaIds = []} = gameData.gvgCity.get(cityId);
|
||||
for(let [_, point] of gameData.gvgAreaPoint) {
|
||||
if(areaIds.indexOf(point.areaId) != -1) dicPoints.push(point);
|
||||
}
|
||||
await GVGTeamModel.initRobots(groupId, serverType, cityId, dicPoints);
|
||||
let teams = await GVGTeamModel.initRobots(groupId, serverType, cityId, dicPoints);
|
||||
teamObj.enterCity(teams);
|
||||
}
|
||||
}
|
||||
|
||||
export function checkAreaIsInCity(cityId: number, areaIds: number[]) {
|
||||
let dicCity = gameData.gvgCity.get(cityId);
|
||||
if(!dicCity) return false;
|
||||
for(let areaId of areaIds) {
|
||||
if(dicCity.areaIds.indexOf(areaId) == -1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user