🐞 fix(gvg): 投石车定时任务
This commit is contained in:
@@ -3,14 +3,18 @@ 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 { GVG_AREA_TYPE, GVG_TECH_TYPE, STATUS } from "../../consts";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
|
||||
import { getGVGBattleData } from "./gvgBattleMemory";
|
||||
import { getGVGBattleData, getGVGBattleMap } from "./gvgBattleMemory";
|
||||
import { GVGCityMapInfo } from "../../domain/gvgField/returnData";
|
||||
import { pick } from "underscore";
|
||||
import { GVG } from "../../pubUtils/dicParam";
|
||||
import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
import { GVGLeaguePrepareModel } from "../../db/GVGLeaguePrepare";
|
||||
import { pinus } from "pinus";
|
||||
import { dispatch } from "../../pubUtils/dispatcher";
|
||||
|
||||
|
||||
/**
|
||||
@@ -63,6 +67,7 @@ export function getBirthAreaOfCity(city: GVGCityType, leagueCode: string) {
|
||||
return isGuard? dicGVGCity.defenseBirth: dicGVGCity.attackBirth;
|
||||
}
|
||||
|
||||
// guild.gvgBattleHandler.startMove 检测
|
||||
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;
|
||||
@@ -122,6 +127,7 @@ export function getGVGWarId(defenseTeam: GVGTeamType) {
|
||||
return GVG.GVG_ROBOT_WARJSON; // 据点守卫使用
|
||||
}
|
||||
|
||||
// guild.gvgBattleHandler.battleStart 里的heroes返回
|
||||
export function getOppHeroes(warId: number, isRobot: boolean, lineup: GVGHeroInfo[]) {
|
||||
let heroes: PvpEnemies[] = [];
|
||||
const dicWar = gameData.war.get(warId);
|
||||
@@ -147,6 +153,7 @@ export function getOppHeroes(warId: number, isRobot: boolean, lineup: GVGHeroInf
|
||||
return heroes
|
||||
}
|
||||
|
||||
// guild.gvgBattleHandler.battleStart 检测
|
||||
export function checkGVGBattleStart(roleId: string, attackTeam: GVGTeamType, defenseTeam: GVGTeamType) {
|
||||
|
||||
if(!attackTeam || !defenseTeam) return STATUS.GVG_BATTLE_TEAM_INVALID;
|
||||
@@ -160,4 +167,58 @@ export function checkGVGBattleStart(roleId: string, attackTeam: GVGTeamType, def
|
||||
if(defenseTeam.durability <= 0) return STATUS.GVG_DEFENSE_TEAM_BROKEN;
|
||||
|
||||
return STATUS.SUCCESS;
|
||||
}
|
||||
|
||||
// gvg激战期开始定时器
|
||||
export async function gvgBattleStart() {
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
|
||||
let { configId } = getGVGConfig();
|
||||
let guardCities = await GVGCityModel.findAllGuardCities(configId);
|
||||
for(let { cityId, groupId, serverType, guardLeague, guardLeagueName } of guardCities) {
|
||||
let sid = dispatch(cityId.toString(), servers)?.id;
|
||||
await pinus.app.rpc.guild.guildRemote.initCatapult.toServer(sid, cityId, groupId, serverType, guardLeague, guardLeagueName);
|
||||
}
|
||||
}
|
||||
|
||||
// 每次活动开始初始化投石车
|
||||
export async function initCatapult(cityId: number, groupId: number, serverType: number, leagueCode: string, leagueName: string) {
|
||||
let { configId } = getGVGConfig();
|
||||
|
||||
let leaguePrepare = await GVGLeaguePrepareModel.findByLeague(configId, leagueCode);
|
||||
let activeTech = leaguePrepare?.activeTech||[];
|
||||
let hasCatapult = false, atk = 0, durability = 0;
|
||||
for(let techId of activeTech) {
|
||||
let dicTech = gameData.gvgTech.get(techId);
|
||||
if(dicTech && dicTech.type == GVG_TECH_TYPE.BATTLE_ITEM_CATAPULT) {
|
||||
hasCatapult = true, atk = dicTech.param[0]; durability = dicTech.param[1];
|
||||
}
|
||||
}
|
||||
if(hasCatapult) {
|
||||
let dicCity = gameData.gvgCity.get(cityId);
|
||||
let areaIds = (dicCity?.areaIds||[]).filter(areaId => {
|
||||
let dicArea = gameData.gvgArea.get(areaId);
|
||||
return dicArea && dicArea.areaType == GVG_AREA_TYPE.CATAPULT;
|
||||
});
|
||||
let teams = await GVGTeamModel.initCatapult(configId, groupId, serverType, cityId, leagueCode, leagueName, areaIds, atk, durability);
|
||||
// 处理内存
|
||||
let teamObj = getGVGBattleData(groupId, serverType);
|
||||
teamObj.enterCity(...teams);
|
||||
}
|
||||
}
|
||||
|
||||
// 投石车投伤害
|
||||
export async function catapultHurt() {
|
||||
for(let [_, teamObj] of getGVGBattleMap()) {
|
||||
let teams = teamObj.findCatapult();
|
||||
for(let catapult of teams) {
|
||||
if(catapult.isBroken) continue;
|
||||
let dicArea = gameData.gvgArea.get(catapult.areaId);
|
||||
let relateArea = dicArea?.relateArea||[];
|
||||
let teamCodes = teamObj.findCatapultAttackTeam(relateArea, catapult.leagueCode);
|
||||
let dicGVGCity = gameData.gvgCity.get(catapult.cityId);
|
||||
let teams = await GVGTeamModel.attackByCatapult(teamCodes, catapult.captapultAtk, dicGVGCity.attackBirth)
|
||||
teamObj.battleEnd(teams);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user