🐞 fix(gvg): 修复城池驻守和机器人刷新逻辑

This commit is contained in:
luying
2023-02-24 15:09:12 +08:00
parent 4b8aa6f803
commit 0271ac726a
8 changed files with 126 additions and 52 deletions

View File

@@ -3,7 +3,7 @@ import { GVGLeagueModel, GVGLeagueType } from "../../db/GVGLeague";
import { GVGTeamModel, GVGTeamType, GVGTeamUpdate } from "../../db/GVGTeam";
import { GVGCityModel, GVGCityType } from "../../db/GVGCity";
import { gameData, getGVGBattleRankReward } from "../../pubUtils/data";
import { GVG_AREA_TYPE, GVG_BATTLE_RANK_TYPE, GVG_TECH_TYPE, MAIL_TYPE, PUSH_ROUTE, REDIS_KEY, STATUS } from "../../consts";
import { GVG_AREA_TYPE, GVG_BATTLE_RANK_TYPE, GVG_PERIOD, GVG_TECH_TYPE, MAIL_TYPE, PUSH_ROUTE, REDIS_KEY, STATUS } from "../../consts";
import { getTimeFun, nowSeconds } from "../../pubUtils/timeUtil";
import { DicGVGAreaPoint } from "../../pubUtils/dictionary/DicGVGAreaPoint";
import { getGVGBattleData, getGVGBattleMap } from "./gvgBattleMemory";
@@ -23,6 +23,7 @@ import { GVGCityAreaPointModel } from "../../db/GVGCityAreaPoint";
import { addCityGuardMessage } from "./gvgRecService";
import { GVGUserDataModel } from "../../db/GVGUserData";
import { RoleModel } from "../../db/Role";
import { getFightTimeByPeriod } from "./gvgFightService";
/**
* 获取本联军上周占领的城池
@@ -67,12 +68,33 @@ export function getGVGTeamMemInfo(team: GVGTeamType): GVGTeamMem {
return teamMem;
}
/**
* 获取 重新进入城池/复活 所在的区域
* @param city GVGCity
* @param leagueCode 联军id
* @returns
*/
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;
}
/**
* 玩家是否可以进入城池
* @param city
* @param leagueCode
* @returns
*/
export function checkEnterCityTime(city: GVGCityType, leagueCode: string) {
let isGuard = city?.guardLeague == leagueCode;
let { startFightTime, endFightTime } = getFightTimeByPeriod(GVG_PERIOD.BATTLE);
if(isGuard && startFightTime - GVG.GVG_GUARD_START_TIME > nowSeconds()) return false;
if(!isGuard && startFightTime > nowSeconds()) return false;
if(endFightTime < nowSeconds()) return false;
return true
}
// guild.gvgBattleHandler.startMove 检测
export function checkMoveStatus(team: GVGTeamType, cityId: number, areaId: number) {
if(!team) return STATUS.GVG_BATTLE_TEAM_NOT_FOUND;
@@ -86,7 +108,9 @@ export function checkMoveStatus(team: GVGTeamType, cityId: number, areaId: numbe
return STATUS.SUCCESS;
}
export async function initRobots(configId: number, groupKey: string, cityId: number) {
export async function initRobots(configId: number, groupKey: string, city: GVGCityType | { cityId: number, guardLeague: string }) {
let { cityId, guardLeague = '' } = city;
if(guardLeague) return [];
let robotTeams = await GVGTeamModel.findRobotTeams(groupKey, cityId);
let updateDicPoints: DicGVGAreaPoint[] = [];
let { areaIds = []} = gameData.gvgCity.get(cityId);
@@ -138,6 +162,16 @@ export async function refreshTeams(configId: number, groupKey: string, roleId: s
return teams
}
/**
* 离开城池
* 当玩家占领据点的时候,可以保留据点;不占领的时候,不保留;退出游戏的时候,全不保留
* @param isForce 是否是玩家关闭游戏的那种离开
* @param roleId
* @param serverId
* @param guildCode
* @param myLeague
* @returns
*/
export async function leaveCity(isForce: boolean, roleId: string, serverId: number, guildCode: string, myLeague?: GVGLeagueType) {
if(!myLeague) myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return;
@@ -388,6 +422,7 @@ export async function gvgBattleSeconds() {
}
export async function gvgBattleEnd() {
console.log('######### gvgBattleEnd #######')
let { configId } = getGVGConfig();
let guardLeagueCnt = new Map<string, number>();
@@ -397,6 +432,11 @@ export async function gvgBattleEnd() {
let [,, groupKey, _cityId] = key.split(':');
return { groupKey, cityId: parseInt(_cityId) };
}).sort((a, b) => b.cityId - a.cityId);
let lastCities = await GVGCityModel.findByConfig(configId);
for(let { cityId, groupKey } of lastCities) {
let hasKey = rankKeys.find(cur => cur.cityId == cityId && cur.groupKey == groupKey);
if(!hasKey) rankKeys.push({ cityId, groupKey });
}
for(let { groupKey, cityId } of rankKeys) {
let dicCity = gameData.gvgCity.get(cityId);
@@ -409,15 +449,25 @@ export async function gvgBattleEnd() {
let rankInfo = <LeagueRankInfo>obj;
let cnt = guardLeagueCnt.get(rankInfo.code)||0;
if(cnt < GVG.GVG_CITY_OCCUPIED_NUMBER) {
await GVGCityModel.guardCity(configId, groupKey, cityId, rankInfo);
let dicCityAdd = gameData.gvgCityAdd.get(dicCity.cityType);
let league = await GVGLeagueModel.findByCodeWithoutPopulate(rankInfo.code);
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, rankInfo.code, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward }, league);
await addCityGuardMessage(league, cityId);
await addGuardCity(configId, groupKey, cityId, rankInfo.code);
guardLeagueCnt.set(rankInfo.code, cnt + 1);
break;
}
}
let guardCity = lastCities.find(city => city.cityId == cityId && city.groupKey == groupKey);
if(guardCity) {
let cnt = guardLeagueCnt.get(guardCity.guardLeague)||0;
if(cnt < GVG.GVG_CITY_OCCUPIED_NUMBER) {
await addGuardCity(configId, groupKey, cityId, guardCity.guardLeague);
guardLeagueCnt.set(guardCity.guardLeague, cnt + 1);
}
}
}
for(let { cityId, groupKey, guardLeague } of lastCities) {
let hasKey = rankKeys.find(cur => cur.cityId == cityId && cur.groupKey == groupKey);
if(hasKey) continue;
await addGuardCity(configId, groupKey, cityId, guardLeague);
}
// 联军排行榜发放奖励
@@ -450,6 +500,16 @@ export async function gvgBattleEnd() {
}
async function addGuardCity(configId: number, groupKey: string, cityId: number, leagueCode: string) {
let dicCity = gameData.gvgCity.get(cityId);
let dicCityAdd = gameData.gvgCityAdd.get(dicCity.cityType);
let league = await GVGLeagueModel.findByCodeWithoutPopulate(leagueCode);
await GVGCityModel.guardCity(configId, groupKey, cityId, league);
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, leagueCode, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward }, league);
await addCityGuardMessage(league, cityId);
await GVGLeagueModel.removeAuto(leagueCode);
}
// —————————— 定时器相关 end —————————— //
// —————————— 推送相关 —————————— //