148 lines
5.8 KiB
TypeScript
148 lines
5.8 KiB
TypeScript
import { GVGTeamMem } from "../../domain/battleField/gvgBattle";
|
|
import { GVGLeagueType } from "../../db/GVGLeague";
|
|
import { GVGTeamModel, GVGTeamType, GVGTeamUpdate } from "../../db/GVGTeam";
|
|
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";
|
|
import { pick } from "underscore";
|
|
import { GVG } from "../../pubUtils/dicParam";
|
|
import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
|
|
|
|
|
|
/**
|
|
* TODO 检查上周是否有占领城池
|
|
* @param league
|
|
* @returns boolean 是否占领
|
|
*/
|
|
export async function checkHasCities(league: GVGLeagueType) {
|
|
return false
|
|
}
|
|
|
|
/**
|
|
* TODO 获取本联军上周占领的城池
|
|
* @param league
|
|
* @returns number[] 城池id
|
|
*/
|
|
export async function getGVGCities(league: GVGLeagueType) {
|
|
return []
|
|
}
|
|
|
|
/**
|
|
* 获取当前城池状态
|
|
* @returns [{cityId: number, guardLeagueCode: string, guardLeagueName: string, teamCnt: number }]
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* 获取内存中队伍的数据结构
|
|
*/
|
|
export function getGVGTeamMemInfo(team: GVGTeamType): GVGTeamMem {
|
|
const teamMem = new GVGTeamMem(team);
|
|
teamMem.isMoving = false;
|
|
teamMem.startMoveTime = 0;
|
|
teamMem.stopMoveTime = 0;
|
|
return teamMem;
|
|
}
|
|
|
|
export function getBirthAreaOfCity(city: GVGCityType, leagueCode: string) {
|
|
let isGuard = city.guardLeague == leagueCode;
|
|
let dicGVGCity = gameData.gvgCity.get(city.cityId);
|
|
return isGuard? dicGVGCity.defenseBirth: dicGVGCity.attackBirth;
|
|
}
|
|
|
|
export function checkMoveStatus(team: GVGTeamType, cityId: number, areaId: number) {
|
|
if(!team) return STATUS.GVG_BATTLE_TEAM_NOT_FOUND;
|
|
if(team.cityId != cityId) return STATUS.GVG_BATTLE_IS_NOT_IN_CITY;
|
|
if(team.pointId > 0) return STATUS.GVG_BATTLE_TEAM_IS_SELLTED;
|
|
if(team.stopMoveTime > 0 && team.stopMoveTime < nowSeconds()) return STATUS.GVG_BATTLE_IS_MOVING;
|
|
let dicArea = gameData.gvgArea.get(areaId);
|
|
if(!dicArea) return STATUS.DIC_DATA_NOT_FOUND;
|
|
if(dicArea.relateArea.indexOf(team.areaId) == -1) return STATUS.GVG_BATTLE_AREA_NOT_RELATE;
|
|
return STATUS.SUCCESS;
|
|
}
|
|
|
|
export async function initRobots(confidId: number, groupId: number, serverType: number, cityId: number) {
|
|
let robotTeams = await GVGTeamModel.findRobotTeams(groupId, serverType, cityId);
|
|
let updateDicPoints: DicGVGAreaPoint[] = [];
|
|
let { areaIds = []} = gameData.gvgCity.get(cityId);
|
|
for(let [_, point] of gameData.gvgAreaPoint) {
|
|
if(areaIds.indexOf(point.areaId) == -1) continue;
|
|
let robotTeam = robotTeams.find(team => team.pointId == point.pointId);
|
|
if(!robotTeam || (!robotTeam.isBroken && robotTeam.configId != confidId) ) {
|
|
updateDicPoints.push(point);
|
|
}
|
|
}
|
|
if(updateDicPoints.length > 0) {
|
|
robotTeams = await GVGTeamModel.initRobots(confidId, groupId, serverType, cityId, updateDicPoints);
|
|
// 存入内存
|
|
let teamObj = getGVGBattleData(groupId, serverType);
|
|
teamObj.enterCity(...robotTeams);
|
|
}
|
|
return robotTeams;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
export function calBattleScoreByCe(isSuccess: boolean, lineupCe: number) {
|
|
let winScore = Math.floor(lineupCe/GVG.GVG_BATTLE_SCORE);
|
|
if(winScore <= 0) winScore = 1;
|
|
return isSuccess? winScore: 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
|
|
} |